/* Sala de estudo à noite: fundo escuro e quente, texto creme, um único acento dourado.
   Na missão, a tela inteira são dois painéis (leitura e bancada) e uma barra fina no topo. */
:root {
  --bg: #14110e; --surface: #1a1612; --raised: #221d18; --line: rgba(255, 232, 196, 0.09); --line-strong: rgba(255, 232, 196, 0.2);
  --text: #e8dfd0; --muted: #9a8f7f; --faint: #6b6257;
  --gold: #e6b450; --gold-dim: #a8843d; --ok: #a9c77d; --bad: #e8866a;
  --display: 'Cinzel Decorative', 'Cinzel', serif;
  --label: 'Cinzel', Georgia, serif;
  --body: 'Crimson Pro', Georgia, 'Times New Roman', serif;
  --mono: 'JetBrains Mono', ui-monospace, Menlo, Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-family: var(--body); font-size: 1.16rem; line-height: 1.55; -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: default; opacity: 0.5; }
:focus-visible { outline: 1px solid var(--gold); outline-offset: 3px; border-radius: 2px; }
h1, h2, h3, h4, p, ul, ol { margin: 0; padding: 0; }
ul, ol { list-style: none; }
#app { min-height: 100%; }
.loading { text-align: center; padding: 5rem 1rem; font-style: italic; color: var(--muted); }
.label { font-family: var(--label); font-weight: 600; font-size: 0.72rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); }
.link { color: var(--muted); font-size: 0.98rem; border-bottom: 1px solid transparent; }
.link:hover, .link:focus-visible { color: var(--text); border-bottom-color: var(--line-strong); }
.link.gold { color: var(--gold); }
.link.gold:hover { border-bottom-color: var(--gold-dim); }

/* ---------- barra do topo ---------- */
.bar { height: 46px; display: flex; align-items: center; gap: 18px; padding: 0 20px; border-bottom: 1px solid var(--line); font-size: 0.98rem; color: var(--muted); }
.bar .home { font-family: var(--label); font-weight: 600; font-size: 0.78rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text); white-space: nowrap; }
.bar .home:hover { color: var(--gold); }
.bar .where { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.bar .grow { flex: 1; min-width: 0; }
.ticks { display: flex; gap: 5px; align-items: center; }
.ticks a { width: 22px; height: 14px; display: grid; place-items: center; }
.ticks a::before { content: ""; width: 100%; height: 3px; border-radius: 2px; background: var(--line-strong); }
.ticks a.done::before { background: var(--gold-dim); }
.ticks a.on::before { background: var(--text); height: 5px; }
.ticks a:hover::before { background: var(--gold); }
.stats { display: flex; gap: 16px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.stats b { color: var(--text); font-weight: 600; }
.stats .cold b { color: var(--muted); }
.bar .who { white-space: nowrap; font-size: 0.92rem; }

/* ---------- capa e estante ---------- */
.cover { max-width: 760px; margin: 0 auto; padding: 56px 24px 96px; }
.cover h1 { font-family: var(--display); font-size: clamp(1.8rem, 5vw, 2.6rem); line-height: 1.15; letter-spacing: 0.01em; margin: 6px 0 10px; text-wrap: balance; }
.cover .tagline { color: var(--muted); font-style: italic; max-width: 52ch; }
.progress { margin: 28px 0 10px; height: 2px; background: var(--line-strong); }
.progress span { display: block; height: 100%; background: var(--gold); }
.resume { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 24px; color: var(--muted); font-size: 1rem; margin-bottom: 44px; }
.part { margin: 34px 0 6px; }
.chapter { border-top: 1px solid var(--line); }
.chapter > summary { cursor: pointer; list-style: none; display: grid; grid-template-columns: 2.6rem 1fr auto; gap: 0 10px; align-items: baseline; padding: 13px 0; }
.chapter > summary::-webkit-details-marker { display: none; }
.chapter .roman { font-family: var(--label); font-size: 0.82rem; color: var(--faint); }
.chapter h2 { font-family: var(--body); font-weight: 500; font-size: 1.2rem; }
.chapter .count { font-size: 0.95rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.chapter .sum { grid-column: 2 / -1; color: var(--muted); font-size: 1rem; font-style: italic; }
.chapter.done .roman, .chapter.current .roman { color: var(--gold); }
.chapter.soon { opacity: 0.45; }
.chapter.soon > summary { cursor: default; }
.chapter > summary:hover h2 { color: var(--gold); }
.chapter.soon > summary:hover h2 { color: inherit; }
.chapter ol { padding: 0 0 14px calc(2.6rem + 10px); }
.chapter li a { display: grid; grid-template-columns: 1.4rem 1fr auto; gap: 6px; padding: 5px 0; color: var(--muted); }
.chapter li a:hover { color: var(--text); }
.chapter li.done a { color: var(--text); }
.chapter li .mark { color: var(--gold-dim); }
.chapter li .kind { font-size: 0.9rem; color: var(--faint); }
.chapter li.next a { color: var(--gold); }
.shelf a { display: block; border-top: 1px solid var(--line); padding: 18px 0; }
.shelf a:hover h2 { color: var(--gold); }
.shelf h2 { font-family: var(--body); font-weight: 500; font-size: 1.35rem; }
.shelf p { color: var(--muted); font-style: italic; font-size: 1rem; }

/* ---------- missão: dois painéis ---------- */
.quest { height: 100vh; height: 100dvh; display: grid; grid-template-rows: auto minmax(0, 1fr); }
.panes { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); min-height: 0; }
.read { overflow-y: auto; padding: 44px 32px 80px; }
.read-inner { max-width: 62ch; margin: 0 auto; }
.read h1 { font-family: var(--body); font-weight: 500; font-size: 2.05rem; line-height: 1.15; margin: 8px 0 22px; text-wrap: balance; }
.prose > * + * { margin-top: 0.85em; }
.prose h2 { font-family: var(--label); font-weight: 600; font-size: 0.74rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--gold-dim); margin-top: 2.2em; }
.prose strong { color: #fff6e6; font-weight: 600; }
.prose ul { list-style: disc; padding-left: 1.2em; }
.prose ol { list-style: decimal; padding-left: 1.2em; }
.prose li + li { margin-top: 0.3em; }
.prose li::marker { color: var(--faint); }
.prose a { border-bottom: 1px solid var(--line-strong); }
.prose a:hover { color: var(--gold); }
.prose code { font-family: var(--mono); font-size: 0.78em; background: var(--raised); border-radius: 3px; padding: 1px 5px; }
.prose pre { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 12px 14px; overflow-x: auto; }
.prose pre code { background: none; padding: 0; font-size: 0.8rem; line-height: 1.65; }
.prose table { border-collapse: collapse; width: 100%; font-size: 1rem; }
.prose th { font-family: var(--label); font-weight: 600; font-size: 0.7rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); text-align: left; }
.prose th, .prose td { padding: 6px 12px 6px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.prose blockquote { margin: 0; padding-left: 14px; border-left: 2px solid var(--gold-dim); color: var(--muted); font-style: italic; }
.pager { display: flex; justify-content: space-between; margin-top: 48px; padding-top: 16px; border-top: 1px solid var(--line); }

.work { display: flex; flex-direction: column; min-height: 0; border-left: 1px solid var(--line); background: var(--surface); position: relative; }
.editor { flex: 1 1 55%; min-height: 0; overflow: hidden; }
.editor .cm-editor { height: 100%; font-size: 0.9rem; background: transparent; }
.editor .cm-editor.cm-focused { outline: none; }
.editor .cm-scroller { font-family: var(--mono); line-height: 1.7; overflow: auto; }
.editor .cm-content { padding: 18px 0; caret-color: var(--gold); }
.editor .cm-gutters { background: transparent; border: 0; color: var(--faint); padding-left: 8px; }
.editor .cm-activeLine, .editor .cm-activeLineGutter { background: rgba(255, 232, 196, 0.035); }
.editor .cm-cursor { border-left-color: var(--gold); }
.editor .cm-selectionBackground, .editor .cm-focused .cm-selectionBackground { background: rgba(230, 180, 80, 0.2) !important; }
.editor .cm-matchingBracket { background: rgba(230, 180, 80, 0.22); outline: none; }
.tok-keyword, .tok-definitionKeyword, .tok-controlKeyword { color: var(--gold); }
.tok-string, .tok-string2 { color: var(--ok); }
.tok-comment { color: var(--faint); font-style: italic; }
.tok-number, .tok-atom, .tok-bool, .tok-literal { color: #e9a184; }
.tok-typeName, .tok-namespace, .tok-className { color: #d9c08a; }
.tok-operator, .tok-punctuation { color: var(--muted); }

.actions { display: flex; align-items: center; gap: 18px; padding: 10px 18px; border-top: 1px solid var(--line); min-height: 52px; }
.run { font-family: var(--label); font-weight: 600; font-size: 0.74rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--gold); border: 1px solid var(--gold-dim); border-radius: 999px; padding: 6px 16px; }
.run:hover:not(:disabled) { background: rgba(230, 180, 80, 0.12); }
.run kbd { font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0; color: var(--gold-dim); margin-left: 8px; text-transform: none; }
.actions .grow { flex: 1; }
.actions .saved { font-size: 0.9rem; font-style: italic; color: var(--faint); }
.result { flex: 0 1 auto; max-height: 45%; overflow-y: auto; padding: 0 18px; }
.result:not(:empty) { padding: 14px 18px 18px; border-top: 1px solid var(--line); }
.verdict { font-size: 1.02rem; }
.verdict b { font-weight: 600; }
.verdict.fail b { color: var(--bad); }
.verdict.win b { color: var(--ok); }
.trials { margin-top: 8px; }
.trials li { display: grid; grid-template-columns: 20px minmax(0, 1fr); padding: 3px 0; font-size: 1rem; color: var(--muted); }
.trials li > span { color: var(--ok); }
.trials li.bad { color: var(--text); }
.trials li.bad > span { color: var(--bad); }
.out { font-family: var(--mono); font-size: 0.76rem; line-height: 1.6; color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; margin: 6px 0 4px; }
.box { margin-top: 12px; }
.box summary { cursor: pointer; }

/* perguntas e respostas abertas ocupam a bancada inteira */
.answer-pane { flex: 1; overflow-y: auto; padding: 44px 32px 96px; }
.answer-inner { max-width: 58ch; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.options { display: flex; flex-direction: column; gap: 2px; }
.options button { text-align: left; padding: 12px 14px; border-left: 2px solid var(--line-strong); font-family: var(--mono); font-size: 0.86rem; line-height: 1.5; color: var(--text); }
.options button:hover:not(:disabled) { border-left-color: var(--gold); background: rgba(255, 232, 196, 0.03); }
.options button.right { border-left-color: var(--ok); color: var(--ok); opacity: 1; }
.options button.wrong { border-left-color: var(--bad); color: var(--bad); opacity: 0.8; }
.answer-inner textarea { width: 100%; min-height: 190px; resize: vertical; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 12px 14px; line-height: 1.5; }
.answer-inner textarea:focus { outline: none; border-color: var(--gold-dim); }
.model { border-top: 1px solid var(--line); padding-top: 18px; }

/* ---------- Tiamat ---------- */
.mascot { width: 44px; height: 44px; border-radius: 50%; overflow: hidden; background: var(--raised); border: 1px solid var(--line-strong); flex: none; transition: transform 0.2s; }
.mascot img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 30%; display: block; }
.mascot:hover { transform: scale(1.08) rotate(-4deg); }
.mascot.cheer { animation: cheer 0.6s ease; }
@keyframes cheer { 30% { transform: translateY(-8px) rotate(6deg); } 60% { transform: translateY(0) rotate(-4deg); } }
.mascot-dock { position: absolute; right: 18px; bottom: 62px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; pointer-events: none; z-index: 5; }
.mascot-dock.low { bottom: 18px; }
.mascot-dock > * { pointer-events: auto; }
.balloon { max-width: min(340px, 70vw); background: var(--raised); border: 1px solid var(--line-strong); border-radius: 12px 12px 2px 12px; padding: 10px 14px; font-size: 1rem; line-height: 1.4; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45); position: relative; overflow: hidden; }
.balloon b { color: var(--gold); font-weight: 600; }
.balloon .prose { font-size: 1rem; }
.balloon .close { float: right; margin: -2px -4px 0 10px; color: var(--faint); font-size: 1.1rem; line-height: 1; }
.balloon .close:hover { color: var(--text); }
.balloon .stay { display: inline-block; margin-top: 2px; }
.balloon .fuse { position: absolute; left: 0; bottom: 0; height: 2px; width: 100%; background: var(--gold); transform-origin: left; animation: fuse 3s linear forwards; }
@keyframes fuse { to { transform: scaleX(0); } }

/* ---------- "isso ao extremo" ---------- */
dialog.extreme { width: min(760px, calc(100vw - 32px)); max-height: min(86vh, 900px); padding: 0; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface); color: var(--text); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6); }
dialog.extreme::backdrop { background: rgba(8, 6, 4, 0.72); }
.extreme-head { display: flex; align-items: center; gap: 16px; padding: 22px 28px 18px; border-bottom: 1px solid var(--line); }
.extreme-head .mascot { width: 60px; height: 60px; }
.extreme-head .xp { font-family: var(--body); font-weight: 600; font-size: 1.9rem; line-height: 1; color: var(--gold); }
.extreme-head p { color: var(--muted); font-size: 1rem; }
.extreme-body { padding: 22px 28px 8px; overflow-y: auto; }
.extreme-body h3 { margin-bottom: 12px; color: var(--gold-dim); }
.extreme-foot { display: flex; justify-content: flex-end; align-items: center; gap: 22px; padding: 16px 28px 22px; }

/* ---------- entrada ---------- */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.gate form { width: min(320px, 100%); display: flex; flex-direction: column; align-items: center; gap: 16px; text-align: center; }
.gate .mascot { width: 76px; height: 76px; }
.gate form { gap: 6px; }
.gate-title { font-size: 1.3rem; margin: 10px 0 14px; }
.gate label { font-family: var(--label); font-weight: 600; font-size: 0.68rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); margin-top: 12px; }
.gate input { width: 100%; background: transparent; border: 0; border-bottom: 1px solid var(--line-strong); padding: 6px 4px 8px; text-align: center; }
.gate .run { margin-top: 22px; }
.gate input:focus { outline: none; border-bottom-color: var(--gold); }
.gate .error { color: var(--bad); min-height: 1.5em; font-size: 1rem; }

@media (max-width: 980px) {
  .quest { height: auto; display: block; }
  .panes { grid-template-columns: minmax(0, 1fr); }
  .read { overflow: visible; padding: 32px 20px 40px; }
  .work { border-left: 0; border-top: 1px solid var(--line); min-height: 70vh; }
  .editor { flex-basis: 320px; }
  .result { max-height: none; }
  .answer-pane { padding: 32px 20px 96px; }
  .bar .where { display: none; }
}
@media (max-width: 560px) {
  .bar { gap: 12px; padding: 0 14px; }
  .ticks a { width: 12px; }
  .stats .streak { display: none; }
  .bar .home { display: none; }
  .cover { padding-top: 36px; }
}
@media (prefers-reduced-motion: reduce) {
  .mascot, .mascot.cheer { animation: none; transition: none; }
  .balloon .fuse { animation-duration: 3s; }
}
