:root {
  --bg: #14161b;
  --panel: #1f222a;
  --panel-2: #2a2e38;
  --line: #3a3f4a;
  --text: #eef0f4;
  --muted: #9aa1ad;
  --red: #cc4b18;          /* red team: warm orange-red, kept apart from the assassin's red */
  --red-text: #ff8f5e;     /* lighter shade for text on the dark background */
  --blue: #2563eb;
  --blue-text: #7ea6ff;
  --neutral: #d9c9a3;
  --neutral-ink: #2a2418;
  --assassin: #000;
  --assassin-edge: #e5383b; /* the assassin list's outline */
  --used-ink: #8a919d;      /* guessed words: muted but readable */
  /* Typewriter accents (titles, labels, clue words). System fonts only, so it works offline. */
  --mono: "American Typewriter", "Courier New", Courier, "Cutive Mono", ui-monospace, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: dark;
}

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

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 max(10px, env(safe-area-inset-right)) calc(80px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); /* room for the cover button */
}

button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

/* ---------- Header (not sticky) ---------- */
header { padding: calc(10px + env(safe-area-inset-top)) 0 2px; }
.bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
h1 { display: flex; align-items: center; gap: 8px; font: 700 19px var(--mono); margin: 0; letter-spacing: .04em; }
h1 .logo { width: 26px; height: 26px; flex: none; margin-top: -2px; } /* the spy sits a little low in its box */

/* Rubber stamp: finished clues, end-of-game screen, privacy cover */
.stamp {
  display: inline-block; padding: 1px 6px 0; border: 1.5px solid currentColor; border-radius: 3px;
  font: 700 10px/1.4 var(--mono); letter-spacing: .12em; text-transform: uppercase;
  transform: rotate(-6deg); opacity: .9; white-space: nowrap;
}
.score { margin: 0; font-weight: 700; font-size: 14px; display: flex; gap: 12px; }

/* Header line 2: "Spymaster for Red · switch" on Setup, the score during the game. */
.bar.sub { min-height: 22px; }
/* Bottom of Setup, under New game (like "Edit setup" in the game): "Spymaster for Red · switch" */
.playing { margin: 8px 0 0; font-size: 14px; color: var(--muted); text-align: center; }
.playing b { font-weight: 750; }
.playing b.red, .score .red { color: var(--red-text); }
.playing b.blue, .score .blue { color: var(--blue-text); }
.playing .link { padding: 4px 2px; font-size: 14px; }
body:not([data-screen="clues"]) .bar.sub, /* header line 2 now only holds the game's score */
body:not([data-screen="setup"]) .playing,
body:not([data-screen="clues"]) .score { display: none; }

/* Subtle text button: "switch", "Edit setup", "View board" */
.link {
  border: 0; background: none; color: var(--muted); padding: 10px; font-size: 14px;
  text-decoration: underline; text-underline-offset: 3px;
}
#editSetup { display: block; margin: 8px auto 0; }
body:not([data-screen="clues"]) #editSetup,
body[data-screen="team"] #newGame { display: none; }

/* ---------- Step 1: choose your team ---------- */
.pick { padding: 12vh 4px 0; text-align: center; }
.pick h2 { margin: 0 0 8px; font: 700 20px var(--mono); letter-spacing: .1em; text-transform: uppercase; }
.pick p { margin: 0 0 28px; color: var(--muted); }
.pick-buttons { display: grid; grid-template-columns: 1fr; gap: 12px; max-width: 360px; margin: 0 auto; } /* stacked: Red above Blue */
.pick-team {
  display: flex; align-items: center; justify-content: center; gap: 14px; padding: 22px 16px;
  border: 0; border-radius: 16px; color: #fff; font: 750 20px system-ui, -apple-system, sans-serif;
}
.pick-team svg { width: 40px; height: 40px; }
.pick-team[data-team="red"] { background: var(--red); }
.pick-team[data-team="blue"] { background: var(--blue); }
.pick-team:active { transform: scale(.97); }

/* ---------- End-of-game banner ---------- */
#banner {
  display: flex; align-items: center; justify-content: center; gap: 12px; margin: 8px 0 4px; padding: 12px;
  border: 2px solid var(--accent); border-radius: 12px; background: var(--panel);
  font: 700 14px var(--mono); letter-spacing: .08em; text-transform: uppercase; text-align: center;
}
#banner .stamp { font-size: 13px; color: var(--accent); }

/* ---------- Setup progress ---------- */
.progress { display: flex; align-items: center; gap: 10px; margin: 10px 0 4px; font-size: 13px; color: var(--muted); }
.progress .track { flex: 1; height: 4px; border-radius: 4px; background: var(--panel-2); overflow: hidden; }
.progress .fill { height: 100%; width: 0; background: var(--text); border-radius: 4px; transition: width .25s ease-out; }
.progress.complete .fill { background: #4ade80; }
.progress b { color: var(--text); font-weight: 650; }
.list .count .ok { color: #4ade80; margin-left: 4px; }

/* ---------- Labels ---------- */
.list h2 .name { display: inline-flex; align-items: center; gap: 6px; }
.list h2 .icon { width: 15px; height: 15px; color: var(--accent); flex: none; }

/* ---------- Screens ---------- */
body:not([data-screen="team"]) #team,
body:not([data-screen="setup"]) #setup,
body:not([data-screen="clues"]) #clues { display: none; }

/* ---------- Lists ---------- */
.list {
  background: var(--panel); border-radius: 12px; padding: 12px 14px 14px; margin-top: 14px;
  border: 2px solid var(--accent, var(--line));
  transition: box-shadow .12s;
}
.list.drop { box-shadow: 0 0 0 2px var(--accent, #fff); }
.list h2 {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  margin: 0 0 10px; font: 700 13px var(--mono); text-transform: uppercase; letter-spacing: .1em; color: var(--muted);
}
.list .count { color: var(--text); font: 650 14px system-ui, -apple-system, sans-serif; text-transform: none; letter-spacing: 0; }
.list h3 { margin: 16px 0 8px; font: 700 11px var(--mono); text-transform: uppercase; letter-spacing: .12em; color: var(--muted); }

.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px 6px; } /* 8px between lines of chips, 6px between chips */
.chips:not(.zone):empty { display: none; }
.chips.zone { min-height: 44px; border-radius: 10px; }
.chips.zone:empty { border: 1px dashed var(--line); display: flex; align-items: center; justify-content: center; }
.chips.zone:empty::before { content: attr(data-empty); color: var(--muted); font-size: 13px; }

/* ---------- Chips ---------- */
.chip {
  display: inline-flex; align-items: stretch; border-radius: 999px; overflow: hidden;
  background: var(--chip-bg, var(--panel-2)); color: var(--chip-ink, #fff);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.chip .word {
  border: 0; background: transparent; color: inherit; padding: 9px 13px;
  font-weight: 750; font-size: 15px; letter-spacing: .02em; text-transform: uppercase;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.chip.small .word { padding: 6px 10px; font-size: 13px; }
/* Setup: press-and-move drags at once, so chips must not scroll the page. In the game, chips
   scroll normally and a drag arms after a short press (JS then blocks scrolling). */
#setup .chip.draggable { touch-action: none; }
.chip.draggable .word { cursor: grab; }
/* Guessed words: outlined in their color, with muted text. */
.chip.used { background: transparent; box-shadow: inset 0 0 0 1.5px var(--accent); color: var(--used-ink); }
/* A quick press effect on tap (Setup's hold-to-delete and dragging override it below). */
.chip:active { transform: scale(.95); transition: transform .08s; }
.chip.armed { transform: scale(1.07); box-shadow: 0 6px 18px #000a; transition: transform .12s ease-out; } /* ready to drag */
.chip.dragging { position: fixed; z-index: 30; box-shadow: 0 8px 24px #000a; transform: scale(1.06); }
.chip.dragging .word { cursor: grabbing; }
.chip.placeholder { background: transparent; outline: 2px dashed #fff5; }
.chip .chip-edit {
  border: 0; outline: none; margin: 4px; padding: 5px 8px; border-radius: 999px; min-width: 0;
  background: #0005; color: inherit; font: 750 16px system-ui, sans-serif; text-transform: uppercase;
}

[data-color="red"] { --accent: var(--red); --chip-bg: var(--red); }
[data-color="blue"] { --accent: var(--blue); --chip-bg: var(--blue); }
[data-color="neutral"] { --accent: var(--neutral); --chip-bg: var(--neutral); --chip-ink: var(--neutral-ink); }
[data-color="assassin"] { --accent: var(--assassin-edge); --chip-bg: var(--assassin); } /* black chips, red outline */

/* Setup: press-and-hold deletes; the chip shrinks and fades while held so you can see it coming. */
.chip.holding { transform: scale(.88); opacity: .55; transition: transform .5s ease-in, opacity .5s ease-in; }

/* ---------- Inputs ---------- */
input.caps { text-transform: uppercase; }
input.caps::placeholder { text-transform: none; }
.add { margin-top: 12px; }
.add input, .clue-text {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--text); font-family: inherit; font-size: 16px; font-weight: 650;
}
.clue-text { font-family: var(--mono); font-weight: 700; letter-spacing: .08em; }
.add input::placeholder, .clue-text::placeholder { color: #6b7280; font-weight: 400; }
.add input:focus, .clue-text:focus { outline: 2px solid var(--accent, #fff); border-color: transparent; }

/* ---------- Clue cards: file folders, with the clue word on the tab ---------- */
.card {
  position: relative; margin: 46px 0 12px; /* room above for the folder tab */ padding: 10px 8px 8px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 0 12px 12px 12px; transition: box-shadow .12s;
}
.card.drop { box-shadow: 0 0 0 2px var(--accent); }
.card-head {
  position: absolute; left: -1px; bottom: calc(100% - 1px); width: 74%;
  display: flex; align-items: center; gap: 2px; padding: 3px 4px 0 4px;
  background: var(--bg); border: 1px solid var(--line); border-bottom: 0; border-radius: 10px 10px 0 0;
}
.card-head .clue-text { flex: 1; min-width: 0; padding: 6px 8px; border: 0; background: transparent; font-size: 16px; }
.card-head .clue-text:focus { outline: none; box-shadow: inset 0 -2px 0 var(--accent); border-radius: 0; }
.card-head .x, .card-head .fold { border: 0; background: none; color: var(--muted); font-size: 22px; line-height: 1; padding: 4px 6px; }
.card-head .fold { font-size: 18px; }
.card .chips.zone { padding: 2px; }
.card.done { opacity: .85; }
.card.done .card-head { background: var(--bg); }

.newclue {
  width: 100%; padding: 12px; border: 1.5px dashed var(--line); border-radius: 12px;
  background: transparent; color: var(--text); font-weight: 700; text-align: center;
}
.newclue small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; margin-top: 2px; }
.newclue.drop { border-color: var(--accent); background: #ffffff0d; }

.list.compact { padding-top: 10px; padding-bottom: 12px; }
.list.compact h2 { margin-bottom: 8px; }

/* ---------- Finished clues (folded to the bottom of Our agents) ---------- */
#doneClues ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.done-line {
  width: 100%; display: flex; align-items: baseline; flex-wrap: wrap; gap: 2px 8px; text-align: left;
  padding: 8px 10px; border: 0; border-radius: 10px; background: var(--bg); font-size: 14px;
}
.done-line { align-items: center; }
.done-line b { font-family: var(--mono); letter-spacing: .08em; }
.done-line s { text-decoration: none; color: var(--used-ink); }
.done-line .stamp { margin-left: auto; color: var(--accent); }
.done-line::after { content: "▾"; color: var(--muted); }

/* ---------- End-of-game screen ---------- */
#endScreen {
  position: fixed; inset: 0; z-index: 55; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; padding: 24px max(24px, env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
  background: #050608; /* fallback for browsers without color-mix() */
  background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--accent) 30%, #0b0c10) 0%, #050608 70%);
  text-align: center; animation: end-in .25s ease-out;
}
#endScreen .stamp {
  font-size: clamp(26px, 9vw, 40px); padding: 8px 18px 6px; border-width: 4px; border-radius: 6px;
  max-width: 100%; white-space: normal; line-height: 1.15; /* long stamps (MISSION COMPLETE) wrap instead of overflowing */
  margin-bottom: 16px; /* the stamp is tilted, so its low corner needs extra room above the text below */
  color: var(--accent); animation: stamp-in .35s cubic-bezier(.2, 1.4, .4, 1) .05s both;
}
#endScreen[data-color="neutral"] .stamp { color: var(--neutral); }
#endScreen p { margin: 0; font: 700 16px var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--text); }
.end-actions { display: grid; gap: 10px; width: min(340px, 100%); margin-top: 18px; }
.end-actions .wide { margin: 0; }
.end-actions #endUndo { background: var(--panel-2); color: var(--text); }
@keyframes end-in { from { opacity: 0; } }
@keyframes stamp-in { from { opacity: 0; transform: rotate(-6deg) scale(1.8); } }

/* ---------- Privacy cover ---------- */
#coverBtn {
  position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 45;
  width: 52px; height: 52px; display: grid; place-items: center; border: 1.5px solid var(--line); border-radius: 50%;
  background: var(--panel); color: var(--text); box-shadow: 0 6px 20px #000a;
  transition: opacity .2s, transform .2s;
}
/* Tucks away while you scroll so it never sits over a word; returns when scrolling stops. */
body.scrolling #coverBtn { opacity: 0; transform: translateY(12px) scale(.9); pointer-events: none; }
/* Only during the game; team choice and Setup happen before the board is on the table. */
body:not([data-screen="clues"]) #coverBtn { display: none; }
#coverBtn svg { width: 26px; height: 26px; }
#cover {
  position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px;
  background: #000; color: var(--muted); font: 14px var(--mono); letter-spacing: .1em; text-transform: uppercase;
  cursor: pointer; -webkit-user-select: none; user-select: none;
}
#cover .stamp { font-size: 30px; padding: 6px 16px 4px; border-width: 4px; border-radius: 6px; color: var(--assassin-edge); }
#cover p { margin: 0; }

/* ---------- Bottom ---------- */
.hint { color: var(--muted); font-size: 12px; text-align: center; margin: 16px 0 12px; }
.wide { display: block; width: 100%; border: 0; border-radius: 10px; padding: 12px; font-weight: 700; }
.wide.primary { background: #e8eaee; color: #111; margin-bottom: 12px; }
.wide.danger { background: #3a1f22; color: #ffb4b0; font-weight: 650; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; top: calc(12px + env(safe-area-inset-top)); transform: translate(-50%, -20px); /* top: never covers words or buttons */
  display: flex; align-items: center; gap: 12px;
  width: max-content; max-width: calc(100vw - 32px); padding: 10px 14px; border-radius: 10px;
  background: #e8eaee; color: #111; font-weight: 600; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 40;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#toast { box-shadow: 0 8px 24px #000a; }

/* Respect "reduce motion": no transitions or press effects (the JS skips its glide animations too). */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
  .chip:active { transform: none; }
}
#toast button { border: 0; background: none; color: #1a5fd0; font-weight: 800; padding: 4px 2px; }
