/* Snooker Club — a snooker hall at night: lamp-lit baize, mahogany, brass,
   the blue cube of chalk. System fonts only (they must load inside China). */
:root {
  --baize: #0e4d33;
  --baize-deep: #072a1b;
  --mahogany: #3b1f14;
  --mahogany-hi: #5c3221;
  --brass: #c9a55a;
  --brass-hi: #efd89a;
  --brass-lo: #8a6a2a;
  --chalk: #3e7cc4;
  --ivory: #f3eee0;
  --ink: #1e140d;
  --muted: #b9c3b4;
  --danger: #ff6b5b;
  --line: rgba(239, 216, 154, 0.18);
  --table-bg: #0c2a1b;

  --serif: "Baskerville", "Songti SC", "STSong", "Noto Serif CJK SC", Georgia, serif;
  --sans: "Avenir Next", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  --figures: "DIN Condensed", "Avenir Next Condensed", "Roboto Condensed", "Arial Narrow", sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--baize-deep);
  color: var(--ivory);
  font-family: var(--sans);
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}
body { position: fixed; inset: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--brass-hi); outline-offset: 2px; }
.hidden { display: none !important; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- Layout (always landscape): table gets the full height ---------- */
#app {
  position: absolute;
  left: 0; top: 0;
  width: 100vw; height: 100vh;
  display: grid;
  grid-template-columns: calc(62px + env(safe-area-inset-left)) 1fr calc(62px + env(safe-area-inset-right));
  grid-template-rows: 1fr;
  grid-template-areas: "left stage right";
  /* the room around the table takes the table's mood */
  background: radial-gradient(ellipse at 50% 45%, var(--table-bg) 0%, #0b1210 100%);
  transition: background 0.4s;
}
#app.rot { transform-origin: top left; transform: rotate(90deg) translateY(-100%); }
#app { isolation: isolate; } /* lets the background canvas sit under the side columns */
#bg { position: absolute; inset: 0; width: 100%; height: 100%; z-index: -1; pointer-events: none; filter: brightness(1.45); } /* lifted so long sessions are easy on the eyes */
#stage { grid-area: stage; position: relative; min-height: 0; min-width: 0; }
#table { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }

/* ---------- Side columns: the marker board ---------- */
.ctl {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 4px;
  min-height: 0;
  background: linear-gradient(90deg, rgba(0,0,0,0.35), rgba(0,0,0,0.1));
}
#ctl-left { grid-area: left; padding-left: calc(5px + env(safe-area-inset-left)); }
#ctl-right { grid-area: right; padding-right: calc(5px + env(safe-area-inset-right)); background: linear-gradient(270deg, rgba(0,0,0,0.35), rgba(0,0,0,0.1)); }

.icon-btn {
  width: 32px; height: 32px; flex: none;
  display: grid; place-items: center;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--mahogany-hi), var(--mahogany));
  color: var(--brass-hi);
}
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.on { background: linear-gradient(180deg, var(--brass-hi), var(--brass)); color: var(--ink); }
#btn-sound .off-icon { display: none; }
#btn-sound.off .off-icon { display: block; }
#btn-sound.off .on-icon { display: none; }
.btn-row { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; }

/* score plates: mahogany with brass figures, like a club marker board */
.player {
  position: relative;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 3px 2px 6px;
  border-radius: 6px;
  background: linear-gradient(180deg, var(--mahogany-hi), var(--mahogany));
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.12), 0 2px 6px rgba(0,0,0,0.5);
  overflow: hidden;
}
.player::after { /* the "to play" lamp */
  content: ""; position: absolute; top: 5px; right: 5px; width: 6px; height: 6px; border-radius: 50%;
  background: #2a1a10;
}
.player.active::after { background: var(--chalk); box-shadow: 0 0 8px var(--chalk); }
.player .name { font-size: 10px; max-width: 100%; padding: 0 9px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.player .score {
  font-family: var(--figures);
  font-size: 26px; line-height: 1; padding-top: 2px;
  color: var(--brass-hi);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 0 rgba(0,0,0,0.6);
}
.player .clock { position: absolute; left: 0; bottom: 0; height: 3px; width: 0; background: var(--chalk); }
.player .clock.low { background: var(--danger); }
#info { text-align: center; font-size: 10px; color: var(--muted); line-height: 1.3; }
#ball-on b { color: var(--ivory); font-size: 12px; font-family: var(--serif); }
.need { color: var(--danger); }

#spin {
  position: relative;
  flex: none;
  width: 48px; height: 48px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fffdf5, #ddd6c2 70%, #a9a28a);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5), 0 0 0 2px var(--brass);
}
#spin::before, #spin::after { content: ""; position: absolute; background: rgba(0, 0, 0, 0.15); }
#spin::before { left: 50%; top: 12%; bottom: 12%; width: 1px; }
#spin::after { top: 50%; left: 12%; right: 12%; height: 1px; }
#spin-dot, #spin-big-dot {
  position: absolute; left: 50%; top: 50%;
  border-radius: 50%;
  background: var(--chalk);
  box-shadow: 0 0 0 2px #fff;
}
#spin-dot { width: 12px; height: 12px; margin: -6px 0 0 -6px; }
#fine {
  position: relative;
  flex: 1;
  width: 44px;
  border-radius: 22px;
  overflow: hidden;
  background: linear-gradient(90deg, #120a05, var(--mahogany-hi) 50%, #120a05);
  border: 1px solid var(--line);
  box-shadow: inset 0 12px 14px rgba(0,0,0,0.75), inset 0 -12px 14px rgba(0,0,0,0.75);
  touch-action: none;
}
#fine .ticks {
  position: absolute; inset: -40px 0;
  background: repeating-linear-gradient(0deg, rgba(239, 216, 154, 0.32) 0 2px, transparent 2px 10px);
}
#fine::after {
  content: ""; position: absolute; left: 6px; right: 6px; top: 50%; height: 2px; margin-top: -1px;
  background: var(--brass-hi); box-shadow: 0 0 6px var(--brass);
}
/* power: a slim cue in a dark track; its tip stays under your finger */
#power {
  --tip: 6px; /* where the cue tip rests (top of the pull) */
  position: relative;
  flex: 1;
  width: 46px;
  border-radius: 23px;
  overflow: hidden;
  background: linear-gradient(90deg, rgba(8,5,3,0.88), rgba(28,17,9,0.78) 50%, rgba(8,5,3,0.88));
  border: 1px solid rgba(239, 216, 154, 0.22);
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.6);
  touch-action: none;
  transition: box-shadow 0.15s;
}
#power.hot { box-shadow: inset 0 2px 8px rgba(0,0,0,0.6), 0 0 16px rgba(255, 120, 80, 0.55); }
.power-scale i {
  position: absolute; right: 0; left: 0;
  top: calc(var(--tip) + (100% - var(--tip)) * 0.92 * var(--k));
  height: 0; border-top: 1px solid rgba(239, 216, 154, 0.22);
  pointer-events: none;
}
.power-scale b {
  position: absolute; right: 3px; top: -11px;
  font: 600 8px/1 var(--sans); color: rgba(239, 216, 154, 0.5);
}
#power-fill {
  position: absolute; left: 0; right: 0; top: 0; height: var(--tip);
  background: linear-gradient(180deg, rgba(239, 216, 154, 0.04), rgba(239, 216, 154, 0.2));
  border-bottom: 1px solid rgba(255, 233, 168, 0.75);
  pointer-events: none;
}
#power.hot #power-fill { background: linear-gradient(180deg, rgba(239, 216, 154, 0.05), rgba(255, 120, 80, 0.3)); border-bottom-color: #ff9a6a; }
#power-cue {
  position: absolute; left: 50%; top: var(--tip);
  width: 12px; height: 140%; margin-left: -6px;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.6));
  pointer-events: none;
  will-change: transform;
}
#power-pct {
  position: absolute; left: 50%; top: 0;
  transform: translate(-50%, -100%);
  padding: 1px 5px; border-radius: 6px;
  background: rgba(10, 6, 3, 0.85); border: 1px solid rgba(239, 216, 154, 0.4);
  font-family: var(--figures); font-size: 14px; color: var(--brass-hi);
  pointer-events: none;
}
#power-pct:empty { display: none; }
.turn-ctl.disabled { opacity: 0.35; pointer-events: none; }

/* ---------- Referee calls: banners and toasts ---------- */
#banner {
  position: absolute; left: 50%; top: 42%; z-index: 15;
  transform: translate(-50%, -50%) scale(0.6);
  font-family: var(--serif);
  font-size: 46px; font-weight: 700; font-style: italic;
  color: var(--ivory); white-space: nowrap;
  text-shadow: 0 0 24px rgba(0,0,0,0.9), 0 3px 0 rgba(0,0,0,0.5);
  opacity: 0; pointer-events: none;
}
#banner.show { animation: banner 1.4s ease-out forwards; }
#banner.foul { color: var(--danger); }
#banner.gold { color: var(--brass-hi); }
@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.12); }
  30% { transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(1); }
}
#toast {
  position: absolute; left: 50%; top: 6px;
  transform: translate(-50%, -20px);
  max-width: 90%;
  padding: 5px 14px;
  border-radius: 4px;
  background: rgba(10, 6, 3, 0.82);
  border-left: 3px solid var(--brass);
  font-size: 12px;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.foul { border-left-color: var(--danger); }
#chat-bubble {
  position: absolute; right: 12px; bottom: 12px;
  padding: 8px 12px; border-radius: 14px 14px 2px 14px;
  background: var(--ivory); color: var(--ink); font-size: 14px;
  opacity: 0; transition: opacity 0.25s; pointer-events: none;
}
#chat-bubble.show { opacity: 1; }
#chat-menu {
  position: absolute; right: 70px; bottom: 8px; z-index: 30;
  width: 320px; max-height: calc(100% - 16px); overflow-y: auto;
  display: flex; flex-direction: column; gap: 6px;
  padding: 8px; border-radius: 10px;
  background: var(--mahogany); border: 1px solid var(--line);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.55);
}
#chat-menu button { border-radius: 6px; border: 0; background: rgba(255, 255, 255, 0.06); color: var(--ivory); }
.reactions { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.reactions button { display: flex; flex-direction: column; align-items: center; padding: 3px 0 4px; font-size: 10px; color: var(--muted) !important; }
.reactions button span { font-size: 26px; line-height: 1.15; }
.reactions button:active { transform: scale(0.92); }
.phrases { display: flex; flex-wrap: wrap; gap: 4px; }
.phrases button { padding: 5px 9px; font-size: 12px; border-radius: 999px !important; }
#chat-form { display: flex; gap: 4px; }
#chat-form input { flex: 1; min-width: 0; padding: 7px 9px; font-size: 14px; }
#chat-form button { padding: 0 12px; background: linear-gradient(180deg, var(--brass-hi), var(--brass)); color: var(--ink); font-weight: 700; }

/* a chat reaction: the emoji pops up over the table and floats away */
.reaction {
  position: absolute; bottom: 18%; z-index: 14;
  display: flex; flex-direction: column; align-items: center;
  pointer-events: none;
  animation: react-float 2.4s cubic-bezier(0.2, 0.8, 0.3, 1) forwards;
}
.reaction.theirs { left: 22%; }
.reaction.mine { right: 22%; }
.reaction span { font-size: 84px; line-height: 1; filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.6)); }
.reaction small { margin-top: 2px; padding: 1px 8px; border-radius: 999px; background: rgba(0, 0, 0, 0.6); font-size: 12px; color: var(--ivory); }
@keyframes react-float {
  0% { opacity: 0; transform: translateY(20px) scale(0.3); }
  12% { opacity: 1; transform: translateY(0) scale(1.25); }
  22% { transform: translateY(-6px) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-140px) scale(0.9); }
}

/* ---------- Screens ---------- */
.screen {
  position: absolute; inset: 0; z-index: 20;
  display: grid; place-items: center;
  padding: 14px calc(14px + env(safe-area-inset-right)) 14px calc(14px + env(safe-area-inset-left));
  background: rgba(3, 10, 6, 0.8);
  backdrop-filter: blur(5px);
  overflow-y: auto;
}
/* start and menu let the live table show through */
.screen.see-through { background: radial-gradient(ellipse at 50% 40%, rgba(3, 10, 6, 0.15), rgba(3, 10, 6, 0.75)); backdrop-filter: none; }

/* dialogs (fouls, online, pause) are mahogany boards with a brass edge */
.panel {
  width: min(420px, 100%);
  max-height: 100%;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 10px;
  padding: 18px;
  border-radius: 10px;
  background: linear-gradient(180deg, var(--mahogany-hi), var(--mahogany) 60%, #2a150c);
  border: 1px solid var(--brass-lo);
  box-shadow: 0 0 0 4px rgba(0,0,0,0.25), 0 24px 60px rgba(0, 0, 0, 0.6);
}
h1, h2 { font-family: var(--serif); font-weight: 700; margin: 0; }
h2 { font-size: 24px; text-align: center; color: var(--brass-hi); }
p { margin: 0; text-align: center; }
.muted { color: var(--muted); font-size: 13px; line-height: 1.45; }
.err { color: var(--danger); font-size: 13px; min-height: 1em; }
input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.3);
  color: var(--ivory);
  font-size: 16px;
  outline: none;
}
input:focus { border-color: var(--brass); }

.big {
  width: 100%;
  padding: 12px 14px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  font-size: 15px; font-weight: 600;
}
.big:active { transform: translateY(1px); }
.big.primary, .brass-btn {
  background: linear-gradient(180deg, var(--brass-hi), var(--brass) 55%, var(--brass-lo));
  color: var(--ink);
  border: 0;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.6), 0 3px 10px rgba(0,0,0,0.4);
}
.big.ghost { background: transparent; }
.brass-btn { padding: 8px 20px; border-radius: 6px; font-weight: 700; }

/* ---------- Start screen ---------- */
.start-panel { display: flex; flex-direction: column; align-items: center; gap: 18px; text-align: center; }
.plaque {
  position: relative;
  padding: 14px 34px;
  border-radius: 4px;
  background: linear-gradient(175deg, #f6e3a8 0%, var(--brass) 38%, #a8833a 62%, #e9cf88 100%);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.7), inset 0 -2px 0 rgba(0,0,0,0.25), 0 10px 30px rgba(0,0,0,0.6);
}
.plaque::before, .plaque::after { /* the screws */
  content: ""; position: absolute; top: 50%; width: 8px; height: 8px; margin-top: -4px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff4cf, #6e5420);
}
.plaque::before { left: 10px; }
.plaque::after { right: 10px; }
.plaque span {
  font-family: var(--serif);
  font-size: 40px; font-weight: 700; letter-spacing: 1px;
  color: #3a2a0c;
  text-shadow: 0 1px 0 rgba(255,255,255,0.55), 0 -1px 0 rgba(0,0,0,0.25); /* engraved */
}
.plaque.small { padding: 6px 26px; align-self: flex-start; }
.plaque.small span { font-size: 22px; }
/* the start button is a cube of chalk */
.chalk {
  width: 200px; padding: 16px 0;
  border: 0; border-radius: 10px;
  font-size: 20px; font-weight: 700; letter-spacing: 0.5px;
  color: #fff;
  background:
    radial-gradient(circle at 50% 45%, rgba(255,255,255,0.18), transparent 60%),
    repeating-radial-gradient(circle at 30% 30%, rgba(255,255,255,0.05) 0 2px, transparent 2px 5px),
    linear-gradient(180deg, #5b97dc, var(--chalk) 60%, #2a5c98);
  box-shadow: inset 0 2px 0 rgba(255,255,255,0.35), inset 0 -4px 0 rgba(0,0,0,0.25), 0 10px 26px rgba(62, 124, 196, 0.45);
}
.chalk:active { transform: translateY(2px); }
.hint { color: var(--muted); font-size: 13px; }

/* ---------- Main menu ---------- */
.menu-board {
  width: min(800px, 100%);
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 18px;
  align-items: center;
}
.menu-modes { display: flex; flex-direction: column; gap: 4px; }
.menu-modes .plaque { margin-bottom: 8px; }
.mode {
  display: flex; flex-direction: column; align-items: flex-start;
  padding: 9px 14px 9px 16px;
  border: 0; border-left: 3px solid transparent;
  background: linear-gradient(90deg, rgba(0,0,0,0.55), rgba(0,0,0,0.15));
  text-align: left;
}
.mode b { font-family: var(--serif); font-size: 19px; font-weight: 700; }
.mode small { color: var(--muted); font-size: 12px; }
.mode:active, .mode:hover { border-left-color: var(--brass); }
.mode.featured { border-left-color: var(--chalk); background: linear-gradient(90deg, rgba(62,124,196,0.35), rgba(0,0,0,0.15)); }
.menu-kit { display: flex; flex-direction: column; gap: 8px; }
.kit {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.45);
  text-align: left;
}
.kit span { font-size: 11px; color: var(--muted); }
.kit b { font-family: var(--serif); font-size: 16px; color: var(--brass-hi); }
#cue-thumb { width: 100%; height: 30px; order: -1; }
#table-thumb { width: 100%; height: 70px; order: -1; border-radius: 4px; }
.kit-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.seg { display: flex; gap: 2px; padding: 3px; border-radius: 6px; background: rgba(0, 0, 0, 0.4); }
.seg button { padding: 7px 10px; border: 0; border-radius: 4px; background: transparent; font-weight: 600; font-size: 13px; color: var(--muted); }
.seg button.on { background: var(--brass); color: var(--ink); }

/* ---------- Shop: cue rack and table showcase ---------- */
.shop {
  width: min(820px, 100%);
  max-height: 100%;
  display: flex; flex-direction: column; gap: 10px;
  min-height: 0;
}
.shop-head { display: flex; align-items: center; justify-content: space-between; }
.shop-head h2 { text-align: left; }

#cue-hero {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 14px;
  align-items: end;
  padding: 10px 14px;
  border-radius: 8px;
  background: radial-gradient(ellipse at 50% 0%, rgba(255, 240, 200, 0.18), transparent 70%), linear-gradient(180deg, #145c3c, var(--baize-deep));
  border: 1px solid var(--line);
}
#cue-hero canvas { grid-column: 1 / -1; width: 100%; height: 56px; }
#cue-hero .hero-name { font-family: var(--serif); font-size: 24px; font-weight: 700; }
#cue-hero .hero-blurb { grid-column: 1 / -1; color: var(--muted); font-size: 13px; text-align: left; }
#cue-hero .stats { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px 12px; font-size: 11px; color: var(--muted); }
#cue-hero .stats div { display: grid; gap: 3px; }
.tier { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; color: var(--tier); }
.tier::before { content: ""; width: 8px; height: 8px; transform: rotate(45deg); background: var(--tier); box-shadow: 0 0 8px var(--tier); }

/* the rack: each cue lies on its own strip of felt */
#cue-list { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; overflow-y: auto; min-height: 0; padding-right: 2px; }
.cue-card {
  position: relative;
  display: grid;
  grid-template-columns: 1fr;
  padding: 6px 10px 4px;
  border: 0; border-radius: 4px;
  background: linear-gradient(180deg, #0f4a31, #0a3523);
  box-shadow: inset 0 -3px 0 rgba(0,0,0,0.35);
  text-align: left;
}
.cue-card canvas { width: 100%; height: 26px; }
.cue-card .card-top { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; font-size: 13px; }
.cue-card .card-top b { font-family: var(--serif); font-weight: 700; }
.cue-card.on { background: linear-gradient(180deg, #1b6e4a, #0e4a31); box-shadow: inset 0 0 0 1px var(--brass), 0 0 14px rgba(239, 216, 154, 0.25); }
.cue-card.on .card-top b { color: var(--brass-hi); }
.bar { height: 5px; border-radius: 3px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--brass), var(--brass-hi)); }

.table-show { display: grid; grid-template-columns: 1.6fr 1fr; gap: 12px; min-height: 0; }
#table-hero canvas { width: 100%; aspect-ratio: 1.9; display: block; filter: drop-shadow(0 12px 22px rgba(0,0,0,0.6)); }
#table-blurb { margin-top: 6px; color: var(--muted); font-size: 13px; text-align: left; }
#table-list { display: flex; flex-direction: column; gap: 3px; overflow-y: auto; }
.table-card {
  display: grid; grid-template-columns: 34px 1fr; align-items: center; gap: 10px;
  padding: 6px 8px;
  border: 0; border-left: 3px solid transparent; border-radius: 0;
  background: rgba(0, 0, 0, 0.35);
  text-align: left;
}
.table-card i { width: 34px; height: 20px; border-radius: 3px; box-shadow: inset 0 0 0 2px rgba(0,0,0,0.35); }
.table-card b { font-family: var(--serif); font-size: 15px; font-weight: 700; }
.table-card.on { border-left-color: var(--brass); background: rgba(201, 165, 90, 0.16); }

/* ---------- Online lobby ---------- */
#room-code { text-align: center; font-family: var(--figures); font-size: 48px; letter-spacing: 10px; color: var(--brass-hi); }
.join { display: flex; gap: 8px; }
.join input { text-transform: uppercase; letter-spacing: 6px; text-align: center; font-weight: 700; }
.join .big { width: auto; padding: 0 22px; }

/* ---------- Enlarged spin selector ---------- */
#spin-modal {
  position: absolute; inset: 0; z-index: 25;
  display: grid; place-items: center;
  background: rgba(0, 0, 0, 0.6);
}
.spin-panel {
  display: flex; align-items: center; gap: 22px;
  padding: 16px 22px; border-radius: 10px;
  background: linear-gradient(180deg, var(--mahogany-hi), var(--mahogany));
  border: 1px solid var(--brass-lo);
}
#spin-big {
  position: relative;
  width: min(62vh, 240px); height: min(62vh, 240px);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fffef8, #e2dccb 60%, #9d9680);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
  touch-action: none;
}
#spin-big::before, #spin-big::after { content: ""; position: absolute; background: rgba(0, 0, 0, 0.18); }
#spin-big::before { left: 50%; top: 6%; bottom: 6%; width: 1px; }
#spin-big::after { top: 50%; left: 6%; right: 6%; height: 1px; }
#spin-big .ring { position: absolute; inset: 10%; border-radius: 50%; border: 2px dashed rgba(180, 30, 30, 0.45); }
#spin-big-dot { width: 22px; height: 22px; margin: -11px 0 0 -11px; }
.spin-side { display: flex; flex-direction: column; gap: 10px; width: 150px; }
#spin-desc { font-family: var(--serif); font-size: 17px; font-weight: 700; min-height: 2.6em; }

/* creatures get a taller picture than a cue */
.cue-card.creature canvas { height: 76px; }
#cue-hero.creature canvas { height: 130px; }

/* ---------- Scoreboard: one slim strip above the table ---------- */
#scoreboard {
  position: absolute; left: 0; right: 0; top: 0; height: 24px; z-index: 6;
  display: flex; align-items: stretch; justify-content: center; gap: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(4,8,16,0.9), rgba(4,8,16,0.7));
  border-bottom: 1px solid rgba(239,216,154,0.3);
  white-space: nowrap;
}
#stage.has-board #table { top: 25px; height: calc(100% - 25px); }
#scoreboard .player {
  width: auto; flex-direction: row; align-items: center; gap: 8px;
  padding: 0 0 0 10px; border-radius: 0;
  background: transparent; box-shadow: none; overflow: visible;
}
#scoreboard .player.right { padding: 0 10px 0 0; }
#scoreboard .player::after { display: none; }
#scoreboard .player .name { max-width: 96px; padding: 0; font-size: 13px; font-weight: 600; color: var(--muted); }
#scoreboard .player.active .name { color: var(--ivory); }
#scoreboard .player .score {
  min-width: 38px; height: 100%; padding: 3px 6px 0; text-align: center;
  font-family: var(--figures); font-size: 21px; line-height: 21px;
  color: #fff; background: rgba(255,255,255,0.07);
}
#scoreboard .player.active .score { background: linear-gradient(180deg, var(--brass-hi), var(--brass)); color: var(--ink); }
#scoreboard .player .clock { left: 0; right: 0; bottom: 0; height: 2px; }
.sb-frames { display: flex; align-items: center; gap: 2px; padding: 0 10px; font-size: 11px; color: var(--muted); }
.sb-frames span { font-family: var(--figures); font-size: 15px; color: var(--brass-hi); }
#info { display: flex; align-items: center; gap: 10px; margin-left: 14px; padding-left: 14px; border-left: 1px solid var(--line); font-size: 12px; color: var(--muted); }
#ball-on b { font-family: var(--serif); color: var(--ivory); font-size: 13px; }
#break b { font-family: var(--figures); font-size: 15px; color: var(--brass-hi); }
#toast { top: 32px; }

/* ---------- Victory: the winner's moment ---------- */
#victory {
  background: radial-gradient(ellipse at 50% 30%, rgba(70, 40, 6, 0.78), rgba(3, 8, 5, 0.94) 70%);
  overflow: hidden;
}
#fireworks { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.v-card {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  width: min(560px, 100%);
  text-align: center;
}
.v-crown { position: relative; width: 74px; height: 74px; }
.v-rays {
  position: absolute; left: 50%; top: 50%; width: 360px; height: 360px;
  margin: -180px 0 0 -180px; border-radius: 50%;
  background: repeating-conic-gradient(rgba(255, 214, 110, 0.32) 0 7deg, transparent 7deg 20deg);
  -webkit-mask: radial-gradient(circle, #000 12%, transparent 66%);
  mask: radial-gradient(circle, #000 12%, transparent 66%);
  animation: v-spin 16s linear infinite;
}
.v-trophy {
  position: relative; width: 100%; height: 100%;
  filter: drop-shadow(0 0 14px rgba(255, 200, 90, 0.75));
  animation: v-drop 0.7s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}
#v-name {
  font-size: 50px; line-height: 1; letter-spacing: 0.01em;
  background: linear-gradient(180deg, #fff6d2 10%, #f2c55a 55%, #b07a1c 90%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 3px 0 rgba(0, 0, 0, 0.55)) drop-shadow(0 0 18px rgba(255, 190, 80, 0.45));
  animation: v-punch 0.8s 0.25s cubic-bezier(0.2, 1.5, 0.4, 1) both;
}
#v-beats { font-family: var(--serif); font-style: italic; font-size: 20px; color: var(--ivory); animation: v-fade 0.5s 0.7s both; }
.v-score {
  display: flex; align-items: center; gap: 12px;
  margin-top: 6px; padding: 6px 18px;
  border-radius: 8px;
  background: linear-gradient(180deg, #14213d, #0a1226);
  border: 1px solid var(--brass);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.35), 0 10px 30px rgba(0, 0, 0, 0.5);
  animation: v-fade 0.5s 0.9s both;
}
.v-score b { font-family: var(--figures); font-size: 46px; line-height: 1; min-width: 1.6ch; font-weight: 700; color: var(--ivory); }
.v-score b.won { color: #ffd56a; text-shadow: 0 0 16px rgba(255, 200, 80, 0.6); }
.v-score i { font-style: normal; font-size: 28px; color: var(--brass); }
.v-player { font-family: var(--serif); font-size: 16px; color: var(--muted); max-width: 9em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#v-breaks { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; animation: v-fade 0.5s 1.3s both; }
#v-breaks li {
  padding: 3px 10px; border-radius: 999px;
  font-size: 13px; color: var(--ivory);
  background: rgba(239, 216, 154, 0.1); border: 1px solid var(--line);
}
#v-breaks li.top { color: #2a1606; font-weight: 700; background: linear-gradient(180deg, #ffe9a8, #e3a937); border-color: #ffe9a8; }
#v-note { font-size: 13px; color: var(--muted); min-height: 1em; animation: v-fade 0.5s 1.3s both; }
.v-buttons { display: flex; gap: 10px; margin-top: 4px; animation: v-fade 0.5s 1.6s both; }
.v-buttons .big { min-width: 150px; }
@keyframes v-spin { to { transform: rotate(360deg); } }
@keyframes v-drop { from { transform: translateY(-60px) scale(0.4); opacity: 0; } }
@keyframes v-punch { 0% { transform: scale(0.2); opacity: 0; } 60% { transform: scale(1.12); opacity: 1; } 100% { transform: scale(1); } }
@keyframes v-fade { from { opacity: 0; transform: translateY(8px); } }
@media (max-height: 420px) {
  .v-card { gap: 2px; }
  .v-crown { width: 54px; height: 54px; }
  #v-name { font-size: 40px; }
  .v-score { margin-top: 4px; padding: 3px 16px; }
  .v-score b { font-size: 38px; }
  .v-buttons .big { padding-top: 10px; padding-bottom: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  .v-rays, .v-trophy, #v-name, #v-beats, .v-score, #v-breaks, #v-note, .v-buttons { animation: none; }
}

/* a break of 30+ during play gets its own call */
#banner.milestone {
  color: #ffd56a; font-size: 54px;
  text-shadow: 0 0 26px rgba(255, 190, 70, 0.8), 0 3px 0 rgba(0, 0, 0, 0.6);
}
#banner.milestone small { display: block; font-size: 18px; font-style: normal; font-family: var(--sans); color: var(--ivory); letter-spacing: 0.04em; text-align: center; }

/* ---------- Defeat: the player was beaten ---------- */
.v-broken, .v-stamp { display: none; }
#victory.lost { background: radial-gradient(ellipse at 50% 35%, rgba(40, 8, 8, 0.82), rgba(4, 2, 2, 0.96) 70%); }
#victory.lost .v-rays, #victory.lost .v-trophy { display: none; }
#victory.lost .v-broken { display: block; position: relative; width: 100%; height: 100%; filter: drop-shadow(0 4px 6px rgba(0,0,0,0.7)); }
#victory.lost .v-half { transform-box: fill-box; transform-origin: center; }
#victory.lost .v-half.a { animation: v-snap-a 0.6s 0.55s cubic-bezier(0.3, 1.6, 0.5, 1) both; }
#victory.lost .v-half.b { animation: v-snap-b 0.6s 0.55s cubic-bezier(0.3, 1.6, 0.5, 1) both; }
#victory.lost #v-name {
  font-size: 40px;
  background: linear-gradient(180deg, #ffffff 10%, #c9c9c9 60%, #7d7d7d 95%);
  -webkit-background-clip: text; background-clip: text;
  filter: drop-shadow(0 3px 0 rgba(0, 0, 0, 0.6));
}
#victory.lost #v-beats { color: #ff8a7a; text-shadow: 0 1px 4px #000, 0 0 10px #000; }
#victory.lost .v-score { border-color: #7a2a22; }
#victory.lost .v-card { animation: v-shake 0.45s 0.55s both; }
#victory.lost .v-stamp {
  display: block;
  position: absolute; left: 50%; top: 38%; z-index: 2;
  padding: 4px 18px;
  font-family: var(--serif); font-weight: 700; font-size: 46px; letter-spacing: 0.06em;
  color: #e0332a; border: 5px double #e0332a; border-radius: 8px;
  background: rgba(40, 0, 0, 0.35);
  text-shadow: 0 0 18px rgba(255, 40, 30, 0.6);
  box-shadow: 0 0 24px rgba(255, 40, 30, 0.35);
  pointer-events: none;
  animation: v-stamp 0.55s cubic-bezier(0.5, 0, 0.75, 0) both, v-stamp-out 0.6s 2.6s ease-in forwards;
}
@keyframes v-stamp {
  0% { opacity: 0; transform: translate(-50%, -50%) rotate(-14deg) scale(3.2); }
  100% { opacity: 0.95; transform: translate(-50%, -50%) rotate(-14deg) scale(1); }
}
@keyframes v-stamp-out { to { opacity: 0; transform: translate(-50%, -50%) rotate(-14deg) scale(0.9); } }
@keyframes v-snap-a { from { transform: none; } to { transform: translate(-3px, 3px) rotate(-14deg); } }
@keyframes v-snap-b { from { transform: none; } to { transform: translate(4px, -2px) rotate(18deg); } }
@keyframes v-shake {
  0%, 100% { transform: none; }
  15% { transform: translate(-8px, 4px); }
  30% { transform: translate(7px, -5px); }
  45% { transform: translate(-6px, 2px); }
  60% { transform: translate(4px, 3px); }
  80% { transform: translate(-2px, -1px); }
}
@media (prefers-reduced-motion: reduce) {
  #victory.lost .v-card, #victory.lost .v-half { animation: none; }
  #victory.lost .v-stamp { animation: v-stamp-out 0.6s 2.6s forwards; transform: translate(-50%, -50%) rotate(-14deg); }
}

/* ---------- Room lobby: names, rock-paper-scissors, cue draft ---------- */
#lobby { background: radial-gradient(ellipse at 50% 30%, rgba(14, 77, 51, 0.85), rgba(3, 10, 6, 0.95) 75%); }
.lobby {
  width: min(760px, 100%);
  display: flex; flex-direction: column; align-items: stretch; gap: 8px;
}
.lobby-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.lobby-head h2 { text-align: left; font-size: 22px; letter-spacing: 0.02em; }
.lobby-head .big { width: auto; padding: 8px 16px; }
.seats { display: grid; grid-template-columns: 1fr auto 1fr; align-items: stretch; gap: 10px; }
.vs { align-self: center; font-family: var(--serif); font-style: italic; font-size: 22px; color: var(--brass); }
.seat {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  min-height: 112px; padding: 8px 10px;
  border-radius: 10px;
  background: linear-gradient(180deg, var(--mahogany-hi), var(--mahogany));
  border: 1px solid var(--line);
  transition: box-shadow 0.25s, border-color 0.25s;
}
.seat.turn { border-color: var(--brass-hi); box-shadow: 0 0 0 2px rgba(239, 216, 154, 0.35), 0 0 22px rgba(239, 216, 154, 0.25); }
.seat.won { border-color: #ffd56a; }
.seat-role { font-size: 11px; color: var(--muted); }
.seat-name { font-family: var(--serif); font-weight: 700; font-size: 22px; color: var(--ivory); min-height: 30px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat-name input { font-family: var(--serif); font-size: 18px; text-align: center; padding: 6px 8px; }
.seat-show { display: flex; flex-direction: column; align-items: center; width: 100%; min-height: 0; }
.seat-show canvas { width: 100%; height: 22px; }
.seat-show canvas.creature { height: 42px; }
.seat-show b { font-family: var(--serif); font-size: 14px; color: var(--brass-hi); }
.hand-big { font-size: 40px; line-height: 1.1; animation: v-punch 0.5s cubic-bezier(0.2, 1.5, 0.4, 1) both; }
.hand-big.wait { font-size: 26px; color: var(--muted); animation: none; }
.seat-status { font-size: 12px; color: var(--brass-hi); min-height: 1em; text-align: center; }
.stage-names { display: flex; justify-content: center; }
.stage-names .big { width: min(320px, 100%); }
.hands { display: flex; justify-content: center; gap: 10px; }
.hands button {
  display: flex; flex-direction: column; align-items: center; gap: 0;
  width: 104px; padding: 6px 0 8px;
  border-radius: 10px; border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--mahogany-hi), var(--mahogany));
  color: var(--ivory); font-size: 13px;
}
.hands button span { font-size: 34px; line-height: 1.15; }
.hands button:active:not(:disabled) { transform: scale(0.95); }
.hands button:disabled { opacity: 0.4; }
#draft-list { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.draft-card {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 6px 5px; min-width: 0;
  border-radius: 8px; border: 1px solid var(--line);
  background: linear-gradient(180deg, #1b3a2b, #0e2419);
  color: var(--ivory);
}
.draft-card canvas { width: 100%; height: 40px; }
.draft-card b { font-family: var(--serif); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.draft-card small { font-size: 9.5px; color: var(--muted); white-space: nowrap; }
.draft-card em { font-style: normal; font-size: 10px; color: #ffd56a; min-height: 0; }
.draft-card:not(:disabled):hover, .draft-card:not(:disabled):focus-visible { border-color: var(--brass-hi); }
.draft-card.taken { opacity: 0.45; filter: grayscale(0.7); }
.draft-card:disabled:not(.taken) { opacity: 0.85; }
#lobby-note { font-size: 13px; color: var(--ivory); min-height: 1.2em; }
#btn-leave { align-self: center; background: none; border: 0; color: var(--muted); font-size: 13px; text-decoration: underline; padding: 4px 8px; }
#history ul { list-style: none; margin: 4px 0 0; padding: 0; font-size: 13px; color: var(--ivory); text-align: center; line-height: 1.6; }
@media (max-height: 380px) {
  .seat { min-height: 96px; padding: 6px 8px; }
  .hand-big { font-size: 34px; }
}

/* bottom-left: points still on the table and how far the player at the table is ahead or behind */
#tally {
  position: absolute; left: 12%; bottom: 3px; z-index: 6;
  padding: 1px 10px; border-radius: 999px;
  background: rgba(4, 8, 16, 0.78); border: 1px solid rgba(239, 216, 154, 0.25);
  font-size: 11px; line-height: 16px; color: var(--muted); white-space: nowrap;
  pointer-events: none;
}
#tally b { font-family: var(--figures); font-size: 14px; color: var(--brass-hi); }
#tally b.need { font-family: var(--sans); font-size: 11px; color: var(--danger); }

/* ---------- Invitations ---------- */
#invite-card {
  position: absolute; left: 50%; top: 12px; z-index: 5;
  transform: translateX(-50%);
  width: min(420px, calc(100% - 32px));
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px 10px 16px;
  border-radius: 10px;
  background: linear-gradient(180deg, var(--mahogany-hi), var(--mahogany));
  border: 1px solid var(--brass);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.6);
  animation: v-fade 0.4s both;
}
#invite-card p { flex: 1; text-align: left; font-size: 14px; }
#invite-card b { color: var(--brass-hi); font-family: var(--serif); font-size: 16px; }
.invite-buttons { display: flex; gap: 6px; }
.invite-buttons .big { width: auto; padding: 8px 14px; }

/* the share help sits outside the rotated game so its arrow always points at WeChat's ··· */
#share-tip {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0, 0, 0, 0.72);
  display: flex; align-items: flex-start; justify-content: flex-end;
  padding: 70px 16px 16px;
  font-family: var(--sans); color: var(--ivory);
}
.share-arrow { display: none; }
#share-tip.wechat .share-arrow {
  display: block; position: absolute; right: 22px; top: 6px;
  width: 60px; height: 60px;
  border-top: 4px solid var(--brass-hi); border-right: 4px solid var(--brass-hi);
  border-radius: 0 40px 0 0;
}
#share-tip.wechat .share-arrow::after {
  content: ""; position: absolute; right: -11px; top: -14px;
  border: 9px solid transparent; border-bottom: 14px solid var(--brass-hi);
}
.share-box {
  width: min(360px, 100%);
  display: flex; flex-direction: column; gap: 10px;
  padding: 16px; border-radius: 12px;
  background: linear-gradient(180deg, var(--mahogany-hi), var(--mahogany));
  border: 1px solid var(--brass-lo);
}
.share-box p { text-align: left; font-size: 15px; line-height: 1.45; }
.share-box b { color: var(--brass-hi); }
.share-wechat { display: none; }
#share-tip.wechat .share-wechat { display: block; font-size: 17px; }
.share-other-w { display: none; }
#share-tip.wechat .share-other { display: none; }
#share-tip.wechat .share-other-w { display: block; }
.share-copy { display: flex; gap: 6px; }
.share-copy input { flex: 1; min-width: 0; font-size: 13px; padding: 8px; text-transform: none; letter-spacing: 0; }
.share-copy button, .share-close {
  padding: 8px 14px; border-radius: 6px; border: 0; font-weight: 700;
  background: linear-gradient(180deg, var(--brass-hi), var(--brass)); color: var(--ink);
}
.share-close { background: rgba(255, 255, 255, 0.1); color: var(--ivory); }

.reaction i {
  position: absolute; left: 50%; top: 30%;
  font-style: normal; font-size: 26px;
  opacity: 0;
  animation: react-bit 1.1s ease-out forwards;
}
@keyframes react-bit {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(0.4); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) rotate(var(--r)) scale(1); }
}
#stage.shake { animation: table-shake 0.4s; }
@keyframes table-shake {
  0%, 100% { transform: none; }
  20% { transform: translate(-6px, 3px); }
  40% { transform: translate(5px, -4px); }
  60% { transform: translate(-4px, 2px); }
  80% { transform: translate(2px, 1px); }
}
