/* Shared retro-terminal theme for wesyarber.net/games.
   Glow is deliberately applied to chrome and big display numbers only, never
   to body copy or form fields — long reading/typing under a glow is tiring. */

:root {
  --bg: hsl(220 25% 7%);
  --bg-cell: hsl(220 24% 10%);
  --bg-raised: hsl(220 22% 13%);
  --line: hsl(220 18% 22%);
  --fg: hsl(210 16% 82%);
  --fg-dim: hsl(215 14% 55%);

  --ansi-red: hsl(2 72% 62%);
  --ansi-green: hsl(140 52% 55%);
  --ansi-yellow: hsl(42 88% 62%);
  --ansi-blue: hsl(205 74% 62%);
  --ansi-magenta: hsl(290 55% 68%);
  --ansi-cyan: hsl(180 55% 58%);

  --accent: var(--ansi-cyan);
  --liberal: var(--ansi-blue);
  --fascist: var(--ansi-red);

  --mono: 'Fira Code', 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --radius: 4px;
  --glow: hsl(180 55% 58% / 0.4);

  /* The board reads these rather than the ANSI names directly, so a skin only
     has to redefine this handful to reclothe every square and stone. */
  --tak-sq: var(--bg-cell);
  --tak-sq-alt: var(--bg-raised);
  --tak-sq-line: var(--line);
  /* Each seat's stones take the colour that seat picked, injected onto <html>
     as --p0-choice / --p1-choice by ui.js. The fallbacks are Amber and Cobalt —
     the yellow and blue a default game ships with. */
  --tak-p0: var(--p0-choice, hsl(45 95% 58%));
  --tak-p1: var(--p1-choice, hsl(212 90% 58%));
  --tak-road: var(--accent);
  --tak-sq-radius: var(--radius);
}

/* --- tek: the board as a printed circuit board ---------------------------- */
/* Solder-mask green, gold-immersion pads, silkscreen-white lettering, and a
   winning road that lights up as a copper trace. Set by a data-theme attribute
   on <html>; games/tak/theme.js owns the switch and index.html applies the
   stored value inline so the page never paints the wrong theme first. */

[data-theme='tek'] {
  --bg: hsl(150 30% 5%);
  --bg-cell: hsl(152 34% 11%);
  --bg-raised: hsl(152 30% 15%);
  --line: hsl(150 22% 26%);
  --fg: hsl(70 8% 90%);
  --fg-dim: hsl(150 12% 58%);

  --ansi-green: hsl(120 60% 55%);
  --ansi-cyan: hsl(45 88% 62%);
  --accent: hsl(45 88% 62%);          /* gold — the pad and trace colour */

  --tak-sq: hsl(152 42% 16%);          /* solder mask */
  --tak-sq-alt: hsl(152 42% 19%);
  --tak-sq-line: hsl(150 30% 26%);
  /* Set directly, so tek keeps its metal palette and ignores the seats' picked
     colours: gold and tinned silver ARE the circuit-board look. */
  --tak-p0: hsl(45 85% 66%);           /* gold pad */
  --tak-p1: hsl(200 16% 78%);          /* tinned silver */
  --tak-road: hsl(28 78% 58%);         /* copper */
  --glow: hsl(45 88% 62% / 0.35);
  --tak-sq-radius: 2px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.55;
}

body { padding: 2rem 1.25rem 4rem; }

.wrap { max-width: 60rem; margin: 0 auto; }
.narrow { max-width: 38rem; }

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

pre.ascii {
  color: var(--accent);
  text-shadow: 0 0 8px var(--glow);
  font-size: 0.8rem;
  line-height: 1.15;
  margin: 0 0 0.5rem;
  overflow-x: auto;
}

h1, h2, h3 { font-weight: 600; letter-spacing: 0.02em; margin: 0 0 0.5rem; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.05rem; color: var(--fg-dim); text-transform: uppercase; }

.muted { color: var(--fg-dim); }
.tagline { color: var(--fg-dim); margin: 0 0 2rem; }

/* --- cells (the tool-grid look) ------------------------------------------ */

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

.cell {
  display: block;
  background: var(--bg-cell);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  color: inherit;
  transition: border-color 0.15s, transform 0.15s;
}
.cell:hover { border-color: var(--accent); transform: translateY(-2px); text-decoration: none; }
.cell.disabled { opacity: 0.45; pointer-events: none; }
.cell h3 { color: var(--fg); }
.cell p { margin: 0.25rem 0 0; color: var(--fg-dim); font-size: 0.85rem; }

.tag {
  display: inline-block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 0.5rem;
  color: var(--fg-dim);
}
.tag.live { color: var(--ansi-green); border-color: var(--ansi-green); }

/* --- panels & controls --------------------------------------------------- */

.panel {
  background: var(--bg-cell);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

button, .btn {
  font-family: var(--mono);
  font-size: 0.9rem;
  background: var(--bg-raised);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.55rem 0.9rem;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.primary { border-color: var(--accent); color: var(--accent); }
button.danger { border-color: var(--ansi-red); color: var(--ansi-red); }
button.ja { border-color: var(--ansi-green); color: var(--ansi-green); }
button.nein { border-color: var(--ansi-red); color: var(--ansi-red); }
button.wide { width: 100%; }

input[type='text'], select {
  font-family: var(--mono);
  font-size: 0.9rem;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.5rem 0.6rem;
  width: 100%;
}
input[type='text']:focus, select:focus { outline: 1px solid var(--accent); border-color: var(--accent); }

label { display: block; font-size: 0.8rem; color: var(--fg-dim); margin-bottom: 0.25rem; }

.row { display: flex; gap: 0.5rem; align-items: center; }
.row + .row { margin-top: 0.5rem; }
.stack > * + * { margin-top: 0.75rem; }
.btn-list { display: flex; flex-direction: column; gap: 0.5rem; }
.btn-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* --- game-specific display ----------------------------------------------- */

.tracks { display: grid; gap: 0.6rem; margin-bottom: 1rem; }
.track { display: flex; align-items: center; gap: 0.4rem; }
.track .label { width: 5.5rem; font-size: 0.75rem; color: var(--fg-dim); text-transform: uppercase; }
.slot {
  width: 1.5rem; height: 2rem;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--bg);
}
.slot.filled-liberal { background: var(--liberal); border-color: var(--liberal); }
.slot.filled-fascist { background: var(--fascist); border-color: var(--fascist); }
.slot.power { border-style: dashed; }

.tracker { display: flex; gap: 0.4rem; align-items: center; }
.pip { width: 0.7rem; height: 0.7rem; border-radius: 50%; border: 1px solid var(--line); }
.pip.on { background: var(--ansi-yellow); border-color: var(--ansi-yellow); }

.readout {
  font-size: 2rem;
  color: var(--accent);
  text-shadow: 0 0 12px var(--glow);
}

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem 0.75rem;
  text-align: center;
  font-size: 0.8rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  background: var(--bg);
  flex: 1;
}
.card.liberal { border-color: var(--liberal); color: var(--liberal); }
.card.fascist { border-color: var(--fascist); color: var(--fascist); }

.role-liberal { color: var(--liberal); }
.role-fascist, .role-hitler { color: var(--fascist); }

.players { display: grid; gap: 0.35rem; }
.player {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 0.85rem;
}
.player.dead { opacity: 0.4; text-decoration: line-through; }
.player .badges { display: flex; gap: 0.35rem; }

.gate { text-align: center; padding: 2rem 1rem; }
.gate .who { font-size: 1.3rem; color: var(--accent); margin-bottom: 1rem; }

.log { font-size: 0.78rem; color: var(--fg-dim); max-height: 12rem; overflow-y: auto; }
.log div { padding: 0.1rem 0; }

.banner { border-radius: var(--radius); padding: 0.6rem 0.8rem; margin-bottom: 1rem; font-size: 0.85rem; }
.banner.liberal { border: 1px solid var(--liberal); color: var(--liberal); }
.banner.fascist { border: 1px solid var(--fascist); color: var(--fascist); }

footer { margin-top: 3rem; font-size: 0.78rem; color: var(--fg-dim); }

/* --- Lost Cities ---------------------------------------------------------- */

.lc-Y { --lc: var(--ansi-yellow); }
.lc-B { --lc: var(--ansi-blue); }
.lc-W { --lc: var(--fg); }
.lc-G { --lc: var(--ansi-green); }
.lc-R { --lc: var(--ansi-red); }

.lc-board { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 34rem) { .lc-board { grid-template-columns: 1fr; } }

.lc-side-head {
  display: flex; justify-content: space-between; align-items: baseline;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.35rem; margin-bottom: 0.4rem;
}
.lc-total { font-size: 1rem; }
.good { color: var(--ansi-green); }
.bad { color: var(--ansi-red); }

.lc-row { display: flex; align-items: center; gap: 0.35rem; min-height: 1.6rem; }
.lc-key {
  width: 1.6rem; flex: none;
  font-size: 0.7rem; text-transform: uppercase; color: var(--lc, var(--fg-dim));
}
.lc-cards { display: flex; gap: 0.2rem; flex-wrap: wrap; flex: 1; }
.lc-score { font-size: 0.75rem; min-width: 2.2rem; text-align: right; }

.lc-card {
  display: inline-block;
  min-width: 1.9rem;
  padding: 0.05rem 0.25rem;
  border: 1px solid var(--lc, var(--line));
  border-radius: 2px;
  color: var(--lc, var(--fg));
  font-size: 0.72rem;
  text-align: center;
}
.lc-card.wager { border-style: dashed; }
.lc-card.empty { color: var(--fg-dim); border-color: var(--line); }

.lc-discards {
  display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap;
  margin-top: 0.9rem; padding-top: 0.75rem; border-top: 1px solid var(--line);
}
.lc-pile { display: inline-flex; align-items: center; gap: 0.2rem; }
.lc-pile-n { font-size: 0.65rem; }

.lc-hand { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.lc-hand-card {
  min-width: 3rem;
  border-color: var(--lc, var(--line));
  color: var(--lc, var(--fg));
  padding: 0.7rem 0.5rem;
}
.lc-hand-card.wager { border-style: dashed; }
.lc-hand-card.selected { background: var(--lc, var(--accent)); color: var(--bg); }

.lc-score-row {
  display: grid; grid-template-columns: 6rem 1fr 1fr;
  gap: 0.5rem; padding: 0.25rem 0; text-align: right;
}
.lc-score-row > :first-child { text-align: left; }
.lc-score-row.total { border-top: 1px solid var(--line); margin-top: 0.35rem; padding-top: 0.6rem; }

/* --- Tak ------------------------------------------------------------------ */

.tak-board {
  display: grid;
  gap: 0.25rem;
  margin: 0 auto;
  max-width: 32rem;
}
.tak-row { display: grid; grid-template-columns: repeat(var(--tak-n, 5), 1fr); gap: 0.25rem; }

.tak-sq {
  position: relative;
  aspect-ratio: 1;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--tak-sq);
  border: 1px solid var(--tak-sq-line);
  border-radius: var(--tak-sq-radius);
  font-family: var(--mono);
  min-width: 0;
  overflow: hidden;
}
.tak-sq.alt { background: var(--tak-sq-alt); }
.tak-sq:disabled { opacity: 1; cursor: default; }
.tak-sq.sel { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.tak-sq.mark { border-color: var(--ansi-yellow); border-style: dashed; }

.tak-coord {
  position: absolute; left: 0.2rem; bottom: 0.1rem;
  font-size: 0.55rem; color: var(--fg-dim); opacity: 0.7;
}
.tak-h {
  position: absolute; right: 0.2rem; top: 0.1rem;
  font-size: 0.6rem; color: var(--ansi-yellow);
}

/* Pieces are drawn as filled shapes so a stone fills most of the square it sits
   in, rather than sitting as a small glyph in the middle. p0 is yellow, p1 is
   blue; the glyph in the markup is a text fallback, hidden with font-size: 0. */
.tak-piece {
  position: relative;
  display: inline-block;
  vertical-align: middle;
  font-size: 0;
  line-height: 0;
  color: transparent;
  background: var(--tak-p0);
  border-radius: 20%;
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.28), 0 1px 2px rgb(0 0 0 / 0.45);
}
.tak-piece.tak-p0 { background: var(--tak-p0); }
.tak-piece.tak-p1 { background: var(--tak-p1); }

/* Inline default sizes (the tutorial legend). */
.tak-piece.tak-F { width: 1.4rem; height: 1.4rem; border-radius: 22%; }
.tak-piece.tak-S { width: 0.55rem; height: 1.5rem; border-radius: 3px; }
.tak-piece.tak-C { width: 1.35rem; height: 1.35rem; border-radius: 50%; }

/* A capstone gets a domed inner ring so it reads apart from a round flat. */
.tak-piece.tak-C::after {
  content: ''; position: absolute; inset: 26%;
  border-radius: 50%;
  box-shadow: inset 0 0 0 2px rgb(255 255 255 / 0.4);
}

/* On the board a stone fills most of its square and scales with board size. */
.tak-sq .tak-piece.tak-F { width: 74%; height: 74%; }
.tak-sq .tak-piece.tak-S { width: 30%; height: 80%; }
.tak-sq .tak-piece.tak-C { width: 66%; height: 66%; }

.tak-dot {
  display: inline-block; width: 0.7rem; height: 0.7rem;
  border-radius: 50%; border: 1px solid var(--line);
}
.tak-dot.tak-p0 { background: var(--tak-p0); }
.tak-dot.tak-p1 { background: var(--tak-p1); }

/* --- the colour picker on the setup screen ------------------------------- */

.tak-player-setup { display: flex; flex-direction: column; gap: 0.4rem; }
.tak-player-setup + .tak-player-setup { margin-top: 0.7rem; }
.tak-player-setup .row { gap: 0.5rem; }
.tak-player-setup .tak-dot {
  width: 0.85rem; height: 0.85rem; flex: 0 0 auto;
}
.tak-player-setup input { flex: 1 1 auto; min-width: 0; }

.tak-swatches { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.tak-swatch {
  width: 1.5rem; height: 1.5rem; padding: 0; flex: 0 0 auto;
  border-radius: 50%; border: 2px solid var(--line);
  cursor: pointer; transition: transform 0.08s ease;
}
.tak-swatch:hover:not(:disabled) { transform: scale(1.12); }
.tak-swatch.chosen {
  border-color: var(--fg);
  box-shadow: 0 0 0 2px var(--bg), 0 0 8px var(--glow, transparent);
}
.tak-swatch:disabled { opacity: 0.28; cursor: not-allowed; }

/* --- the winning road, drawn as a trace ---------------------------------- */
/* ui.js emits a centre pad plus one segment per direction the road leaves the
   square by, so the win reads as a single line running off both board edges.
   Segments sit under the stone (z-index 0 vs the piece's auto stacking). */

.tak-trace-pad, .tak-trace {
  position: absolute;
  background: var(--tak-road);
  box-shadow: 0 0 10px var(--tak-road);
  pointer-events: none;
  animation: tak-energise 0.5s ease-out both;
}
.tak-trace-pad {
  left: 50%; top: 50%;
  width: 44%; height: 44%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  opacity: 0.85;
}
.tak-trace { --w: 16%; }
.tak-trace-n { left: 50%; bottom: 50%; width: var(--w); height: 50%; transform: translateX(-50%); }
.tak-trace-s { left: 50%; top: 50%; width: var(--w); height: 50%; transform: translateX(-50%); }
.tak-trace-e { top: 50%; left: 50%; height: var(--w); width: 50%; transform: translateY(-50%); }
.tak-trace-w { top: 50%; right: 50%; height: var(--w); width: 50%; transform: translateY(-50%); }

.tak-sq.road { border-color: var(--tak-road); }

@keyframes tak-energise {
  from { opacity: 0; filter: brightness(2.4); }
  to { opacity: 0.85; filter: none; }
}
@media (prefers-reduced-motion: reduce) {
  .tak-trace-pad, .tak-trace { animation: none; }
}

/* --- the theme switch ----------------------------------------------------- */

.theme-switch { display: flex; align-items: center; gap: 0.35rem; }
.theme-switch button { font-size: 0.75rem; padding: 0.2rem 0.5rem; }
.theme-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; }

/* Tek's board furniture: silkscreen coordinates, a via under every empty
   square, and stack heights in copper rather than yellow. */
[data-theme='tek'] .tak-sq {
  background-image: radial-gradient(circle at 50% 50%,
    hsl(150 20% 8% / 0.9) 0 6%, transparent 6.5%);
}
[data-theme='tek'] .tak-coord { color: var(--fg); opacity: 0.5; letter-spacing: 0.05em; }
[data-theme='tek'] .tak-h { color: var(--tak-road); }
[data-theme='tek'] .tak-piece.tak-F,
[data-theme='tek'] .tak-piece.tak-S,
[data-theme='tek'] .tak-piece.tak-C {
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.3), 0 0 7px rgb(120 220 255 / 0.4);
}

.tak-status-row {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.35rem 0.4rem; border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 0.85rem;
}
.tak-status-row + .tak-status-row { margin-top: 0.25rem; }
.tak-status-row.active { border-color: var(--accent); }
.tak-flats { margin-left: auto; color: var(--fg-dim); font-size: 0.75rem; }

/* --- networked play ------------------------------------------------------ */

.net-pill {
  margin-left: auto;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.15rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--fg-dim);
}
.net-pill.net-online { color: var(--ansi-green); border-color: var(--ansi-green); }
.net-pill.net-connecting,
.net-pill.net-reconnecting { color: var(--ansi-yellow); border-color: var(--ansi-yellow); }
.net-pill.net-offline { color: var(--ansi-red); border-color: var(--ansi-red); }

.danger-text { color: var(--ansi-red); }
