:root {
  --navy: #0c1529;
  --navy-2: #16223d;
  --line: #2a3a5c;
  --cyan: #5fd4f4;
  --orange: #e8553e;
  --orange-d: #a8321f;
  --pink: #ff5a7a;
  --cream: #f6efe0;
  --text: #eaf6ff;
  --pixel: 'Silkscreen', 'Courier New', monospace;
  --mono: 'VT323', 'Courier New', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  background: #2c6bcf;
  color: var(--text);
  font-family: var(--mono);
  -webkit-font-smoothing: none;
  user-select: none;
}
button { font-family: var(--pixel); cursor: pointer; }
input, textarea { user-select: text; -webkit-user-select: text; }
.hidden { display: none !important; }

#scene {
  position: fixed; left: 0; top: 0;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
#scene-fg { position: fixed; left: 0; top: 0; pointer-events: none; image-rendering: pixelated; }
.scanlines {
  position: fixed; inset: 0; pointer-events: none; z-index: 5;
  background:
    repeating-linear-gradient(to bottom, rgba(255,255,255,0.05) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse at center, transparent 55%, rgba(5,10,25,0.35) 100%);
}

/* ---------- HUD ---------- */
.hud {
  position: fixed; top: 14px; left: 16px; right: 16px; z-index: 20;
  display: flex; justify-content: flex-end; align-items: center; gap: 10px;
  pointer-events: none;
}
.hud > * { pointer-events: auto; }
.hud-game { display: flex; gap: 10px; align-items: center; margin-right: auto; }
.hud-logo {
  font-family: var(--pixel); font-weight: 700; font-size: 18px; letter-spacing: .12em; color: #fff;
  text-shadow: -2px 0 var(--pink), 2px 0 var(--cyan), 0 2px 0 rgba(12,21,41,.4);
  margin-right: 6px;
}
.hud-pill {
  font-family: var(--pixel); font-size: 12px; letter-spacing: .2em; color: var(--cyan);
  background: rgba(12,21,41,.85); border: 2px solid var(--line); padding: 6px 10px;
}
.hud-pill b { color: #fff; font-weight: 700; margin-left: 4px; }
.hud-score { font-size: 16px; padding: 8px 14px; }
.hud-score b { font-family: var(--mono); font-size: 32px; letter-spacing: .04em; vertical-align: -4px; margin-left: 6px; }
.btn-icon {
  width: 42px; height: 42px; font-size: 18px; line-height: 1;
  background: var(--navy); border: 2px solid var(--line); color: #fff;
  box-shadow: 0 4px 0 #050a14;
}
.btn-icon:active { transform: translateY(3px); box-shadow: 0 1px 0 #050a14; }

/* ---------- altitude bar ---------- */
#altbar {
  position: fixed; right: 26px; top: 15vh; height: 62vh; width: 10px; z-index: 8;
}
#altbar .track {
  position: absolute; inset: 0;
  background: rgba(12,21,41,.7); border: 2px solid var(--cyan);
  box-shadow: 0 0 0 2px var(--navy);
}
#alt-fill {
  position: absolute; left: 0; right: 0; top: 0; height: 0;
  background: repeating-linear-gradient(to bottom, #8ff0ff 0 3px, var(--cyan) 3px 6px);
}
.zone-tick { position: absolute; left: -5px; right: -5px; height: 2px; background: var(--navy); transform: translateY(-1px); }
.zone-icon {
  position: absolute; right: 20px; transform: translateY(-50%);
  font-size: 17px; line-height: 1; filter: drop-shadow(2px 2px 0 rgba(12,21,41,.7));
}
#alt-marker { position: absolute; left: 50%; top: 0; transform: translate(-50%, -50%); transition: none; }
.alt-parrot { display: block; width: 44px; image-rendering: pixelated; filter: drop-shadow(0 2px 0 rgba(12,21,41,.5)); }
#alt-readout {
  position: absolute; top: calc(100% + 12px); right: -14px; white-space: nowrap;
  font-family: var(--pixel); font-size: 11px; letter-spacing: .15em; color: #fff;
  background: rgba(12,21,41,.85); border: 2px solid var(--line); padding: 4px 6px;
}

/* ---------- tooltip + banner ---------- */
.tooltip {
  position: fixed; z-index: 9; transform: translateX(-50%);
  background: var(--navy); color: #fff; border: 2px solid var(--line);
  font-family: var(--mono); font-size: 26px; line-height: 1; padding: 6px 12px 4px;
  white-space: nowrap; pointer-events: none;
  box-shadow: 0 4px 0 rgba(5,10,20,.5);
}
.tooltip::before {
  content: ''; position: absolute; left: 50%; top: -9px; margin-left: -7px;
  border: 7px solid transparent; border-top: 0; border-bottom: 9px solid var(--line);
}
.banner {
  position: fixed; top: 17vh; left: 50%; z-index: 12; transform: translateX(-50%);
  font-family: var(--pixel); font-weight: 700; font-size: clamp(20px, 3.6vw, 42px); letter-spacing: .18em;
  color: #fff; white-space: nowrap; pointer-events: none;
  text-shadow: -3px 0 var(--pink), 3px 0 var(--cyan), 0 5px 0 rgba(12,21,41,.35);
}
.banner-anim { animation: bannerIn 2.3s steps(12) forwards; }
@keyframes bannerIn {
  0% { opacity: 0; transform: translate(-50%, -12px) scale(.9); }
  12% { opacity: 1; transform: translate(-50%, 0) scale(1.04); }
  20% { transform: translate(-50%, 0) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -6px); }
}

/* ---------- screens ---------- */
.screen { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
.screen button, .screen input, .screen .panel, .screen .start-actions { pointer-events: auto; }

.start {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: 11vh 20px 4vh;
}
.title {
  font-family: var(--pixel); font-weight: 700;
  font-size: clamp(36px, 9.6vw, 132px); line-height: 1; letter-spacing: .05em; color: #fff;
  text-shadow: -0.025em 0 0 var(--pink), 0.025em 0 0 var(--cyan), 0 0.06em 0 rgba(12,21,41,.45);
  animation: glitch 5s steps(1) infinite;
}
@keyframes glitch {
  0%, 90%, 100% { transform: none; }
  91% { transform: translateX(4px) skewX(-8deg); }
  93% { transform: translateX(-4px); }
  95% { transform: translateX(2px) skewX(5deg); }
  97% { transform: none; text-shadow: 0.08em 0 0 var(--pink), -0.08em 0 0 var(--cyan); }
}
.subtitle {
  margin-top: 2.4vh;
  font-family: var(--pixel); font-weight: 700; font-size: clamp(14px, 2vw, 24px); letter-spacing: .45em; color: #000;
  text-shadow: none;
}
.tagline {
  margin-top: 1.6vh; font-size: clamp(20px, 2.2vw, 28px); letter-spacing: .12em; color: #000;
  text-shadow: none;
}
.start-spacer { flex: 1; min-height: 120px; }
.start-actions { display: flex; flex-direction: column; align-items: center; gap: 14px; width: min(620px, 92vw); }
.start-actions .row { display: flex; gap: 12px; width: 100%; }
.start-actions .row .btn-ghost { flex: 1; }
.start-status {
  font-family: var(--pixel); font-size: 13px; letter-spacing: .2em; color: #fff;
  background: rgba(12,21,41,.85); border: 2px solid var(--line); padding: 6px 12px;
}
.footer {
  font-family: var(--pixel); font-size: 12px; letter-spacing: .25em; color: #000;
  text-shadow: none; margin-top: 4px;
}
.credit {
  position: absolute; right: 18px; bottom: 14px; pointer-events: auto;
  font-family: var(--pixel); font-size: 11px; letter-spacing: .2em; color: #fff;
  text-shadow: 2px 2px 0 var(--navy);
}
.credit a { color: var(--cyan); text-decoration: none; }
.credit a:hover { text-decoration: underline; }

/* ---------- buttons ---------- */
.btn-primary {
  width: 100%;
  font-size: clamp(18px, 2.3vw, 28px); font-weight: 700; letter-spacing: .32em;
  padding: 20px 24px 22px; color: #fff;
  background: var(--orange); border: 3px solid var(--navy);
  box-shadow: inset 0 -6px 0 var(--orange-d), inset 0 3px 0 #ff8a6e, 0 6px 0 var(--navy);
  text-shadow: 2px 2px 0 var(--orange-d);
  transition: transform .05s, filter .1s;
}
.btn-primary:hover { filter: brightness(1.07); }
.btn-primary:active { transform: translateY(4px); box-shadow: inset 0 -2px 0 var(--orange-d), 0 2px 0 var(--navy); }
.btn-primary.sm { width: auto; font-size: 16px; padding: 12px 20px 14px; letter-spacing: .25em; }
.btn-ghost {
  font-size: 14px; letter-spacing: .25em; color: #fff; padding: 12px 16px;
  background: var(--navy); border: 3px solid var(--cyan);
  box-shadow: 0 0 0 2px var(--navy), 0 5px 0 #050a14;
}
.btn-ghost:hover { background: var(--navy-2); }
.btn-ghost:active { transform: translateY(3px); box-shadow: 0 0 0 2px var(--navy), 0 2px 0 #050a14; }

/* ---------- play panel ---------- */
.panel {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(760px, calc(100vw - 96px));
  background: rgba(12,21,41,.94); border: 3px solid var(--cyan);
  box-shadow: 0 0 0 3px var(--navy), 0 10px 0 rgba(0,0,0,.3);
  padding: 16px 22px 20px;
}
.timer { height: 12px; background: #050a14; border: 2px solid var(--line); margin-bottom: 10px; }
#timer-fill { height: 100%; width: 100%; background: repeating-linear-gradient(90deg, var(--cyan) 0 12px, #3fb3d6 12px 14px); }
.timer.urgent #timer-fill { background: repeating-linear-gradient(90deg, var(--orange) 0 12px, #b8402c 12px 14px); animation: blink .5s steps(1) infinite; }
@keyframes blink { 50% { opacity: .55; } }
.q-meta { display: flex; justify-content: space-between; font-family: var(--pixel); font-size: 12px; letter-spacing: .25em; color: var(--cyan); }
.q-text { font-size: clamp(28px, 3.4vw, 42px); line-height: 1.02; margin: 10px 0 14px; color: #fff; }
#answer-form { display: flex; gap: 10px; }
#answer {
  flex: 1; min-width: 0;
  font-family: var(--mono); font-size: 30px; padding: 8px 14px 6px;
  background: #050a14; color: #fff; border: 3px solid var(--line); outline: none; border-radius: 0;
}
#answer:focus { border-color: var(--cyan); }
#answer::placeholder { color: #4d6286; }
.btn-dive {
  font-size: 16px; font-weight: 700; letter-spacing: .2em; padding: 0 18px; color: #fff;
  background: var(--orange); border: 3px solid var(--navy);
  box-shadow: inset 0 -4px 0 var(--orange-d);
}
.btn-dive:active { transform: translateY(2px); }
.feedback { min-height: 26px; margin-top: 8px; font-size: 24px; color: #ffd38a; }
.feedback.checking { color: var(--cyan); animation: blink 1s steps(1) infinite; }
.shake { animation: shake .35s; }
@keyframes shake { 0%,100% { transform: none; } 20% { transform: translateX(-6px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(3px); } }

.chip {
  display: inline-block; font-family: var(--pixel); font-weight: 700; font-size: 13px; letter-spacing: .15em;
  color: var(--navy); background: var(--c); padding: 5px 9px 4px; border: 2px solid var(--navy);
  box-shadow: 0 3px 0 rgba(0,0,0,.35); white-space: nowrap;
}
.result {
  position: fixed; left: 50%; top: 58%; transform: translate(-50%, -50%);
  width: min(640px, calc(100vw - 64px)); text-align: center; pointer-events: auto;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  color: #000;
  text-shadow: 0 0 10px rgba(255,255,255,.55);
  animation: resIn .35s steps(6);
}
@keyframes resIn { from { opacity: 0; transform: translate(-50%, -46%); } }
.res-icon { font-size: 56px; line-height: 1; }
.res-title { font-family: var(--pixel); font-weight: 700; font-size: clamp(34px, 7vw, 64px); letter-spacing: .12em; line-height: 1; color: #000; }
.res-scale { display: flex; align-items: center; gap: 10px; font-family: var(--pixel); font-size: 12px; letter-spacing: .2em; color: #000; }
.res-bar { display: flex; gap: 3px; }
.res-bar i { display: block; width: 26px; height: 8px; }
.res-answer { font-size: clamp(30px, 4vw, 44px); color: #000; }
.res-pts-line { font-size: 28px; color: #000; }
.res-pts-line b { font-family: var(--pixel); font-weight: 700; font-size: 22px; letter-spacing: .1em; color: #000; }
.res-sub { font-size: 24px; color: #000; line-height: 1.1; }
.res-sub b { color: #000; font-weight: normal; }
.btn-next {
  margin-top: 10px; width: min(360px, 100%);
  font-size: 18px; font-weight: 700; letter-spacing: .3em; padding: 14px; color: var(--navy);
  background: var(--cyan); border: 3px solid var(--navy); box-shadow: inset 0 -5px 0 #2fa3c4;
}
.btn-next:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
.btn-next:active { transform: translateY(2px); }

/* ---------- end card ---------- */
.end-card { max-height: 78vh; overflow-y: auto; text-align: center; padding: 18px 22px 18px; }
.end-kicker { font-family: var(--pixel); font-size: 12px; letter-spacing: .3em; color: var(--cyan); }
.end-score { font-family: var(--pixel); font-weight: 700; font-size: 26px; color: #9fb4d6; margin-top: 6px; }
.end-score span { font-family: var(--mono); font-size: clamp(72px, 11vw, 116px); line-height: .9; color: #fff; letter-spacing: 0.04em; text-shadow: 4px 4px 0 rgba(0, 0, 0, 0.45); }
.end-zone { font-family: var(--pixel); font-size: 15px; letter-spacing: .2em; color: #fff; margin-top: 2px; }
.end-rank { font-family: var(--pixel); font-size: 12px; letter-spacing: .3em; color: #ffd38a; margin-top: 6px; }
.end-grid { display: flex; justify-content: center; gap: 6px; margin: 12px 0 8px; }
.end-grid i { display: block; width: 34px; height: 12px; border: 2px solid var(--navy); box-shadow: inset 0 -3px 0 rgba(0,0,0,.25); }
.end-list { list-style: none; text-align: left; margin: 6px 0 14px; }
.end-list li {
  display: grid; grid-template-columns: 1.1fr 1.3fr auto 52px; align-items: center; gap: 10px;
  padding: 6px 0; border-bottom: 2px dashed var(--line); font-size: 22px;
}
.el-q { color: #9fb4d6; }
.el-a { color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.el-a i { color: #66789a; }
.el-p { font-family: var(--pixel); font-size: 13px; text-align: right; color: #fff; }
.end-list .chip { font-size: 10px; padding: 4px 6px 3px; }
.end-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.share-fallback {
  display: block; width: 100%; margin-top: 12px; padding: 8px 10px; resize: none;
  font: 14px/1.4 var(--pixel); color: #fff; background: rgba(12,21,41,.85); border: 2px solid var(--line);
}
.end-foot { font-family: var(--pixel); font-size: 11px; letter-spacing: .25em; color: #9fb4d6; margin-top: 14px; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 30; background: rgba(5,10,25,.6); display: grid; place-items: center; padding: 20px; }
.modal-card {
  width: min(680px, 100%); max-height: 90vh; overflow-y: auto;
  background: var(--navy); border: 3px solid var(--cyan); box-shadow: 0 0 0 3px var(--navy), 0 12px 0 rgba(0,0,0,.4);
  padding: 22px 26px; font-size: 24px; line-height: 1.15; color: #dbe8f8;
}
.modal-card h2 { font-family: var(--pixel); font-size: 22px; letter-spacing: .3em; color: #fff; margin-bottom: 12px; text-shadow: -2px 0 var(--pink), 2px 0 var(--cyan); }
.modal-card h3 { font-family: var(--pixel); font-size: 12px; letter-spacing: .3em; color: var(--cyan); margin: 14px 0 8px; }
.modal-card p { margin-bottom: 10px; }
.modal-card b { color: #fff; font-weight: normal; }
.legend-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.legend { list-style: none; }
.legend li { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 7px; font-size: 22px; }
.legend.zones li { justify-content: flex-start; }
.legend.zones em { margin-left: auto; color: #66789a; font-style: normal; }
.modal-card .btn-primary { margin-top: 16px; }

/* ---------- small screens ---------- */
@media (max-width: 640px) {
  #altbar { right: 12px; width: 8px; }
  .zone-icon { right: 14px; font-size: 13px; }
  .alt-parrot { width: 32px; }
  #alt-readout { font-size: 9px; right: -8px; }
  .panel { width: calc(100vw - 64px); left: 12px; transform: translateY(-50%); padding: 12px 14px 14px; }
  .hud-logo { display: none; }
  .end-list li { grid-template-columns: 1fr auto; font-size: 20px; }
  .end-list .el-q { grid-column: 1 / -1; font-size: 16px; }
  .legend-cols { grid-template-columns: 1fr; gap: 4px; }
  .modal { padding: 12px; }
  .modal-card { max-height: 86vh; padding: 14px 16px; font-size: 18px; line-height: 1.1; }
  .modal-card h2 { font-size: 16px; margin-bottom: 8px; }
  .modal-card h3 { font-size: 10px; margin: 10px 0 6px; }
  .modal-card p { margin-bottom: 7px; }
  .legend li { font-size: 17px; margin-bottom: 4px; }
  .modal-card .btn-primary { margin-top: 10px; padding: 12px 16px 14px; font-size: 16px; }
  .start-actions .row { flex-direction: column; }
}
@media (max-height: 560px) {
  .start { padding-top: 6vh; }
  .start-spacer { min-height: 40px; }
}

/* parrot hover tip in How to Play */
.parrot-tip { position: relative; cursor: help; border-bottom: 2px dotted currentColor; }
.parrot-tip::after {
  content: attr(data-tip); position: absolute; left: 50%; bottom: calc(100% + 6px);
  transform: translateX(-50%); white-space: nowrap; padding: 4px 8px;
  background: #0c1529; color: #fff; border: 2px solid #46b04a; font-size: .85em;
  opacity: 0; pointer-events: none; transition: opacity .12s; z-index: 10;
}
.parrot-tip:hover::after, .parrot-tip:focus::after { opacity: 1; }

/* ---------- start -> first prompt transition ---------- */
.start.leaving { animation: start-out .55s cubic-bezier(.5, 0, .75, 0) forwards; pointer-events: none; }
.start.leaving * { pointer-events: none !important; }
@keyframes start-out { to { transform: translateY(-110vh); } }
.panel.enter { animation: panel-in .65s cubic-bezier(.2, .9, .3, 1.1) both; }
@keyframes panel-in { from { translate: 0 100vh; } to { translate: 0 0; } }
