/* Card Games — the shared UI system.

   Every hub page *and* every game client loads this file. It owns the shell:
   page frame, top bar, buttons, forms, panels, chips, tables, modals, toasts.
   The point is that a game screen and the dashboard are visibly the same app.

   A game's flair is one declaration:

       body { --accent: #57c98b; }

   Buttons, focus rings, chips, links, the page glow and every highlight are
   derived from --accent, so setting it re-skins the whole shell. Anything past
   that — cards, felt, seats, piles — lives in the game's own stylesheet, on top
   of this one. Games should add, never restyle the shell, or the hub stops
   feeling like one place. */

/* ============================ Tokens ============================ */

:root {
  color-scheme: dark;

  /* The one knob a game turns. --accent-ink must stay readable on --accent. */
  --accent: #f0c458;
  --accent-ink: #241a02;

  --bg: #0d1211;
  --surface: rgba(255, 255, 255, .042);   /* translucent: the page glow shows through */
  --surface-hi: rgba(255, 255, 255, .075);
  --surface-solid: #151d1a;               /* modals and menus, which must be opaque */
  --sunken: rgba(0, 0, 0, .3);            /* inputs, code blocks, scroll areas */

  --ink: #edf2ef;
  --ink-2: rgba(237, 242, 239, .66);
  --ink-3: rgba(237, 242, 239, .42);

  --line: rgba(255, 255, 255, .09);
  --line-2: rgba(255, 255, 255, .17);

  --good: #6fd39a;
  --bad: #ff9b8b;

  /* Table felt, for game clients that want it (see .felt). */
  --felt: #1d5b3b;
  --felt-2: #123b27;

  --r-1: 9px;
  --r-2: 14px;
  --r-3: 20px;
  --r-full: 999px;

  --sh-1: 0 1px 2px rgba(0, 0, 0, .35);
  --sh-2: 0 10px 28px -12px rgba(0, 0, 0, .7);
  --sh-3: 0 30px 70px -24px rgba(0, 0, 0, .85);

  --font: "Inter", "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, sans-serif;

  /* Derived from --accent, so a game never sets these by hand. */
  --accent-soft: color-mix(in srgb, var(--accent) 16%, transparent);
  --accent-line: color-mix(in srgb, var(--accent) 45%, transparent);
  --accent-text: color-mix(in srgb, var(--accent) 88%, white);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* ============================ Base ============================ */

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background:
    radial-gradient(1100px 560px at 50% -220px, var(--accent-soft), transparent 72%),
    var(--bg);
  background-attachment: fixed;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: clamp(22px, 2.3vw, 27px); font-weight: 700; letter-spacing: -.02em; }
h3 { font-size: 17px; font-weight: 650; letter-spacing: -.01em; }

/* Section headings are quiet labels, not titles — the content is the loud part. */
h2 {
  font-size: 11.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .13em;
  color: var(--ink-3);
}

section { margin-bottom: 32px; }
section > h2 { margin-bottom: 12px; }

.sub { color: var(--ink-2); font-size: 14px; }
.empty {
  border: 1px dashed var(--line-2); border-radius: var(--r-2);
  padding: 26px 20px; text-align: center; color: var(--ink-2); font-size: 14px;
}
.panel > .empty, .panel .empty { border: none; padding: 20px; }

/* Focus is one ring everywhere, and only for keyboard users. */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ============================ Layout ============================ */

.wrap { max-width: 1080px; margin: 0 auto; padding: 0 20px 56px; }
.wrap.narrow { max-width: 440px; }
.wrap.wide { max-width: 1180px; }

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap;
  margin-bottom: 26px; padding: 12px 0;
  border-bottom: 1px solid var(--line);
  /* Blurred rather than solid, so the page glow carries through the bar. */
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px) saturate(1.3);
}
.topbar .brand {
  display: flex; align-items: center; gap: 10px;
  font-size: 17px; font-weight: 700; letter-spacing: -.01em;
  color: var(--ink);
}
.topbar .brand:hover { text-decoration: none; color: var(--ink); }
.topbar .brand .pips {
  color: var(--accent); letter-spacing: -.14em; font-size: 19px;
}
.topbar nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.topbar .who {
  font-size: 13px; color: var(--ink-3); margin-right: 6px;
  white-space: nowrap;
}
.topbar .who b { color: var(--ink-2); font-weight: 600; }

/* Text-weight nav links; the current page is marked, not disabled-looking. */
.navlink {
  font-size: 13.5px; font-weight: 550; color: var(--ink-2);
  padding: 6px 11px; border-radius: var(--r-full);
}
.navlink:hover { background: var(--surface-hi); color: var(--ink); text-decoration: none; }
.navlink.on { background: var(--accent-soft); color: var(--accent-text); }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.tight { gap: 6px; }
.grow { flex: 1; min-width: 180px; }
.center { text-align: center; }
.hidden { display: none !important; }

/* ============================ Buttons ============================ */

button, .btn {
  --btn-bg: var(--accent);
  --btn-ink: var(--accent-ink);
  --btn-line: transparent;
  appearance: none; font: inherit; font-weight: 600; letter-spacing: -.01em;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 16px; border-radius: var(--r-1);
  border: 1px solid var(--btn-line);
  background: var(--btn-bg); color: var(--btn-ink);
  cursor: pointer; white-space: nowrap;
  touch-action: manipulation;   /* no double-tap zoom delay on phones */
  box-shadow: var(--sh-1);
  transition: filter .14s ease, background .14s ease, border-color .14s ease, transform .08s ease;
}
button:hover, .btn:hover { filter: brightness(1.09); text-decoration: none; }
button:active, .btn:active { transform: translateY(1px); }
button:disabled, .btn.disabled {
  opacity: .42; cursor: not-allowed; filter: none; transform: none; box-shadow: none;
}

/* Outlined. The default choice for anything that is not the main action. */
button.secondary, .btn.secondary {
  --btn-bg: transparent; --btn-ink: var(--ink); --btn-line: var(--line-2);
  box-shadow: none;
}
button.secondary:hover, .btn.secondary:hover { background: var(--surface-hi); filter: none; }

/* Borderless, for dense rows and toolbars. */
button.quiet, .btn.quiet {
  --btn-bg: transparent; --btn-ink: var(--ink-2); box-shadow: none;
}
button.quiet:hover, .btn.quiet:hover { background: var(--surface-hi); color: var(--ink); filter: none; }

button.danger, .btn.danger {
  --btn-bg: transparent; --btn-ink: var(--bad);
  --btn-line: color-mix(in srgb, var(--bad) 42%, transparent);
  box-shadow: none;
}
button.danger:hover, .btn.danger:hover {
  background: color-mix(in srgb, var(--bad) 14%, transparent); filter: none;
}

button.tiny, .btn.tiny { font-size: 12.5px; padding: 5px 11px; gap: 5px; }
button.big, .btn.big { font-size: 16px; padding: 11px 22px; }
button.block, .btn.block { width: 100%; }

/* ============================ Forms ============================ */

label { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 6px; }
input[type=text], input[type=password], select, textarea {
  font: inherit; width: 100%; color: var(--ink);
  padding: 10px 12px; border-radius: var(--r-1);
  border: 1px solid var(--line-2); background: var(--sunken);
  transition: border-color .14s ease, background .14s ease;
}
input::placeholder { color: var(--ink-3); }
input:hover, select:hover { border-color: rgba(255, 255, 255, .28); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); background: rgba(0, 0, 0, .38);
}
select option { background: var(--surface-solid); color: var(--ink); }
.field { margin-bottom: 15px; }

.msg { font-size: 13.5px; min-height: 20px; margin-top: 10px; color: var(--ink-2); }
.msg.error { color: var(--bad); }
.msg.ok { color: var(--good); }

/* ============================ Surfaces ============================ */

.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-2); padding: 20px;
}
.panel.flush { padding: 0; }

/* Opt-in card-table surface for game clients. Retint with --felt / --felt-2. */
.felt {
  background:
    radial-gradient(ellipse at 50% 0%, var(--felt) 0%, var(--felt-2) 78%);
  border: 1px solid rgba(0, 0, 0, .35);
  border-radius: var(--r-3);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .09), var(--sh-2);
}

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 600; letter-spacing: .01em;
  background: var(--surface-hi); color: var(--ink-2);
  border: 1px solid var(--line); border-radius: var(--r-full);
  padding: 2px 9px; white-space: nowrap;
}
.chip.accent { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent-text); }
.chip.live { background: color-mix(in srgb, var(--good) 18%, transparent); border-color: color-mix(in srgb, var(--good) 40%, transparent); color: var(--good); }
.chip.off { background: color-mix(in srgb, var(--bad) 15%, transparent); border-color: color-mix(in srgb, var(--bad) 38%, transparent); color: var(--bad); }

/* A one-line notice above the content: "you have a game on the go". */
.callout {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: var(--accent-soft); border: 1px solid var(--accent-line);
  border-radius: var(--r-2); padding: 13px 16px; margin-bottom: 24px;
}

/* ============================ Game tiles ============================ */

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }

/* --game-accent is set inline per tile from the game module's `accent`. It
   tints trim only — never a text background — so a dark game colour cannot
   make a label unreadable. */
.tile {
  --game-accent: var(--accent);
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; gap: 8px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-2); padding: 18px;
  transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.tile::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: linear-gradient(90deg,
    color-mix(in srgb, var(--game-accent) 85%, white), transparent 85%);
}
.tile:hover {
  transform: translateY(-3px);
  border-color: color-mix(in srgb, var(--game-accent) 55%, transparent);
  box-shadow: var(--sh-2);
}
.tile .tile-icon {
  font-size: 26px; line-height: 1; margin-bottom: 2px;
  color: color-mix(in srgb, var(--game-accent) 60%, white);
}
.tile .tile-tag { color: var(--ink-2); font-size: 14px; flex: 1; }
.tile .tile-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.tile .row { margin-top: 10px; }

/* ============================ Open tables ============================ */

.rooms { display: flex; flex-direction: column; gap: 8px; }
.room {
  --game-accent: var(--accent);
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--line);
  border-left: 3px solid color-mix(in srgb, var(--game-accent) 70%, white);
  border-radius: var(--r-2); padding: 12px 16px;
  transition: background .14s ease;
}
.room:hover { background: var(--surface-hi); }
.room .code {
  font-size: 19px; font-weight: 700; letter-spacing: .18em;
  color: var(--accent-text); min-width: 78px;
  font-variant-numeric: tabular-nums;
}
.room .room-info { flex: 1; min-width: 190px; }
.room .room-info .line1 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-weight: 600; }
.room .room-info .line2 { font-size: 13px; color: var(--ink-2); }
.room .away { color: var(--ink-3); }

/* ============================ Tables ============================ */

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
th {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em;
  color: var(--ink-3);
}
tbody tr { transition: background .12s ease; }
tbody tr:hover { background: var(--surface-hi); }
tbody tr.me { background: var(--accent-soft); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap-cell { white-space: normal; }

/* ============================ Stats ============================ */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(122px, 1fr)); gap: 10px; }
.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-2); padding: 14px 16px;
}
.stat .n {
  font-size: 25px; font-weight: 700; letter-spacing: -.02em;
  color: var(--ink); font-variant-numeric: tabular-nums; line-height: 1.2;
}
.stat .k {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .09em;
  color: var(--ink-3); margin-top: 3px;
}

/* ============================ Modals ============================ */

/* Games use these for their lobby, rules and game-over screens, so those
   screens match the hub's dialogs instead of inventing their own. */
.overlay {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  padding: 20px; overflow: auto;
  background: rgba(6, 10, 9, .66);
  backdrop-filter: blur(7px);
  animation: fade-in .16s ease;
}
.modal {
  position: relative; overflow: hidden;
  width: min(460px, 100%);
  background: var(--surface-solid); border: 1px solid var(--line-2);
  border-radius: var(--r-3); padding: 26px;
  box-shadow: var(--sh-3);
  animation: rise-in .18s ease;
}
.modal.wide { width: min(600px, 100%); }
.modal::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 2px;
  background: linear-gradient(90deg, var(--accent), transparent 80%);
}
.modal h2 {
  font-size: 19px; font-weight: 700; letter-spacing: -.01em;
  text-transform: none; color: var(--ink); margin-bottom: 8px;
}
.modal p { color: var(--ink-2); font-size: 14.5px; }
.modal .row { margin-top: 18px; }
.modal-foot { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 20px; }
.fine {
  font-size: 12.5px; color: var(--ink-3); line-height: 1.55;
  margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line);
}

@keyframes fade-in { from { opacity: 0; } }
@keyframes rise-in { from { opacity: 0; transform: translateY(8px); } }

/* ============================ Transient UI ============================ */

/* Full-width strip pinned to the top: connection lost, server going down. */
.netbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 80;
  padding: 7px 14px; text-align: center;
  font-size: 13.5px; font-weight: 600;
  background: color-mix(in srgb, var(--bad) 88%, black); color: #fff;
  box-shadow: var(--sh-2);
}

.toast {
  position: fixed; bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  left: 50%; transform: translateX(-50%);
  z-index: 70; pointer-events: none;
  background: var(--surface-solid); color: var(--ink);
  border: 1px solid var(--line-2); border-left: 3px solid var(--accent);
  border-radius: var(--r-1); padding: 9px 16px;
  font-size: 13.5px; font-weight: 600;
  box-shadow: var(--sh-2);
  animation: rise-in .16s ease;
}

/* ============================ Sign-in ============================ */

.auth-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-3); padding: 30px;
  box-shadow: var(--sh-2);
}
.auth-head { text-align: center; margin-bottom: 24px; }
.auth-head .pips { font-size: 30px; color: var(--accent); letter-spacing: -.16em; }
.auth-head h1 { font-size: 23px; margin-top: 10px; }

/* Segmented control. Also fine for any two-or-three-way switch in a game. */
.tabs {
  display: flex; gap: 4px; margin-bottom: 20px;
  background: var(--sunken); padding: 4px; border-radius: var(--r-1);
}
.tabs button {
  flex: 1; --btn-bg: transparent; --btn-ink: var(--ink-3);
  box-shadow: none; padding: 7px; font-size: 14px;
}
.tabs button:hover { background: var(--surface-hi); color: var(--ink); filter: none; }
.tabs button.on { --btn-bg: var(--accent); --btn-ink: var(--accent-ink); }

/* ============================ Responsive & motion ============================ */

@media (max-width: 560px) {
  .wrap { padding: 0 14px 44px; }
  .topbar { padding: 10px 0; margin-bottom: 20px; }
  .topbar .who { display: none; }
  .modal { padding: 22px 18px; }
  .room .code { min-width: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
