/* MENDAX viewer. Design tokens follow the approved mock (docs/design/table-mock.html). */
:root {
  --bg: #0d1015;
  --bg-2: #12161c;
  --surface: rgba(24, 29, 37, 0.92);
  --surface-solid: #181d25;
  --surface-2: #1f252f;
  --line: rgba(255, 255, 255, 0.07);
  --line-2: rgba(255, 255, 255, 0.12);
  --text: #e7e9ec;
  --text-2: #a6adb8;
  --muted: #6f7782;
  --felt-1: #24584d;
  --felt-2: #1a443b;
  --felt-3: #12332c;
  --rim-1: #0a0d11;
  --rim-2: #232a33;
  --accent: #8fd3bf;
  --accent-soft: rgba(143, 211, 191, 0.16);
  --paco-1: #f3cf7a;
  --paco-2: #d9a441;
  --paco-ink: #5b3b05;
  --die-1: #fbfaf6;
  --die-2: #e6e2d8;
  --pip: #1f252d;
  --hidden-fill: rgba(255, 255, 255, 0.07);
  --hidden-line: rgba(255, 255, 255, 0.16);
  --hidden-ink: rgba(255, 255, 255, 0.35);
  --lose: #ef8a7e;
  --gain: #7fd6a0;
  --palifico: #c9a7f2;
  --call: #ffd38a;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --seat-0: #7fa7e8; --seat-1: #e3b06a; --seat-2: #93c47d;
  --seat-3: #b79be8; --seat-4: #e68a9a; --seat-5: #71c6d6;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #eef0ed;
  --bg-2: #e6e9e5;
  --surface: rgba(255, 255, 255, 0.94);
  --surface-solid: #ffffff;
  --surface-2: #f3f4f2;
  --line: rgba(20, 30, 40, 0.08);
  --line-2: rgba(20, 30, 40, 0.14);
  --text: #1c2228;
  --text-2: #4d5761;
  --muted: #858d96;
  --felt-1: #3b7d6b;
  --felt-2: #2f6a5a;
  --felt-3: #25574a;
  --rim-1: #2a2f35;
  --rim-2: #4a525c;
  --accent: #1f8a6e;
  --accent-soft: rgba(31, 138, 110, 0.12);
  --pip: #20262d;
  --hidden-fill: rgba(20, 30, 40, 0.06);
  --hidden-line: rgba(20, 30, 40, 0.18);
  --hidden-ink: rgba(20, 30, 40, 0.38);
  --lose: #c8564a;
  --gain: #2e9b5c;
  --palifico: #8a5cc9;
  --call: #b07818;
  --shadow: 0 8px 24px rgba(30, 40, 50, 0.14);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: radial-gradient(1200px 700px at 40% 45%, var(--bg-2), var(--bg));
  color: var(--text);
  font: 14px/1.4 ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "tnum" 1;
  overflow: hidden;
}
button { font: inherit; color: inherit; }
.app { display: grid; grid-template-rows: 56px auto minmax(0, 1fr) 72px; height: 100vh; }
.topbar { grid-row: 1; }
.banner { grid-row: 2; }
.stage { grid-row: 3; }
.controls { grid-row: 4; }

/* ---- top bar --------------------------------------------------------------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 20px; border-bottom: 1px solid var(--line); min-width: 0;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.wordmark { font-weight: 650; letter-spacing: 0.14em; font-size: 13px; }
.file { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.pill {
  font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  padding: 3px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent);
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.pill.done { background: var(--surface-2); color: var(--text-2); }
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }
.meta { color: var(--text-2); font-size: 13px; display: flex; gap: 12px; white-space: nowrap; }
.meta b { color: var(--text); font-weight: 600; }
.meta .sep { color: var(--muted); }
.meta .pal { color: var(--palifico); font-weight: 600; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.segmented { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); }
.segmented button {
  font-size: 12.5px; color: var(--text-2); background: transparent; border: 0;
  padding: 5px 12px; border-radius: 7px; cursor: pointer; transition: background 0.15s, color 0.15s;
}
.segmented button:hover { color: var(--text); }
.segmented button.on { background: var(--surface-solid); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18); }
.select {
  font: inherit; font-size: 12.5px; color: var(--text-2); padding: 6px 10px; border-radius: 9px;
  background: var(--surface-2); border: 1px solid var(--line); cursor: pointer;
}
.select:disabled { opacity: 0.45; cursor: default; }
.icon-btn {
  width: 32px; height: 32px; display: grid; place-items: center; border-radius: 9px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { color: var(--text); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.banner {
  padding: 8px 20px; font-size: 13px; color: var(--text); background: color-mix(in srgb, var(--lose) 18%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--lose) 40%, transparent);
}

/* ---- stage ----------------------------------------------------------------- */
.stage { display: grid; grid-template-columns: 1fr 300px; min-height: 0; }
.table-area { position: relative; min-width: 0; overflow: hidden; }
.table {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(76%, 900px); aspect-ratio: 2.05 / 1; border-radius: 50%;
  background: linear-gradient(180deg, var(--rim-2), var(--rim-1));
  padding: 14px; box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
.felt {
  width: 100%; height: 100%; border-radius: 50%;
  background: radial-gradient(ellipse at 50% 42%, var(--felt-1), var(--felt-2) 62%, var(--felt-3));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05), inset 0 18px 60px rgba(0, 0, 0, 0.28);
  display: grid; place-items: center; position: relative;
}
.felt::after { content: ""; position: absolute; inset: 9%; border-radius: 50%; border: 1px solid rgba(255, 255, 255, 0.06); pointer-events: none; }

/* ---- table centre ---------------------------------------------------------- */
.center { text-align: center; color: #f3f5f2; position: relative; z-index: 1; max-width: 70%; }
.eyebrow { font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: rgba(243, 245, 242, 0.62); }
.headline { font-size: 34px; font-weight: 650; letter-spacing: -0.01em; margin: 6px 0 4px; }
.bid-big { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 6px 0 4px; }
.bid-big .qty { font-size: 64px; font-weight: 650; letter-spacing: -0.02em; line-height: 1; }
.bid-big .times { font-size: 30px; color: rgba(243, 245, 242, 0.55); font-weight: 400; }
.call-big { font-size: 52px; font-weight: 700; letter-spacing: 0.06em; color: #ffe2a8; margin: 4px 0; line-height: 1.05; }
.by { font-size: 13px; color: rgba(243, 245, 242, 0.75); display: flex; align-items: center; justify-content: center; gap: 6px; }
.swatch { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex: none; }
.table-badges { display: flex; gap: 8px; justify-content: center; margin-bottom: 14px; }
.tchip {
  font-size: 11px; letter-spacing: 0.04em; padding: 4px 10px; border-radius: 999px;
  background: rgba(0, 0, 0, 0.22); color: rgba(243, 245, 242, 0.75); border: 1px solid rgba(255, 255, 255, 0.06);
}
.tchip.palifico { background: rgba(201, 167, 242, 0.18); color: #e6d6fb; border-color: rgba(201, 167, 242, 0.35); }
.verdict { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; align-items: center; }
.verdict .count { font-size: 15px; color: rgba(243, 245, 242, 0.85); }
.verdict .count b { font-size: 22px; color: #fff; }
.verdict .need { font-size: 12.5px; color: rgba(243, 245, 242, 0.6); }
.outcome {
  margin-top: 4px; font-size: 14px; font-weight: 600; padding: 6px 14px; border-radius: 999px;
  background: rgba(239, 138, 126, 0.18); color: #ffc9c1; border: 1px solid rgba(239, 138, 126, 0.35);
}
.outcome.gain { background: rgba(127, 214, 160, 0.16); color: #c9f2d8; border-color: rgba(127, 214, 160, 0.35); }
.outcome.neutral { background: rgba(255, 255, 255, 0.08); color: #eef0ee; border-color: rgba(255, 255, 255, 0.16); }
.next-note { font-size: 12px; color: rgba(243, 245, 242, 0.62); margin-top: 2px; }
.ranking { list-style: none; padding: 0; margin: 14px auto 0; display: flex; flex-direction: column; gap: 4px; text-align: left; width: fit-content; }
.ranking li { display: grid; grid-template-columns: 26px 10px auto; gap: 8px; align-items: center; font-size: 13px; color: rgba(243, 245, 242, 0.8); }
.ranking li .place { color: rgba(243, 245, 242, 0.5); font-size: 12px; text-align: right; }
.ranking li:first-child { color: #fff; font-weight: 600; }
.btn {
  margin-top: 14px; font-size: 13px; font-weight: 600; padding: 7px 16px; border-radius: 999px; cursor: pointer;
  background: rgba(255, 255, 255, 0.92); color: #13201c; border: 0;
}

/* ---- seats ----------------------------------------------------------------- */
.seat {
  position: absolute; transform: translate(-50%, -50%) scale(var(--seat-scale, 1)); width: 200px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.chip-slot { height: 28px; display: flex; align-items: center; justify-content: center; }
.plate {
  width: 100%; background: var(--surface); border: 1px solid var(--line-2); border-radius: 16px;
  padding: 10px 12px 11px; box-shadow: var(--shadow); position: relative;
  transition: border-color 0.25s, box-shadow 0.25s, opacity 0.4s;
}
.seat.active .plate { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow); }
.seat.hurt .plate { border-color: color-mix(in srgb, var(--lose) 60%, transparent); }
.seat.helped .plate { border-color: color-mix(in srgb, var(--gain) 60%, transparent); }
.seat.winner .plate { border-color: var(--paco-1); box-shadow: 0 0 0 3px rgba(243, 207, 122, 0.18), var(--shadow); }
.seat.out .plate { opacity: 0.42; box-shadow: none; }
.plate-top { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex: none;
  font-weight: 650; font-size: 14px; color: var(--c); background: color-mix(in srgb, var(--c) 16%, transparent);
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--c) 70%, transparent);
}
.who { min-width: 0; flex: 1; }
.name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.type { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tag { display: inline-block; font-size: 10.5px; font-weight: 650; letter-spacing: 0.08em; text-transform: uppercase; margin-top: 1px; }
.tag.pal { color: var(--palifico); }
.tag.win { color: var(--paco-2); }
.count-badge { text-align: right; line-height: 1.05; flex: none; }
.count-badge .n { font-size: 20px; font-weight: 650; }
.count-badge .l { font-size: 10.5px; color: var(--muted); letter-spacing: 0.04em; }
.out-tag { font-size: 11px; color: var(--muted); letter-spacing: 0.04em; white-space: nowrap; flex: none; }
.tray { display: flex; gap: 5px; margin-top: 9px; justify-content: center; min-height: 26px; flex-wrap: wrap; }
.thinking { display: inline-flex; gap: 3px; margin-left: 6px; vertical-align: 2px; }
.thinking i { width: 4px; height: 4px; border-radius: 50%; background: var(--accent); animation: think 1.2s infinite ease-in-out; }
.thinking i:nth-child(2) { animation-delay: 0.15s; }
.thinking i:nth-child(3) { animation-delay: 0.3s; }
@keyframes think { 0%, 80%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }
.action-chip {
  font-size: 12.5px; font-weight: 600; padding: 4px 10px 4px 8px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line-2); display: inline-flex; align-items: center; gap: 6px;
  box-shadow: var(--shadow); white-space: nowrap;
}
.action-chip.latest { border-color: color-mix(in srgb, var(--accent) 60%, transparent); }
.action-chip.call { color: var(--call); border-color: color-mix(in srgb, var(--call) 50%, transparent); letter-spacing: 0.08em; padding: 4px 12px; }
.delta {
  position: absolute; top: -10px; right: 12px; font-size: 12px; font-weight: 700; padding: 2px 9px;
  border-radius: 999px; background: var(--surface-solid); color: var(--text-2);
  border: 1px solid var(--line-2); box-shadow: var(--shadow); white-space: nowrap;
}
.delta.lose { color: var(--lose); border-color: color-mix(in srgb, var(--lose) 55%, transparent); }
.delta.gain { color: var(--gain); border-color: color-mix(in srgb, var(--gain) 55%, transparent); }

/* ---- dice ------------------------------------------------------------------ */
.die { display: block; flex: none; transition: opacity 0.3s, transform 0.3s, filter 0.3s; }
.die.dim { opacity: 0.32; }
.die.hit { filter: drop-shadow(0 0 6px rgba(143, 211, 191, 0.75)); transform: translateY(-2px); }
.die.hit.paco { filter: drop-shadow(0 0 6px rgba(243, 207, 122, 0.85)); }
.inline-bid { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; color: inherit; vertical-align: middle; }
.inline-bid .x { opacity: 0.5; }

/* ---- history panel --------------------------------------------------------- */
.history {
  border-left: 1px solid var(--line); padding: 18px 16px 18px 18px; overflow: auto;
  display: flex; flex-direction: column; gap: 18px; min-height: 0;
}
.h-title { font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); margin: 0 0 8px; display: flex; justify-content: space-between; align-items: center; }
.h-title .tag { margin: 0; }
.h-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.h-item { display: grid; grid-template-columns: 10px 1fr auto; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 10px; color: var(--text-2); }
.h-item .bid { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; color: var(--text); }
.h-item.latest { background: var(--accent-soft); color: var(--text); }
.h-item.call .bid { color: var(--call); letter-spacing: 0.08em; font-size: 12px; }
.h-empty { color: var(--muted); font-size: 12.5px; padding: 7px 10px; }
.h-rounds { display: flex; flex-direction: column; gap: 8px; }
.h-round {
  text-align: left; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line);
  font-size: 12.5px; color: var(--text-2); display: flex; flex-direction: column; gap: 4px; cursor: pointer; width: 100%;
  transition: border-color 0.15s;
}
.h-round:hover { border-color: var(--line-2); }
.h-round .rt { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; }
.h-round .res b { color: var(--text); font-weight: 600; }
.h-round .inline-bid { color: var(--text); }
.h-round .lose { color: var(--lose); font-weight: 600; }
.h-round .gain { color: var(--gain); font-weight: 600; }

/* ---- controls -------------------------------------------------------------- */
.controls { border-top: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 0 20px; gap: 20px; }
.scrub { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 12px; min-width: 0; }
.pos { white-space: nowrap; min-width: 92px; }
.track { position: relative; height: 18px; flex: 1; max-width: 380px; cursor: pointer; touch-action: none; }
.track::before { content: ""; position: absolute; left: 0; right: 0; top: 7px; height: 4px; border-radius: 4px; background: var(--surface-2); }
.track .fill { position: absolute; left: 0; top: 7px; height: 4px; border-radius: 4px; background: var(--accent); }
.track .tick { position: absolute; top: 4px; width: 1.5px; height: 10px; background: var(--line-2); pointer-events: none; }
.track .knob { position: absolute; top: 9px; width: 12px; height: 12px; border-radius: 50%; transform: translate(-50%, -50%); background: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3); pointer-events: none; }
.transport { display: flex; align-items: center; gap: 6px; }
.tbtn { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; border: 0; background: transparent; color: var(--text-2); cursor: pointer; }
.tbtn:hover { background: var(--surface-2); color: var(--text); }
.tbtn.play { width: 44px; height: 44px; border-radius: 50%; background: var(--text); color: var(--bg); margin: 0 6px; }
.tbtn.play:hover { background: var(--text); color: var(--bg); opacity: 0.9; }
.speed { justify-self: end; display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }

/* ---- subtle motion (only when stepping forward one frame) ------------------ */
.anim .a-roll { animation: roll 0.45s cubic-bezier(.2, .8, .2, 1) both; }
.anim .a-roll:nth-child(2) { animation-delay: 0.04s; } .anim .a-roll:nth-child(3) { animation-delay: 0.08s; }
.anim .a-roll:nth-child(4) { animation-delay: 0.12s; } .anim .a-roll:nth-child(5) { animation-delay: 0.16s; }
@keyframes roll { from { opacity: 0; transform: translateY(-6px) rotate(-25deg) scale(0.8); } }
.anim .a-pop { animation: pop 0.32s cubic-bezier(.2, .9, .3, 1.3) both; }
@keyframes pop { from { opacity: 0; transform: scale(0.82); } }
.anim .a-swap { animation: swap 0.35s ease-out both; }
@keyframes swap { from { opacity: 0; transform: translateY(6px); } }
.anim .a-fade { animation: fade 0.5s ease-out both; }
@keyframes fade { from { opacity: 0; } }
.anim .a-flip { animation: flip 0.45s ease-out both; }
@keyframes flip { from { opacity: 0.2; transform: rotateY(90deg); } }
.anim .a-slide { animation: slide 0.3s ease-out both; }
@keyframes slide { from { opacity: 0; transform: translateX(8px); } }
@media (prefers-reduced-motion: reduce) {
  .anim * { animation: none !important; }
  .die, .plate { transition: none; }
}

/* ---- smaller windows (seats also scale in JS, see renderSeats) -------------- */
.segmented button, .select { white-space: nowrap; }
@media (max-width: 1180px) {
  .stage { grid-template-columns: 1fr 260px; }
  .file { display: none; }
}
@media (max-width: 1000px) {
  .stage { grid-template-columns: 1fr; }
  .history { display: none; }
  .meta { display: none; }
}
@media (max-width: 760px) {
  .topbar, .controls { padding: 0 12px; gap: 10px; }
  .pos, .speed > span, .file, #saveBtn { display: none; }
  .segmented button { padding: 5px 8px; }
  .track { min-width: 90px; }
  .tbtn { width: 32px; }
}
