:root {
  color-scheme: dark;
  --bg: #02030a;
  --ink: #f4f7fb;
  --muted: #9aabc2;
  --accent: #ff5c39;
  --panel: rgba(7, 11, 22, 0.9);
  --line: rgba(255, 255, 255, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

body {
  min-height: 100vh;
  min-height: 100svh;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

#stage {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(100vw, calc(100vh * 9 / 16));
  width: min(100vw, calc(100svh * 9 / 16));
  height: min(100vh, calc(100vw * 16 / 9));
  height: min(100svh, calc(100vw * 16 / 9));
  transform: translate(-50%, -50%);
  background: #070b18;
  overflow: hidden;
  container-type: size;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: default;
}

#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: calc(18px + env(safe-area-inset-top)) 16px 0;
  text-align: center;
  pointer-events: none;
  color: var(--ink);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.85);
}

#stage.home #hud {
  left: 31%;
  right: 31%;
}

#profile,
#record {
  position: absolute;
  z-index: 4;
  top: calc(12px + env(safe-area-inset-top));
  max-width: 30%;
  color: var(--ink);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.85);
}

#profile {
  left: 12px;
}

#record {
  right: 12px;
  text-align: right;
  pointer-events: none;
}

#profile[hidden],
#record[hidden],
#nick-dialog[hidden] {
  display: none !important;
}

#nickname {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  margin: 0;
  padding: 2px 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: clamp(11px, 3cqw, 13px);
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.15;
  cursor: pointer;
  touch-action: manipulation;
}

#nickname-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#nickname svg {
  width: 13px;
  height: 13px;
  flex: none;
}

#nickname:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

#record-distance {
  margin: 0;
  font-size: clamp(13px, 3.4cqw, 16px);
  font-weight: 760;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  white-space: nowrap;
}

#record .label {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.12em;
}

#stage.home #hud,
#stage.home #record {
  color: #fff;
  text-shadow:
    0 1px 2px rgba(0, 0, 0, 0.95),
    0 0 3px rgba(0, 0, 0, 0.9),
    1px 0 0 rgba(0, 0, 0, 0.65),
    -1px 0 0 rgba(0, 0, 0, 0.65),
    0 1px 0 rgba(0, 0, 0, 0.65),
    0 -1px 0 rgba(0, 0, 0, 0.65);
}

#stage.home #hud .label,
#stage.home #record .label {
  color: #fff;
  font-weight: 800;
}

#stage.home #record-distance {
  font-size: clamp(15px, 4cqw, 18px);
}

#stage.home #record .label {
  font-size: 11px;
}

#nick-dialog {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + env(safe-area-inset-top)) 24px calc(24px + env(safe-area-inset-bottom));
  background: rgba(2, 4, 10, 0.56);
  touch-action: manipulation;
}

.nick-panel {
  width: min(88%, 340px);
}

#nick-input {
  width: 100%;
  margin-top: 16px;
  min-height: 48px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
  font: inherit;
  font-size: 18px;
  font-weight: 700;
  text-align: center;
  user-select: text;
  -webkit-user-select: text;
}

#nick-input:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

.nick-error {
  margin: 10px 0 0;
  color: #ffb199;
  font-size: 13px;
  font-weight: 700;
}

.nick-error[hidden] {
  display: none !important;
}

.nick-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 18px;
}

#nick-cancel,
#nick-save {
  touch-action: manipulation;
  min-width: 118px;
  min-height: 48px;
  padding: 0 16px;
  border-radius: 999px;
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.14em;
  cursor: pointer;
}

#nick-cancel {
  border: 2px solid var(--line);
  background: transparent;
  color: var(--ink);
}

#nick-save {
  border: 0;
  background: var(--accent);
  color: white;
}

#nick-cancel:focus-visible,
#nick-save:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

#hud .label,
.kicker,
.stats dt {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.22em;
}

#distance {
  margin: 2px 0 0;
  font-size: 28px;
  font-size: 7.2cqw;
  font-weight: 760;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

#flyby {
  position: absolute;
  top: calc(108px + env(safe-area-inset-top));
  left: 0;
  right: 0;
  z-index: 2;
  margin: 0;
  text-align: center;
  pointer-events: none;
  color: var(--ink);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.85);
}

#flyby p {
  margin: 0;
}

#flyby-kicker {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.22em;
}

#flyby-name {
  margin-top: 3px;
  font-size: 18px;
  font-weight: 760;
  letter-spacing: 0.14em;
}

#flyby-distance {
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}

#flyby.gold #flyby-kicker {
  color: #d4b06a;
}

#flyby.story #flyby-kicker {
  color: var(--ink);
  font-size: 15px;
  letter-spacing: 0.12em;
}

#flyby.story #flyby-name {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

#flyby.story #flyby-distance {
  margin-top: 3px;
  letter-spacing: 0.01em;
}

#controls {
  position: absolute;
  z-index: 4;
  left: 16px;
  top: calc(18px + env(safe-area-inset-top) + 14px + 2px + 28px + 10px);
  top: calc(18px + env(safe-area-inset-top) + 14px + 2px + 7.2cqw + 10px);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#sound,
#haptic {
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: rgba(7, 11, 22, 0.45);
  color: var(--ink);
  cursor: pointer;
}

#sound svg,
#haptic svg {
  width: 22px;
  height: 22px;
  display: block;
  margin: 0 auto;
}

#haptic .haptic-off,
#sound .sound-off {
  display: none;
}

#haptic[aria-pressed="false"] .haptic-on {
  display: none;
}

#haptic[aria-pressed="false"] .haptic-off {
  display: block;
}

#sound[aria-pressed="false"] .sound-on {
  display: none;
}

#sound[aria-pressed="false"] .sound-off {
  display: block;
}

#sound:focus-visible,
#haptic:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

#flyby[hidden] {
  display: none !important;
}

#deep-space {
  position: absolute;
  top: calc(108px + env(safe-area-inset-top));
  left: 18px;
  right: 18px;
  z-index: 2;
  margin: 0;
  text-align: center;
  pointer-events: none;
  color: var(--ink);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.85);
}

#deep-space p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.35;
}

#deep-space-title {
  margin-top: 0;
  color: var(--ink);
  font-size: 18px;
  font-weight: 760;
  letter-spacing: 0.12em;
}

#deep-space[hidden] {
  display: none !important;
}

body.banner-inset #stage {
  top: calc((100vh - var(--ad-banner-height)) / 2);
  top: calc((100svh - var(--ad-banner-height)) / 2);
  width: min(100vw, calc((100vh - var(--ad-banner-height)) * 9 / 16));
  width: min(100vw, calc((100svh - var(--ad-banner-height)) * 9 / 16));
  height: min(calc(100vh - var(--ad-banner-height)), calc(100vw * 16 / 9));
  height: min(calc(100svh - var(--ad-banner-height)), calc(100vw * 16 / 9));
}

#overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(2, 4, 10, 0.56);
  touch-action: manipulation;
}

body.banner-inset #overlay {
  overflow: auto;
}

#overlay[hidden] {
  display: none !important;
}

.panel {
  width: min(88%, 380px);
  padding: 28px 22px 18px;
  border-radius: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  text-align: center;
  color: var(--ink);
}

.kicker {
  color: var(--accent);
}

h1 {
  margin: 8px 0 0;
  font-size: 30px;
  font-size: 7.2cqw;
  line-height: 1.05;
  letter-spacing: 0.08em;
  font-weight: 800;
}

.banner {
  display: inline-block;
  margin: 14px 0 0;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 92, 57, 0.16);
  color: #ffb199;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.banner[hidden] {
  display: none !important;
}

.stats {
  margin: 22px 0 8px;
}

.stats div + div {
  margin-top: 14px;
}

.stats dd {
  margin: 4px 0 0;
  font-size: 22px;
  font-size: 5cqw;
  font-weight: 760;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
}

#launch {
  position: absolute;
  left: 50%;
  top: 34%;
  z-index: 2;
  transform: translate(-50%, -50%);
  min-width: 220px;
  min-height: 68px;
  padding: 0 36px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: white;
  font: inherit;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.18em;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
}

#launch[hidden] {
  display: none !important;
}

#launch:hover {
  filter: brightness(1.06);
}

#launch:active {
  transform: translate(-50%, -50%) scale(0.98);
}

#launch:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

#continue,
#restart,
#leaderboards-ended {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

#continue[hidden],
#restart[hidden],
#leaderboards-ended[hidden] {
  display: none !important;
}

.btn-icon {
  width: 28px;
  height: 28px;
  flex: none;
  object-fit: contain;
}

#continue {
  touch-action: manipulation;
  margin-top: 22px;
  min-width: 210px;
  min-height: 54px;
  padding: 0 22px;
  border: 2px solid #e6d089;
  border-radius: 999px;
  background: #f4e3a6;
  color: #2c2416;
  font: inherit;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.14em;
  cursor: pointer;
}

#continue:hover {
  filter: brightness(1.06);
}

#continue:active {
  transform: scale(0.98);
}

#continue:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

#continue:disabled {
  opacity: 0.55;
  cursor: default;
}

.repair-copy {
  margin: 10px 0 0;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.repair-ad {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.04em;
}

.repair-status {
  margin: 8px 0 0;
  color: #ffb199;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

#restart {
  touch-action: manipulation;
  margin-top: 12px;
  min-width: 210px;
  min-height: 54px;
  padding: 0 22px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: white;
  font: inherit;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.14em;
  cursor: pointer;
}

#restart:hover {
  filter: brightness(1.06);
}

#restart:active {
  transform: scale(0.98);
}

#restart:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

.credit {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
}

.rank-line {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.rank-line:empty {
  display: none;
}

#score-retry {
  touch-action: manipulation;
  margin-top: 8px;
  min-height: 36px;
  padding: 0 16px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
  cursor: pointer;
}

#score-retry[hidden] {
  display: none !important;
}

#score-retry:focus-visible,
#leaderboards:focus-visible,
#leaderboards-ended:focus-visible,
#boards-back:focus-visible,
#board-retry:focus-visible,
.board-tabs button:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

#leaderboards {
  position: absolute;
  left: 50%;
  top: calc(34% + 78px);
  z-index: 2;
  transform: translate(-50%, -50%);
  min-width: 220px;
  min-height: 48px;
  padding: 0 22px;
  border: 2px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  background: rgba(7, 11, 22, 0.55);
  color: white;
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.14em;
  cursor: pointer;
  touch-action: manipulation;
}

#leaderboards[hidden] {
  display: none !important;
}

#leaderboards:active {
  transform: translate(-50%, -50%) scale(0.98);
}

#leaderboards-ended {
  touch-action: manipulation;
  margin-top: 12px;
  min-width: 210px;
  min-height: 46px;
  padding: 0 16px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  cursor: pointer;
}

#leaderboards-ended .btn-icon {
  width: 24px;
  height: 24px;
}

#leaderboards-ended:active,
#boards-back:active,
#board-retry:active,
.board-tabs button:active {
  transform: scale(0.98);
}

#overlay {
  overflow: auto;
}

.panel {
  max-height: 100%;
}

#boards {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: calc(12px + env(safe-area-inset-top)) 14px calc(14px + env(safe-area-inset-bottom));
  background: #070b18;
  color: var(--ink);
  touch-action: manipulation;
}

#boards[hidden] {
  display: none !important;
}

.board-head {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}

#boards-back {
  justify-self: start;
  touch-action: manipulation;
  min-height: 40px;
  padding: 0 14px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.12em;
  cursor: pointer;
}

.boards-title {
  margin: 0;
  text-align: center;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.board-head::after {
  content: "";
}

.board-tabs {
  display: flex;
  gap: 8px;
}

.board-tabs button {
  flex: 1;
  min-height: 40px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.12em;
  cursor: pointer;
  touch-action: manipulation;
}

.board-tabs button[aria-selected="true"] {
  border-color: transparent;
  background: var(--accent);
  color: white;
}

#board-reset {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-align: center;
}

#board-reset[hidden] {
  display: none !important;
}

#board-countdown {
  font-variant-numeric: tabular-nums;
}

#board-status {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

#board-status:empty,
#board-status:has(#board-message:empty):not(:has(#board-spinner:not([hidden]))):not(:has(#board-retry:not([hidden]))) {
  display: none;
}

#board-message {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  text-align: center;
}

#board-message:empty {
  display: none;
}

#board-retry {
  touch-action: manipulation;
  min-height: 40px;
  padding: 0 18px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.12em;
  cursor: pointer;
}

#board-retry[hidden],
#board-spinner[hidden],
#board-me[hidden] {
  display: none !important;
}

.board-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: board-spin 0.8s linear infinite;
}

@keyframes board-spin {
  to {
    transform: rotate(360deg);
  }
}

#board-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: auto;
  flex: 1;
  min-height: 0;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

.board-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 8px 6px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.board-row.mine {
  background: rgba(255, 92, 57, 0.18);
  border-radius: 8px;
}

.board-rank,
.board-km {
  font-weight: 760;
}

.board-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}

#board-me {
  margin: 0;
  padding: 10px 6px;
  border-top: 1px solid var(--line);
  background: rgba(255, 92, 57, 0.18);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 760;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

#shot-panel {
  position: absolute;
  left: 50%;
  bottom: calc(10px + env(safe-area-inset-bottom));
  z-index: 8;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: min(92%, 420px);
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(7, 11, 22, 0.94);
  color: var(--ink);
  pointer-events: auto;
}

#shot-panel[hidden] {
  display: none !important;
}

.shot-status,
.shot-field {
  grid-column: 1 / -1;
}

.shot-status {
  margin: 0;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-align: center;
}

.shot-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

#shot-dest,
#shot-panel button {
  min-height: 44px;
  border-radius: 999px;
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.06em;
}

#shot-dest {
  padding: 0 12px;
  border: 1px solid var(--line);
  background: #10182a;
  color: var(--ink);
}

#shot-panel button {
  border: 0;
  background: var(--accent);
  color: white;
  cursor: pointer;
}

#shot-hide {
  grid-column: 1 / -1;
  background: transparent;
  border: 2px solid var(--line);
}
