:root {
  --bg: #f6f3ec;
  --panel: #ffffff;
  --ink: #1e1b16;
  --muted: #6f6a60;
  --line: #ddd7ca;
  --card: #efe9db;
  --key: #2f8f5b;
  --key-soft: #d9f0e2;
  --neutral: #c9b892;
  --neutral-soft: #efe6d1;
  --assassin: #1a1a1a;
  --assassin-soft: #d8d5d0;
  --select: #2563eb;
  --bar: #2563eb;
  --bar-dim: #b9c8ec;
  --danger: #b91c1c;
  --highlight: #7c3aed;
  --radius: 10px;
  --header-h: 104px;
  /* Two type families:
     --font-ui    everything: labels, buttons, numbers, body copy.
     --font-words the "game material": the page title, the words on the cards, and those same
                  card words wherever they reappear (clue chips, distribution labels, banner).
     To try a different display face, change --font-words and the Google Fonts <link> in index.html. */
  --font-ui: "Outfit", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-words: "Victor Mono", "Cascadia Code", Consolas, monospace;
  font-family: var(--font-ui);
}
/* card words wherever they appear */
.word { font-family: var(--font-words); }

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); display: flex; flex-direction: column; overflow: hidden; }
h1, h2, h3 { margin: 0; font-weight: 650; }
h2 { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
h3 { font-size: 17px; margin-bottom: 4px; }
a { color: var(--select); }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--danger); font-size: 13px; margin: 8px 0 0; }

/* header: centered title, actions on the right */
.top {
  flex: 0 0 auto; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 20px 24px 14px; min-height: var(--header-h);
}
.subtitle { margin: 2px 0 0; font-size: 15px; color: var(--muted); }
.title-wrap { text-align: center; }
.top h1 { font-family: var(--font-words); font-size: 32px; font-weight: 600; letter-spacing: -.01em; }
.actions { display: flex; justify-content: flex-end; gap: 8px; }
.notice { margin: 2px 0 0; font-size: 12px; color: #7a5200; }
.notice.bad { color: var(--danger); }

input[type="number"], input[type="text"] {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 0; font: inherit; background: #fff;
}
button {
  font: inherit; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; cursor: pointer; color: var(--ink);
}
button.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
button.icon { width: 38px; padding: 0; height: 38px; display: inline-grid; place-items: center; font-weight: 700; }
#new-game-btn .plus { display: none; font-size: 22px; line-height: 1; }
button:disabled { opacity: .5; cursor: default; }

/* ---- three panes: board (fixed) | clues (scrolls) | distribution (scrolls) ---- */
main { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 0 16px; }
main.playing { grid-template-columns: 2fr 1fr; }
main.playing .right { display: none; }
main.playing .mid { padding-right: 24px; }
.left {
  min-height: 0; display: flex; flex-direction: column; padding: 4px 8px 12px 24px;
}
.left-top { flex: 0 0 auto; }
.board-area {
  flex: 1 1 auto; min-height: 0; container-type: size;
  display: flex; align-items: center; justify-content: center;
}
.col-scroll {
  min-height: 0; overflow-y: auto; padding: 4px 0 16px; display: flex; flex-direction: column; gap: 14px;
}
.right { padding-right: 24px; }
.col-scroll { scrollbar-width: thin; scrollbar-color: #cfc8b8 transparent; scrollbar-gutter: stable; }
.col-scroll::-webkit-scrollbar { width: 8px; }
.col-scroll::-webkit-scrollbar-track { background: transparent; }
.col-scroll::-webkit-scrollbar-thumb { background: #cfc8b8; border-radius: 999px; border: 2px solid var(--bg); }
.col-scroll::-webkit-scrollbar-thumb:hover { background: #b5ad9a; }

/* right-column boxes: square corners to contrast with the cards */
.box { background: var(--panel); border: 1px solid var(--line); border-radius: 0; padding: 14px 16px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.explorer-hint { margin: 4px 0 6px; }
.seg button { padding: 3px 10px; font-size: 12px; border-radius: 999px; }
.seg button.on { background: var(--ink); color: #fff; border-color: var(--ink); }

/* status + game-over banner above the board */
.status { flex: 0 0 auto; display: flex; gap: 24px; align-items: baseline; margin-top: 12px; font-size: 14px; }
.status .big { font-size: 24px; font-weight: 700; }
.status .tag { padding: 2px 8px; border-radius: 6px; font-weight: 600; font-size: 12px; }
.status .tag.won { background: var(--key-soft); color: var(--key); }
.status .tag.lost { background: var(--assassin-soft); color: var(--assassin); }
.status .tag.in_progress { background: var(--card); color: var(--muted); }
.banner {
  padding: 12px 18px; margin-bottom: 10px;
  border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel); font-size: 14px;
}
.banner b { display: block; font-size: 24px; font-weight: 650; line-height: 1.2; }
.banner > span { display: block; margin-top: 2px; }
.banner.won { border-color: var(--key); background: var(--key-soft); }
.banner.lost { border-color: var(--assassin); background: var(--assassin-soft); }

/* board: fits the available area, 5:3 overall */
.grid {
  display: grid; grid-template-columns: repeat(5, 1fr); grid-template-rows: repeat(5, 1fr); gap: 10px;
  width: min(100cqw, calc(100cqh * 5 / 3)); aspect-ratio: 5 / 3;
}
/* Every card has an inset ring: a strip of card color at the edge, a thin white ring, then the fill.
   Selecting a card (or highlighting a turn's guesses) just recolors that ring. */
.card {
  position: relative; border-radius: var(--radius); min-height: 0;
  display: flex; align-items: center; justify-content: center; text-align: center; padding: 10px;
  font-family: var(--font-words); font-weight: 600; font-size: clamp(12px, 1.3vw, 20px); letter-spacing: .04em;
  background: var(--card); cursor: pointer; user-select: none;
  outline: 2px solid rgba(255, 255, 255, .85); outline-offset: -6px;
  transition: transform .08s ease, box-shadow .08s ease, outline-color .08s ease;
}
.grid:not(.archived) .card:hover:not(.revealed) { transform: translateY(-1px); box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.grid.archived .card { cursor: default; }
/* spymaster's secret key: subtle role tint + dot on hidden cards */
.card.role-key { background: var(--key-soft); }
.card.role-assassin { background: var(--assassin-soft); }
.card.role-key::after, .card.role-assassin::after {
  content: ""; position: absolute; top: 10px; right: 10px; width: 7px; height: 7px; border-radius: 50%;
}
.card.role-key::after { background: var(--key); }
.card.role-assassin::after { background: var(--assassin); }
.card.selected { outline-color: var(--highlight); }
.card.revealed { cursor: default; color: #fff; }
.card.revealed.role-key { background: var(--key); }
.card.revealed.role-neutral { background: var(--neutral); color: #3b3222; }
.card.revealed.role-assassin { background: var(--assassin); }
.card.revealed::after { display: none; }
.card.just { outline-color: var(--highlight); }

/* clue input box */
.clue-form { display: flex; gap: 8px; margin-top: 10px; }
.clue-form input { flex: 1; min-width: 0; text-transform: uppercase; font-weight: 600; letter-spacing: .05em; }
.clue-form button { border-radius: 0; }
#selected-count { margin: 8px 0 0; }
.hint { margin: 8px 0 0; line-height: 1.4; }

/* distribution panel header lines */
.turnline { margin: 10px 0 0; font-size: 14px; display: flex; flex-wrap: wrap; align-items: baseline; }
.turnline b { font-weight: 650; margin-right: 4px; }
.turnline .sep { color: var(--line); margin: 0 10px; }
.result { margin: 6px 0 2px; font-size: 14px; }
.result b { font-weight: 650; margin-right: 4px; }
.result .sub { font-weight: 400; color: var(--muted); font-size: 13px; }
#dist-meta { margin: 4px 0 0; }
.row {
  display: grid; grid-template-columns: 126px 1fr 44px; gap: 8px; align-items: center;
  padding: 3px 0; font-size: 13px;
}
.row .w { display: flex; gap: 5px; align-items: center; white-space: nowrap; overflow: hidden; }
.row .w .word { font-weight: 600; font-size: 14px; letter-spacing: .02em; }
.row .w .m { font-size: 11px; font-weight: 700; padding: 0 5px; border-radius: 4px; }
.m.int { background: #e0e7ff; color: #3730a3; }
.m.hit { background: var(--key-soft); color: var(--key); }
.m.miss { background: var(--neutral-soft); color: #6b5a3a; }
.m.assassin { background: var(--assassin); color: #fff; }
.row .bar { position: relative; height: 16px; background: #f1eee6; overflow: hidden; }
.row .bar > i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--bar-dim); }
.row.intended .bar > i { background: var(--bar); }
.row.taken .bar > i { background: var(--neutral); }
.row.intended.taken .bar > i { background: var(--key); }
.row.taken.assassin .bar > i { background: var(--assassin); }
.row .bar > b { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--danger); opacity: .7; }
.row .p { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.legend { display: flex; gap: 10px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin: 8px 0 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; margin-right: 4px; vertical-align: -1px; }

/* history explorer */
.hist {
  display: grid; grid-template-columns: 22px 1fr; gap: 6px; padding: 8px 8px; margin: 0 -8px;
  border-top: 1px solid var(--line); font-size: 13px; cursor: pointer;
}
.hist:hover { background: var(--bg); }
.hist.active { background: #eef2ff; }
.hist .num { color: var(--muted); font-variant-numeric: tabular-nums; }
.hist .cw { font-weight: 700; letter-spacing: .04em; }
.hist .line { color: var(--muted); }
.hist .chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.chip { font-size: 11px; padding: 1px 7px; border-radius: 3px; border: 1.5px solid currentColor; background: transparent; color: var(--muted); }
.chip .word { font-size: 12px; font-weight: 600; letter-spacing: .03em; }
.chip.hit { color: var(--key); }
.chip.miss { color: #8a7648; }
.chip.assassin { color: var(--assassin); }
.chip.wanted { color: #7c8aa5; border-style: dashed; }

/* game summary: four headline stats */
.summary-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; margin: 10px 0 2px; font-size: 12px; color: var(--muted); }
.summary-stats b { display: block; font-size: 20px; color: var(--ink); }


/* welcome dialog */
.welcome { width: min(560px, 92vw); }
.welcome-title { font-family: var(--font-words); font-size: 40px; font-weight: 600; text-align: center; text-transform: none; letter-spacing: -.01em; color: var(--ink); }
.welcome-sub { text-align: center; margin: 2px 0 14px; font-size: 15px; }
.welcome h3 { margin-top: 14px; }
.welcome ul { padding-left: 20px; margin: 6px 0; }
.welcome li { margin: 4px 0; line-height: 1.4; font-size: 14px; }
.welcome .dialog-actions { justify-content: center; margin-top: 22px; }
.welcome .dialog-actions button { padding: 10px 22px; font-size: 15px; }

/* dialogs */
dialog {
  border: 1px solid var(--line); border-radius: 14px; padding: 22px 24px; width: min(520px, 92vw);
  color: var(--ink); background: var(--panel);
}
dialog::backdrop { background: rgba(30, 27, 22, .45); }
dialog p { margin: 8px 0; line-height: 1.45; font-size: 14px; }
dialog li {font-size: 14px;}
dialog input[type="number"] { border-radius: 8px; }
.field { display: block; margin: 14px 0 0; font-size: 14px; font-weight: 600; }
.field .muted { font-weight: 400; margin-left: 4px; }
.field input[type="number"] { display: block; margin-top: 6px; width: 120px; }
fieldset.field { border: 0; padding: 0; }
fieldset legend { padding: 0; margin-bottom: 4px; }
.radio { display: block; font-weight: 400; margin: 6px 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* credit, pinned bottom-right */
.credit { flex: 0 0 auto; text-align: right; padding: 2px 24px 8px; font-size: 12px; color: var(--muted); }
.credit a { color: var(--muted); text-decoration: underline; text-underline-offset: 2px; }
.credit a:hover { color: var(--ink); }

/* narrow screens: stack and scroll normally */
@media (max-width: 900px) {
  body { overflow: auto; display: block; }
  /* compact header: title left, icon buttons right */
  .top { grid-template-columns: 1fr auto; padding: 14px 16px 8px; min-height: 0; }
  .top-spacer, .subtitle { display: none; }
  .title-wrap { text-align: left; }
  .top h1 { font-size: 26px; }
  #new-game-btn { width: 38px; height: 38px; padding: 0; display: inline-grid; place-items: center; }
  #new-game-btn .label { display: none; }
  #new-game-btn .plus { display: block; }
  .card::after { top: 6px !important; right: 6px !important; width: 5px !important; height: 5px !important; }
  .card { font-size: 13px; padding: 8px 6px; outline-offset: -4px; }
  main { display: block; }
  .left { padding: 4px 16px; }
  .board-area { container-type: normal; display: block; }
  .grid { width: 100%; }
  .col-scroll { overflow: visible; padding: 14px 16px; }
  .right { padding: 0 16px 14px; }
  .credit { padding: 0 16px 16px; }
}
