:root {
  --bg: #0f1115;
  --bg-2: #171a21;
  --panel: #1c2029;
  --panel-2: #232834;
  --line: #2c3340;
  --text: #e7ebf0;
  --muted: #97a1b0;
  --accent: #6ee7a8;
  --accent-2: #ffd479;
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.35);

  /* Card category themes */
  --c-gub: #43c06d;
  --c-barricade: #b9863e;
  --c-trap: #9a6ad1;
  --c-event: #4f8bf0;
  --c-hazard: #e0594f;
  --c-tool: #2bb6a8;
  --c-interrupt: #e7a13a;
  --c-wild: #d36bd0;
}

* {
  box-sizing: border-box;
}
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background: radial-gradient(1200px 800px at 70% -10%, #1a2230 0%, var(--bg) 60%);
  color: var(--text);
  font:
    14px/1.45 ui-sans-serif,
    system-ui,
    -apple-system,
    Segoe UI,
    Roboto,
    sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---- Top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
}
.brand {
  font-weight: 700;
  font-size: 16px;
}
.brand span {
  color: var(--accent);
}
.brand em {
  color: var(--muted);
  font-style: normal;
  font-weight: 500;
  margin-left: 4px;
}
.picker {
  display: flex;
  gap: 6px;
  align-items: center;
}
.meta {
  color: var(--muted);
  font-size: 12.5px;
  margin-left: auto;
}
.live {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #ff6b6b;
  font-weight: 700;
  letter-spacing: 0.5px;
}
.live .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #ff5252;
  animation: pulse 1.2s infinite;
}
@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.25;
  }
}

select,
button,
input[type='range'] {
  font: inherit;
  color: var(--text);
}
select,
button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
}
button:hover {
  border-color: var(--accent);
}
button:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ---- Layout ---- */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 340px;
  grid-template-rows: 1fr auto;
  grid-template-areas:
    'board side'
    'hand side';
  gap: 14px;
  padding: 14px;
  min-height: 0;
}
.layout:focus {
  outline: none;
}
.board {
  grid-area: board;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-content: flex-start;
  overflow: auto;
}
.side {
  grid-area: side;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}
.handbar {
  grid-area: hand;
  min-height: 188px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 0;
  padding-top: 8px;
}

/* ---- Player tableaus ---- */
.tableau {
  --player: var(--line);
  /* faint wash of the player's color over the panel */
  background: color-mix(in srgb, var(--player) 8%, var(--panel));
  border: 1px solid var(--line);
  border-top: 4px solid var(--player); /* colored top banner per player */
  border-radius: 14px;
  padding: 12px;
  min-width: 240px;
  flex: 1 1 240px;
  max-width: 360px;
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s;
}
.tableau.active {
  /* whose turn it is, in that player's OWN color: a brighter wash + ring + glow
     so there's no second hue competing with the player's banner color */
  background: color-mix(in srgb, var(--player) 16%, var(--panel));
  box-shadow:
    0 0 0 2px var(--player),
    0 0 20px -4px var(--player),
    var(--shadow);
}
.tableau .who {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}
.tableau .turn {
  color: var(--player);
  font-size: 12px;
  line-height: 1;
}
.tableau .name {
  font-weight: 700;
  color: var(--player);
}
.tableau .score {
  margin-left: auto;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 10px;
  font-variant-numeric: tabular-nums;
}
.tableau .hand-count {
  color: var(--muted);
  font-size: 12px;
}
.tableau .units {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 60px;
}
.tableau .empty {
  color: var(--muted);
  font-style: italic;
  font-size: 12.5px;
  padding: 8px 0;
}
.crown {
  filter: drop-shadow(0 0 6px var(--accent-2));
}

/* ---- Cards ---- */
.card {
  --theme: var(--muted);
  position: relative;
  /* Height is fixed (unchanged from before); width derives from the real card
     art's 5:7 ratio (750×1050) so the artwork is never distorted or cropped. */
  height: 146px;
  aspect-ratio: 5 / 7;
  border-radius: 10px;
  background: linear-gradient(160deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-top: 3px solid var(--theme);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card.sm {
  height: 130px;
}
/* Card art (Cole's official illustrations) under the themed frame. `contain`
   shows the whole illustration with no crop or distortion; the box is already
   5:7, so the letterboxing is sub-pixel. */
.card .art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
/* The themed text face (fallback for any card without art). */
.card.textface {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.card .glyph {
  font-size: 22px;
  line-height: 1;
}
.card .cname {
  font-weight: 700;
  font-size: 12.5px;
  color: var(--text);
}
.card .ctype {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--theme);
  font-weight: 700;
}
.card .ctext {
  font-size: 10px;
  color: var(--muted);
  overflow: hidden;
  flex: 1;
}
.card.gub {
  --theme: var(--c-gub);
}
.card.barricade {
  --theme: var(--c-barricade);
}
.card.trap {
  --theme: var(--c-trap);
}
.card.event {
  --theme: var(--c-event);
}
.card.hazard {
  --theme: var(--c-hazard);
}
.card.tool {
  --theme: var(--c-tool);
}
.card.interrupt {
  --theme: var(--c-interrupt);
}
.card.wild {
  --theme: var(--c-wild);
}

.card .overlay-chip {
  position: absolute;
  bottom: 6px;
  left: 6px;
  right: 6px;
  font-size: 10px;
  font-weight: 700;
  text-align: center;
  padding: 3px 4px;
  border-radius: 6px;
  /* Default backing so chips stay legible over the card art; protected/trapped
     variants below override it with their category colors. */
  background: rgba(8, 10, 14, 0.72);
  color: var(--text);
  backdrop-filter: blur(2px);
}
.card.protected {
  border-color: var(--c-barricade);
}
.card.protected .overlay-chip {
  background: rgba(185, 134, 62, 0.85);
  color: #1a1206;
}
.card.trapped {
  filter: saturate(0.5) brightness(0.8);
  border-color: var(--c-trap);
}
.card.trapped .overlay-chip {
  background: rgba(154, 106, 209, 0.85);
  color: #160a26;
}
.card.ring {
  --theme: var(--c-trap);
}

/* Face-down card back (opponent hands) */
.card.back {
  display: flex;
  background:
    repeating-linear-gradient(45deg, #20262f, #20262f 6px, #252c37 6px, #252c37 12px), var(--panel);
  border-top-color: var(--line);
}
.card.back .glyph {
  margin: auto;
  opacity: 0.5;
  font-size: 26px;
}

/* Fanned hand */
.handbar .card {
  transform-origin: bottom center;
  margin: 0 -14px;
  transition:
    transform 0.18s,
    margin 0.18s;
}
.handbar .card:hover {
  transform: translateY(-16px) scale(1.04) !important;
  z-index: 5;
}
.handbar .hand-empty {
  color: var(--muted);
  font-style: italic;
  align-self: center;
}
.handbar .hand-label {
  position: absolute;
  left: 16px;
  bottom: 14px;
  color: var(--muted);
  font-size: 12px;
}

/* ---- Side panels ---- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}
.panel h3 {
  margin: 0 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
}
.thought .move {
  font-weight: 700;
  margin-bottom: 6px;
}
.thought .move .arrow {
  color: var(--accent);
}
.thought .bubble {
  font-size: 13px;
  color: var(--text);
  background: var(--panel-2);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 8px 10px;
}
.thought .reason {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}
.thought .by {
  margin-top: 8px;
  font-size: 11px;
  color: var(--muted);
}

.commentary .feed {
  max-height: 200px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.commentary .cline {
  font-size: 12.5px;
  line-height: 1.4;
  background: var(--panel-2);
  border-radius: 8px;
  padding: 6px 9px;
}
.commentary .spk {
  font-weight: 700;
  margin-right: 4px;
}
.commentary .cmuted {
  color: var(--muted);
  font-style: italic;
}

.log {
  flex: 1;
  overflow: auto;
  min-height: 120px;
}
.log ol {
  margin: 0;
  padding: 0;
  list-style: none;
}
.log li {
  padding: 6px 8px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 12.5px;
  border: 1px solid transparent;
}
.log li:hover {
  background: var(--panel-2);
}
.log li.current {
  background: var(--panel-2);
  border-color: var(--accent);
}
.log li .ev {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-left: 8px;
}
.log li .head .who {
  color: var(--accent);
  font-weight: 700;
}

/* ---- Outcome / spoiler ---- */
.outcome {
  display: none;
}
.outcome.show {
  display: block;
}
.outcome .hidden-note {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}
.outcome .reveal {
  border-color: var(--accent-2);
  color: var(--accent-2);
}
.outcome table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.outcome td {
  padding: 4px 6px;
  border-bottom: 1px solid var(--line);
}
.outcome .win {
  color: var(--accent);
  font-weight: 700;
}
.outcome .banner {
  font-size: 15px;
  font-weight: 800;
  margin-bottom: 8px;
}

/* Closing-frame redaction */
.redacted {
  margin: auto;
  text-align: center;
  color: var(--muted);
  padding: 40px;
}
.redacted .big {
  font-size: 22px;
  margin-bottom: 12px;
}

/* ---- Transport ---- */
.transport {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--bg-2);
  border-top: 1px solid var(--line);
}
.transport button {
  min-width: 38px;
}
.transport #scrub {
  flex: 1;
  accent-color: var(--accent);
}
.transport .pos {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-width: 150px;
  text-align: center;
  font-size: 12.5px;
}
.transport .speed {
  color: var(--muted);
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.letters {
  display: inline-flex;
  gap: 3px;
  margin-left: 8px;
}
.letters b {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  display: inline-grid;
  place-items: center;
  font-size: 11px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
}
.letters b.on {
  background: var(--c-event);
  color: #fff;
  border-color: var(--c-event);
}

/* Build-identity badge (bottom-right). Rendered by version-badge.js from
   /api/version — unobtrusive at rest, brightens on hover. */
.version-badge {
  position: fixed;
  right: 8px;
  bottom: 6px;
  z-index: 1000;
  font:
    11px/1.4 ui-monospace,
    SFMono-Regular,
    Menlo,
    monospace;
  color: var(--muted);
  background: rgba(28, 32, 41, 0.55);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px 7px;
  opacity: 0.45;
  transition: opacity 0.15s ease;
  pointer-events: auto;
}
.version-badge:hover {
  opacity: 1;
}
.version-badge a {
  color: var(--accent);
  text-decoration: none;
}
.version-badge a:hover {
  text-decoration: underline;
}
