:root {
  color-scheme: dark;
  font-family: system-ui, sans-serif;
  --bg: #05070d;
  --panel: #0d1220;
  --border: #1e2840;
  --text: #d8deea;
  --muted: #7d889e;
  --accent: #6fb3ff;
  --error: #ff6b6b;
  --crystal: #7df9ff;
  --locked: #ffb84d;
  /* Safe areas: Discord's insets, or the browser's own (needs viewport-fit=cover). */
  --sait: var(--discord-safe-area-inset-top, env(safe-area-inset-top, 0px));
  --saib: var(--discord-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
  --sail: var(--discord-safe-area-inset-left, env(safe-area-inset-left, 0px));
  --sair: var(--discord-safe-area-inset-right, env(safe-area-inset-right, 0px));
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

input,
button {
  font: inherit;
  padding: 0.5rem 0.75rem;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
}

button {
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

button.primary {
  background: #16304f;
  border-color: var(--accent);
  font-weight: 600;
}

button.danger {
  border-color: var(--error);
}

h2 {
  margin: 0 0 0.25rem;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.muted,
.player {
  color: var(--muted);
}

.status {
  margin: 0;
  color: var(--error);
}

.loading {
  margin-top: 4rem;
  text-align: center;
  color: var(--muted);
}

/* Sign-in views from webapp-client, centered on the page. */
.webapp-login,
.webapp-status,
.webapp-error {
  max-width: 24rem;
  margin: 4rem auto 0;
  padding: 0 1rem;
}

.webapp-login {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.webapp-status {
  color: var(--muted);
}

.webapp-error {
  color: var(--error);
}

/* Status screen (status.rs): the status, the week's top 10 (week.rs, once
   shown: `.with-week`) and how to play (help.rs). Stacked on narrow screens;
   side by side once the help can be at least ~28rem wide (narrower, its
   ability rows wrap). With the week panel, status and week share a row and
   the help goes below, until all three fit. */
.status-screen {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
  gap: 2rem;
  max-width: 64rem;
  margin: 0 auto;
  padding: calc(2rem + var(--sait)) calc(1rem + var(--sair)) calc(2rem + var(--saib))
    calc(1rem + var(--sail));
}

@media (min-width: 56rem) {
  .status-screen {
    grid-template-columns: minmax(0, 24rem) minmax(0, 1fr);
  }
}

@media (min-width: 48rem) {
  .status-screen.with-week {
    grid-template-columns: minmax(0, 24rem) minmax(0, 22rem);
    justify-content: center;
  }

  .status-screen.with-week .help {
    grid-column: 1 / -1;
  }
}

@media (min-width: 80rem) {
  .status-screen.with-week {
    grid-template-columns: minmax(0, 24rem) minmax(0, 20rem) minmax(28rem, 1fr);
    max-width: 84rem;
  }

  .status-screen.with-week .help {
    grid-column: auto;
  }
}

.status-main {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.status-screen h1 {
  margin: 0;
  font-size: 1.5rem;
  color: var(--accent);
}

.status-screen p {
  margin: 0;
}

.your-ship {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.your-ship img {
  width: 48px;
  height: 48px;
  filter: drop-shadow(0 0 3px rgba(170, 210, 255, 0.6)) drop-shadow(0 0 8px rgba(111, 179, 255, 0.35));
}

.status-screen .sign-out {
  align-self: flex-start;
}

.score {
  display: flex;
  gap: 2.5rem;
}

.score-value {
  display: block;
  font-size: 2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.score-label {
  font-size: 0.85rem;
  color: var(--muted);
}

/* Under the score: week score, or the runs still needed for one. */
.status-screen .week-note {
  margin-top: -0.5rem;
  font-size: 0.85rem;
}

.runs {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  list-style: none;
  font-variant-numeric: tabular-nums;
}

.runs li {
  display: flex;
  justify-content: space-between;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--border);
}

.runs li.abandoned span:first-child {
  color: var(--locked);
}

/* The week's top 10 (week.rs). */
.week {
  padding: 1rem 1.25rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.week-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin: 0.25rem 0 0.75rem;
  font-weight: 600;
}

.week-nav button {
  padding: 0.15rem 0.6rem;
  line-height: 1.2;
}

.week-nav button:disabled {
  cursor: default;
  opacity: 0.35;
  border-color: var(--border);
}

.week-list {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  list-style: none;
  font-variant-numeric: tabular-nums;
}

.week-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.35rem;
  border-bottom: 1px solid var(--border);
}

.week-list li.you {
  background: #16304f;
  border-radius: 4px;
}

.week-list .rank {
  width: 1.5rem;
  text-align: right;
  color: var(--muted);
}

.week-list img {
  width: 24px;
  height: 24px;
}

/* Long display names are cut off rather than widening the panel. */
.week-list .name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.week-list .week-score {
  font-weight: 600;
}

/* How to play (help.rs). */
.help {
  padding: 1rem 1.25rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  line-height: 1.45;
}

.help h3 {
  margin: 1rem 0 0.25rem;
  font-size: 1rem;
  color: var(--accent);
}

.help h3:first-child {
  margin-top: 0;
}

.status-screen .help p {
  margin: 0 0 0.5rem;
}

.help .icon {
  vertical-align: middle;
}

.help ul {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0 0 0.5rem;
  padding: 0;
  list-style: none;
}

.help li {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.help-keys li {
  flex-wrap: nowrap;
}

.help-keys .icon {
  flex: none;
}

/* Wide enough for eight icons and the arrow (Fast Jump 2), so the names line
   up; only Super Jump is longer. */
.help-icons {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  min-width: calc(8 * 22px + 8 * 3px + 1em + 4px);
}

.help-icons img {
  width: 22px;
  height: 22px;
}

.help-icons .arrow {
  width: 1em;
  margin: 0 2px;
  text-align: center;
  color: var(--muted);
}

/* Run screen (panel.rs): info panel (1/3) + hex grid (2/3). */
.game {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
  height: 100dvh;
  padding: var(--sait) var(--sair) var(--saib) var(--sail);
}

.info {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  padding: 12px;
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--border);
}

.head {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.countdown {
  font-size: 1.6rem;
  font-weight: 700;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.urgent {
  color: var(--error);
}

.stats {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-variant-numeric: tabular-nums;
}

.stats-end {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* Mute toggle (sound.rs). */
button.sound {
  padding: 0 4px;
  line-height: 1;
  background: none;
  border-color: transparent;
}

button.sound:hover {
  border-color: var(--accent);
}

.crystals {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--crystal);
}

.icon {
  width: 1.4em;
  height: 1.4em;
}

.ship-note {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--locked);
}

.storage {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  max-width: 16rem;
}

.slot {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border: 1px solid var(--border);
  border-radius: 4px;
}

.slot img {
  width: 85%;
  height: 85%;
}

/* Abilities: the use button, and the move button in an aligned column. */
.abilities {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
}

.ability {
  display: flex;
  align-items: center;
  gap: 3px;
  min-height: 44px;
  padding: 0 8px;
  overflow: hidden;
  white-space: nowrap;
  background: #111a2e;
}

.ability img {
  width: 22px;
  height: 22px;
  /* Long effects (super jump has 11 icons) shrink rather than clip their move. */
  min-width: 12px;
  object-fit: contain;
}

.ability.move {
  justify-content: center;
  min-width: 44px;
}

.ability .arrow {
  margin: 0 2px;
  color: var(--muted);
}

.ability[disabled] {
  opacity: 0.4;
  cursor: default;
}

.ability[disabled]:hover {
  border-color: var(--border);
}

.ability.selected {
  background: #16304f;
  border-color: var(--accent);
}

.ability.queued {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.abandon.full {
  margin-top: auto;
}

.abandon.compact {
  display: none;
}

.confirm {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.grid {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  padding: 8px;
}

.grid-note {
  position: absolute;
  color: var(--muted);
}

/* The tiny-window overlay (countdown and crystals), hidden until then. */
.overlay {
  display: none;
  position: absolute;
  top: 4px;
  left: 6px;
  font-size: 0.85rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 3px #000;
  pointer-events: none;
}

/* Hex grid (grid.rs). */
.hex-grid {
  display: block;
  width: 100%;
  height: 100%;
}

.hex polygon {
  fill: var(--panel);
  stroke: var(--border);
  stroke-width: 0.5;
}

.hex.off-map polygon {
  fill: none;
  stroke-opacity: 0.3;
}

.hex.locked polygon {
  stroke: var(--locked);
  stroke-dasharray: 2 1;
}

/* The player's own hex, under their ship. Before the actionable and queued
   styles, so those still show on it. */
.hex.own polygon {
  fill: #1a2c44;
  stroke: var(--accent);
  stroke-width: 0.8;
}

.hex.actionable {
  cursor: pointer;
}

.hex.actionable polygon {
  stroke: var(--muted);
}

.hex.actionable:hover polygon {
  stroke: var(--accent);
}

.hex.queued polygon {
  fill: #16304f;
  stroke: var(--accent);
  stroke-width: 1;
}

.hex .item,
.hex .ship,
.hex text,
.hex circle {
  pointer-events: none;
}

/* The ship sprites are dark: a faint glow lifts them off the grid. */
.hex .ship {
  filter: drop-shadow(0 0 1px rgba(170, 210, 255, 0.6)) drop-shadow(0 0 2.5px rgba(111, 179, 255, 0.35));
}

.hex.locked .item {
  opacity: 0.4;
}

.countdown-label {
  font-size: 6px;
  font-weight: 700;
  fill: var(--locked);
  text-anchor: middle;
  dominant-baseline: central;
}

/* The "2" on a hex holding a pair, outlined to read over the sprite. */
.pair-label {
  font-size: 5px;
  font-weight: 700;
  fill: #fff;
  stroke: #000;
  stroke-width: 1px;
  paint-order: stroke;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

/* Scanner ring: slot outlines and crystal markers beyond the view. */
.ring-slot {
  fill: none;
  stroke: var(--border);
  stroke-width: 0.4;
  stroke-dasharray: 1.5 1.5;
}

.scan {
  cursor: pointer;
}

.scan polygon {
  fill: #08202a;
  stroke: var(--crystal);
  stroke-width: 0.9;
}

.scan.locked polygon {
  fill: #241a08;
  stroke: var(--locked);
  stroke-dasharray: 2 1;
}

.scan:hover polygon {
  stroke-width: 1.6;
}

.scan text {
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

.scan .num {
  font-size: 7px;
  fill: var(--crystal);
}

.scan.locked .num {
  fill: var(--locked);
}

.scan-badge circle {
  fill: var(--locked);
  stroke: var(--bg);
  stroke-width: 0.5;
}

.scan-badge.stack circle {
  fill: #e0e6f0;
}

.scan-badge text {
  font-size: 4.6px;
  fill: #000;
}

.scan-tip {
  position: fixed;
  z-index: 10;
  padding: 4px 8px;
  font-size: 12px;
  white-space: nowrap;
  background: #000c;
  border: 1px solid var(--border);
  border-radius: 4px;
  pointer-events: none;
}

/* Short landscape (Discord phones, small windows): a compact panel, and the
   grid column keeps the view's own aspect ratio (about 1.14). */
@media (max-height: 520px) and (min-aspect-ratio: 5/4) {
  .game {
    grid-template-columns: minmax(0, 1fr) min(calc((100dvh - var(--sait) - var(--saib)) * 1.14), 62vw);
  }
}

/* Portrait (mobile web held upright): the grid on top, the compact panel below. */
@media (max-aspect-ratio: 1/1) {
  .game {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: min(calc((100vw - var(--sail) - var(--sair)) / 1.14), 58dvh) minmax(0, 1fr);
  }

  .grid {
    grid-row: 1;
    padding: 4px;
  }

  .info {
    grid-row: 2;
    border-right: 0;
    border-top: 1px solid var(--border);
  }

  .storage {
    max-width: none;
  }
}

/* The compact panel, for both layouts above. */
@media (max-height: 520px) and (min-aspect-ratio: 5/4), (max-aspect-ratio: 1/1) {
  .info {
    gap: 8px;
    padding: 8px 10px;
  }

  .head {
    flex-direction: row;
    align-items: center;
    gap: 12px;
  }

  .countdown {
    min-width: 2.5ch;
    font-size: 1.4rem;
  }

  .stats {
    flex: 1;
    justify-content: flex-start;
    gap: 12px;
  }

  .storage {
    grid-template-columns: repeat(12, 1fr);
    gap: 3px;
  }

  .ability {
    min-height: 38px;
  }

  .ability img {
    width: 20px;
    height: 20px;
  }

  .abandon.full {
    display: none;
  }

  .abandon.compact {
    display: block;
    margin-left: auto;
  }

  .abandon.compact button {
    padding: 2px 6px;
    font-size: 0.8rem;
  }
}

@media (max-height: 520px) and (min-aspect-ratio: 5/4) {
  .storage {
    max-width: 24rem;
  }
}

/* Tiny windows (Discord picture-in-picture, grid tiles): the grid only, with
   a countdown and crystal overlay. A glance view, so no badges. */
@media (max-height: 300px) {
  .game {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
  }

  .info {
    display: none;
  }

  .grid {
    grid-row: auto;
    padding: 2px;
  }

  .overlay {
    display: block;
  }

  .scan-badge {
    display: none;
  }
}
