:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
  background: #080d25;
  color: #f3f7ff;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  min-height: 100%;
  overflow: hidden;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% -20%, #293a78, #080d25 55%);
  touch-action: manipulation;
}

.game-shell {
  position: relative;
  height: min(100vh, calc(100vw * 16 / 9));
  height: min(100dvh, calc(100vw * 16 / 9));
  max-width: 100vw;
  aspect-ratio: 9 / 16;
  overflow: hidden;
  background: #0d1637;
  box-shadow: 0 0 80px #000a;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.layer {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 28px;
  text-align: center;
  background: linear-gradient(#080d25cc, #111d47ee);
  backdrop-filter: blur(8px);
}

.layer[hidden] { display: none; }
.layer.compact { background: #080d2599; }

.language-layer { gap: 14px; }

.mission-terminal {
  justify-content: flex-start;
  align-items: stretch;
  gap: 12px;
  padding: max(20px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
  background:
    linear-gradient(90deg, #ffffff08 1px, transparent 1px) 0 0 / 32px 32px,
    linear-gradient(#ffffff08 1px, transparent 1px) 0 0 / 32px 32px,
    radial-gradient(circle at 80% 0, #24505c, transparent 38%),
    linear-gradient(160deg, #142a36, #07111c 70%);
  overflow: hidden;
}

.terminal-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 12px;
  align-items: start;
  padding-right: 56px;
  text-align: left;
}

.terminal-header h1 {
  margin-top: 6px;
  font-size: clamp(27px, 8vw, 38px);
  line-height: 1;
}

.terminal-header .small-button {
  border: 1px solid #4a6878;
  background: #102531;
}

.mission-grid {
  min-height: 0;
  flex: 1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: minmax(70px, 1fr);
  gap: 8px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 2px;
}

.mission-card {
  position: relative;
  min-width: 0;
  min-height: 70px;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 10px;
  border: 1px solid #355063;
  border-radius: 10px;
  background: linear-gradient(145deg, #19313d, #0b1721);
  color: #edf8ff;
  text-align: left;
  box-shadow: inset 0 0 0 1px #ffffff08, 0 6px 14px #0005;
}

.mission-card:disabled {
  filter: saturate(.25);
  opacity: .48;
}

.mission-card.current {
  border-color: #72f7d4;
  box-shadow: inset 0 0 16px #72f7d41c, 0 0 16px #72f7d424;
}

.mission-number {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid #72f7d4;
  border-radius: 8px;
  color: #72f7d4;
  font: 900 18px/1 ui-monospace, monospace;
}

.mission-meta {
  min-width: 0;
  display: grid;
  gap: 5px;
}

.mission-name {
  overflow: hidden;
  color: #bad0dc;
  font-size: 10px;
  letter-spacing: .05em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mission-stars {
  color: #ffcd75;
  font-size: 15px;
  letter-spacing: .12em;
}

.terminal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.standalone-footer,
.local-note {
  color: #9eb5c1;
  font-size: 12px;
  text-align: center;
}

.standalone-footer a,
.layer > a {
  color: #72e8d1;
}

.terminal-actions button {
  min-width: 0;
  min-height: 48px;
  padding-inline: 8px;
  border: 1px solid #355063;
  border-radius: 10px;
  font-size: 12px;
}

.tutorial-card {
  position: absolute;
  z-index: 8;
  left: 16px;
  right: 16px;
  bottom: max(18px, env(safe-area-inset-bottom));
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 15px;
  border: 1px solid #72f7d4;
  border-radius: 14px;
  background: #07111eef;
  box-shadow: 0 18px 36px #000b, inset 0 0 30px #72f7d414;
  text-align: center;
}

.tutorial-card[hidden] { display: none; }
.tutorial-card h2 { font-size: 18px; }
.tutorial-card p { margin: 0; color: #c2d5de; font-size: 13px; line-height: 1.35; }

.tutorial-animation {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #72f7d4;
  font-size: 25px;
}

.tutorial-animation i {
  position: relative;
  width: 70px;
  height: 2px;
  background: #72f7d455;
}

.tutorial-animation i::after {
  content: '›';
  position: absolute;
  top: -15px;
  left: 0;
  color: #fff;
  font: 900 26px/1 system-ui;
  animation: tutorial-slide 1.3s ease-in-out infinite;
}

.scanner-control {
  position: absolute;
  z-index: 7;
  left: 50%;
  bottom: 106px;
  min-width: 190px;
  min-height: 46px;
  transform: translateX(-50%);
  border: 1px solid #8deaff;
  border-radius: 10px;
  background: #123747e8;
  color: #dff8ff;
}

.results-terminal {
  gap: 13px;
  background: radial-gradient(circle at 50% 18%, #255166, transparent 38%), linear-gradient(#0c202b, #07111cf5);
}

.result-stars {
  color: #ffcd75;
  font-size: 58px;
  line-height: 1;
  letter-spacing: .08em;
  filter: drop-shadow(0 0 12px #ffb45466);
}

.result-stats {
  width: min(280px, 100%);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0;
}

.result-stats div {
  padding: 12px;
  border: 1px solid #355063;
  border-radius: 10px;
  background: #0e1d27;
}

.result-stats dt { color: #86a5b7; font-size: 11px; }
.result-stats dd { margin: 5px 0 0; color: #edf8ff; font: 900 22px/1 ui-monospace, monospace; }

.cosmetics-terminal {
  justify-content: flex-start;
  gap: 12px;
  padding-top: max(34px, env(safe-area-inset-top));
  background: linear-gradient(160deg, #142a36, #07111cf5);
}

.cosmetic-choices {
  width: 100%;
  min-height: 0;
  flex: 1;
  display: grid;
  gap: 8px;
  overflow-y: auto;
}

.cosmetic-option {
  min-width: 0;
  border: 1px solid #355063;
  border-radius: 10px;
  background: #102531;
  color: #edf8ff;
}

.cosmetic-option[aria-pressed="true"] { border-color: #72f7d4; }

.language-layer > button:not(.text-button) {
  width: min(280px, 100%);
  min-height: 56px;
}

.eyebrow {
  margin: 0;
  color: #67f5d6;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .2em;
}

h1 {
  max-width: 300px;
  margin: 0;
  font-size: clamp(34px, 10vw, 54px);
  line-height: .96;
}

h2 {
  margin: 0;
  font-size: 32px;
}

.layer p {
  margin: 0;
  color: #c0cce7;
  font-size: 18px;
}

.tutorial-demo {
  font-size: 52px;
  animation: pulse 1.1s ease-in-out infinite;
}

button {
  min-width: 180px;
  min-height: 50px;
  border: 0;
  border-radius: 16px;
  padding: 12px 18px;
  background: #67f5d6;
  color: #071b1b;
  font: 900 16px/1 system-ui;
  cursor: pointer;
  box-shadow: 0 9px 24px #0005;
}

button.secondary {
  background: #2b3a69;
  color: #eef3ff;
}

button:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.leaderboard-layer {
  justify-content: flex-start;
  align-items: stretch;
  padding: 20px 16px max(18px, env(safe-area-inset-bottom));
  gap: 10px;
}

.leaderboard-header {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  text-align: center;
}

.leaderboard-header h2 { font-size: 27px; }

.small-button {
  min-width: 44px;
  min-height: 44px;
  width: 44px;
  padding: 0;
  background: #24355f;
  color: #fff;
}

.leaderboard-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: #111b3b;
}

.leaderboard-tab {
  min-width: 0;
  min-height: 44px;
  background: transparent;
  color: #9eafd1;
  box-shadow: none;
}

.leaderboard-tab.active {
  background: #2b3e71;
  color: #fff;
}

.status-line { min-height: 20px; font-size: 13px !important; }

.leaderboard-rows {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid #304678;
  border-radius: 15px;
  background: #101936;
}

.leaderboard-row {
  display: grid;
  grid-template-columns: 30px 36px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 50px;
  padding: 7px 10px;
  border-bottom: 1px solid #ffffff12;
  text-align: left;
}

.leaderboard-row img {
  width: 30px;
  height: 22px;
  object-fit: cover;
  border-radius: 3px;
}

.leaderboard-row .avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
}

.leaderboard-row.top-three .rank {
  color: #f4bc52;
  font-weight: 900;
}

.my-rank-row {
  position: sticky;
  bottom: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  padding: 11px;
  border: 1px solid #67f5d6;
  border-radius: 12px;
  background: #173d43;
}

.my-rank-row[hidden] { display: none; }

.leaderboard-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
}

.leaderboard-footer a,
.text-button { color: #aebddd; }

.text-button {
  min-width: 0;
  min-height: 44px;
  padding: 4px;
  background: transparent;
  box-shadow: none;
  font-size: 12px;
}

.country-layer {
  justify-content: flex-start;
  padding: 24px 18px max(18px, env(safe-area-inset-bottom));
}

.country-search {
  width: 100%;
  min-height: 44px;
  border: 1px solid #40598d;
  border-radius: 12px;
  padding: 10px;
  background: #101936;
  color: #fff;
}

.country-rows {
  width: 100%;
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.country-option {
  min-width: 0;
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 9px;
  border: 1px solid #304678;
  border-radius: 12px;
  background: #172446;
  color: #fff;
  text-align: left;
}

.country-option[aria-selected="true"] {
  border-color: #67f5d6;
  background: #173d43;
}

.country-option img { width: 30px; }

.country-edit-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
}

.flag-code {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 22px;
  flex: 0 0 30px;
  border-radius: 3px;
  background: #24355f;
  color: #dce7ff;
  font-size: 11px;
  font-weight: 900;
}
.result-ranking { display: grid; gap: 4px; }
.result-ranking p { font-size: 14px; }

.icon-button {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: 12px;
  z-index: 5;
  min-width: 44px;
  min-height: 44px;
  width: 44px;
  padding: 0;
  border-radius: 50%;
  background: #172653cc;
  color: #fff;
}

.settings-button {
  left: 12px;
  right: auto;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.policy-page {
  display: block;
  min-height: 100%;
  overflow: auto;
  padding: 24px;
}

.policy-card {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 28px;
  border: 1px solid #304678;
  border-radius: 18px;
  background: #101936;
  line-height: 1.65;
}

.policy-card h1 { font-size: clamp(28px, 7vw, 44px); }
.policy-card h2 { margin-top: 28px; font-size: 24px; }
.policy-card a { color: #67f5d6; }
.policy-card hr { margin: 36px 0; border-color: #304678; }

@keyframes pulse {
  50% { transform: translateY(8px); opacity: .65; }
}

@keyframes tutorial-slide {
  50% { left: 52px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}

@media (max-width: 390px) {
  .mission-terminal { padding-inline: 12px; }
  .mission-grid { grid-template-columns: 1fr; }
  .mission-card { min-height: 62px; }
}

@media (max-width: 420px) {
  .country-rows { grid-template-columns: 1fr; }
  .leaderboard-row {
    grid-template-columns: 26px 30px minmax(0, 1fr) auto;
    padding-inline: 7px;
  }
}

@media (min-aspect-ratio: 9/16) {
  .game-shell {
    height: 100vh;
    height: 100dvh;
    width: auto;
  }

  .game-shell::after {
    content: '';
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: env(safe-area-inset-bottom);
    pointer-events: none;
  }
}
