:root {
  --bg: #070b12;
  --bg-panel: #0c121b;
  --bg-elev: #141c28;
  --line: #2a3646;
  --ink: #e8eef5;
  --ink-dim: #8fa3b5;
  --accent: #3ee0b0;
  --accent-deep: #0c2a22;
  --navy: #1a2744;
  --warm: #e4c38a;
  --danger: #ff6b63;
  --radius: 16px;
  --serif: "Instrument Serif", "Iowan Old Style", Georgia, serif;
  --sans: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0; min-height: 100%;
  background: var(--bg); color: var(--ink); font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overscroll-behavior: none;
}

body {
  min-height: 100dvh;
  background-image:
    radial-gradient(900px 480px at 80% -10%, rgba(62, 224, 176, .08), transparent 55%),
    radial-gradient(700px 400px at 0% 100%, rgba(26, 39, 68, .55), transparent 50%);
}

html.flight-active, html.flight-active body {
  overflow: hidden;
  height: 100dvh;
  height: 100svh;
}

#app { min-height: 100dvh; display: flex; }
.screen { display: none; width: 100%; }
.screen.is-active { display: flex; flex-direction: column; }

/* ---------- splash ---------- */

#screen-splash.is-active { min-height: 100dvh; }
.splash {
  position: relative;
  flex: 1;
  min-height: 100dvh;
  display: flex;
  align-items: flex-end;
  overflow: hidden;
}
.splash-hero, .splash-hero img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover; object-position: 62% 35%;
}
.splash-veil {
  position: absolute; inset: 0;
  background:
    linear-gradient(180deg, rgba(7,11,18,.15) 0%, rgba(7,11,18,.25) 38%, rgba(7,11,18,.92) 78%, #070b12 100%),
    repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0,0,0,.04) 3px);
  pointer-events: none;
}
.splash-copy {
  position: relative;
  z-index: 1;
  width: min(720px, 100%);
  padding: 28px 22px calc(28px + env(safe-area-inset-bottom, 0px));
  opacity: 0;
  transform: translateY(12px);
  animation: rise .8s ease .15s forwards;
}
.splash .btn-primary { opacity: 0; pointer-events: none; transform: translateY(8px); }
.splash.is-ready .btn-primary:not(:disabled) {
  opacity: 1; pointer-events: auto; transform: none;
  transition: opacity .4s ease, transform .4s ease;
}
.splash.is-ready .btn-primary:disabled {
  opacity: .38; pointer-events: none; transform: none;
}
@keyframes rise { to { opacity: 1; transform: none; } }

.lockup {
  margin: 0 0 10px;
  font-size: 11px; letter-spacing: .28em; text-transform: uppercase;
  color: var(--accent); font-weight: 600;
}
.wordmark {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(84px, 26vw, 168px);
  font-weight: 400; line-height: .8;
  letter-spacing: -.04em;
}
.sub {
  margin: 10px 0 0;
  font-family: var(--mono);
  font-size: 13px; color: var(--warm);
  letter-spacing: .04em;
}
.line {
  margin: 14px 0 22px;
  font-size: clamp(16px, 3.4vw, 20px);
  line-height: 1.35; max-width: 22ch;
}

.status-row {
  display: flex; align-items: center; gap: 9px;
  margin: 0 0 16px; font-size: 13px; color: var(--ink-dim);
}
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--ink-dim);
  box-shadow: 0 0 0 3px rgba(143,163,181,.15); flex: none;
}
.dot.ok { background: var(--accent); box-shadow: 0 0 0 3px rgba(62,224,176,.18); }
.dot.warn { background: var(--warm); box-shadow: 0 0 0 3px rgba(228,195,138,.18); }

.block-card {
  margin: 0 0 16px; padding: 14px 16px;
  background: rgba(255, 107, 99, .08);
  border: 1px solid rgba(255, 107, 99, .35);
  border-radius: 12px;
}
.block-card p { margin: 0 0 12px; color: var(--ink); line-height: 1.5; font-size: 14px; }

.disclaimer {
  margin: 16px 0 0;
  font-size: 11.5px; line-height: 1.55; color: #6d7f90; max-width: 62ch;
}

/* ---------- painéis ---------- */

#screen-commander.is-active,
#screen-debrief.is-active {
  align-items: stretch;
  height: 100dvh;
  height: 100svh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 0 env(safe-area-inset-bottom, 0px);
}

.commander-top {
  position: sticky;
  top: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 12px 8px;
  background: rgba(7, 11, 18, .94);
  border-bottom: 1px solid var(--line);
}
.commander-top .btn-ghost {
  min-width: 48px;
  min-height: 48px;
  padding: 0 18px;
}

.panel {
  width: min(1040px, calc(100% - 24px));
  margin: 20px auto 28px;
  padding: clamp(20px, 4vw, 36px);
  background: linear-gradient(180deg, var(--bg-panel), #090e16);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 11px; letter-spacing: .22em; text-transform: uppercase;
  color: var(--accent); font-weight: 600;
}
h1, h2 {
  margin: 0 0 12px;
  font-family: var(--serif);
  font-weight: 400;
  letter-spacing: -.02em;
}
h1 { font-size: clamp(28px, 6vw, 48px); line-height: 1.05; max-width: 16ch; }
h2 { font-size: clamp(26px, 5vw, 40px); }
.lead { margin: 0 0 22px; color: var(--ink-dim); line-height: 1.6; max-width: 58ch; }

/* ---------- comandante ---------- */

.cartas {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 22px;
}
.carta {
  text-align: left;
  padding: 0 0 16px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: inherit;
  cursor: pointer;
  min-height: 48px;
  font: inherit;
}
.carta.is-on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.carta-foto {
  height: 148px;
  background: #101820;
  border-radius: 13px 13px 0 0;
  overflow: hidden;
}
.carta-foto svg { display: block; width: 100%; height: 148px; }
.carta h2 { font-size: 26px; margin: 14px 16px 6px; }
.carta p { margin: 0 16px 8px; color: var(--ink-dim); font-size: 14px; line-height: 1.5; }
.carta-tese { color: var(--warm) !important; font-size: 13px !important; }

.restricoes {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 18px;
}
.toggle {
  display: flex; align-items: center; gap: 10px;
  min-height: 48px; font-size: 15px;
}
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span {
  font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink-dim); font-weight: 600;
}
select, input[type="text"] {
  width: 100%; padding: 12px;
  min-height: 48px;
  background: var(--bg-elev); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px;
  font-family: inherit; font-size: 16px; appearance: none;
}
.seed-row { display: flex; gap: 8px; }
.seed-row input { font-family: var(--mono); }
.seed-row .btn-ghost { flex: 0 0 48px; padding: 0; }

/* ---------- botões ---------- */

.btn-primary, .btn-ghost, .btn-pause, .btn-tape, .btn-pic-force, .btn-rail-toggle {
  font-family: inherit; font-weight: 600; border-radius: 12px; cursor: pointer;
  min-height: 48px; touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.btn-primary {
  width: 100%; padding: 14px 18px;
  background: var(--accent); color: var(--accent-deep); border: none; font-size: 16px;
}
.btn-primary:disabled { opacity: .38; cursor: not-allowed; }
.btn-ghost {
  padding: 12px 16px; background: transparent; color: var(--ink);
  border: 1px solid var(--line); font-size: 15px;
}
.btn-inline { width: 100%; margin-top: 10px; }
select:focus-visible, input:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* ---------- live ---------- */

#screen-live {
  position: relative; padding: 0;
  height: 100dvh; height: 100svh; overflow: hidden;
}
#screen-live canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  background: #102033;
}

.hud {
  position: absolute; left: 0; right: 0; top: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px 8px;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 88px 10px 12px;
  background: linear-gradient(180deg, rgba(7,11,18,.9), transparent);
  pointer-events: none;
}
.hud-block { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.hud-label { font-size: 8px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-dim); font-weight: 700; }
.hud-value { font-family: var(--mono); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-fonte.is-jev { color: var(--accent); }
.hud-fonte.is-block { color: var(--danger); }
.hud-next {
  position: absolute;
  left: 12px; right: 12px;
  top: calc(88px + env(safe-area-inset-top, 0px));
  margin: 0;
  font-size: 12px; color: var(--ink-dim);
  pointer-events: none;
}
.hud-evasao { display: none; }

.btn-pic-force {
  pointer-events: auto;
  position: absolute;
  top: calc(8px + env(safe-area-inset-top, 0px));
  right: 10px;
  border: 1px solid var(--line);
  background: rgba(12,18,27,.78); color: var(--ink);
  padding: 0 10px; font-size: 11px; letter-spacing: .04em; text-transform: uppercase;
}

.tape-bar {
  position: absolute;
  left: 0; right: 0;
  bottom: 0;
  z-index: 6;
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, rgba(7,11,18,.2), rgba(7,11,18,.94) 28%);
}
.btn-tape, .tape-bar .btn-pause {
  border: 1px solid var(--line);
  background: rgba(12,18,27,.92);
  color: var(--ink);
}
.btn-tape {
  flex: 1;
  padding: 0 12px;
  font-size: 15px;
}
.btn-tape:disabled { opacity: .38; cursor: not-allowed; }
.tape-bar .btn-pause {
  flex: 0 0 48px;
  width: 48px;
  min-width: 48px;
  padding: 0;
  font-family: var(--mono);
  font-size: 18px;
  border-color: var(--accent);
  color: var(--accent);
}
.pausa-banner {
  position: absolute;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  z-index: 5;
  margin: 0;
  padding: 8px 18px;
  min-height: 48px;
  display: flex;
  align-items: center;
  font-family: var(--serif);
  font-size: 32px;
  letter-spacing: .06em;
  background: rgba(8,12,18,.86);
  border: 1px solid var(--line);
  border-radius: 14px;
  pointer-events: none;
}

.btn-rail-toggle {
  position: absolute;
  right: 10px;
  bottom: calc(68px + env(safe-area-inset-bottom, 0px));
  z-index: 4;
  padding: 0 16px;
  background: rgba(12,18,27,.88);
  border: 1px solid var(--line);
  color: var(--accent);
}

.rail {
  position: absolute;
  left: 0; right: 0;
  bottom: 0;
  z-index: 3;
  max-height: 42%;
  overflow: auto;
  padding: 14px 14px calc(124px + env(safe-area-inset-bottom, 0px));
  background: rgba(8,12,18,.94);
  border-top: 1px solid var(--line);
  transform: translateY(72%);
  transition: transform .22s ease;
}
.rail.is-open { transform: none; }
.rail header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.chip-fonte {
  font-family: var(--mono); font-size: 11px; letter-spacing: .12em;
  padding: 3px 8px; border-radius: 99px; border: 1px solid var(--line);
}
.chip-fonte.is-jev { color: var(--accent); border-color: var(--accent); }
.chip-fonte.is-block { color: var(--danger); border-color: var(--danger); }
.rail-lat { font-family: var(--mono); font-size: 11px; color: var(--ink-dim); }
.rail-inc { margin: 0 0 10px; font-size: 13px; line-height: 1.4; color: var(--ink-dim); }
.painel-escolha { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.painel-label { font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-dim); }
.painel-escolha strong { font-size: 18px; font-family: var(--serif); }
.bars { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
.bar-row { display: grid; grid-template-columns: 72px 1fr 36px; gap: 6px; align-items: center; }
.bar-name { font-size: 10px; color: var(--ink-dim); }
.bar-track { height: 5px; background: var(--bg-elev); border-radius: 3px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--accent); }
.bar-val { font-family: var(--mono); font-size: 10px; text-align: right; color: var(--ink-dim); }
.bar-row.is-on .bar-name { color: var(--accent); }
.painel-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }
.painel-meta div { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; }
.painel-meta span { color: var(--ink-dim); }
.painel-meta b { font-family: var(--mono); font-weight: 500; }

.selo-jev {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: calc(96px + env(safe-area-inset-top, 0px));
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 20px);
  margin: 0;
  padding: 8px 18px 12px;
  text-align: center;
  pointer-events: none;
  background: rgba(7, 11, 18, .82);
  border: 1px solid rgba(62, 224, 176, .55);
  border-radius: 18px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .35);
}
.selo-kicker {
  margin: 0;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--accent);
}
.selo-manobra {
  margin: 2px 0 0;
  font-family: var(--serif);
  font-size: clamp(34px, 10vw, 68px);
  font-weight: 400;
  line-height: .95;
  letter-spacing: -0.02em;
  color: #f4f1ea;
}
.selo-ms {
  margin: 6px 0 0;
  font-family: var(--mono);
  font-size: clamp(26px, 7vw, 44px);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--accent);
}
.pic-override {
  position: absolute;
  left: 10px; right: 10px;
  bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  z-index: 5;
  padding: 12px 14px;
  background: rgba(8, 12, 18, .92);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.pic-override p { margin: 0 0 10px; font-size: 13px; color: var(--ink-dim); }
.pic-actions { display: flex; flex-direction: column; gap: 8px; }

.webgl-fallback {
  position: absolute; inset: auto 12px 30%;
  z-index: 2;
  padding: 14px;
  background: rgba(12,18,27,.92);
  border: 1px solid var(--line);
  border-radius: 12px;
}

/* ---------- debrief ---------- */

.kpis {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
}
.kpis div {
  padding: 12px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.kpis span { display: block; font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-dim); }
.kpis strong { font-family: var(--serif); font-size: 28px; font-weight: 400; }

.verdict {
  margin: 0 0 18px; padding: 14px 16px;
  background: rgba(62, 224, 176, .06);
  border-left: 3px solid var(--accent);
  border-radius: 0 10px 10px 0;
  line-height: 1.55;
}
.verdict .aviso { color: var(--warm); }

.debrief-inc {
  margin-bottom: 16px; padding: 16px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.debrief-inc.is-ok { border-color: rgba(62, 224, 176, .35); }
.debrief-inc h3 { font-family: var(--sans); font-size: 15px; font-weight: 600; margin: 0 0 6px; letter-spacing: 0; }
.inc-meta { margin: 0 0 10px; font-size: 12px; color: var(--warm); }
.debrief-cols { display: grid; grid-template-columns: 1fr; gap: 10px; }
.debrief-col h4 { margin: 0 0 6px; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); }
.debrief-col ul { list-style: none; margin: 0; padding: 0; }
.debrief-col li { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; padding: 3px 0; }
.debrief-col span { color: var(--ink-dim); }
.inc-estado { margin: 10px 0 0; font-size: 12px; color: var(--ink-dim); }
.debrief-block { padding: 14px; border: 1px dashed var(--warm); border-radius: 12px; color: var(--warm); }
.result-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 18px; }

@media (min-width: 768px) {
  .splash-copy { padding: 48px 56px 56px; }
  .cartas { grid-template-columns: repeat(3, 1fr); }
  .restricoes { grid-template-columns: repeat(3, 1fr); }
  .kpis { grid-template-columns: repeat(4, 1fr); }
  .debrief-cols { grid-template-columns: 1fr 1fr; }
  .result-actions { flex-direction: row; flex-wrap: wrap; }
  .result-actions .btn-primary { width: auto; flex: 1; }
  .result-actions .btn-ghost { width: auto; flex: 1; }
  .btn-rail-toggle { display: none; }
  .rail {
    left: auto; right: 16px; top: 110px; bottom: 16px;
    width: min(340px, 34vw);
    max-height: none;
    transform: none;
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 16px;
    background: rgba(8,12,18,.88);
  }
  .selo-jev { top: 108px; }
  .pic-override { left: auto; right: 16px; width: min(340px, 34vw); bottom: 24px; }
  .hud { padding-right: 24px; gap: 10px 18px; }
  .btn-pic-force { right: 20px; }
  .tape-bar {
    left: 16px;
    right: auto;
    bottom: 16px;
    padding: 0;
    background: transparent;
  }
  .tape-bar .btn-tape { flex: 0 0 auto; min-width: 48px; }
  .pic-override { bottom: 24px; }
  .btn-rail-toggle { bottom: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
  .splash-copy { opacity: 1; transform: none; }
}
