/* ============ Tokens (tema único: escuro, minimalista) ============ */
:root {
  --bg: #090b10;
  --bg-2: #0f121a;
  --panel: #131722;
  --panel-2: #1a1f2d;
  --line: rgba(255, 255, 255, .08);
  --line-2: rgba(255, 255, 255, .14);
  --text: #e9edf5;
  --mut: #8d95a8;
  --faint: #596176;

  --good: #4ade80;
  --ok: #60a5fa;
  --warn: #fbbf24;
  --bad: #f87171;

  --c: #60a5fa;               /* cor da família do indicador atual (definida por página) */
  --r: 14px;
  --r-sm: 9px;
  --ease: cubic-bezier(.22, .8, .24, 1);
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "JetBrains Mono", "Cascadia Code", Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; }
html { color-scheme: dark; scroll-behavior: smooth; scroll-snap-type: y proximity; }
body { background: var(--bg); color: var(--text); font: 400 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; min-height: 100dvh; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
::selection { background: color-mix(in srgb, var(--c) 40%, transparent); }

/* transições de página (View Transitions) */
::view-transition-old(root), ::view-transition-new(root) { animation-duration: .28s; }

/* ============ Botões / chips ============ */
.btn {
  display: inline-flex; align-items: center; gap: .45em; padding: .5em 1em; border-radius: 999px;
  border: 1px solid var(--line-2); background: rgba(255, 255, 255, .04); cursor: pointer;
  transition: background .2s var(--ease), border-color .2s var(--ease), transform .15s var(--ease);
  font-size: 13px; font-weight: 500; white-space: nowrap;
}
.btn:hover { background: rgba(255, 255, 255, .09); border-color: rgba(255, 255, 255, .25); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--c); border-color: transparent; color: #0a0c10; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.1); background: var(--c); }
.btn[disabled], .btn.off { opacity: .35; pointer-events: none; }
.chip { display: inline-flex; align-items: center; gap: .4em; font-size: 12px; color: var(--mut); }
.chip::before { content: ""; width: .6em; height: .6em; border-radius: 50%; background: var(--c); }
.mono { font-family: var(--mono); }

/* ============ Página de indicador ============ */
.topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 20; display: flex; align-items: center; gap: 14px;
  padding: 14px 20px; pointer-events: none;
  background: linear-gradient(var(--bg) 20%, transparent);
}
.topbar > * { pointer-events: auto; }
.topbar .back {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  border: 1px solid var(--line-2); background: rgba(255, 255, 255, .04); transition: .2s var(--ease);
}
.topbar .back:hover { background: rgba(255, 255, 255, .1); transform: scale(1.06); }
.topbar .back svg { width: 16px; height: 16px; }
.topbar .title { display: flex; flex-direction: column; line-height: 1.15; }
.topbar .title b { font-size: 15px; font-weight: 600; }
.topbar .title small { font: 12px var(--mono); color: var(--mut); }
.topbar .spacer { flex: 1; }
.study-nav { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--mut); }
.study-nav a, .study-nav span.arrow {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  border: 1px solid var(--line-2); transition: .2s var(--ease);
}
.study-nav a:hover { background: rgba(255, 255, 255, .1); color: var(--text); }
.study-nav span.arrow { opacity: .25; }
.study-nav .pos { min-width: 5.5em; text-align: center; font-variant-numeric: tabular-nums; }

.dots {
  position: fixed; right: 16px; top: 50%; transform: translateY(-50%); z-index: 20;
  display: flex; flex-direction: column; gap: 14px;
}
.dots a { width: 9px; height: 9px; border-radius: 50%; background: var(--faint); transition: .25s var(--ease); position: relative; }
.dots a.on { background: var(--c); transform: scale(1.5); }
.dots a::after {
  content: attr(data-label); position: absolute; right: 18px; top: 50%; transform: translateY(-50%);
  font-size: 11px; color: var(--mut); opacity: 0; transition: opacity .2s; white-space: nowrap; pointer-events: none;
}
.dots a:hover::after { opacity: 1; }

.panel { min-height: 100dvh; scroll-snap-align: start; position: relative; display: flex; flex-direction: column; justify-content: center; padding: 72px clamp(16px, 4vw, 56px) 40px; }
.panel + .panel { border-top: 1px solid var(--line); }
.panel-label {
  position: absolute; left: clamp(16px, 4vw, 56px); bottom: 16px; font-size: 11px; letter-spacing: .14em;
  text-transform: uppercase; color: var(--faint);
}
.soon { margin: auto; text-align: center; color: var(--mut); display: grid; gap: 10px; place-items: center; }
.soon i { width: 64px; height: 64px; border-radius: 50%; border: 2px dashed var(--c); opacity: .6; animation: spin 14s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Seção 2 — teia local */
.teia-host { position: relative; width: 100%; flex: 1; min-height: calc(100dvh - 112px); border-radius: var(--r); overflow: hidden; background: radial-gradient(ellipse at center, var(--bg-2), var(--bg) 75%); }
.teia-host canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* ============ Seção 1 — player de história ============ */
/* a largura também respeita a ALTURA da tela: palco 16:9 + controles (≈ 48 px) + padding do painel (112 px) têm de caber em 100dvh,
   senão em notebook (ex.: 1366×650 úteis) o painel cresce e a barra de controles e a legenda saem da tela */
.story { width: min(1100px, 100%, max(320px, calc((100dvh - 168px) * 16 / 9))); margin: 0 auto; }
.story-stage { position: relative; aspect-ratio: 16 / 9; width: 100%; border-radius: var(--r); overflow: hidden; background: radial-gradient(ellipse at 50% 40%, var(--bg-2), var(--bg)); border: 1px solid var(--line); }
.story-stage svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.story-cap {
  position: absolute; left: 0; right: 0; bottom: 6%; text-align: center; font-size: clamp(14px, 2vw, 22px); font-weight: 500;
  letter-spacing: -.01em; pointer-events: none; transition: opacity .3s var(--ease);
}
.story-ui { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.story-ui button {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line-2); background: rgba(255, 255, 255, .04);
  display: grid; place-items: center; cursor: pointer; transition: .2s var(--ease); flex: none;
}
.story-ui [hidden] { display: none; }
.story-ui button:hover { background: rgba(255, 255, 255, .1); }
.story-ui svg { width: 14px; height: 14px; fill: currentColor; }
.story-bar { position: relative; flex: 1; height: 22px; cursor: pointer; display: flex; align-items: center; }
.story-bar::before { content: ""; position: absolute; left: 0; right: 0; height: 3px; border-radius: 3px; background: var(--line-2); }
.story-fill { position: absolute; left: 0; height: 3px; border-radius: 3px; background: var(--c); width: 0; }
.story-tick { position: absolute; width: 2px; height: 9px; background: var(--bg); top: 50%; transform: translateY(-50%); }
.story-time { font: 12px var(--mono); color: var(--mut); min-width: 5.5em; text-align: right; }

/* formato vertical (mobile/Instagram, 9:16): o palco acompanha a ALTURA útil da tela e fica centralizado */
.story.portrait { width: min(100%, 520px, max(240px, calc((100dvh - 168px) * 9 / 16))); }
.story.portrait .story-stage { aspect-ratio: 9 / 16; }
.story-time { white-space: nowrap; }
/* telas estreitas (celular): a barra de tempo ocupa uma linha só e os botões ficam embaixo dela */
@media (max-width: 520px) {
  .story-ui { flex-wrap: wrap; row-gap: 6px; }
  .story-bar { order: -1; flex: 1 1 100%; }
  .story-time { margin-left: auto; min-width: 0; }
}
.story.portrait .story-ui { gap: 8px; }

/* baixar vídeo: menu (Desktop 16:9 / Mobile 9:16) e painel de progresso sobre o palco */
.story-ui { position: relative; }
.story-dl {
  position: absolute; right: 0; bottom: calc(100% + 10px); z-index: 5; width: min(300px, 92vw); padding: 12px;
  display: grid; gap: 8px; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: var(--r);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .5);
}
.story-dl[hidden], .story-export[hidden] { display: none; }
.story-dl b { font-size: 13px; font-weight: 600; }
.story-dl b small { font-weight: 400; color: var(--mut); margin-left: .4em; }
.story-dl em { font-size: 11px; line-height: 1.35; color: var(--mut); font-style: normal; }
.story-ui .story-dl button {
  width: auto; height: auto; border-radius: var(--r-sm); padding: 9px 12px; display: grid; gap: 1px; text-align: left; place-items: start;
}
.story-dl button span { font-size: 14px; font-weight: 600; }
.story-dl button small { font-size: 11px; color: var(--mut); }
.story-export { position: absolute; inset: 0; z-index: 6; display: grid; place-items: center; background: color-mix(in srgb, var(--bg) 82%, transparent); }
.xp-box { width: min(86%, 380px); display: grid; gap: 10px; text-align: center; font-size: 14px; }
.xp-box b { font-weight: 600; }
.xp-box p, .xp-box em { color: var(--mut); font-size: 12px; font-style: normal; line-height: 1.4; }
.xp-bar { height: 6px; border-radius: 6px; background: var(--line-2); overflow: hidden; }
.xp-bar i { display: block; height: 100%; width: 0; background: var(--c); }
.xp-box button { justify-self: center; padding: 7px 18px; border-radius: 999px; border: 1px solid var(--line-2); background: rgba(255, 255, 255, .06); cursor: pointer; font-size: 13px; }
.xp-box button:hover { background: rgba(255, 255, 255, .12); }

/* ============ Seção 3 — simulação ============ */
.sim { width: min(1100px, 100%); margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: clamp(16px, 3vw, 40px); align-items: start; }
@media (max-width: 860px) { .sim { grid-template-columns: 1fr; } }
.sim-controls, .sim-out { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; }
.sim-out { position: sticky; top: 76px; }
.seg { display: inline-flex; padding: 3px; border-radius: 999px; background: var(--bg-2); border: 1px solid var(--line); margin-bottom: 18px; }
.seg button { border: 0; background: none; padding: .4em 1.1em; border-radius: 999px; font-size: 13px; color: var(--mut); cursor: pointer; transition: .2s var(--ease); }
.seg button.on { background: var(--c); color: #0a0c10; font-weight: 600; }
.group-title { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--faint); margin: 18px 0 8px; }
.group-title:first-of-type { margin-top: 0; }

.field { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: baseline; margin-bottom: 14px; }
.field label { font-size: 13px; color: var(--mut); }
.field output, .field .num { font: 600 13px var(--mono); color: var(--text); text-align: right; }
.field input[type=range] { grid-column: 1 / -1; width: 100%; }
.field .hint { grid-column: 1 / -1; font-size: 11px; color: var(--faint); }
.field input[type=number], .field input[type=text] {
  grid-column: 1 / -1; width: 100%; padding: .55em .8em; border-radius: var(--r-sm); background: var(--bg-2);
  border: 1px solid var(--line-2); outline: none; font: 14px var(--mono); transition: border-color .2s;
}
.field input[type=number]:focus { border-color: var(--c); }

input[type=range] { -webkit-appearance: none; appearance: none; height: 22px; background: transparent; cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: linear-gradient(90deg, var(--c) var(--p, 50%), var(--line-2) var(--p, 50%)); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 4px; background: var(--line-2); }
input[type=range]::-moz-range-progress { height: 4px; border-radius: 4px; background: var(--c); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; margin-top: -6px; border-radius: 50%; background: #fff; border: 3px solid var(--c); box-shadow: 0 2px 8px rgba(0, 0, 0, .5); transition: transform .15s var(--ease); }
input[type=range]::-webkit-slider-thumb:hover { transform: scale(1.2); }
input[type=range]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 3px solid var(--c); }

/* resultado */
.result { display: grid; gap: 16px; }
.metric-main { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.metric-main .val { font: 700 clamp(40px, 6vw, 64px)/1 var(--font); letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.metric-main .lbl { color: var(--mut); font-size: 13px; }
.verdict { display: inline-flex; align-items: center; gap: .5em; padding: .3em .8em; border-radius: 999px; font-size: 13px; font-weight: 600; background: color-mix(in srgb, var(--t, var(--mut)) 16%, transparent); color: var(--t, var(--mut)); }
.verdict::before { content: ""; width: .55em; height: .55em; border-radius: 50%; background: currentColor; }
[data-tone=good] { --t: var(--good); } [data-tone=ok] { --t: var(--ok); } [data-tone=warn] { --t: var(--warn); } [data-tone=bad] { --t: var(--bad); }
.reading { font-size: 15px; line-height: 1.55; color: var(--text); }
.notes { display: grid; gap: 4px; font-size: 12px; color: var(--mut); }
.notes li { list-style: none; padding-left: 1.1em; position: relative; }
.notes li::before { content: "·"; position: absolute; left: .3em; color: var(--warn); }
.related { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
.rel { padding: 10px 12px; border-radius: var(--r-sm); background: var(--bg-2); border: 1px solid var(--line); display: grid; gap: 2px; transition: border-color .2s; }
.rel[data-tone] { border-color: color-mix(in srgb, var(--t) 40%, transparent); }
.rel small { font-size: 11px; color: var(--mut); }
.rel b { font: 600 17px var(--mono); font-variant-numeric: tabular-nums; }
.recent { margin-top: 14px; display: grid; gap: 4px; font-size: 12px; color: var(--mut); }
.recent div { display: flex; justify-content: space-between; gap: 8px; }
.htmx-request .result { opacity: .75; transition: opacity .15s; }

/* ============ Utilitários ============ */
.fade-in { animation: fadeIn .5s var(--ease) both; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { * { animation-duration: .01ms !important; transition-duration: .01ms !important; } html { scroll-behavior: auto; } }
