/* ===== Terminal Confusion ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0b1026;
  --bg2: #141a3a;
  --card: #1a2148;
  --ink: #eef1ff;
  --muted: #9aa3cf;
  --accent: #ffb703;
  --accent2: #4cc9f0;
  --good: #43d17c;
  --bad: #ef476f;
  --ring: #3a4480;
  --flap: #10142e;
}

html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  min-height: 100vh;
  min-height: 100dvh;
  /* Map-room background: graticule grid + flight paths + waypoints + vignette */
  background-color: var(--bg);
  background-image:
    radial-gradient(120% 100% at 50% 0%, rgba(76, 201, 240, 0.07) 0%, rgba(11, 16, 38, 0) 55%),
    repeating-linear-gradient(0deg, rgba(76, 201, 240, 0.045) 0 1px, transparent 1px 90px),
    repeating-linear-gradient(90deg, rgba(76, 201, 240, 0.045) 0 1px, transparent 1px 90px),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1400' height='900'%3E%3Cg fill='none' stroke='%234cc9f0' stroke-opacity='0.13' stroke-width='2' stroke-dasharray='2 14' stroke-linecap='round'%3E%3Cpath d='M-60,640 Q340,180 760,330 T1460,140'/%3E%3Cpath d='M-60,180 Q420,520 860,380 T1460,640'/%3E%3Cpath d='M120,960 Q520,600 940,700 T1500,430'/%3E%3C/g%3E%3Cg fill='%23ffb703' fill-opacity='0.22'%3E%3Ccircle cx='340' cy='356' r='4'/%3E%3Ccircle cx='760' cy='330' r='4'/%3E%3Ccircle cx='1010' cy='247' r='4'/%3E%3Ccircle cx='420' cy='468' r='4'/%3E%3Ccircle cx='860' cy='380' r='4'/%3E%3Ccircle cx='940' cy='700' r='4'/%3E%3C/g%3E%3Cg fill='%23eef1ff' fill-opacity='0.16'%3E%3Cpath d='M760,330 l34,-9 -12,7 26,9 -8,5 -28,-7 -16,12 -1,-8 5,-9z'/%3E%3Cpath d='M420,468 l-30,12 11,-9 -24,-6 8,-6 25,4 13,-14 2,8 -5,11z'/%3E%3C/g%3E%3Cg stroke='%23ffb703' stroke-opacity='0.10' stroke-width='4' stroke-dasharray='26 20'%3E%3Cline x1='60' y1='60' x2='60' y2='840'/%3E%3Cline x1='1340' y1='60' x2='1340' y2='840'/%3E%3C/g%3E%3C/svg%3E");
  background-attachment: fixed;
  background-size: auto, auto, auto, cover;
}

.hidden { display: none !important; }

.screen {
  max-width: 760px;
  margin: 0 auto;
  padding: 28px 18px calc(48px + env(safe-area-inset-bottom));
  text-align: center;
}

/* ===== Split-flap departure-board title ===== */
.title.flap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
}
.flap-word { display: flex; gap: 4px; flex-wrap: nowrap; }
.flap-word span {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-weight: 800;
  font-size: clamp(1.35rem, 6.2vw, 2.6rem);
  line-height: 1.55;
  width: 1.32em;
  color: var(--ink);
  background: linear-gradient(180deg, #232a55 0%, #191f45 48%, var(--flap) 52%, #0d1129 100%);
  border: 1px solid #2b3364;
  border-radius: 0.14em;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.45);
  position: relative;
}
.flap-word span::after {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 50%;
  height: 1px;
  background: rgba(0, 0, 0, 0.55);
}
.flap-word.amber span { color: var(--accent); }

.title.small {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.8rem, 5vw, 2.4rem);
  margin-top: 16px;
}

.tagline {
  color: var(--muted);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  margin: 16px 0 26px;
}

.challenge-banner {
  background: linear-gradient(90deg, #2a1d5c, #1d2f5c);
  border: 1px solid var(--ring);
  border-radius: 12px;
  padding: 12px 16px;
  margin: 0 auto 24px;
  max-width: 520px;
  font-size: 0.95rem;
}
.challenge-banner strong { color: var(--accent); }

/* ===== Mode cards (boarding passes) ===== */
.mode-cards {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 34px;
}
.mode-card {
  background: linear-gradient(160deg, #1e2653 0%, var(--card) 60%);
  border: 2px solid var(--ring);
  border-radius: 20px;
  color: var(--ink);
  padding: 34px 26px 28px;
  width: 300px;
  min-height: 260px;
  justify-content: center;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  transition: transform 0.15s, border-color 0.15s;
  font: inherit;
  position: relative;
  overflow: hidden;
}
/* boarding-pass perforation edge */
.mode-card::before {
  content: "";
  position: absolute;
  top: 0; bottom: 0; left: 14px;
  border-left: 2px dashed rgba(154, 163, 207, 0.35);
}
.mode-card:hover { transform: translateY(-3px); border-color: var(--accent); }
.mode-emoji { font-size: 3.8rem; line-height: 1; }
.mode-name { font-weight: 700; font-size: 1.35rem; }
.mode-sub { color: var(--ink); font-size: 1.05rem; }
.mode-hint { color: var(--muted); font-size: 0.88rem; }
.mode-card select {
  font: inherit;
  font-size: 1.05rem;
  background: var(--bg2);
  color: var(--ink);
  border: 1px solid var(--ring);
  border-radius: 8px;
  padding: 6px 8px;
  max-width: 100%;
  cursor: pointer;
}

.howto {
  text-align: left;
  background: rgba(20, 26, 58, 0.75);
  border: 1px solid var(--ring);
  border-radius: 14px;
  padding: 14px 18px;
  max-width: 500px;
  margin: 0 auto;
}
.howto h2 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 1.5px; color: var(--muted); margin-bottom: 8px; }
.howto li { margin: 6px 0 6px 4px; list-style: none; color: #cdd3f5; font-size: 0.85rem; }

/* ===== Game HUD ===== */
.hud {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin-bottom: 8px;
}
.hud-item {
  background: rgba(26, 33, 72, 0.9);
  border: 1px solid var(--ring);
  border-radius: 12px;
  padding: 8px 18px;
  min-width: 92px;
}
.hud-label { display: block; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted); margin-bottom: 4px; }
.hud-score.dropping .flap-digits span { animation: pulse 0.4s; }
@keyframes pulse { 50% { transform: scale(1.15); color: var(--bad); } }

/* ===== Split-flap scoreboard digits (same family as the title board) ===== */
.flap-digits {
  display: inline-flex;
  gap: 3px;
  justify-content: center;
  perspective: 300px;
}
.flap-digits span {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-weight: 800;
  font-size: 1.55rem;
  line-height: 1.5;
  width: 1.3em;
  text-align: center;
  color: var(--ink);
  background: linear-gradient(180deg, #232a55 0%, #191f45 48%, var(--flap) 52%, #0d1129 100%);
  border: 1px solid #2b3364;
  border-radius: 4px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.45);
  position: relative;
  backface-visibility: hidden;
}
.flap-digits span::after {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 50%;
  height: 1px;
  background: rgba(0, 0, 0, 0.55);
}
.hud-score .flap-digits span { color: var(--accent); }
.flap-digits.xl span { font-size: clamp(2.8rem, 10vw, 4rem); border-radius: 10px; color: var(--accent); }
@keyframes flapflip {
  0% { transform: rotateX(-90deg); filter: brightness(0.55); }
  100% { transform: rotateX(0deg); filter: brightness(1); }
}
.flap-digits span.flip { animation: flapflip 0.32s ease-out both; }

/* ===== Compass ===== */
#compass-wrap { margin: 0 auto; max-width: 640px; }
#compass { width: 100%; height: auto; display: block; }

.clue-group { opacity: 0; animation: fadein 0.6s forwards; }
@keyframes fadein { to { opacity: 1; } }
.hint-line { opacity: 0; animation: fadein 0.5s forwards; }

/* ===== Buttons ===== */
.actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 6px;
}
.big-btn {
  font: inherit;
  font-size: 1.08rem;
  font-weight: 700;
  background: var(--accent);
  color: #1a1200;
  border: none;
  border-radius: 14px;
  padding: 14px 30px;
  cursor: pointer;
  transition: transform 0.12s, filter 0.12s;
}
.big-btn small { font-weight: 600; opacity: 0.75; font-size: 0.82em; }
.big-btn:hover:not(:disabled) { transform: translateY(-2px); filter: brightness(1.08); }
.big-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.big-btn.ghost { background: rgba(26, 33, 72, 0.9); color: var(--ink); border: 2px solid var(--accent2); }

/* ===== Flying −20 penalty ===== */
.fly-penalty {
  position: fixed;
  z-index: 100;
  transform: translate(-50%, -50%) scale(0.3);
  opacity: 0;
  font-size: 3.4rem;
  font-weight: 900;
  color: var(--bad);
  text-shadow: 0 0 18px rgba(239, 71, 111, 0.8), 0 2px 10px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  will-change: transform, opacity;
}
.fly-penalty.pop {
  transition: transform 0.3s cubic-bezier(0.2, 1.6, 0.4, 1), opacity 0.2s;
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
}
.fly-penalty.fly {
  transition: transform 0.65s cubic-bezier(0.55, -0.15, 0.75, 0.5), opacity 0.65s;
  opacity: 0.25;
}

/* ===== Overlays / modals ===== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 24, 0.82);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 18px;
}
.modal {
  background: var(--card);
  border: 1px solid var(--ring);
  border-radius: 18px;
  padding: 26px 24px;
  width: 100%;
  max-width: 440px;
  text-align: center;
}
.modal h2 { margin-bottom: 6px; }
.modal-sub { color: var(--muted); font-size: 0.88rem; margin-bottom: 16px; }

#guess-input {
  width: 100%;
  font: inherit;
  font-size: 1.05rem; /* ≥16px so iOS doesn't zoom the page on focus */
  padding: 12px 14px;
  border-radius: 10px;
  border: 2px solid var(--ring);
  background: var(--bg2);
  color: var(--ink);
  outline: none;
}
#guess-input:focus { border-color: var(--accent2); }

#suggestions { list-style: none; margin: 8px 0 14px; text-align: left; max-height: 220px; overflow-y: auto; }
#suggestions li {
  padding: 11px 12px; /* comfy touch targets */
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.95rem;
}
#suggestions li .code { color: var(--accent2); font-weight: 700; font-family: ui-monospace, Menlo, monospace; }
#suggestions li:hover, #suggestions li.active { background: rgba(76, 201, 240, 0.15); }
#suggestions li.selected { background: rgba(255, 183, 3, 0.2); outline: 1px solid var(--accent); }

/* ===== Reveal ===== */
.reveal-emoji { font-size: 3rem; }
.reveal-answer { margin: 10px 0 4px; font-size: 1.1rem; }
.reveal-answer strong { color: var(--accent2); }
.reveal-points { color: var(--muted); margin-bottom: 18px; }
.reveal-points strong { color: var(--accent); font-size: 1.2rem; }

/* ===== End screen ===== */
.final-score {
  font-size: clamp(2.6rem, 9vw, 4rem);
  font-weight: 800;
  color: var(--accent);
  margin: 6px 0 2px;
}
.final-score small { font-size: 0.4em; color: var(--muted); font-weight: 600; }

.breakdown {
  list-style: none;
  max-width: 480px;
  margin: 22px auto;
  text-align: left;
  background: rgba(20, 26, 58, 0.7);
  border: 1px solid var(--ring);
  border-radius: 14px;
  padding: 6px 4px;
}
.breakdown li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  font-size: 0.98rem;
}
.breakdown li:last-child { border-bottom: none; }
.breakdown .code { font-family: ui-monospace, Menlo, monospace; color: var(--accent2); font-weight: 700; min-width: 46px; }
.breakdown .pts { margin-left: auto; font-weight: 700; }
.breakdown .pts.zero { color: var(--bad); }
.breakdown .pts.scored { color: var(--good); }

.end-actions { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.share-feedback { color: var(--good); margin-top: 12px; min-height: 1.2em; font-size: 0.9rem; word-break: break-all; }
#share-preview {
  display: block;
  width: min(300px, 85%);
  margin: 14px auto 0;
  border-radius: 14px;
  border: 1px solid var(--ring);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

/* ===== SVG styles ===== */
.compass-ring { fill: none; stroke: var(--ring); stroke-width: 2; }
.compass-radar { fill: none; stroke: var(--ring); stroke-width: 1; opacity: 0.35; stroke-dasharray: 4 8; }
.compass-tick { stroke: var(--ring); stroke-width: 2; }
.compass-dir { fill: var(--muted); font-size: 20px; font-weight: 700; }
.center-circle { fill: var(--card); stroke: var(--accent); stroke-width: 3; }
.center-q { fill: var(--accent); font-size: 52px; font-weight: 800; }
.center-sub { fill: var(--muted); font-size: 15px; }
.clue-arrow { stroke: var(--accent2); stroke-width: 3.5; fill: none; }
.clue-head { fill: var(--accent2); }
.clue-code { fill: var(--ink); font-size: 24px; font-weight: 800; font-family: ui-monospace, Menlo, monospace; }
.clue-city { fill: var(--accent); font-size: 17px; font-weight: 600; }
.clue-dist { fill: var(--muted); font-size: 15px; }

/* ===== Mobile ===== */
@media (max-width: 560px) {
  .screen { padding: 14px 12px calc(36px + env(safe-area-inset-bottom)); }
  .hud { gap: 8px; }
  .hud-item { min-width: 0; flex: 1; max-width: 140px; padding: 6px 8px; }
  .hud-item .flap-digits span { font-size: 1.25rem; }
  .mode-cards { flex-direction: column; align-items: stretch; }
  .mode-card { width: 100%; }
  .actions { flex-direction: column; align-items: stretch; }
  .actions .big-btn { width: 100%; padding: 15px 20px; }
  .end-actions .big-btn { flex: 1; padding: 14px 16px; }
  .howto { padding: 14px 16px; }
  .flap-word { gap: 3px; }
}
