:root {
  --bg: #05070f;
  --text: #e8eaf2;
  --muted: #94a3b8;
  --kiro: #9d5cff;
  --kiro-soft: #c9b1ff;
  --cyan: #22d3ee;
  --orange: #ff9900;
  --pink: #ff4f9a;
  --lime: #a3e635;
  --sky: #60a5fa;
  --violet: #a78bfa;
  --green: #4ade80;
  --danger: #ff5c7a;
  --glass: rgba(14, 18, 38, 0.55);
  --border: rgba(255, 255, 255, 0.1);
  --font: "Segoe UI Variable Display", "Segoe UI", "SF Pro Display", -apple-system, system-ui, sans-serif;
  --mono: "Cascadia Code", "SF Mono", "JetBrains Mono", Consolas, ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  position: fixed;
  inset: 0;
  touch-action: none;
}

canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

/* ---------- HUD ---------- */

.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(14px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  pointer-events: none;
  transition: transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* Upside-down regions put the floor at the top of the screen: sit the HUD just below it. */
#app[data-flipped="true"] .hud { transform: translateY(calc(var(--floor-h, 46px) - 6px)); }

.brand,
.pill,
.icon-btn {
  background: var(--glass);
  border: 1px solid var(--border);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px 7px 10px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.brand img {
  width: 18px;
  height: auto;
  filter: drop-shadow(0 0 6px rgba(157, 92, 255, 0.9));
}

.brand-region {
  padding-left: 10px;
  border-left: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
}

.score {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  font-size: clamp(44px, 9vh, 84px);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(180deg, #ffffff 0%, #e2d6ff 55%, #a78bfa 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 22px rgba(157, 92, 255, 0.55));
  transition: opacity 0.3s ease;
}

.score.bump { animation: bump 0.28s ease-out; }

@keyframes bump {
  0% { transform: translateX(-50%) scale(1); }
  40% { transform: translateX(-50%) scale(1.18); }
  100% { transform: translateX(-50%) scale(1); }
}

#app[data-state="ready"] .score { opacity: 0; }

.hud-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}

.pill {
  display: flex;
  align-items: baseline;
  gap: 8px;
  height: 40px;
  padding: 0 14px;
  border-radius: 12px;
  line-height: 40px;
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.pill-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 12px;
  color: var(--text);
  cursor: pointer;
  transition: background 0.2s ease, transform 0.1s ease, opacity 0.2s ease;
}

.icon-btn:hover { background: rgba(157, 92, 255, 0.28); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn:focus-visible { outline: 2px solid var(--kiro); outline-offset: 2px; }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn .icon-off { display: none; }
.icon-btn.muted .icon-on { display: none; }
.icon-btn.muted .icon-off { display: block; }

#app:not([data-state="playing"]):not([data-state="paused"]) #pauseBtn {
  opacity: 0.35;
  pointer-events: none;
}

/* ---------- Toast ---------- */

.toast {
  position: absolute;
  top: 24%;
  left: 50%;
  z-index: 2;
  padding: 10px 18px;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(157, 92, 255, 0.35), rgba(255, 153, 0, 0.25));
  border: 1px solid rgba(255, 255, 255, 0.18);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  width: max-content;
  max-width: calc(100vw - 32px);
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 8px);
  pointer-events: none;
}

.toast.show { animation: toast 2.2s ease forwards; }

@keyframes toast {
  0% { opacity: 0; transform: translate(-50%, 8px); }
  12% { opacity: 1; transform: translate(-50%, 0); }
  80% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -8px); }
}

/* ---------- Overlays ---------- */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  /* Centred with auto margins rather than place-items, so a panel taller than the screen
     scrolls from its top instead of being cut off at both ends. */
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y; /* #app blocks touch gestures for the game; panels may still scroll */
  padding: 24px;
  background: radial-gradient(ellipse at center, rgba(5, 7, 15, 0.2), rgba(5, 7, 15, 0.7));
  transition: opacity 0.35s ease, visibility 0.35s ease;
}

.overlay.instant,
.overlay.instant .panel { transition: none; }

.overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.overlay > .panel { margin: auto; }

.panel {
  position: relative;
  width: min(460px, 100%);
  padding: 32px 32px 26px;
  border-radius: 24px;
  text-align: center;
  background: linear-gradient(160deg, rgba(34, 26, 70, 0.72), rgba(10, 14, 30, 0.78));
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5), 0 0 70px rgba(157, 92, 255, 0.16);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  backdrop-filter: blur(18px) saturate(140%);
  cursor: default;
  transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.panel::before {
  content: "";
  position: absolute;
  inset: 0;
  padding: 1px;
  border-radius: inherit;
  background: linear-gradient(135deg, rgba(201, 177, 255, 0.75), rgba(34, 211, 238, 0.2) 45%, rgba(255, 153, 0, 0.55));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

.panel-sm { width: min(340px, 100%); }

.overlay.hidden .panel { transform: translateY(14px) scale(0.97); }

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--kiro-soft);
}

.eyebrow-danger { color: #ff9fb2; }

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 10px var(--cyan);
  animation: pulse 1.6s ease-in-out infinite;
}

.dot-red { background: var(--danger); box-shadow: 0 0 10px var(--danger); }
.dot-green { background: var(--green); box-shadow: 0 0 10px var(--green); }

/* Leaderboard status dot on the Leaderboard buttons: amber while checking, green when the
   shared leaderboard is connected, red when scores are only being kept in this browser. */
.board-btn .board-dot { flex: none; background: var(--orange); box-shadow: 0 0 10px var(--orange); }
.board-btn[data-board-status="shared"] .board-dot { background: var(--green); box-shadow: 0 0 10px var(--green); }
.board-btn[data-board-status="local"] .board-dot { background: var(--danger); box-shadow: 0 0 10px var(--danger); }
.dot-amber { background: var(--orange); box-shadow: 0 0 10px var(--orange); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

h1, h2 {
  margin: 12px 0 10px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.05;
  background: linear-gradient(100deg, #ffffff 0%, #d8c6ff 40%, #ffb86b 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

h1 { font-size: clamp(42px, 9vw, 62px); }
h2 { font-size: clamp(32px, 7vw, 44px); }

#startTitle { margin: 0 0 12px; }

.byline {
  margin: 8px 0 18px;
  font-size: 13px;
  color: var(--muted);
}

.byline-foot { margin: 20px 0 0; font-size: 12px; }

.byline strong {
  font-weight: 600;
  color: var(--kiro-soft);
}

.tagline {
  margin: 0 auto 22px;
  max-width: 340px;
  font-size: 15px;
  line-height: 1.5;
  color: var(--muted);
}

kbd {
  display: inline-block;
  min-width: 22px;
  padding: 2px 7px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-bottom-width: 2px;
  background: rgba(255, 255, 255, 0.07);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-width: 200px;
  padding: 14px 26px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(135deg, #b07cff 0%, #7c3aed 55%, #5b21b6 100%);
  box-shadow: 0 10px 30px rgba(124, 58, 237, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.3);
  color: #fff;
  font-family: var(--font);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

.btn-primary:hover { filter: brightness(1.1); box-shadow: 0 14px 38px rgba(124, 58, 237, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.3); }
.btn-primary:active { transform: scale(0.97); }
.btn-primary:focus-visible { outline: 2px solid var(--kiro-soft); outline-offset: 3px; }
.btn-primary kbd { background: rgba(0, 0, 0, 0.2); border-color: rgba(255, 255, 255, 0.3); }

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 18px;
  margin: 22px 0 0;
  padding: 0;
  list-style: none;
  font-size: 12px;
  color: var(--muted);
}

.controls li { display: flex; align-items: center; gap: 7px; }

/* The full screen tip under the key list on the main menu */
.fs-note {
  margin: 12px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.fs-note kbd { margin: 0 3px; }

.best-line {
  margin: 18px 0 0;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}

.best-line strong { color: var(--text); }

/* Learning tip on the game-over panel */
.tip {
  margin: -6px 0 18px;
  padding: 12px 14px 13px;
  border-radius: 12px;
  border: 1px solid rgba(34, 211, 238, 0.3);
  background: linear-gradient(160deg, rgba(34, 211, 238, 0.1), rgba(34, 211, 238, 0.02) 70%);
  text-align: left;
}

.tip[hidden] { display: none; }

.tip-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.tip-badge {
  flex: none;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid rgba(34, 211, 238, 0.4);
  background: rgba(34, 211, 238, 0.12);
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #a5f3fc;
}

.tip-title {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text);
}

.tip-text {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.5;
  color: #cbd5e1;
}

.tip[data-kind="kiro"] {
  border-color: rgba(157, 92, 255, 0.4);
  background: linear-gradient(160deg, rgba(157, 92, 255, 0.16), rgba(157, 92, 255, 0.03) 70%);
}

.tip[data-kind="kiro"] .tip-badge {
  border-color: rgba(201, 177, 255, 0.45);
  background: rgba(157, 92, 255, 0.18);
  color: var(--kiro-soft);
}

/* ---------- Recovery quiz ---------- */

.quiz-panel { width: min(520px, 100%); text-align: left; }
.quiz-panel .eyebrow { display: flex; justify-content: center; }
.quiz-panel h2 { margin: 10px 0 14px; font-size: clamp(28px, 6vw, 36px); text-align: center; }
.quiz-panel .cause { margin-bottom: 12px; }

.quiz-stakes {
  margin: 0 0 14px;
  font-size: 13px;
  text-align: center;
  color: var(--muted);
}

.quiz-stakes strong { color: var(--text); }

/* Countdown from 60: a bar that drains, with the seconds beside it. */
.quiz-timer {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 16px;
}

.quiz-timer[hidden] { display: none; }

.quiz-timer-bar {
  flex: 1;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

.quiz-timer-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--cyan), var(--kiro));
  transform-origin: left center;
  transition: background 0.3s ease;
}

.quiz-timer-num {
  min-width: 34px;
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 800;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.quiz-timer[data-level="mid"] .quiz-timer-bar span { background: linear-gradient(90deg, var(--orange), #ffb86b); }
.quiz-timer[data-level="mid"] .quiz-timer-num { color: #ffd29a; }
.quiz-timer[data-level="low"] .quiz-timer-bar span { background: linear-gradient(90deg, var(--danger), #ff9fb2); }
.quiz-timer[data-level="low"] .quiz-timer-num { color: #ff9fb2; animation: pulse 1s ease-in-out infinite; }

.quiz-q {
  margin: 0 0 12px;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.35;
  color: var(--text);
}

.quiz-options {
  display: grid;
  gap: 8px;
  margin: 0 0 14px;
}

.quiz-option {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border: 1px solid rgba(201, 177, 255, 0.24);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.3;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.2s ease, transform 0.1s ease;
}

.quiz-option kbd { flex: none; }
.quiz-option:hover:not(:disabled) { border-color: rgba(201, 177, 255, 0.6); background: rgba(157, 92, 255, 0.16); }
.quiz-option:active:not(:disabled) { transform: scale(0.99); }
.quiz-option:focus-visible { outline: 2px solid var(--kiro-soft); outline-offset: 2px; }
.quiz-option:disabled { cursor: default; }

/* For a moment after the question appears, answers ignore input (no accidental taps). */
.quiz-options.arming .quiz-option { opacity: 0.55; pointer-events: none; }

.quiz-option.correct {
  border-color: rgba(74, 222, 128, 0.7);
  background: rgba(74, 222, 128, 0.14);
  box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.12);
}

.quiz-option.correct kbd { border-color: rgba(74, 222, 128, 0.7); color: #bbf7d0; }

.quiz-option.wrong {
  border-color: rgba(255, 92, 122, 0.7);
  background: rgba(255, 92, 122, 0.14);
}

.quiz-option.wrong kbd { border-color: rgba(255, 92, 122, 0.7); color: #ff9fb2; }
.quiz-option.dim { opacity: 0.45; }

.quiz-explain { margin: 0 0 14px; }
.quiz-explain[data-verdict="right"] .tip-badge { border-color: rgba(74, 222, 128, 0.6); background: rgba(74, 222, 128, 0.14); color: #bbf7d0; }
.quiz-explain[data-verdict="wrong"] .tip-badge { border-color: rgba(255, 92, 122, 0.6); background: rgba(255, 92, 122, 0.14); color: #ff9fb2; }

.quiz-panel #quizNext { display: flex; width: 100%; }
.quiz-panel #quizNext[hidden] { display: none; }

.quiz-hint {
  margin: 0;
  font-size: 12px;
  text-align: center;
  color: var(--muted);
}

.quiz-hint[hidden] { display: none; }

/* Give up on the question: end the run now instead of waiting out the clock. */
.quiz-panel #quizEnd {
  display: flex;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-top: 14px;
  border-color: rgba(255, 92, 122, 0.35);
  color: #ffc2cd;
}
.quiz-panel #quizEnd:hover { background: rgba(255, 92, 122, 0.14); border-color: rgba(255, 92, 122, 0.6); }
.quiz-panel #quizEnd:disabled { opacity: 0.5; pointer-events: none; }
.quiz-panel #quizEnd[hidden] { display: none; }

/* 3-2-1 before a recovered run carries on */
.countdown {
  position: absolute;
  top: 34%;
  left: 50%;
  z-index: 2;
  transform: translate(-50%, -50%);
  font-family: var(--mono);
  font-size: clamp(72px, 16vw, 120px);
  font-weight: 800;
  line-height: 1;
  color: #fff;
  text-shadow: 0 0 30px rgba(157, 92, 255, 0.8), 0 0 60px rgba(34, 211, 238, 0.4);
  pointer-events: none;
}

.countdown[hidden] { display: none; }
.countdown.tick { animation: count-tick 0.9s ease-out; }

@keyframes count-tick {
  from { opacity: 0; transform: translate(-50%, -50%) scale(1.6); }
  25% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  to { opacity: 0.85; transform: translate(-50%, -50%) scale(0.92); }
}

.cause {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0 18px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 92, 122, 0.28);
  background: rgba(255, 92, 122, 0.08);
  font-family: var(--mono);
  font-size: 12.5px;
  text-align: left;
  color: #ffc2cd;
}

.cause-tag {
  flex: none;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(255, 92, 122, 0.25);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: #ffd6de;
}

.new-best {
  display: none;
  margin: -6px auto 16px;
  width: max-content;
  padding: 5px 12px;
  border-radius: 999px;
  background: linear-gradient(135deg, #ffb347, #ff7a00);
  box-shadow: 0 6px 20px rgba(255, 153, 0, 0.35);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #1a1206;
}

.new-best.show { display: block; animation: pop 0.5s cubic-bezier(0.2, 1.6, 0.4, 1); }

@keyframes pop {
  0% { transform: scale(0.6); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 24px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 8px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
}

.stat-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat-value {
  font-size: 26px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* ---------- Leaderboard and name capture ---------- */

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.actions .btn-primary { min-width: 180px; }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 13px 20px;
  border-radius: 14px;
  border: 1px solid rgba(201, 177, 255, 0.28);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.12s ease;
}

.btn-ghost:hover { background: rgba(157, 92, 255, 0.18); border-color: rgba(201, 177, 255, 0.5); }
.btn-ghost:active { transform: scale(0.97); }
.btn-ghost:focus-visible { outline: 2px solid var(--kiro-soft); outline-offset: 3px; }

#boardBtnStart { margin-top: 18px; padding: 9px 16px; font-size: 13px; }
.btn-small { margin-top: 14px; padding: 9px 16px; font-size: 13px; }

/* ---------- Main menu: region tiles ---------- */

/* The incident report's two ways on, one above the other at the same width: Redeploy, then back
   to the main menu to change region. */
.deploy-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.deploy-row .btn-primary,
.deploy-row .btn-ghost { width: min(280px, 100%); min-width: 0; }

.btn-icon {
  flex: none;
  width: 18px;
  height: 18px;
  color: var(--cyan);
  filter: drop-shadow(0 0 6px rgba(34, 211, 238, 0.6));
}

/* Start screen: the two steps as cards with a dashed edge, like the Region and VPC boxes in the
   diagram behind. Step 1 holds the region tiles and step 2 the Deploy button, with an arrow from
   one down to the other. */
#startScreen .panel { width: min(720px, 100%); }
#startScreen .tagline { max-width: 520px; margin-bottom: 18px; }

.deploy-steps {
  display: grid;
  row-gap: 18px;
  text-align: left;
}

.deploy-steps .step {
  position: relative;
  display: grid;
  row-gap: 10px;
  padding: 12px;
  border: 1px dashed rgba(201, 177, 255, 0.38);
  border-radius: 16px;
  background: linear-gradient(160deg, rgba(157, 92, 255, 0.1), rgba(5, 7, 15, 0.28) 70%);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

/* The step you are working in lights up: hovering, or a tile or the button focused. */
.deploy-steps .step:hover,
.deploy-steps .step:focus-within {
  border-color: rgba(201, 177, 255, 0.7);
  background: linear-gradient(160deg, rgba(157, 92, 255, 0.16), rgba(5, 7, 15, 0.28) 70%);
  box-shadow: 0 0 0 3px rgba(157, 92, 255, 0.1), 0 10px 30px rgba(0, 0, 0, 0.25);
}

/* Deploy, or Space, before a region is chosen: step 1 gives a shake and a glow. */
#step1.nudge { animation: nudge 0.6s ease; }

@keyframes nudge {
  0%, 100% { transform: none; }
  15% { transform: translateX(-6px); border-color: var(--kiro-soft); box-shadow: 0 0 0 4px rgba(157, 92, 255, 0.35), 0 0 34px rgba(157, 92, 255, 0.35); }
  35% { transform: translateX(5px); }
  55% { transform: translateX(-3px); }
  75% { transform: translateX(2px); border-color: var(--kiro-soft); box-shadow: 0 0 0 4px rgba(157, 92, 255, 0.2); }
}

@keyframes nudge-glow {
  15%, 75% { border-color: var(--kiro-soft); box-shadow: 0 0 0 4px rgba(157, 92, 255, 0.35), 0 0 34px rgba(157, 92, 255, 0.35); }
}

/* Step 2: its label beside the Deploy button. */
#step2 {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 14px;
}

#step2 .btn-primary { min-width: 190px; }

/* The arrow from step 1 down to step 2: a small round badge on the gap between the cards, with
   a chevron pointing at step 2. */
#step2::before,
#step2::after {
  content: "";
  position: absolute;
  left: 50%;
  pointer-events: none;
}

#step2::before {
  top: -21px;
  width: 22px;
  height: 22px;
  margin-left: -11px;
  border: 1px solid rgba(201, 177, 255, 0.45);
  border-radius: 50%;
  background: #120d2a;
  box-shadow: 0 0 12px rgba(157, 92, 255, 0.35);
}

#step2::after {
  top: -13px;
  width: 6px;
  height: 6px;
  margin-left: -3px;
  border-top: 2px solid var(--kiro-soft);
  border-right: 2px solid var(--kiro-soft);
  transform: rotate(135deg);
}

.step-label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0;
  /* Sized by its column, not by its text, so a long label wraps instead of widening it. */
  width: 0;
  min-width: 100%;
}

.step-num {
  flex: none;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  margin-top: 1px;
  border-radius: 50%;
  border: 1px solid rgba(201, 177, 255, 0.5);
  background: rgba(157, 92, 255, 0.2);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  color: var(--kiro-soft);
}

.step-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  line-height: 1.2;
}

.step-text strong { font-size: 13px; font-weight: 700; color: var(--text); }
.step-text span { font-size: 11.5px; color: var(--muted); }

/* Deploy before a region is chosen: grey and flat. aria-disabled rather than disabled, so the
   button still takes a click (which points at the tiles) and stays in the tab order. */
.btn-primary[aria-disabled="true"],
.btn-primary[aria-disabled="true"]:hover {
  background: linear-gradient(135deg, rgba(148, 163, 184, 0.3), rgba(71, 85, 105, 0.36));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  color: rgba(226, 232, 240, 0.5);
  filter: none;
  cursor: not-allowed;
}

.btn-primary[aria-disabled="true"]:active { transform: none; }
.btn-primary[aria-disabled="true"] kbd { opacity: 0.55; }

/* ... and a small pop as it turns purple. */
#startBtn[aria-disabled="false"] { animation: deploy-ready 0.45s cubic-bezier(0.2, 1.4, 0.4, 1); }

@keyframes deploy-ready {
  0% { transform: scale(0.94); box-shadow: 0 0 0 0 rgba(176, 124, 255, 0.7), 0 10px 30px rgba(124, 58, 237, 0.45); }
  60% { transform: scale(1.03); box-shadow: 0 0 0 10px rgba(176, 124, 255, 0), 0 10px 30px rgba(124, 58, 237, 0.45); }
  100% { transform: none; }
}

.region-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

/* A region tile: its live preview on top, its name and region below. Each level has its accent:
   the colour as an RGB triple, so it can be used at any opacity, and a light tint for text. */
.region-tile {
  --accent: 34, 211, 238;
  --accent-text: #a5f3fc;
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(var(--accent), 0.3);
  border-radius: 14px;
  background: linear-gradient(160deg, rgba(var(--accent), 0.1), rgba(5, 7, 15, 0.6) 70%);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.region-tile[data-theme="crew"] { --accent: 255, 79, 154; --accent-text: #ffc2dc; }
.region-tile[data-theme="dark"] { --accent: 163, 230, 53; --accent-text: #d9f99d; }
.region-tile[data-theme="wind"] { --accent: 96, 165, 250; --accent-text: #bfdbfe; }
.region-tile[data-theme="flipped"] { --accent: 255, 153, 0; --accent-text: #ffd29a; }
.region-tile[data-theme="snow"] { --accent: 226, 232, 240; --accent-text: #f8fafc; }
.region-tile[data-theme="deja"] { --accent: 167, 139, 250; --accent-text: #ddd6fe; }

.region-tile:hover {
  transform: translateY(-2px);
  border-color: rgba(var(--accent), 0.7);
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(var(--accent), 0.25);
}

.region-tile:active { transform: scale(0.985); }

.region-tile:focus-visible {
  outline: 2px solid rgb(var(--accent));
  outline-offset: 3px;
}

.region-tile[aria-checked="true"] {
  border-color: rgb(var(--accent));
  box-shadow: 0 0 0 2px rgba(var(--accent), 0.6), 0 0 28px rgba(var(--accent), 0.35);
}

/* Once a region is chosen the others step back a little, until hovered or focused. */
.region-grid.has-choice .region-tile[aria-checked="false"] { opacity: 0.68; }
.region-grid.has-choice .region-tile[aria-checked="false"]:hover,
.region-grid.has-choice .region-tile[aria-checked="false"]:focus-visible { opacity: 1; }

.tile-view {
  position: relative;
  display: block;
  aspect-ratio: 16 / 9;
  background: #05070f;
}

.tile-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  cursor: inherit;
}

/* The tick on the chosen tile */
.tile-check {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 22px;
  height: 22px;
  padding: 4px;
  border-radius: 50%;
  background: rgb(var(--accent));
  color: #05070f;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
  opacity: 0;
  transform: scale(0.5);
  transition: opacity 0.18s ease, transform 0.28s cubic-bezier(0.2, 1.6, 0.4, 1);
}

.region-tile[aria-checked="true"] .tile-check { opacity: 1; transform: none; }

.tile-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: 7px 10px 8px;
}

.tile-name {
  font-size: 13.5px;
  font-weight: 700;
  line-height: 1.15;
}

/* One line, so every tile is the same height. A location too long for a narrow tile is cut short
   with an ellipsis; the full name is in the tile's accessible name. */
.tile-city {
  overflow: hidden;
  font-size: 11px;
  line-height: 1.25;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--muted);
}

/* The region code on the preview's top-left corner, like the Region label on an AWS diagram */
.tile-code {
  position: absolute;
  top: 6px;
  left: 6px;
  padding: 1px 5px;
  border: 1px solid rgba(var(--accent), 0.45);
  border-radius: 5px;
  background: rgba(5, 7, 15, 0.74);
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--accent-text);
  pointer-events: none;
}

/* Shorter screens, such as a 1366 by 768 laptop: a tighter menu, so the tiles and Deploy fit
   without scrolling. */
@media (max-height: 820px) and (min-width: 561px) {
  #startScreen .panel { padding-top: 22px; padding-bottom: 20px; }
  #startTitle { font-size: 46px; margin-bottom: 4px; }
  #startScreen .tagline { margin-bottom: 12px; }
  .tile-text { padding: 6px 10px 7px; }
  #startScreen .controls { margin-top: 14px; }
  #startScreen .best-line { margin-top: 10px; }
  #boardBtnStart { margin-top: 10px; }
  #startScreen .byline-foot { margin-top: 12px; }
}

/* Lives indicator in the HUD (Kiro Crew only) */
.lives {
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  border-color: rgba(255, 79, 154, 0.35);
}

.lives[hidden] { display: none; } /* .pill sets display: flex, which would override hidden */

.lives img {
  width: 16px;
  height: auto;
  filter: drop-shadow(0 0 5px rgba(201, 177, 255, 0.9));
  transition: opacity 0.25s ease, transform 0.25s ease, filter 0.25s ease;
}

.lives img.lost {
  opacity: 0.22;
  transform: scale(0.8);
  filter: grayscale(1);
}

.lives img[hidden] { display: none; }

.rank-line {
  min-height: 18px;
  margin: -12px 0 14px;
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 600;
  color: #ffc98a;
}

.player-line {
  margin: 16px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}

.player-line strong { color: var(--text); font-weight: 600; }

.link-btn {
  margin-left: 4px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--kiro-soft);
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.name-score {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  margin: 0 0 20px;
  font-size: 44px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.name-score small {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.field-label {
  display: block;
  margin-bottom: 8px;
  text-align: left;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.field {
  width: 100%;
  padding: 13px 14px;
  border-radius: 12px;
  border: 1px solid rgba(201, 177, 255, 0.3);
  background: rgba(5, 7, 15, 0.55);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  font-weight: 600;
  -webkit-user-select: text;
  user-select: text;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.field:focus {
  outline: none;
  border-color: var(--kiro);
  box-shadow: 0 0 0 3px rgba(157, 92, 255, 0.25);
}

.field::placeholder { color: rgba(148, 163, 184, 0.55); }

.field-hint {
  min-height: 16px;
  margin: 8px 0 20px;
  text-align: left;
  font-size: 12px;
  color: var(--muted);
}

.board {
  margin: 4px 0 14px;
  padding: 0;
  list-style: none;
  text-align: left;
}

.board li {
  display: grid;
  /* Fixed region and score columns, so they line up from row to row */
  grid-template-columns: 34px minmax(0, 1fr) 112px 48px;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 12px;
  font-size: 15px;
}

.board li:nth-child(odd) { background: rgba(255, 255, 255, 0.035); }

.board li.me {
  background: linear-gradient(90deg, rgba(157, 92, 255, 0.28), rgba(157, 92, 255, 0.06));
  box-shadow: inset 0 0 0 1px rgba(201, 177, 255, 0.35);
}

.board .rank {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

.board li:nth-child(1) .rank { color: #ffd166; }
.board li:nth-child(2) .rank { color: #d9e2ec; }
.board li:nth-child(3) .rank { color: #e8a26a; }

.board .who {
  overflow: hidden;
  font-weight: 600;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.board .who small {
  margin-left: 8px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
}

/* Region the player's best score was set in, coloured like its level in the region picker.
   Empty for scores saved before regions were recorded. */
.board .where {
  justify-self: start;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}

.board .where[data-theme] {
  padding: 4px 8px;
  border: 1px solid rgba(34, 211, 238, 0.4);
  border-radius: 999px;
  background: rgba(34, 211, 238, 0.1);
  color: #a5f3fc;
}

.board .where[data-theme="crew"] {
  border-color: rgba(255, 79, 154, 0.45);
  background: rgba(255, 79, 154, 0.12);
  color: #ffc2dc;
}

.board .where[data-theme="dark"] {
  border-color: rgba(163, 230, 53, 0.4);
  background: rgba(163, 230, 53, 0.1);
  color: #d9f99d;
}

.board .where[data-theme="wind"] {
  border-color: rgba(96, 165, 250, 0.45);
  background: rgba(96, 165, 250, 0.12);
  color: #bfdbfe;
}

.board .where[data-theme="snow"] {
  border-color: rgba(226, 232, 240, 0.45);
  background: rgba(226, 232, 240, 0.12);
  color: #f8fafc;
}

.board .where[data-theme="flipped"] {
  border-color: rgba(255, 153, 0, 0.45);
  background: rgba(255, 153, 0, 0.12);
  color: #ffd29a;
}

.board .where[data-theme="deja"] {
  border-color: rgba(167, 139, 250, 0.45);
  background: rgba(167, 139, 250, 0.12);
  color: #ddd6fe;
}

.board .pts {
  text-align: right;
  font-size: 17px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.board-empty,
.board-note {
  margin: 0 0 18px;
  font-size: 12.5px;
  color: var(--muted);
}

.board-note:empty { display: none; }

@media (max-width: 560px) {
  .brand-name, .brand-region { display: none; }
  .brand { padding: 9px; }
  .panel { padding: 26px 20px 22px; }
  .deploy-row .btn-primary,
  .deploy-row .btn-ghost { width: 100%; }
  /* Two columns of region tiles, and the Deploy button full width under its label. */
  .region-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .tile-view { aspect-ratio: 4 / 3; } /* narrow tiles: a taller preview, so Kiro is not a dot */
  .tile-text { padding: 6px 8px 7px; }
  .tile-name { font-size: 13px; }
  .deploy-steps .step { padding: 10px; }
  #step2 { grid-template-columns: minmax(0, 1fr); row-gap: 10px; }
  #step2 .btn-primary { width: 100%; min-width: 0; }
  /* Narrow boards put the region under the name, so names keep their width */
  .board li { grid-template-columns: 34px minmax(0, 1fr) 48px; row-gap: 0; }
  .board .rank { grid-row: 1 / span 2; }
  .board .who { grid-column: 2; grid-row: 1; }
  .board .where { grid-column: 2; grid-row: 2; margin-top: 5px; }
  .board .where:empty { display: none; }
  .board li:has(.where:empty) .rank,
  .board li:has(.where:empty) .pts { grid-row: 1; }
  .board .pts { grid-column: 3; grid-row: 1 / span 2; }
  .score {
    top: calc(max(14px, env(safe-area-inset-top)) + 58px);
    font-size: 52px;
  }
}

/* The tiles fill a phone screen, or a short landscape one, so step 2 stays in reach at the
   bottom while they scroll under it. */
@media (max-width: 560px), (max-height: 600px) {
  #step2,
  #step2:hover,
  #step2:focus-within {
    position: sticky;
    bottom: max(10px, env(safe-area-inset-bottom));
    z-index: 2;
    background: linear-gradient(160deg, #1d1642, #0c1024 75%);
    box-shadow: 0 -12px 28px rgba(5, 7, 15, 0.75);
  }
  /* Held at the bottom, step 2 sits over the tiles, so the arrow between the steps goes. */
  #step2::before,
  #step2::after { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .dot, .score.bump, .toast.show, .new-best.show, .countdown.tick, .quiz-timer-num { animation-duration: 0.01s; }
  .hud, .region-tile, .tile-check { transition: none; }
  .region-tile:hover { transform: none; }
  #startBtn[aria-disabled="false"] { animation: none; }
  #step1.nudge { animation-name: nudge-glow; } /* a glow, without the shake */
}
