@font-face {
  font-family: 'Big Shoulders';
  src: url('/fonts/big-shoulders.woff2') format('woff2');
  font-weight: 600 900;
  font-display: swap;
}
@font-face {
  font-family: 'Big Shoulders Stencil';
  src: url('/fonts/big-shoulders-stencil.woff2') format('woff2');
  font-weight: 700 900;
  font-display: swap;
}
@font-face {
  font-family: 'Atkinson Hyperlegible Next';
  src: url('/fonts/atkinson-hyperlegible-next.woff2') format('woff2');
  font-weight: 400 700;
  font-display: swap;
}

:root {
  /* palette */
  --desk: #15233d;        /* page: agency navy */
  --desk-raised: #1e3052; /* inputs, quiet buttons */
  --desk-line: #2c416a;
  --frame: #0a1426;       /* clue board body */
  --paper: #f3f4ef;       /* dry-erase surface */
  --ink: #0a1426;         /* text and loops on the whiteboard */
  --chalk: #e3e8f1;       /* text on the desk */
  --muted: #9aaac4;
  --marker: #e5383b;      /* dry-erase red */
  --signal: #ffd166;      /* focus, live */

  --display: 'Big Shoulders', 'Arial Narrow', sans-serif;
  --stencil: 'Big Shoulders Stencil', 'Big Shoulders', 'Arial Narrow', sans-serif;
  --body: 'Atkinson Hyperlegible Next', system-ui, sans-serif;

  --gutter: clamp(16px, 4vw, 40px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }

body {
  background: var(--desk);
  color: var(--chalk);
  font: 400 1.0625rem/1.5 var(--body);
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}

#app {
  max-width: 1360px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) max(var(--gutter), env(safe-area-inset-right)) 56px
    max(var(--gutter), env(safe-area-inset-left));
}

h1, h2, p { margin: 0; }
button, input { font: inherit; color: inherit; }

:where(a, button, input, [tabindex]):focus-visible {
  outline: 3px solid var(--signal);
  outline-offset: 3px;
}

/* ---------- type ---------- */

.wordmark {
  font: 900 clamp(3.25rem, 11vw, 6rem) / 0.9 var(--stencil);
  letter-spacing: 0.01em;
  color: var(--paper);
  margin: 0;
}

.tagline {
  color: var(--muted);
  max-width: 34ch;
  font-size: 1.125rem;
}

.field-label { font-weight: 700; color: var(--chalk); }
.field-help { color: var(--muted); font-size: 0.9375rem; max-width: 48ch; }

/* ---------- buttons & inputs ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: 8px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn-primary { background: var(--paper); color: var(--ink); }
.btn-primary:hover { background: #fff; }
.btn-quiet { background: var(--desk-raised); color: var(--chalk); box-shadow: inset 0 0 0 1px var(--desk-line); }
.btn-quiet:hover { background: #253a62; }
.btn-danger { background: var(--marker); color: #fff; }
.btn-wide { width: 100%; }

.text-btn {
  background: none;
  border: 0;
  padding: 6px 2px;
  color: var(--muted);
  font-size: 0.9375rem;
  text-decoration: underline;
  text-decoration-color: var(--desk-line);
  text-underline-offset: 4px;
  cursor: pointer;
}
.text-btn:hover { color: var(--chalk); text-decoration-color: currentColor; }

input[type='text'] {
  background: var(--desk-raised);
  border: 1px solid var(--desk-line);
  border-radius: 8px;
  min-height: 44px;
  padding: 0 12px;
  min-width: 0;
}
input[type='text']::placeholder { color: #7586a3; }
input[type='text']:focus { border-color: var(--muted); }

.notice { color: #ff8a8c; font-size: 0.9375rem; }
.notice:empty { display: none; }

/* ---------- home ---------- */

#app.home {
  display: grid;
  gap: 28px 64px;
  grid-template-columns: minmax(0, 1fr);
  padding-top: max(40px, env(safe-area-inset-top));
}

.masthead { display: grid; gap: 14px; justify-items: start; }

.hero-board { max-width: 560px; width: 100%; }
.hero-board .cell { cursor: default; }

.home-actions { display: grid; gap: 36px; align-content: start; max-width: 460px; }

.panel { display: grid; gap: 12px; }
.panel + .panel { padding-top: 32px; border-top: 1px solid var(--desk-line); }
.panel-title { font: 800 2rem / 1 var(--display); color: var(--paper); }
.panel-title label { cursor: pointer; }
.panel .btn-wide { margin-top: 6px; }

.count-picker { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.count {
  min-height: 56px;
  border: 1px solid var(--desk-line);
  border-radius: 8px;
  background: var(--desk-raised);
  font: 800 1.75rem / 1 var(--display);
  cursor: pointer;
  touch-action: manipulation;
}
.count:hover { background: #253a62; }
.count[aria-pressed='true'] { background: var(--paper); border-color: var(--paper); color: var(--ink); }

.join-form { display: flex; gap: 8px; }
.code-input {
  flex: 1;
  width: 0; /* let flex size it; the default size=20 would set a huge min-content width */
  font: 800 1.625rem / 1 var(--display) !important;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}
.code-input::placeholder { letter-spacing: 0.2em; }

.missing-title { font: 800 clamp(2rem, 6vw, 3rem) / 1.05 var(--display); color: var(--paper); margin-top: 16px; }

@media (min-width: 900px) {
  #app.home {
    grid-template-columns: minmax(0, 1.15fr) minmax(340px, 0.85fr);
    grid-template-areas: 'mast mast' 'board actions';
    align-items: start;
    padding-top: 64px;
  }
  .masthead { grid-area: mast; }
  .hero-board { grid-area: board; max-width: none; }
  .home-actions { grid-area: actions; padding-top: 8px; }
}

/* ---------- table ---------- */

.table-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 0 calc(-1 * var(--gutter));
  padding: 10px var(--gutter);
  background: rgba(21, 35, 61, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--desk-line);
}
.wordmark-link { text-decoration: none; display: none; }
.wordmark-link .wordmark { font-size: 1.75rem; }
.table-id { flex: 1; display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.table-label { color: var(--muted); }
.table-code { font: 900 2rem / 1 var(--stencil); letter-spacing: 0.08em; color: var(--paper); }

.status { display: inline-flex; align-items: center; gap: 6px; font-size: 0.875rem; color: var(--muted); align-self: center; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status[data-state='live'] .status-dot { background: #4ade80; box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.22); }
.status[data-state='offline'] .status-dot { background: var(--marker); }
.status[data-state='offline'] .status-text { color: #ff8a8c; }

.mission-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 20px;
}
.mission-summary { font: 800 1.75rem / 1 var(--display); color: var(--paper); }
.mission-label { display: block; font: 400 0.9375rem / 1.4 var(--body); color: var(--muted); }

.legend { color: var(--muted); font-size: 0.9375rem; margin-top: 10px; max-width: 70ch; }
.legend strong { color: var(--chalk); font-weight: 700; }
.legend-mark { width: 1.35em; height: 1.35em; vertical-align: -0.35em; margin-right: 2px; background: var(--paper); border-radius: 4px; }
.legend-mark .ink { animation: none; }

.table .notice { margin-top: 12px; }

.boards {
  display: grid;
  gap: 40px 32px;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 330px), 1fr));
  margin-top: 28px;
}
.boards[data-count='1'] { max-width: 560px; }
.boards[data-count='2'] { grid-template-columns: repeat(auto-fill, minmax(min(100%, 400px), 1fr)); max-width: 1000px; }
.boards[data-count='4'] { grid-template-columns: repeat(auto-fill, minmax(min(100%, 380px), 1fr)); }

.suspect { display: grid; gap: 10px; }
.suspect-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.suspect-title { font: 800 1.875rem / 1 var(--display); color: var(--paper); }
.suspect-num { font-family: var(--stencil); }

.taken { display: flex; align-items: center; gap: 10px; }
.taken-label { color: var(--muted); font-size: 0.9375rem; white-space: nowrap; }
.taken-input { flex: 1; width: 0; }
.suspect.is-taken .taken-input { border-color: var(--muted); font-weight: 700; }

@media (min-width: 640px) {
  .wordmark-link { display: block; }
  .table-id { justify-content: center; }
}
@media (max-width: 639px) {
  .wide-only { display: none; }
  .table-label { display: none; }
  .table-code { font-size: 1.75rem; }
}

/* ---------- dialogs ---------- */

.sheet {
  width: min(440px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--desk-line);
  border-radius: 12px;
  background: var(--desk);
  color: var(--chalk);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}
.sheet::backdrop { background: rgba(5, 10, 20, 0.7); }
.sheet-body { display: grid; gap: 14px; padding: 24px; }
.sheet-title { font: 800 1.875rem / 1.05 var(--display); color: var(--paper); }
.sheet-text { color: var(--muted); }
.sheet-field { display: grid; gap: 10px; }
.sheet-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-top: 6px; }

.invite-code {
  font: 900 clamp(3.5rem, 16vw, 4.75rem) / 1 var(--stencil);
  letter-spacing: 0.12em;
  color: var(--paper);
  text-align: center;
  padding: 8px 0;
}
.invite-link { font-size: 0.9375rem; color: var(--chalk); overflow-wrap: anywhere; user-select: all; text-align: center; }

@media (max-width: 480px) {
  .sheet { margin: auto auto 12px; }
  .sheet-actions .btn { flex: 1; }
}

/* ---------- clue board ---------- */

.board-svg { display: block; width: 100%; height: auto; user-select: none; -webkit-user-select: none; overflow: visible; }

.board-frame { fill: var(--frame); }
.cell { --cell-paper: var(--paper); cursor: pointer; outline: none; touch-action: manipulation; }
.wedge { fill: var(--cell-paper); stroke: var(--frame); stroke-width: 7; stroke-linejoin: round; }
.disc { fill: var(--cell-paper); }
.cut { fill: var(--cell-paper); }
.cut-line { fill: none; stroke: var(--cell-paper); stroke-width: 1.7; stroke-linecap: round; }

.hub-mark { fill: var(--paper); font: 900 68px var(--stencil); }
.num { fill: var(--ink); font: 800 30px var(--display); }

@media (hover: hover) {
  .board-svg[role] .cell:hover { --cell-paper: #ffffff; }
}
.cell:focus-visible .wedge { stroke: var(--signal); stroke-width: 5; }
.cell:focus-visible .disc { stroke: var(--signal); stroke-width: 4; }

/* marks */
.mark-x, .mark-o { display: none; pointer-events: none; }
.cell[data-state='1'] .mark-x, .cell[data-state='2'] .mark-o { display: inline; }

.fade { fill: var(--paper); fill-opacity: 0.74; }
.suit-cell .fade { stroke: var(--frame); stroke-width: 7; stroke-linejoin: round; }
.ink { fill: none; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 1; stroke-dashoffset: 0; }
.ink-x { stroke: var(--marker); stroke-width: 6.5; }
.ink-o { stroke: var(--ink); stroke-width: 3.4; }
.suit-cell .ink-x { stroke-width: 7.5; }
.suit-cell .ink-o { stroke-width: 4.5; }

/* Draw-on only for marks that change while you watch (your tap or another player's). */
.cell.fresh .ink { animation: draw 240ms cubic-bezier(0.3, 0.6, 0.4, 1) both; }
.cell.fresh .ink-second { animation-delay: 120ms; }
.cell.fresh .ink-o { animation-duration: 340ms; }
@keyframes draw {
  from { stroke-dashoffset: 1.02; } /* just past 1 so the round cap doesn't leave a dot */
  to { stroke-dashoffset: 0; }
}

.legend-x .ink-x { stroke-width: 3; }
.legend-o .ink-o { stroke-width: 2.4; }

@media (prefers-reduced-motion: reduce) {
  .cell .ink { animation: none !important; }
}
