/* Server-browser directory page — pixel-art underwater theme.
 *
 * Art under /assets/ is copied from games/seaquest/assets/themes/Joe/
 * (animated GIFs animate themselves; CSS only drifts them around).
 * The page itself is fully server-rendered and ships zero JS, so all
 * motion and interactivity here is CSS-only. */

@font-face {
  font-family: 'Press Start 2P';
  src: url('/fonts/press-start-2p.woff2') format('woff2');
  font-display: swap;
}

:root {
  --ink: #eaf7f3;
  --ink-muted: #9cc4bc;
  --ink-dim: #6e9a92;
  --panel: rgba(6, 28, 36, 0.88);
  --panel-border: rgba(143, 212, 200, 0.22);
  --panel-border-bright: rgba(143, 212, 200, 0.55);
  --field: #0a242c;
  --accent: #f0954f;       /* sunset orange from the backdrop */
  --accent-deep: #c96f33;
  --seafoam: #7ef0b2;
  --sky: #8fc7ff;
  --sand: #ffd089;
  --shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
  --pixel: 'Press Start 2P', monospace;
}

* { box-sizing: border-box; }

html { height: 100%; overflow-x: hidden; }

body {
  margin: 0;
  min-height: 100%;
  /* Decorative drifting sprites animate off-screen; clamp horizontal overflow
   * at the root so they can never add a horizontal scrollbar. */
  overflow-x: hidden;
  color: var(--ink);
  background: #0a2a33; /* matches the backdrop's mid-water tone while it loads */
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* ---- decorative sea layer ------------------------------------------- */

.sea {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background: url('/assets/background.gif') center / cover no-repeat;
  image-rendering: pixelated;
}

/* Darken toward the bottom so panels and text stay readable over the
 * bright sunset band at the top of the art. */
.sea::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    rgba(4, 16, 22, 0.30),
    rgba(4, 16, 22, 0.55) 45%,
    rgba(2, 10, 14, 0.78)
  );
}

.sea img {
  position: absolute;
  image-rendering: pixelated;
  will-change: transform;
}

.swim { left: 0; }

/* The shark has no markings, so mirroring it for the rightward lane is fine. */
.shark {
  top: 30%;
  width: 144px;                       /* 48px native × 3 */
  animation: drift-right 95s linear infinite;
}

/* The sub stays unflipped (leftward) — flipping it mirrors its hull markings
 * into backwards "text". */
.sub {
  top: 52%;
  width: 132px;                       /* 44px native × 3 */
  animation: drift-left 70s linear infinite;
  animation-delay: -28s;
}

.diver {
  top: 68%;
  width: 42px;                        /* 14px native × 3 */
  animation: drift-left 150s linear infinite;
  animation-delay: -60s;
}

.kraken {
  bottom: -10px;
  left: -16px;
  width: 228px;                       /* 76px native × 3 */
  animation: lurk 7s ease-in-out infinite alternate;
}

.bubble { width: 24px; bottom: -30px; opacity: 0.7; }
.b1 { left: 12%; animation: rise 34s linear infinite; }
.b2 { left: 47%; animation: rise 26s linear infinite; animation-delay: -12s; }
.b3 { left: 84%; animation: rise 41s linear infinite; animation-delay: -25s; }

@keyframes drift-left {
  from { transform: translateX(105vw); }
  to   { transform: translateX(-240px); }
}

/* Sprites face left in the source art; flip for the return lane. */
@keyframes drift-right {
  from { transform: translateX(-240px) scaleX(-1); }
  to   { transform: translateX(105vw) scaleX(-1); }
}

@keyframes lurk {
  from { transform: translateY(14px); }
  to   { transform: translateY(-4px); }
}

@keyframes rise {
  to { transform: translateY(-110vh); }
}

@media (prefers-reduced-motion: reduce) {
  .swim, .bubble { display: none; }
  .kraken { animation: none; }
}

/* ---- page chrome ------------------------------------------------------ */

.wrap {
  position: relative;
  z-index: 1;
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
}

/* The masthead sits over the brightest band of the backdrop (the sunset);
 * every line gets a hard pixel shadow to stay readable. */
.masthead {
  text-align: center;
  margin-bottom: 1.5rem;
  text-shadow: 1px 1px 0 rgba(4, 16, 22, 0.85);
}

.masthead h1 {
  margin: 0;
  font-family: var(--pixel);
  font-size: clamp(18px, 4vw, 30px);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--sand);
  text-shadow:
    3px 3px 0 rgba(0, 0, 0, 0.55),
    0 0 18px rgba(240, 149, 79, 0.35);
}

.strapline {
  margin: 0.7rem 0 0;
  font-family: var(--pixel);
  font-size: 9px;
  letter-spacing: 0.35em;
  text-transform: uppercase;
  color: #d8ece6; /* over the sunset band — muted teal washes out there */
  text-shadow: 1px 1px 0 rgba(4, 16, 22, 0.85), 0 0 10px rgba(4, 16, 22, 0.7);
}

/* Pill backdrop: the status line sits directly over the sunset band,
 * where muted text alone is unreadable. */
.status {
  display: inline-block;
  margin: 0.9rem 0 0;
  padding: 0.4rem 0.9rem;
  font-size: 0.85rem;
  color: var(--ink);
  background: rgba(4, 16, 22, 0.65);
  border-radius: 999px;
}

.status .refresh {
  color: var(--seafoam);
  text-decoration-style: dotted;
  text-underline-offset: 3px;
}

.hidden-note {
  display: inline-block;
  margin-top: 0.4rem;
  padding: 0.25rem 0.7rem;
  font-size: 0.78rem;
  color: var(--sand);
  background: rgba(4, 16, 22, 0.65);
  border-radius: 999px;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---- server cards ------------------------------------------------------ */

/* Official / Unverified server groups (portal Servers tab). Each non-empty
 * group renders under its own heading; the router's generic page emits a flat
 * list (no groups), so these rules only kick in where the markup is present. */
.server-group { margin-bottom: 1.7rem; }
.server-group:last-child { margin-bottom: 0; }

.group-head { margin-bottom: 0.9rem; }

.group-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  font-family: var(--pixel);
  font-size: 11px;
  line-height: 1.5;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink);
}

.server-group-official .group-title { color: var(--seafoam); }

.group-count {
  font-family: ui-monospace, monospace;
  font-size: 0.7rem;
  color: var(--ink-dim);
  background: rgba(4, 16, 22, 0.55);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 0.05rem 0.45rem;
}

.group-note {
  margin: 0.35rem 0 0;
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--ink-muted);
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 1.1rem;
}

.card {
  background: var(--panel);
  border: 2px solid var(--panel-border);
  border-radius: 6px;
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem 1.1rem;
  transition: border-color 0.15s, transform 0.15s;
}

.card:hover {
  border-color: var(--panel-border-bright);
  transform: translateY(-2px);
}

.card header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6rem;
}

.card h2 {
  margin: 0;
  font-family: var(--pixel);
  font-size: 12px;
  line-height: 1.6;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.badge {
  flex-shrink: 0;
  font-family: var(--pixel);
  font-size: 7px;
  padding: 4px 6px 3px;
  border-radius: 3px;
  letter-spacing: 0.08em;
}

.badge-open { color: var(--seafoam); background: #143c2e; border: 1px solid #2e7d55; }
.badge-live { color: var(--sand);    background: #4a3014; border: 1px solid #8a5a2b; }

.meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.8rem;
  margin-top: 0.45rem;
  font-size: 0.85rem;
}

.meta .game { color: var(--seafoam); font-weight: 600; }
.meta .version { color: var(--ink-dim); font-family: ui-monospace, monospace; font-size: 0.78rem; }

.meta .ruleset {
  color: var(--ink-muted);
  border: 1px solid var(--panel-border);
  border-radius: 3px;
  padding: 0.05rem 0.4rem;
  font-size: 0.78rem;
}

.meta .ruleset[title] { cursor: help; border-bottom-style: dotted; }

/* Official-server badge — a colored sibling of the ruleset pill. Green reads
 * "verified"; the unverified variant stays neutral (muted, not alarm-red) so a
 * community server looks ordinary, not broken. */
.meta .official,
.meta .unofficial {
  border-radius: 3px;
  padding: 0.05rem 0.4rem;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  cursor: help;
}

.meta .official {
  color: var(--seafoam);
  background: #143c2e;
  border: 1px solid #2e7d55;
}

.meta .unofficial {
  color: var(--ink-dim);
  background: rgba(4, 16, 22, 0.55);
  border: 1px solid var(--panel-border);
}

.players {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin-top: 0.8rem;
}

.meter {
  flex: 1;
  height: 10px;
  background: #07191f;
  border: 1px solid var(--panel-border);
  border-radius: 2px;
  overflow: hidden;
}

.meter .fill {
  display: block;
  height: 100%;
  background: var(--seafoam);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.28);
}

.players .count {
  font-family: var(--pixel);
  font-size: 9px;
  color: var(--ink);
  white-space: nowrap;
}

.players .observers {
  font-size: 0.75rem;
  color: var(--sand);
  white-space: nowrap;
}

.roster {
  margin-top: 0.45rem;
  font-size: 0.8rem;
  color: var(--ink-muted);
  font-style: italic;
  overflow-wrap: anywhere;
}

.roster::before { content: 'crew: '; font-style: normal; color: var(--ink-dim); }

/* ---- QR action tiles ---------------------------------------------------- */

.tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem;
  margin-top: 1rem;
}

.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  text-decoration: none;
}

.tile .qr {
  display: block;
  width: 96px;
  padding: 4px;
  background: #fff;
  border-radius: 3px;
  box-shadow: var(--shadow);
}

.tile .qr svg { display: block; width: 100%; height: auto; }

.tile:hover .qr { outline: 3px solid var(--accent); }

.tile .caption {
  font-family: var(--pixel);
  font-size: 8px;
  letter-spacing: 0.1em;
}

.tile-join  .caption { color: var(--seafoam); }
.tile-watch .caption { color: var(--sky); }
.tile-solo  .caption { color: var(--sand); }

.no-web {
  margin-top: 1rem;
  font-size: 0.8rem;
  font-style: italic;
  color: var(--ink-dim);
}

/* ---- empty state / footer ------------------------------------------------ */

.empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 3rem 1rem;
  background: var(--panel);
  border: 2px solid var(--panel-border);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.empty img { image-rendering: pixelated; }

.empty p {
  margin: 1rem 0 0;
  font-family: var(--pixel);
  font-size: 11px;
  color: var(--ink);
}

.empty .sub { font-size: 8px; color: var(--ink-dim); }

.note {
  margin-top: 2rem;
  text-align: center;
}

.note p {
  margin: 0 auto;
  max-width: 620px;
  font-size: 0.78rem;
  color: var(--ink-dim);
}

@media (max-width: 480px) {
  .wrap { padding: 1.25rem 0.8rem 2rem; }
  .tiles { justify-content: center; }
}

/* ======================================================================
 * Portal landing site — tabbed shell, leaderboard, editor pages.
 * The game-router server-browser page ignores these classes; they live in
 * the one shared stylesheet so both surfaces share a single download.
 * ==================================================================== */

/* ---- tab navigation --------------------------------------------------- */

.tabs {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 1.1rem;
}

.tab {
  font-family: var(--pixel);
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
  text-decoration: none;
  padding: 0.6rem 0.85rem 0.5rem;
  border: 2px solid var(--panel-border);
  border-radius: 4px;
  background: rgba(4, 16, 22, 0.55);
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.tab:hover { color: var(--ink); border-color: var(--panel-border-bright); }

.tab.active {
  color: #10222b;
  background: var(--accent);
  border-color: var(--accent-deep);
  box-shadow: var(--shadow);
}

/* Leaderboard window selector (Day/Week/Month/Year/All-time) — a compact
   sub-tab row above the durable board. */
.lb-windows {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.9rem;
}

.lb-win {
  font-family: var(--pixel);
  font-size: 8px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
  cursor: pointer;
  padding: 0.45rem 0.6rem 0.4rem;
  border: 2px solid var(--panel-border);
  border-radius: 4px;
  background: rgba(4, 16, 22, 0.55);
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.lb-win:hover { color: var(--ink); border-color: var(--panel-border-bright); }

.lb-win.active {
  color: #10222b;
  background: var(--accent);
  border-color: var(--accent-deep);
}

/* Board-type selector (Verified / Unverified) — the two-board split, a primary
   toggle above the window row. Shares the window selector's chrome; the active
   state is a touch bolder to read as the headline control. */
.lb-boards {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.6rem;
}

.lb-board {
  font-family: var(--pixel);
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
  cursor: pointer;
  padding: 0.5rem 0.75rem 0.45rem;
  border: 2px solid var(--panel-border);
  border-radius: 4px;
  background: rgba(4, 16, 22, 0.55);
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.lb-board:hover { color: var(--ink); border-color: var(--panel-border-bright); }

.lb-board.active {
  color: #10222b;
  background: var(--accent);
  border-color: var(--accent-deep);
}

/* Always-visible board disclaimer (verified vs self-reported). */
.lb-note {
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--ink-muted);
  margin: 0 0 0.9rem;
}

/* Editor links — a lighter, secondary nav row under the tabs. The outbound
 * arrow marks them as full-page navigations (they load the game client),
 * distinct from the in-page tab switches above. */
.tools {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.85rem;
}

.tool {
  font-family: var(--pixel);
  font-size: 8px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--sky);
  text-decoration: none;
  padding: 0.5rem 0.7rem 0.45rem;
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  background: rgba(4, 16, 22, 0.45);
  transition: border-color 0.15s, color 0.15s;
}

.tool::after { content: " \2197"; color: var(--ink-dim); }
.tool:hover { color: var(--ink); border-color: var(--panel-border-bright); }

/* Progressive enhancement: panels only collapse to one-at-a-time once the
 * inline boot script has set <html class="js">. With JS off, every panel
 * renders stacked and the whole page stays usable. */
.panel { margin-top: 1.3rem; }
html.js .panel { display: none; }
html.js .panel.active { display: block; }
html:not(.js) .panel + .panel { margin-top: 2rem; }

.panel-title {
  font-family: var(--pixel);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin: 0 0 0.9rem;
}
/* The per-panel heading is a redundant signpost when JS shows one panel at a
 * time (the active tab already labels it); keep it only in the no-JS stack. */
html.js .panel-title { display: none; }

/* ---- leaderboard table ------------------------------------------------ */

.lb-wrap { overflow-x: auto; }

.lb {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 2px solid var(--panel-border);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.lb th {
  font-family: var(--pixel);
  font-size: 8px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-dim);
  text-align: left;
  padding: 0.75rem 0.9rem;
  background: rgba(4, 16, 22, 0.5);
}

.lb td { padding: 0.6rem 0.9rem; border-top: 1px solid var(--panel-border); vertical-align: baseline; }
.lb tbody tr:hover { background: rgba(143, 212, 200, 0.06); }

.lb .rank { font-family: var(--pixel); font-size: 11px; color: var(--ink-muted); width: 3rem; }
.lb tr:first-child .rank { color: var(--sand); }
.lb .name { color: var(--ink); overflow-wrap: anywhere; }
.lb .name .anon { color: var(--ink-dim); font-style: italic; }
.lb .score { font-family: var(--pixel); font-size: 11px; color: var(--ink); text-align: right; white-space: nowrap; }
/* Time (play duration) + Date VALUES match the score cell exactly — pixel font,
   same size + ink colour. Scoped to `td` so the `th` headers keep the standard
   header look (.lb th). */
.lb td.lb-dur, .lb td.lb-date {
  font-family: var(--pixel);
  font-size: 11px;
  color: var(--ink);
  white-space: nowrap;
}
.lb td.lb-dur { text-align: right; font-variant-numeric: tabular-nums; }
/* Per-run tags under the player name (device + build version). A chip style,
   deliberately distinct from the ranking columns — the board doesn't sort on
   them, so they read as metadata about the run, not a scored dimension. */
.lb .lb-badges { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.35rem; }
.lb .lb-badge {
  font-family: var(--pixel);
  font-size: 8px;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
  background: rgba(143, 212, 200, 0.08);
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  padding: 0.15rem 0.4rem;
  line-height: 1.4;
  white-space: nowrap;
}
.lb .lb-badge--device { text-transform: uppercase; }
/* Trailing "watch replay" column: a compact play-icon link, not the row name. */
.lb th.watch-h, .lb .watch { width: 2.5rem; text-align: center; white-space: nowrap; }
.lb .watch-link {
  display: inline-block;
  color: var(--seafoam);
  font-size: 13px;
  line-height: 1;
  text-decoration: none;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  transition: background 0.12s ease, color 0.12s ease;
}
.lb .watch-link:hover, .lb .watch-link:focus-visible { background: rgba(143, 212, 200, 0.16); color: var(--ink); }

/* Empty-state messages (e.g. an empty leaderboard) sit in a panel like the
 * cards, so copy never floats containerless over the sea background. */
.hint {
  color: var(--ink-muted);
  text-align: center;
  padding: 2.5rem 1.5rem;
  background: var(--panel);
  border: 2px solid var(--panel-border);
  border-radius: 6px;
  box-shadow: var(--shadow);
}
.hint p { margin: 0; }
.hint .sub { color: var(--ink-dim); font-size: 0.82rem; margin-top: 0.6rem; }

/* ---- editor placeholder pages + footer nav ---------------------------- */

.editor-cta {
  text-align: center;
  background: var(--panel);
  border: 2px solid var(--panel-border);
  border-radius: 6px;
  box-shadow: var(--shadow);
  padding: 3rem 1.5rem;
}
.editor-cta h2 { font-family: var(--pixel); font-size: 14px; color: var(--sand); margin: 0; }
.editor-cta p { color: var(--ink-muted); max-width: 540px; margin: 1rem auto 0; }
.editor-cta .coming {
  display: inline-block;
  margin-top: 1.2rem;
  font-family: var(--pixel);
  font-size: 8px;
  color: var(--accent);
  border: 1px solid var(--accent-deep);
  border-radius: 3px;
  padding: 0.4rem 0.65rem;
}

.footer-nav {
  margin-top: 2.2rem;
  display: flex;
  gap: 0.7rem;
  justify-content: center;
  flex-wrap: wrap;
}
.footer-nav a {
  font-family: var(--pixel);
  font-size: 8px;
  letter-spacing: 0.06em;
  color: var(--sky);
  text-decoration: none;
  border: 1px solid var(--panel-border);
  border-radius: 3px;
  padding: 0.45rem 0.65rem;
}
.footer-nav a:hover { border-color: var(--panel-border-bright); color: var(--ink); }
