/* Landfall
 *
 * One file, no framework, no build step - the same bargain the rest of the
 * box makes. Cyan rather than the gallery's amber and the arena's amber, so
 * a glance tells you which game you are looking at before you read a word.
 *
 * Every text pair here clears 4.5:1 against the surface it sits on. The
 * muted grey is #94a3b8 and not the #64748b that looked better and failed.
 */

:root {
  --bg: #070a11;
  --panel: #101725;
  --panel-hi: #16203180;
  --line: #22304a;
  --ink: #e8eef8;
  --dim: #94a3b8;
  --cyan: #2ad4d4;
  --cyan-dim: #14595c;
  --warn: #f0a020;
  --bad: #f05c8a;
  --radius: 14px;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  /* The board is a fixed viewport; nothing on this page ever scrolls, and a
   * rubber-band scroll on iOS during a turn reads as the game dropping the
   * input. */
  overscroll-behavior: none;
  touch-action: none;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  height: 100%;
  /* Not 100vh: mobile browsers count the address bar in vh, so the bottom
   * of the HUD would sit under it until the user scrolled. */
  height: 100dvh;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 3px solid var(--cyan);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ------------------------------- board ------------------------------- */
#view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: var(--bg);
  /* Crisp cell edges when the territory layer is scaled up. */
  image-rendering: pixelated;
}

/* -------------------------------- HUD -------------------------------- */
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  padding: max(10px, env(safe-area-inset-top))
           max(10px, env(safe-area-inset-right))
           max(10px, env(safe-area-inset-bottom))
           max(10px, env(safe-area-inset-left));
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 10px;
}
#hud[hidden] { display: none; }

.hud-top {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.pill {
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
  padding: 6px 12px;
  background: #0d1420cc;
  border: 1px solid var(--line);
  border-radius: 999px;
  backdrop-filter: blur(6px);
  font-variant-numeric: tabular-nums;
  font-size: 0.86rem;
}
.pill-k { color: var(--dim); font-size: 0.76rem; letter-spacing: 0.04em;
          text-transform: uppercase; }
.pill strong { font-weight: 700; }

.pill-btn {
  pointer-events: auto;
  color: var(--ink);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  margin-left: auto;
}
.pill-btn:hover { border-color: var(--bad); color: var(--bad); }

/* Under a minute left, the clock earns some attention. */
#clockwrap.urgent { border-color: var(--warn); }
#clockwrap.urgent strong { color: var(--warn); }

/* ---------------------------- standings ---------------------------- */
#lead {
  list-style: none;
  margin: 0;
  padding: 0;
  align-self: start;
  justify-self: end;
  display: grid;
  gap: 4px;
  width: min(232px, 42vw);
}

#lead li {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 5px 9px;
  background: #0d1420cc;
  border: 1px solid var(--line);
  border-left-width: 3px;
  border-radius: 8px;
  font-size: 0.8rem;
  backdrop-filter: blur(6px);
  /* The bar behind the row IS the territory share - so the leaderboard is
   * also the chart, and there is no second thing to keep in sync. */
  background-image: linear-gradient(to right,
    var(--share-c, transparent) var(--share, 0%),
    transparent var(--share, 0%));
}
#lead li.me { border-color: var(--ink); }
#lead li.dead { opacity: 0.45; }
#lead .dot { width: 10px; height: 10px; border-radius: 3px; }
#lead .who {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#lead .who .bot {
  color: var(--dim);
  font-size: 0.72rem;
  margin-left: 4px;
}
#lead .pct { font-variant-numeric: tabular-nums; color: var(--dim); }
#lead li.me .pct { color: var(--ink); }

/* ----------------------------- bottom ----------------------------- */
.hud-bottom {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
}

.stats { display: flex; gap: 8px; }
.stat {
  display: flex;
  flex-direction: column;
  padding: 6px 12px;
  background: #0d1420cc;
  border: 1px solid var(--line);
  border-radius: 10px;
  backdrop-filter: blur(6px);
  min-width: 78px;
}
.stat-k {
  color: var(--dim);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.stat strong { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.stat-sub { color: var(--dim); font-size: 0.8rem; font-weight: 400; }
/* The trail counter turns as it approaches the class limit, because that
 * number going bad is the one thing that kills you with no warning. */
.stat.warm strong { color: var(--warn); }
.stat.hot strong { color: var(--bad); }

#mini {
  width: 132px;
  height: 132px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0a0f18cc;
  image-rendering: pixelated;
  backdrop-filter: blur(6px);
}

/* ----------------------------- ability ----------------------------- */
#abil {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + 156px);
  pointer-events: auto;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  border: 1px solid var(--cyan-dim);
  background: #0d1420e0;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  display: grid;
  place-items: center;
  grid-template-areas: "a";
  backdrop-filter: blur(6px);
  transition: transform 90ms ease, border-color 160ms ease;
}
#abil > * { grid-area: a; }
#abil:active { transform: scale(0.94); }
#abil.ready {
  border-color: var(--cyan);
  box-shadow: 0 0 0 1px #2ad4d440, 0 0 22px #2ad4d440;
}
#abil.live {
  border-color: var(--warn);
  box-shadow: 0 0 0 1px #f0a02050, 0 0 26px #f0a02060;
}
#abil-glyph {
  font-size: 1.5rem;
  transform: translateY(-9px);
  filter: drop-shadow(0 0 6px #2ad4d4aa);
}
#abil-label {
  transform: translateY(16px);
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--dim);
}
#abil.ready #abil-label, #abil.live #abil-label { color: var(--ink); }
#abil-cd {
  transform: translateY(1px);
  font-size: 1.15rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--dim);
}
/* Conic sweep for the cooldown: --p is written from JS, 0 to 1. */
#abil-ring {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: conic-gradient(var(--cyan) calc(var(--p, 0) * 360deg),
                             transparent 0);
  opacity: 0.16;
}

/* ---------------------------- thumb pad ---------------------------- */
#touch { display: none; }

/* Coarse pointer AND no hover: a touchscreen laptop keeps its keyboard. */
@media (hover: none) and (pointer: coarse) {
  #touch {
    display: grid;
    position: fixed;
    left: max(14px, env(safe-area-inset-left));
    bottom: calc(max(14px, env(safe-area-inset-bottom)) + 8px);
    width: 168px;
    height: 168px;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 5px;
    pointer-events: auto;
  }
  #touch button {
    background: #0d1420cc;
    border: 1px solid var(--line);
    border-radius: 12px;
    color: var(--dim);
    font-size: 1.1rem;
    display: grid;
    place-items: center;
    padding: 0;
  }
  #touch button:active { background: #1b2740; color: var(--cyan);
                         border-color: var(--cyan); }
  #pad-up { grid-area: 1 / 2; }
  #pad-left { grid-area: 2 / 1; }
  #pad-right { grid-area: 2 / 3; }
  #pad-down { grid-area: 3 / 2; }

  #mini { width: 96px; height: 96px; }
  #lead { width: min(190px, 46vw); }
  #abil { bottom: calc(max(14px, env(safe-area-inset-bottom)) + 190px); }
}

/* ------------------------------ toast ------------------------------ */
#toast {
  position: fixed;
  left: 50%;
  top: 68px;
  transform: translate(-50%, -12px);
  padding: 8px 16px;
  background: #0d1420e6;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.86rem;
  pointer-events: none;
  opacity: 0;
  transition: opacity 200ms ease, transform 200ms ease;
  max-width: 84vw;
  text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ------------------------- cards and menu ------------------------- */
#menu, #over {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow-y: auto;
  background: radial-gradient(120% 90% at 50% -10%, #12203a 0%, #05070c 62%);
  z-index: 5;
}
#menu[hidden], #over[hidden] { display: none; }

#over {
  background: #05070ccc;
  backdrop-filter: blur(4px);
  z-index: 4;
}

.card {
  width: min(560px, 100%);
  background: #0e1522f2;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(20px, 4vw, 30px);
  box-shadow: 0 30px 80px #00000080;
}

.wordmark {
  margin: 0;
  font-size: clamp(2rem, 7vw, 2.9rem);
  letter-spacing: -0.03em;
  font-weight: 800;
  line-height: 1;
}
.wordmark span { color: var(--cyan); }

.tagline { color: var(--dim); margin: 10px 0 22px; }

.eyebrow {
  margin: 0 0 6px;
  color: var(--cyan);
  font-size: 0.74rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.field {
  display: block;
  border: 0;
  padding: 0;
  margin: 0 0 18px;
  min-width: 0;
}
.field > span, .field legend {
  display: block;
  padding: 0;
  margin-bottom: 7px;
  font-size: 0.74rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--dim);
}

input[type="text"] {
  width: 100%;
  padding: 11px 13px;
  background: #070b12;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  font: inherit;
}
input[type="text"]:focus { border-color: var(--cyan); outline: none; }
input::placeholder { color: #5a6b82; }

details.field summary {
  cursor: pointer;
  font-size: 0.74rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 10px;
}
details.field summary:hover { color: var(--cyan); }
details.field[open] summary { color: var(--ink); }

/* ----------------------------- pickers ----------------------------- */
.picker {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(148px, 1fr));
  gap: 8px;
}
.picker-slim { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); }

.opt {
  position: relative;
  text-align: left;
  padding: 11px 12px;
  background: #0a1018;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease,
              transform 140ms ease;
}
.opt:hover { border-color: #3a4c6e; transform: translateY(-1px); }
.opt[aria-checked="true"] {
  border-color: var(--cyan);
  background: #0f2028;
  box-shadow: inset 0 0 0 1px #2ad4d433;
}
.opt-name { display: block; font-weight: 700; }
.opt-sub {
  display: block;
  color: var(--dim);
  font-size: 0.78rem;
  margin-top: 2px;
}

/* The three numbers that decide a class, as bars. Reading "9.5 vs 7.0" is
 * work; seeing one bar longer than another is not. */
.opt-bars { display: grid; gap: 3px; margin-top: 9px; }
.opt-bar {
  display: grid;
  grid-template-columns: 42px 1fr;
  align-items: center;
  gap: 6px;
  font-size: 0.66rem;
  color: var(--dim);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.opt-bar i {
  height: 5px;
  border-radius: 3px;
  background: #1b2740;
  overflow: hidden;
  display: block;
}
.opt-bar i::after {
  content: "";
  display: block;
  height: 100%;
  width: var(--v, 0%);
  background: var(--cyan);
  border-radius: 3px;
}
.opt[aria-checked="true"] .opt-bar i::after { background: var(--cyan); }

.hint {
  color: var(--dim);
  font-size: 0.82rem;
  margin: 9px 0 0;
  min-height: 1.4em;
}

.play {
  width: 100%;
  padding: 14px;
  background: var(--cyan);
  color: #04181a;
  border: 0;
  border-radius: 11px;
  font: inherit;
  font-weight: 800;
  font-size: 1.02rem;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: filter 140ms ease, transform 140ms ease;
}
.play:hover { filter: brightness(1.1); transform: translateY(-1px); }
.play:disabled { filter: grayscale(0.7) brightness(0.7); cursor: wait;
                 transform: none; }

.status { min-height: 1.4em; margin: 10px 0 0; font-size: 0.86rem;
          color: var(--warn); text-align: center; }

.footnote { color: #6b7c93; font-size: 0.76rem; margin: 18px 0 0;
            text-align: center; }
.muted { color: var(--dim); }

/* --------------------------- round result --------------------------- */
#over-list {
  list-style: none;
  counter-reset: rank;
  margin: 18px 0;
  padding: 0;
  display: grid;
  gap: 6px;
}
#over-list li {
  counter-increment: rank;
  display: grid;
  grid-template-columns: 26px 10px 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  background: #0a1018;
  border: 1px solid var(--line);
  border-radius: 9px;
  font-size: 0.9rem;
}
#over-list li::before {
  content: counter(rank);
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}
#over-list li:first-child { border-color: var(--cyan); }
#over-list li:first-child::before { color: var(--cyan); font-weight: 700; }
#over-list .dot { width: 10px; height: 10px; border-radius: 3px; }
#over-list .k { color: var(--dim); font-size: 0.8rem;
                font-variant-numeric: tabular-nums; }
#over-list .p { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ------------------------------ loader ------------------------------ */
#loader {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
  color: var(--dim);
  z-index: 20;
  text-align: center;
  padding: 20px;
}
#loader[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; }
}
