/* ══════════════════════════════════════════════════════ tokens */

:root {
  --ink:      #14162e;   /* ground: printed card stock in a dim room */
  --ink-2:    #1c1f42;
  --ink-3:    #262a55;
  --line:     #33376a;
  --bone:     #f3eee4;   /* the card face */
  --bone-dim: #cdc6b8;
  --text:     #edeaf6;
  --muted:    #8c8fb8;
  --peri:     #7c7cff;   /* you, actions, selection */
  --coral:    #ff5b69;   /* the team is apart */
  --mint:     #4fd6a0;   /* the team agrees */

  --display: 'Bricolage Grotesque', ui-sans-serif, system-ui, sans-serif;
  --body:    'Public Sans', ui-sans-serif, system-ui, -apple-system, sans-serif;
  --mono:    'JetBrains Mono', ui-monospace, Menlo, Consolas, monospace;

  --r: 10px;
  --pad: clamp(16px, 3vw, 28px);
}

* { box-sizing: border-box; }

/* Class selectors below set `display`, which would otherwise out-specify the
   browser's own [hidden] rule. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--ink);
  color: var(--text);
  font: 15px/1.55 var(--body);
  -webkit-font-smoothing: antialiased;
}

body {
  background-image:
    radial-gradient(90% 60% at 50% -10%, #232852 0%, transparent 60%);
  background-attachment: fixed;
}

button, input, select { font: inherit; color: inherit; }

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

:focus-visible {
  outline: 2px solid var(--peri);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ══════════════════════════════════════════════════════ primitives */

.wordmark {
  margin: 0;
  font-family: var(--display);
  font-weight: 800;
  font-size: 28px;
  letter-spacing: -0.035em;
}

.wordmark.sm { font-size: 18px; }

.eyebrow {
  margin: 0 0 12px;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.eyebrow .count {
  margin-left: 10px;
  letter-spacing: 0.08em;
  text-transform: none;
  color: #5f639a;
}

.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 16px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
}

.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--peri);
  color: #0d0f24;
}

.btn-primary:hover:not(:disabled) { background: #9494ff; }

.btn-primary:disabled {
  background: var(--ink-3);
  color: var(--muted);
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
  font-weight: 500;
}

.btn-ghost:hover { border-color: var(--peri); color: var(--text); }

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.switch input { accent-color: var(--peri); width: 15px; height: 15px; }
.switch:hover { color: var(--text); }

.select select {
  appearance: none;
  padding: 7px 26px 7px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--ink-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238c8fb8' stroke-width='1.5' fill='none'/%3E%3C/svg%3E") no-repeat right 10px center;
  font-size: 13px;
  cursor: pointer;
}

/* ══════════════════════════════════════════════════════ gate */

.gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--ink);
  background-image: radial-gradient(80% 60% at 50% 0%, #262b58 0%, #101228 70%);
}

.gate-card {
  width: min(430px, 100%);
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(20, 22, 46, .78);
  backdrop-filter: blur(14px);
}

.gate-card h1 {
  margin: 14px 0 26px;
  font-family: var(--display);
  font-weight: 600;
  font-size: 25px;
  line-height: 1.22;
  letter-spacing: -0.025em;
  text-wrap: balance;
}

.field { display: block; margin-bottom: 14px; }

.field span {
  display: block;
  margin-bottom: 6px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.field input {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f1128;
}

.field input:focus { outline: none; border-color: var(--peri); }

.gate-card .btn { width: 100%; margin-top: 8px; }

.gate-note {
  margin: 16px 0 0;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

/* ══════════════════════════════════════════════════════ shell */

.app {
  display: grid;
  grid-template-areas: "top top" "stage side" "hand hand";
  grid-template-columns: minmax(0, 1fr) 268px;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100dvh;
}

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px var(--pad);
  border-bottom: 1px solid var(--line);
}

.slug {
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-left: auto;
}

.stage {
  grid-area: stage;
  padding: clamp(20px, 4vw, 40px) var(--pad);
  display: flex;
  flex-direction: column;
  gap: clamp(24px, 4vw, 40px);
  overflow-y: auto;
}

/* ══════════════════════════════════════════════════════ story */

.story-input {
  width: 100%;
  padding: 0 0 10px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(22px, 3.4vw, 34px);
  letter-spacing: -0.025em;
  transition: border-color .15s;
}

.story-input::placeholder { color: var(--line); }
.story-input:focus { outline: none; border-bottom-color: var(--peri); }

/* ══════════════════════════════════════════════════════ the table */

.seats {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
}

.seat { width: 76px; text-align: center; }

.seat-card {
  position: relative;
  height: 104px;
  transform-style: preserve-3d;
  transition: transform .45s cubic-bezier(.2, .8, .3, 1);
}

.seat.flipped .seat-card { transform: rotateY(180deg); }

.face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: var(--r);
  backface-visibility: hidden;
}

.face-back {
  border: 1px solid var(--line);
  background: var(--ink-2);
}

/* Hatched card back — the "nobody can see this yet" state. */
.face-back.filled {
  border-color: transparent;
  background:
    repeating-linear-gradient(45deg, #6a6ae8 0 5px, #5a5ad4 5px 10px);
  box-shadow: 0 6px 18px -8px #000;
}

.face-back.waiting::after {
  content: '';
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--line);
}

.face-front {
  transform: rotateY(180deg);
  background: var(--bone);
  color: var(--ink);
  font-family: var(--display);
  font-weight: 800;
  font-size: 30px;
  letter-spacing: -0.03em;
  box-shadow: 0 6px 18px -8px #000;
}

.face-front.abstain { color: var(--bone-dim); font-size: 26px; }

.seat-name {
  margin-top: 9px;
  font-size: 12.5px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seat.you .seat-name { color: var(--peri); }
.seat.offline { opacity: .38; }

.seat-role {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.seat.observer .seat-card { height: 104px; opacity: .5; }
.seat.observer .face-back { background: none; border-style: dashed; }

.table.folded { display: none; }

.empty-table {
  color: var(--muted);
  font-size: 14px;
}

/* ══════════════════════════════════════════════════════ actions */

.actions {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}

/* ══════════════════════════════════════════════════════ spread strip
   The signature: votes plotted on the deck itself, so the distance between
   the lowest and highest card is the thing you look at first. */

.spread { animation: rise .4s cubic-bezier(.2, .8, .3, 1) both; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
}

.verdict {
  display: flex;
  align-items: baseline;
  gap: clamp(20px, 4vw, 44px);
  flex-wrap: wrap;
  margin-bottom: 26px;
}

.stat span {
  display: block;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat b {
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(30px, 5vw, 46px);
  letter-spacing: -0.04em;
  line-height: 1.05;
}

.stat.agree b { color: var(--mint); }
.stat.apart b { color: var(--coral); }

.strip {
  display: grid;
  align-items: end;
  gap: 0 4px;
  padding-bottom: 4px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
}

.tick {
  grid-row: 2;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 12px;
  text-align: center;
  color: var(--muted);
  min-width: 34px;
}

.tick.hit { color: var(--text); border-top-color: var(--bone-dim); }

.chips {
  grid-row: 1;
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  gap: 4px;
  min-height: 30px;
}

.chip {
  max-width: 100%;
  padding: 3px 7px;
  border-radius: 5px;
  background: var(--ink-3);
  font-size: 11px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  animation: drop .3s cubic-bezier(.2, .8, .3, 1) both;
}

.chip.you { background: var(--peri); color: #0d0f24; }

@keyframes drop {
  from { opacity: 0; transform: translateY(-8px); }
}

/* The bar that spans lowest → highest card. Its width *is* the disagreement. */
.range-bar {
  grid-row: 3;
  height: 3px;
  margin-top: 8px;
  border-radius: 2px;
  background: var(--coral);
  animation: stretch .45s cubic-bezier(.2, .8, .3, 1) both;
  transform-origin: left;
}

.range-bar.agree { background: var(--mint); }

@keyframes stretch {
  from { transform: scaleX(0); }
}

.spread-note {
  margin: 18px 0 0;
  font-size: 13px;
  color: var(--muted);
  max-width: 62ch;
}

/* ══════════════════════════════════════════════════════ history */

.history {
  grid-area: side;
  padding: clamp(20px, 4vw, 40px) var(--pad) 20px 0;
  border-left: 1px solid var(--line);
  padding-left: 20px;
  overflow-y: auto;
}

.history-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.history-list li {
  padding: 11px 0;
  border-bottom: 1px solid var(--ink-3);
}

.history-list .h-title {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-list .h-meta {
  margin-top: 3px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
}

.history-list .h-meta b { color: var(--text); font-weight: 500; }
.history-list .h-meta .apart { color: var(--coral); }
.history-list .h-meta .agree { color: var(--mint); }

.history-empty { font-size: 13px; color: var(--muted); }

/* ══════════════════════════════════════════════════════ hand */

.hand {
  grid-area: hand;
  padding: 16px var(--pad) 20px;
  border-top: 1px solid var(--line);
  background: rgba(14, 16, 38, .72);
  backdrop-filter: blur(10px);
}

.rail {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 6px;
  overscroll-behavior-x: contain;
}

.card {
  flex: 0 0 auto;
  width: 58px;
  height: 82px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--ink-2);
  font-family: var(--display);
  font-weight: 800;
  font-size: 21px;
  letter-spacing: -0.03em;
  color: var(--text);
  cursor: pointer;
  transition: transform .16s cubic-bezier(.2,.8,.3,1), border-color .16s, background .16s;
}

.card:hover:not(:disabled) { transform: translateY(-7px); border-color: var(--peri); }

.card.picked {
  background: var(--bone);
  border-color: var(--bone);
  color: var(--ink);
  transform: translateY(-12px);
  box-shadow: 0 12px 26px -12px #000;
}

.card:disabled { opacity: .35; cursor: not-allowed; }

/* ══════════════════════════════════════════════════════ status */

.conn, .toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 15px;
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 12px;
  z-index: 40;
}

.conn {
  top: 14px;
  border: 1px solid var(--coral);
  background: var(--ink-2);
  color: var(--coral);
}

.toast {
  bottom: 132px;
  background: var(--bone);
  color: var(--ink);
  font-weight: 500;
}

/* ══════════════════════════════════════════════════════ narrow */

@media (max-width: 860px) {
  .app { grid-template-areas: "top" "stage" "side" "hand"; grid-template-columns: 1fr; height: auto; min-height: 100dvh; }
  .stage { overflow-y: visible; }
  .history { border-left: 0; border-top: 1px solid var(--line); padding: 24px var(--pad); }
  .topbar { flex-wrap: wrap; }
  .topbar-right { width: 100%; margin-left: 0; }
  .seat { width: 62px; }
  .seat-card { height: 86px; }
  .face-front { font-size: 25px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
  .seat.flipped .seat-card { transform: none; }
  .seat.flipped .face-back { opacity: 0; }
  .seat.flipped .face-front { transform: none; }
}
