/* Codename Corgo: everything visual. A night-navy spy's desk, cream codename cards, the Reds' red
   and the Merles' blue, squirrels in tan and the Cat in black; Duet's pups in green. Three shapes:
   a desk (the packs beside the board, the board sized to the window), a tablet, and a phone (the
   packs above the board, the page scrolls). The safe area of an installed iPhone app is padded
   exactly once, on .game and .screen; heights run 100% down from html, never 100vh. */

:root {
  --night: #101a33;
  --night-2: #16244a;
  --night-3: #1e3160;
  --ink: #f4ecd8;
  --ink-dim: #b9b3a3;
  --cream: #f4e8cc;
  --cream-2: #ead9b4;
  --card-ink: #3a2816;
  --red: #d2462f;
  --red-soft: #f6d2c8;
  --red-ink: #7d1f10;
  --blue: #2f6fc4;
  --blue-soft: #d3e1f6;
  --blue-ink: #163f7a;
  --squirrel: #c4a774;
  --squirrel-soft: #ece0c4;
  --cat: #1c1a22;
  --pup: #3f9b5a;
  --pup-soft: #d2ecd8;
  --side-b: #c7922b;
  --gold: #f2b544;
  --radius: 12px;
  --gap: clamp(5px, 0.8vw, 10px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: radial-gradient(1200px 700px at 15% -10%, #24386e 0%, transparent 60%), radial-gradient(900px 600px at 110% 110%, #2a1f45 0%, transparent 60%), var(--night);
  background-attachment: fixed;
  color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
#app { height: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--gold); }
h1, h2, h3, h4 { margin: 0; line-height: 1.15; }
.small { font-size: 0.85rem; color: var(--ink-dim); }
.hint { color: var(--ink-dim); font-size: 0.92rem; margin: 6px 0 0; }
.t-red { --tone: var(--red); }
.t-blue { --tone: var(--blue); }
.t-a, .t-duet { --tone: var(--pup); }
.t-b { --tone: var(--side-b); }
.t-cat { --tone: #6d6779; }
b.t-red { color: #ff8b73; }
b.t-blue { color: #8db8ff; }

/* ——— buttons ——— */
button, .btn, a.primary, a.ghost-btn {
  cursor: pointer;
  border: 1px solid #ffffff2a;
  background: #ffffff12;
  border-radius: 10px;
  padding: 9px 14px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.15s, transform 0.1s, border-color 0.15s;
}
button:hover:not(:disabled), .btn:hover, a.ghost-btn:hover { background: #ffffff20; }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: default; }
.primary, a.primary {
  background: linear-gradient(180deg, #ffc95e, var(--gold));
  border-color: #b9801a;
  color: #2b1a05;
  font-weight: 700;
  padding: 11px 20px;
  box-shadow: 0 2px 0 #9b6a12;
}
.primary:hover:not(:disabled) { background: linear-gradient(180deg, #ffd477, #f7bf55); }
.primary.danger { background: linear-gradient(180deg, #ff7a63, var(--red)); border-color: #8f2414; color: #fff; box-shadow: 0 2px 0 #7a1d10; }
.ghost-btn { background: transparent; }
.warn { color: #ffb3a6; }
.link { background: none; border: none; color: var(--gold); text-decoration: underline; padding: 4px; }
.icon-btn { padding: 6px 10px; font-size: 1.15rem; background: transparent; border-color: transparent; position: relative; }
.badge { position: absolute; top: -2px; right: -2px; background: var(--red); color: #fff; font-size: 0.7rem; border-radius: 9px; padding: 1px 5px; font-weight: 700; }
input[type="text"], textarea, select {
  background: #0b1328;
  border: 1px solid #ffffff2e;
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
}
input[type="text"]:focus, textarea:focus, select:focus { border-color: var(--gold); box-shadow: 0 0 0 3px #f2b54433; }

/* ——— the screens before the board ——— */
.screen {
  min-height: 100%;
  padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(28px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  display: flex;
  justify-content: center;
}
.screen-inner { width: 100%; max-width: 760px; display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; }
.screen h1 { font-size: clamp(2rem, 6vw, 3.1rem); letter-spacing: 0.02em; font-weight: 900; text-shadow: 0 3px 0 #0006; }
.tag { max-width: 560px; color: var(--ink); margin: 0; font-size: 1.05rem; }
.welcome, .join-code { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; align-items: center; }
.welcome input { min-width: 200px; }
.join-code input { width: 6.5em; text-transform: uppercase; text-align: center; letter-spacing: 0.15em; }
.join-code label { color: var(--ink-dim); }
.whoami { display: flex; align-items: center; gap: 10px; }
.home-go { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.hero { display: grid; grid-template-columns: repeat(4, 76px); gap: 8px; margin: 8px 0 4px; perspective: 600px; }
.hero-card {
  height: 52px;
  border-radius: 9px;
  background: linear-gradient(180deg, var(--cream), var(--cream-2));
  color: var(--card-ink);
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  box-shadow: 0 3px 0 #0005;
  overflow: hidden;
  transform: rotate(calc((var(--i) - 3.5) * 1.6deg));
  border: 2px solid var(--tone, transparent);
}
.hero-card img { width: 100%; height: 100%; object-fit: cover; }
ul.seats { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
ul.seats li { display: flex; align-items: center; gap: 6px; background: #ffffff10; border-radius: 20px; padding: 4px 12px 4px 4px; }

/* the portraits */
.avatar {
  --size: 30px;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  flex: none;
  display: inline-grid;
  place-items: center;
  background: var(--face, none) center / cover, var(--ground);
  color: #fff;
  font-weight: 800;
  font-size: 0.85rem;
  box-shadow: 0 0 0 2px #0004;
}
.avatar[data-face] span { visibility: hidden; }

/* ——— the home tabs ——— */
.home-tabs { width: 100%; text-align: left; background: #0b13288c; border: 1px solid #ffffff1a; border-radius: var(--radius); padding: 12px; }
.tabs { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.tab { padding: 7px 12px; }
.tab[aria-selected="true"] { background: var(--gold); color: #2b1a05; border-color: var(--gold); font-weight: 700; }
.tab-count:not(:empty) { background: #0004; border-radius: 8px; padding: 0 6px; font-size: 0.8rem; }
.empty { color: var(--ink-dim); text-align: center; margin: 14px 0; }
.my-tables, .history, .ranks { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.my-table { display: flex; align-items: center; gap: 8px; background: #ffffff0c; border-radius: 10px; padding: 8px; }
.my-table.hot { outline: 2px solid var(--gold); }
.my-table-main { flex: 1; color: inherit; text-decoration: none; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.my-table-top { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.my-code { font-family: ui-monospace, monospace; letter-spacing: 0.1em; }
.my-table-top .mode, .my-table-top em { font-size: 0.75rem; background: #ffffff14; border-radius: 6px; padding: 1px 6px; font-style: normal; }
.state { color: var(--ink-dim); font-size: 0.9rem; }
.my-table.hot .state { color: var(--gold); font-weight: 700; }
.my-table-corgis { display: flex; gap: 8px; align-items: center; color: var(--ink-dim); font-size: 0.85rem; min-width: 0; }
.my-table-corgis .names { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.my-table-acts { display: flex; gap: 4px; }
.faces { display: inline-flex; }
.faces .avatar { --size: 22px; font-size: 0.65rem; margin-right: -5px; }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tile { background: #ffffff0c; border-radius: 10px; padding: 10px; text-align: center; display: flex; flex-direction: column; }
.tile b { font-size: 1.5rem; }
.tile span { color: var(--ink-dim); font-size: 0.8rem; }
.moments { display: flex; flex-wrap: wrap; gap: 6px; }
.moments span { background: #ffffff0c; border-radius: 8px; padding: 3px 8px; font-size: 0.85rem; }
.home-tabs h3 { margin: 12px 0 8px; font-size: 1rem; }
.past { display: flex; align-items: center; gap: 10px; background: #ffffff0a; border-radius: 10px; padding: 8px; }
.past.won { background: #f2b5441a; }
.place { width: 28px; text-align: center; font-size: 1.2rem; }
.past-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.past-meta { color: var(--ink-dim); font-size: 0.8rem; }
.ranks li { display: flex; align-items: center; gap: 10px; background: #ffffff0a; border-radius: 10px; padding: 8px; }
.ranks li.you { outline: 2px solid var(--gold); }
.rank { width: 28px; text-align: center; font-weight: 800; }
.rank-name { flex: 1; }
.rank-name em { margin-left: 6px; font-size: 0.75rem; color: var(--gold); }
.rank-stats { color: var(--ink-dim); font-size: 0.85rem; }

/* ——— the lobby ——— */
.lobby .screen-inner { max-width: 980px; }
.invite { width: 100%; max-width: 620px; display: flex; flex-direction: column; gap: 6px; align-items: center; }
.table-code { display: flex; gap: 10px; align-items: baseline; }
.table-code b { font-family: ui-monospace, monospace; font-size: 1.8rem; letter-spacing: 0.2em; color: var(--gold); }
.linkrow { display: flex; gap: 6px; width: 100%; }
.linkrow input { flex: 1; min-width: 0; }
.packs-box, .options, .lobby-chat { width: 100%; text-align: left; background: #0b13288c; border: 1px solid #ffffff1a; border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.packs { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pack { border-radius: var(--radius); padding: 12px; background: linear-gradient(180deg, color-mix(in srgb, var(--tone) 32%, transparent), color-mix(in srgb, var(--tone) 10%, transparent)); border: 1px solid color-mix(in srgb, var(--tone) 60%, transparent); display: flex; flex-direction: column; gap: 6px; }
.pack-head { display: flex; align-items: center; gap: 10px; }
.pack h4 { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-dim); margin-top: 4px; }
.crest { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; box-shadow: 0 0 0 3px var(--tone); background: var(--night-2); }
.people { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.person { display: flex; align-items: center; gap: 8px; background: #0003; border-radius: 8px; padding: 4px 6px; min-height: 38px; }
.person.away { opacity: 0.6; }
.person-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person em, .member em { font-style: normal; font-size: 0.72rem; background: #ffffff1c; border-radius: 6px; padding: 1px 6px; }
.person em.away, .member em.away { color: var(--ink-dim); }
.place { width: auto; max-width: 150px; font-size: 0.8rem; padding: 4px 6px; }
li.empty { color: var(--ink-dim); font-style: italic; padding: 4px 6px; }
.join-btn { align-self: flex-start; font-size: 0.9rem; padding: 6px 10px; }
.unpicked { display: flex; flex-direction: column; gap: 6px; }
.unpicked > span { color: var(--ink-dim); font-size: 0.9rem; }
.opt { display: flex; flex-direction: column; gap: 6px; }
.opt-label { font-weight: 700; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.opt-label small { font-weight: 400; color: var(--ink-dim); }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button[aria-pressed="true"], .chip[aria-pressed="true"], .num-pick button[aria-pressed="true"] { background: var(--gold); color: #2b1a05; border-color: var(--gold); font-weight: 700; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip small { opacity: 0.75; font-size: 0.75rem; }
.custom-words { width: 100%; resize: vertical; font-family: ui-monospace, monospace; text-transform: uppercase; }
.custom-acts { display: flex; gap: 10px; align-items: center; }
.pic-peek { display: flex; gap: 6px; flex-wrap: wrap; }
.pic-peek img { width: 64px; height: 64px; border-radius: 8px; object-fit: cover; }
.opt-read { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.opt-read li { display: flex; justify-content: space-between; gap: 10px; }
.opt-read span { color: var(--ink-dim); }
.mode-blurb { margin: -2px 0 0; }
.lobby-go { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.lobby-go .deal { font-size: 1.15rem; padding: 13px 34px; }
.lobby-acts { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

/* ——— the chat ——— */
.chat { display: flex; flex-direction: column; gap: 8px; min-height: 0; flex: 1; }
.chat-lines { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; }
.drawer .chat-lines { max-height: none; flex: 1; }
.chat-lines li { display: flex; gap: 8px; align-items: flex-start; }
.chat-lines li.mine { flex-direction: row-reverse; }
.chat-bubble { background: #ffffff12; border-radius: 10px; padding: 6px 10px; display: flex; flex-direction: column; max-width: 80%; word-break: break-word; }
.chat-lines li.mine .chat-bubble { background: #f2b5442b; }
.chat-bubble b { font-size: 0.78rem; color: var(--ink-dim); }
.chat-empty { color: var(--ink-dim); font-style: italic; }
.chat-quick { display: flex; gap: 4px; flex-wrap: wrap; }
.chat-quick button { font-size: 0.8rem; padding: 4px 8px; }
.chat-say { display: flex; gap: 6px; }
.chat-say input { flex: 1; min-width: 0; }

/* ——— the board screen ——— */
.game {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  gap: 8px;
}
.topbar { display: flex; align-items: center; gap: 12px; min-height: 48px; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; font-weight: 900; letter-spacing: 0.02em; }
.brand img { width: 34px; height: 34px; border-radius: 9px; object-fit: cover; }
.score { flex: 1; display: flex; justify-content: center; align-items: center; gap: 12px; }
.score-team { display: flex; align-items: baseline; gap: 8px; padding: 4px 14px; border-radius: 12px; background: color-mix(in srgb, var(--tone) 22%, transparent); border: 2px solid transparent; }
.score-team b { font-size: 1.8rem; font-weight: 900; color: color-mix(in srgb, var(--tone) 50%, white); }
.score-team.now { border-color: var(--tone); box-shadow: 0 0 18px color-mix(in srgb, var(--tone) 55%, transparent); }
.score-dash { color: var(--ink-dim); }
.score-duet { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: center; }
.pups b { font-size: 1.5rem; color: #8fe0a5; }
.treats { display: flex; gap: 2px; font-size: 1.15rem; }
.treat.eaten { filter: grayscale(1); opacity: 0.25; }
.timer { font-variant-numeric: tabular-nums; font-weight: 800; background: #ffffff14; border-radius: 10px; padding: 4px 10px; }
.timer.low { background: var(--red); animation: pulse 1s infinite; }
.top-acts { display: flex; gap: 2px; }
.stage { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(170px, 230px) 1fr minmax(190px, 260px); gap: 12px; }
.center { min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.right-col { display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.team-panel {
  border-radius: var(--radius);
  padding: 12px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--tone) 30%, #0b1328), #0b1328cc);
  border: 1px solid color-mix(in srgb, var(--tone) 55%, transparent);
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-self: start;
}
.panel-head { display: flex; align-items: center; gap: 10px; }
.panel-head p { margin: 2px 0 0; font-size: 0.85rem; color: var(--ink-dim); }
.team-panel h4 { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-dim); margin-top: 4px; }
.members { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.member { display: flex; align-items: center; gap: 6px; position: relative; font-size: 0.92rem; }
.member.away { opacity: 0.55; }
.member-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member .avatar { --size: 24px; font-size: 0.7rem; }
.bubble { position: absolute; left: 30px; bottom: 100%; background: var(--cream); color: var(--card-ink); border-radius: 10px; padding: 3px 8px; font-size: 0.8rem; white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; z-index: 5; box-shadow: 0 4px 12px #0007; animation: rise 0.25s ease-out; }
.log { border-radius: var(--radius); padding: 12px; background: #0b1328b3; border: 1px solid #ffffff1a; display: flex; flex-direction: column; gap: 8px; min-height: 0; flex: 1; }
.log h3 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-dim); }
.log-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; min-height: 0; }
.log-turn { border-left: 3px solid var(--tone, #fff4); padding-left: 8px; display: flex; flex-direction: column; gap: 3px; }
.log-who { font-size: 0.8rem; color: var(--ink-dim); }
.log-clue { font-weight: 800; letter-spacing: 0.04em; }
.picks { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px; }
.pick { font-size: 0.75rem; border-radius: 6px; padding: 2px 6px; background: #ffffff14; display: inline-flex; gap: 4px; align-items: baseline; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.pick small { opacity: 0.6; }
.pick img { width: 26px; height: 26px; border-radius: 4px; object-fit: cover; align-self: center; }
.pick:has(img) { padding: 2px 6px 2px 2px; align-items: center; }
.pick.k-red { background: var(--red); color: #fff; }
.pick.k-blue { background: var(--blue); color: #fff; }
.pick.k-squirrel { background: var(--squirrel); color: #3b2a12; }
.pick.k-cat { background: #000; color: #fff; outline: 1px solid #fff6; }
.pick.k-agent { background: var(--pup); color: #fff; }
.log-empty { color: var(--ink-dim); font-style: italic; }
.status-line { text-align: center; font-weight: 700; padding: 6px 12px; border-radius: 10px; background: color-mix(in srgb, var(--tone, #ffffff) 22%, transparent); align-self: center; max-width: 100%; }

/* the board: as big as the window lets it be, the cards in their own shape (words wide, pictures square) */
.board-wrap { flex: 1; min-height: 0; container-type: size; display: grid; place-items: center; }
.grid {
  --ar: 1.55;
  --cols: 5;
  --rows: 5;
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  gap: var(--gap);
  width: min(100cqw, calc((100cqh - (var(--rows) - 1) * var(--gap)) * var(--cols) * var(--ar) / var(--rows) + (var(--cols) - 1) * var(--gap)));
}
.grid[data-kind="pictures"] { --ar: 1; }
.card {
  position: relative;
  aspect-ratio: var(--ar);
  border-radius: clamp(6px, 1cqw, 12px);
  background: linear-gradient(180deg, var(--cream), var(--cream-2));
  color: var(--card-ink);
  display: grid;
  place-items: center;
  box-shadow: 0 3px 0 #00000059, inset 0 0 0 2px #fff6;
  container-type: inline-size;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.12s, box-shadow 0.15s, filter 0.15s;
  overflow: hidden;
}
.card::before { content: ""; position: absolute; inset: 7%; border: 1px dashed #3a281633; border-radius: 6px; pointer-events: none; }
.grid[data-kind="pictures"] .card::before { display: none; }
.word { font-weight: 900; text-transform: uppercase; letter-spacing: 0.02em; font-size: min(15cqi, calc(116cqi / var(--len))); text-align: center; padding: 0 4%; line-height: 1.05; word-break: keep-all; overflow-wrap: normal; position: relative; z-index: 1; }
.pic { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.card.can { cursor: pointer; }
.card.can:hover { transform: translateY(-2px); box-shadow: 0 6px 0 #00000059, inset 0 0 0 2px #fff9; }
.card.can:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.card.marked { outline: 3px solid var(--gold); outline-offset: 1px; box-shadow: 0 4px 16px #f2b544a0; }
/* the key, where this corgi may see it: a Sniffmaster, a Duet side, or everyone once it's over */
.card[data-key="red"]:not(.turned) { background: linear-gradient(180deg, #f9ddd4, var(--red-soft)); box-shadow: 0 3px 0 #00000059, inset 0 0 0 3px var(--red); color: var(--red-ink); }
.card[data-key="blue"]:not(.turned) { background: linear-gradient(180deg, #e2ecfa, var(--blue-soft)); box-shadow: 0 3px 0 #00000059, inset 0 0 0 3px var(--blue); color: var(--blue-ink); }
.card[data-key="squirrel"]:not(.turned) { background: linear-gradient(180deg, #f3ead6, var(--squirrel-soft)); box-shadow: 0 3px 0 #00000059, inset 0 0 0 3px var(--squirrel); }
.card[data-key="cat"]:not(.turned) { background: linear-gradient(180deg, #34303c, var(--cat)); color: #f4ecd8; box-shadow: 0 3px 0 #00000059, inset 0 0 0 3px #000; }
.card[data-key="agent"]:not(.turned) { background: linear-gradient(180deg, #e2f4e6, var(--pup-soft)); box-shadow: 0 3px 0 #00000059, inset 0 0 0 3px var(--pup); color: #1d5530; }
.game[data-mode="duet"] .card[data-key="squirrel"]:not(.turned) { box-shadow: 0 3px 0 #00000059, inset 0 0 0 2px #fff6; background: linear-gradient(180deg, var(--cream), var(--cream-2)); }
.grid[data-kind="pictures"] .card[data-key]:not(.turned) .pic { opacity: 0.9; }
.grid[data-kind="pictures"] .card[data-key]:not(.turned)::after { content: ""; position: absolute; inset: 0; border-radius: inherit; box-shadow: inset 0 0 0 5px var(--keyc, transparent); pointer-events: none; }
.grid[data-kind="pictures"] .card[data-key="red"]::after { --keyc: var(--red); }
.grid[data-kind="pictures"] .card[data-key="blue"]::after { --keyc: var(--blue); }
.grid[data-kind="pictures"] .card[data-key="squirrel"]::after { --keyc: var(--squirrel); }
.grid[data-kind="pictures"] .card[data-key="cat"]::after { --keyc: #000; }
.grid[data-kind="pictures"] .card[data-key="agent"]::after { --keyc: var(--pup); }
/* a turned card wears its cover */
.cover { position: absolute; inset: 0; border-radius: inherit; overflow: hidden; z-index: 2; box-shadow: inset 0 0 0 3px var(--cc, #0000); }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card[data-turned="red"] .cover { --cc: var(--red); }
.card[data-turned="blue"] .cover { --cc: var(--blue); }
.card[data-turned="squirrel"] .cover { --cc: var(--squirrel); }
.card[data-turned="cat"] .cover { --cc: #000; }
.card[data-turned="agent"] .cover { --cc: var(--pup); }
.ribbon { position: absolute; left: 0; right: 0; bottom: 0; background: color-mix(in srgb, var(--cc) 85%, #000); color: #fff; font-weight: 800; font-size: max(8px, 9cqi); text-transform: uppercase; text-align: center; letter-spacing: 0.04em; padding: 1px 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ribbon:empty { display: none; }
.card.flip .cover { animation: flip 0.6s cubic-bezier(0.3, 1.4, 0.6, 1) both; }
.marks { position: absolute; top: 4%; left: 4%; display: flex; gap: 2px; z-index: 3; flex-wrap: wrap; max-width: 92%; }
.paw { width: max(16px, 13cqi); height: max(16px, 13cqi); border-radius: 50%; background: #2b2f45; color: #fff; display: grid; place-items: center; font-size: max(9px, 7cqi); font-weight: 800; box-shadow: 0 1px 3px #0008; }
.paw.me { background: var(--gold); color: #2b1a05; }
.fetch { position: absolute; bottom: 5%; left: 50%; transform: translateX(-50%); z-index: 4; padding: 2px 8px; font-size: max(10px, 9cqi); font-weight: 800; background: var(--gold); color: #2b1a05; border-color: #b9801a; white-space: nowrap; box-shadow: 0 2px 6px #0007; animation: rise-fetch 0.18s ease-out; }
.zoom { position: absolute; top: 3%; right: 3%; z-index: 4; padding: 1px 4px; font-size: max(10px, 8cqi); background: #0008; border-color: transparent; opacity: 0; transition: opacity 0.15s; }
.card:hover .zoom, .card:focus-within .zoom { opacity: 1; }
@media (pointer: coarse) { .zoom { opacity: 0.85; } }
.passed { position: absolute; bottom: 5%; left: 5%; z-index: 3; background: #fffd; color: #3b2a12; border-radius: 8px; padding: 0 4px; font-size: max(10px, 9cqi); display: flex; align-items: center; gap: 1px; box-shadow: 0 1px 3px #0006; }
.passed small { font-weight: 800; font-size: 0.75em; }
.keys { position: absolute; bottom: 5%; right: 5%; display: flex; gap: 3px; z-index: 3; }
.keys i { width: max(9px, 8cqi); height: max(9px, 8cqi); border-radius: 50%; display: block; box-shadow: 0 0 0 1.5px #fffc; }
.k-agent { background: var(--pup); }
.k-cat { background: #000; }
.k-squirrel { background: var(--squirrel); }

/* the clue bar */
.cluebar { min-height: 58px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; }
.clue-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: center; }
.clue-input { width: 13em; text-transform: uppercase; font-weight: 800; letter-spacing: 0.05em; }
.num-pick { display: flex; gap: 3px; flex-wrap: wrap; justify-content: center; }
.num-pick button { padding: 7px 0; width: 36px; font-weight: 700; }
.clue-now { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: center; }
.clue-pill { display: inline-flex; align-items: stretch; border-radius: 12px; overflow: hidden; background: var(--cream); color: var(--card-ink); box-shadow: 0 3px 0 #0006, 0 0 0 3px var(--tone, var(--pup)); }
.clue-word { padding: 6px 16px; font-weight: 900; font-size: 1.35rem; letter-spacing: 0.06em; }
.clue-num { padding: 6px 14px; font-weight: 900; font-size: 1.35rem; background: var(--tone, var(--pup)); color: #fff; }
.clue-by { color: var(--ink-dim); font-size: 0.9rem; }
.end-btn { font-weight: 700; }
.thinking { letter-spacing: 0.3em; animation: pulse 1.4s infinite; color: var(--ink-dim); }
.join-in { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: center; }
.join-in button.t-red { background: var(--red); border-color: var(--red); }
.join-in button.t-blue { background: var(--blue); border-color: var(--blue); }
.take-over { font-size: 0.9rem; }
.over-acts { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: center; }

/* the chat drawer */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(360px, 100%); background: #0d1630f2; border-left: 1px solid #ffffff22; padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; z-index: 30; box-shadow: -10px 0 40px #0008; backdrop-filter: blur(6px); }
.drawer[hidden] { display: none; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; }

/* the end of a game */
.over { position: fixed; inset: 0; background: #050913b3; display: grid; place-items: center; z-index: 25; padding: 16px; backdrop-filter: blur(3px); }
.over[hidden] { display: none; }
.over-card { background: linear-gradient(180deg, color-mix(in srgb, var(--tone) 40%, var(--night-2)), var(--night-2)); border: 2px solid var(--tone); border-radius: 18px; padding: 20px; max-width: 420px; width: 100%; text-align: center; display: flex; flex-direction: column; gap: 10px; align-items: center; box-shadow: 0 20px 60px #000a; animation: rise 0.35s ease-out; }
.over-card img { width: 100%; max-width: 300px; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 12px; }
.over-card h2 { font-size: 1.6rem; }
.over-card p { margin: 0; }

/* toasts, the banner, dialogs */
.toasts { position: fixed; bottom: max(84px, calc(env(safe-area-inset-bottom) + 76px)); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column-reverse; gap: 6px; z-index: 50; width: min(92vw, 460px); pointer-events: none; }
.toast { background: #0b1328f0; border: 1px solid #ffffff2a; border-radius: 10px; padding: 9px 14px; text-align: center; box-shadow: 0 8px 24px #0008; transition: opacity 0.4s, transform 0.4s; }
.toast.error { border-color: var(--red); background: #3a1410f0; }
.toast.good { border-color: var(--pup); background: #10301cf0; }
.toast.gone { opacity: 0; transform: translateY(8px); }
.banner { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: none; z-index: 40; animation: banner 1.9s ease-out forwards; }
.banner strong { font-size: clamp(2.2rem, 8vw, 4.2rem); font-weight: 900; color: #fff; text-shadow: 0 4px 0 color-mix(in srgb, var(--tone, var(--gold)) 80%, #000), 0 0 40px #000; }
.banner span { font-size: 1.2rem; font-weight: 700; background: #000a; padding: 4px 12px; border-radius: 10px; margin-top: 8px; }
.banner.red { --tone: var(--red); }
.banner.blue { --tone: var(--blue); }
.banner.duet { --tone: var(--pup); }
.banner.cat { --tone: #444; }
dialog.panel { background: var(--night-2); color: var(--ink); border: 1px solid #ffffff2a; border-radius: 16px; padding: 18px; max-width: min(560px, 94vw); width: 100%; max-height: 88vh; overflow-y: auto; box-shadow: 0 30px 80px #000c; }
dialog.panel::backdrop { background: #050913b3; }
dialog.panel h2 { margin-bottom: 10px; padding-right: 30px; }
dialog .close { position: absolute; top: 10px; right: 10px; padding: 2px 10px; font-size: 1.3rem; }
.ask-row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.menu-list { display: flex; flex-direction: column; gap: 8px; }
.menu-list > button, .menu-list > a { justify-content: flex-start; }
.rules-body h3 { margin: 14px 0 6px; color: var(--gold); }
.rules-body ul { padding-left: 20px; margin: 6px 0; }
.rules-body li { margin: 4px 0; }
.zoom-dialog figure { margin: 0; text-align: center; }
.zoom-dialog img { width: 100%; max-width: 420px; border-radius: 12px; }
.zoom-dialog figcaption { color: var(--ink-dim); margin-top: 6px; }
body.offline::after { content: "Reconnecting…"; position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%); background: var(--red); color: #fff; padding: 6px 14px; border-radius: 10px; z-index: 60; font-weight: 700; }

@keyframes flip { from { transform: perspective(600px) rotateY(90deg) scale(0.9); opacity: 0.3; } to { transform: none; opacity: 1; } }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes pulse { 50% { opacity: 0.55; } }
@keyframes banner { 0% { opacity: 0; transform: scale(0.85); } 12% { opacity: 1; transform: scale(1.04); } 20% { transform: scale(1); } 80% { opacity: 1; } 100% { opacity: 0; } }
@keyframes rise-fetch { from { opacity: 0; } to { opacity: 1; } }

/* ——— a tablet, or a narrow desk ——— */
@media (max-width: 1100px) {
  .stage { grid-template-columns: minmax(150px, 190px) 1fr minmax(160px, 210px); gap: 8px; }
  .brand span { display: none; }
}

/* ——— a phone, or anything narrow: the packs above the board, the page scrolls ——— */
@media (max-width: 820px) {
  .game { height: auto; min-height: 100%; }
  .topbar { gap: 6px; }
  .brand img { width: 30px; height: 30px; }
  .score { gap: 6px; }
  .score-team { padding: 2px 8px; gap: 5px; }
  .score-team b { font-size: 1.35rem; }
  .score-team span { font-size: 0.8rem; }
  .treats { font-size: 0.9rem; }
  .stage { display: grid; grid-template-columns: 1fr 1fr; grid-template-areas: "left right" "center center" "log log"; gap: 8px; }
  .stage > .left { grid-area: left; }
  .center { grid-area: center; }
  .right-col { display: contents; }
  .right-col > .team-panel { grid-area: right; }
  .right-col > .log { grid-area: log; max-height: 320px; }
  .team-panel { padding: 8px; gap: 4px; align-self: stretch; }
  .team-panel h4 { display: none; }
  .crest { width: 34px; height: 34px; }
  .panel-head h2 { font-size: 1rem; }
  .panel-head p { font-size: 0.75rem; }
  .members { flex-direction: row; flex-wrap: wrap; gap: 4px 8px; }
  .member { font-size: 0.8rem; }
  .member em:not(.you) { display: none; }
  .board-wrap { container-type: inline-size; display: block; }
  .grid { width: 100%; --ar: 1.25; }
  .grid[data-kind="pictures"] { --ar: 1; }
  .clue-input { width: 100%; }
  .clue-form { width: 100%; }
  .packs { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .status-line { font-size: 0.92rem; }
}
@media (max-width: 420px) {
  :root { --gap: 4px; }
  .word { letter-spacing: 0; }
  .num-pick button { width: 31px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
