/* BigPool AI Table v2 — written from scratch (clean-room, Oct 2026). */
@font-face { font-family: BigPoolDisplay; src: url('/pool/css/Montserrat-Black.woff2') format('woff2'); font-weight: 900; font-display: swap; }

:root {
  --bg: #070908; --surface: #101411; --raised: #151a17; --line: rgba(255,255,255,0.09);
  --text: #f5f7f5; --soft: #c9d0cc; --muted: #89948e;
  --green: #68d391; --green-bright: #8be3aa; --gold: #d9b45d; --red: #f07d73;
  --font-body: 'DM Sans', Inter, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-head: Manrope, 'DM Sans', ui-sans-serif, system-ui, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); font: 15px/1.4 var(--font-body); overflow: hidden; overscroll-behavior: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
canvas#canvas_game { position: fixed; inset: 0; display: block; touch-action: none; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- HUD ---------- */
.hud { position: fixed; top: calc(6px + var(--safe-t)); left: calc(10px + var(--safe-l)); right: calc(10px + var(--safe-r)); display: grid; grid-template-columns: minmax(0, 1fr) minmax(104px, 210px) minmax(0, 1fr) auto; gap: 10px; align-items: center; pointer-events: none; z-index: 5; }
.plate { pointer-events: auto; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; padding: 6px 12px 8px 6px; background: rgba(16,20,17,0.86); border: 1px solid var(--line); border-radius: 14px; position: relative; min-width: 0; backdrop-filter: blur(6px); transition: border-color .2s, box-shadow .2s; }
.plate.opp { grid-template-columns: auto 1fr auto; }
.plate.is-turn { border-color: rgba(104,211,145,0.7); box-shadow: 0 0 0 1px rgba(104,211,145,0.35), 0 0 22px rgba(104,211,145,0.18); }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font: 800 15px var(--font-head); background: linear-gradient(140deg, #2f8a58, #173b28); color: #fff; }
.avatar.ai { background: linear-gradient(140deg, #8a6f2e, #3a2d10); }
.who { min-width: 0; }
.name { font: 800 14px var(--font-head); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rack { display: flex; flex-wrap: nowrap; gap: 3px; margin-top: 4px; min-height: 15px; overflow: hidden; }
.chip { flex: 0 0 auto; width: 15px; height: 15px; aspect-ratio: 1; border-radius: 50%; display: inline-grid; place-items: center; background: var(--c); font: 800 8px/1 var(--font-head); font-style: normal; color: #fff; text-shadow: 0 0 2px #000; box-shadow: inset 0 -2px 3px rgba(0,0,0,0.35), inset 0 1px 1px rgba(255,255,255,0.25); }
.chip.stripe { background: linear-gradient(#f6f3e8 0 24%, var(--c) 24% 76%, #f6f3e8 76%); color: #111; text-shadow: none; }
.chip.stripe::before { content: ""; }
.chip.gone { opacity: 0.22; filter: grayscale(0.6); }
.left { font: 800 18px var(--font-head); color: var(--soft); }
.bar { position: absolute; left: 12px; right: 12px; bottom: 3px; height: 2px; border-radius: 2px; background: var(--line); overflow: hidden; }
.bar::after { content: ""; position: absolute; inset: 0; width: calc(var(--p, 0) * 100%); background: var(--green); transition: width .4s; }
.mid { text-align: center; pointer-events: none; min-width: 0; }
.score { display: inline-flex; gap: 6px; align-items: baseline; padding: 2px 10px; border-radius: 999px; background: rgba(16,20,17,0.86); border: 1px solid var(--line); }
.score span { font-size: 10px; letter-spacing: 1.4px; text-transform: uppercase; color: var(--muted); font-weight: 800; }
.score b { font: 900 16px BigPoolDisplay, var(--font-head); color: var(--gold); font-variant-numeric: tabular-nums; }
.status { margin-top: 4px; font-size: 12px; line-height: 1.3; color: var(--soft); text-shadow: 0 1px 3px #000; max-width: 34ch; margin-inline: auto; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.icon { pointer-events: auto; width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: rgba(16,20,17,0.86); font-size: 20px; cursor: pointer; }

/* ---------- Controls ---------- */
.controls { position: fixed; inset: 0; pointer-events: none; z-index: 4; }
.controls > * { pointer-events: auto; transition: opacity .2s; }
body:not(.can-shoot) .controls > * { opacity: 0.25; pointer-events: none; }
/* Power slider: a cue-butt grip you pull back along a ticked rail, then release. */
.power { position: absolute; left: calc(12px + var(--safe-l)); top: 82px; bottom: calc(18px + var(--safe-b)); width: 62px; display: flex; flex-direction: column; align-items: center; gap: 8px; touch-action: none; cursor: grab; user-select: none; }
.power:active { cursor: grabbing; }
.power-head { display: grid; justify-items: center; gap: 1px; line-height: 1; }
.power-title { font: 800 9px var(--font-head); letter-spacing: 1.6px; text-transform: uppercase; color: var(--muted); }
#power-label { font: 900 15px BigPoolDisplay, var(--font-head); color: var(--soft); font-variant-numeric: tabular-nums; transition: color .15s; }
.power.is-pulling #power-label { color: var(--gold); }
.power .track { position: relative; flex: 1; width: 30px; min-height: 90px; border-radius: 16px; background: linear-gradient(90deg, #0a0d0b, #1a211d 50%, #0a0d0b); border: 1px solid rgba(255,255,255,0.1); box-shadow: inset 0 2px 8px rgba(0,0,0,0.7), 0 0 0 4px rgba(255,255,255,0.02); }
.power .ticks { position: absolute; inset: 8px 7px; background: repeating-linear-gradient(to bottom, transparent 0 calc(10% - 1px), rgba(255,255,255,0.13) calc(10% - 1px) 10%); border-radius: 4px; }
.power .fill { position: absolute; left: 3px; right: 3px; top: 3px; height: calc(var(--p, 0) * (100% - 6px)); border-radius: 13px; background: linear-gradient(180deg, var(--green-bright), var(--gold) 65%, var(--red)); background-size: 100% calc(100% / max(var(--p, 0), 0.0001)); box-shadow: 0 0 12px rgba(217,180,93,0.35); }
.power .handle { position: absolute; left: 50%; top: calc(3px + var(--p, 0) * (100% - 6px)); width: 50px; height: 24px; transform: translate(-50%, -50%); border-radius: 12px;
  background: linear-gradient(180deg, #f1dfb4, #c49a5a 55%, #8a6534); box-shadow: 0 6px 14px rgba(0,0,0,0.55), inset 0 1px 0 rgba(255,255,255,0.6), inset 0 -2px 0 rgba(0,0,0,0.25); transition: box-shadow .2s; }
.power .handle::before, .power .handle::after { content: ""; position: absolute; left: 6px; right: 6px; height: 3px; background: #1d140a; border-radius: 2px; }
.power .handle::before { top: 4px; } .power .handle::after { bottom: 4px; }
.power .handle i { position: absolute; inset: 9px 10px; background: repeating-linear-gradient(90deg, rgba(0,0,0,0.35) 0 2px, transparent 2px 5px); border-radius: 2px; }
.power-hint { font: 700 10px/1.25 var(--font-head); color: var(--muted); text-align: center; letter-spacing: .3px; }
.power-hint .hint-port { display: none; }
/* Your turn and you haven't pulled yet: the grip glows so it is easy to find. */
body.can-shoot .power:not(.touched) .handle { animation: grip-call 1.6s ease-in-out infinite; }
body.can-shoot .power:not(.touched) .power-hint { color: var(--gold); }
@keyframes grip-call { 0%, 100% { box-shadow: 0 6px 14px rgba(0,0,0,0.55), inset 0 1px 0 rgba(255,255,255,0.6), 0 0 0 0 rgba(217,180,93,0.55); } 50% { box-shadow: 0 6px 14px rgba(0,0,0,0.55), inset 0 1px 0 rgba(255,255,255,0.6), 0 0 0 8px rgba(217,180,93,0); } }
.right-stack { position: absolute; right: calc(14px + var(--safe-r)); top: 80px; bottom: 20px; width: 64px; display: flex; flex-direction: column; align-items: center; gap: 10px; overflow: hidden; }
.spin-btn { background: none; border: 0; padding: 0; display: grid; justify-items: center; gap: 2px; cursor: pointer; }
.spin-btn small { font-size: 10px; color: var(--muted); text-align: center; max-width: 64px; }
.mini-ball { position: relative; width: 48px; height: 48px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff, #e8e4d6 55%, #a9a495); box-shadow: 0 2px 8px rgba(0,0,0,0.5); display: block; }
[data-spin-dot] { position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; left: 50%; top: 50%; border-radius: 50%; background: var(--red); box-shadow: 0 0 0 2px rgba(255,255,255,0.7); }
.fine-wrap { flex: 1 1 auto; width: 44px; display: flex; flex-direction: column; align-items: center; gap: 4px; min-height: 0; overflow: hidden; }
.fine-step { flex: none; width: 44px; height: 30px; border-radius: 10px; border: 1px solid var(--line); background: rgba(16,20,17,0.86); font-size: 11px; color: var(--soft); cursor: pointer; }
.fine { flex: 1 1 auto; min-height: 0; width: 40px; border-radius: 14px; border: 1px solid var(--line); touch-action: none; cursor: ns-resize;
  background: repeating-linear-gradient(0deg, #2a322d 0 2px, #121614 2px 9px); box-shadow: inset 0 10px 14px rgba(0,0,0,0.6), inset 0 -10px 14px rgba(0,0,0,0.6); }

/* Portrait: HUD on top, controls along the bottom. */
body.portrait .hud { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; grid-template-areas: "a b m" "s s s"; }
body.portrait .plate[data-game-profile="player"] { grid-area: a; }
body.portrait .plate.opp { grid-area: b; }
body.portrait .icon { grid-area: m; }
body.portrait .mid { grid-area: s; display: flex; gap: 8px; justify-content: center; align-items: center; }
body.portrait .status { margin: 0; }
/* Portrait plates: drop the big count (the subtitle already says "5 left") so all seven chips fit as true circles. */
body.portrait .plate { grid-template-columns: auto minmax(0, 1fr); gap: 6px; padding: 6px 8px 8px 6px; }
body.portrait .plate .left { display: none; }
body.portrait .avatar { width: 28px; height: 28px; font-size: 12px; }
body.portrait .rack { gap: 1.5px; }
body.portrait .chip { width: 12px; height: 12px; font-size: 6.5px; }
body.portrait .power { left: 14px; right: 128px; top: auto; bottom: calc(14px + var(--safe-b)); width: auto; height: 74px; display: grid; grid-template-columns: 44px minmax(0, 1fr); grid-template-rows: 1fr auto; gap: 4px 10px; align-items: center; }
body.portrait .power-head { grid-row: 1 / span 2; }
body.portrait .power .track { height: 30px; min-height: 0; width: auto; flex: none; background: linear-gradient(180deg, #0a0d0b, #1a211d 50%, #0a0d0b); }
body.portrait .power .ticks { inset: 7px 8px; background: repeating-linear-gradient(to left, transparent 0 calc(10% - 1px), rgba(255,255,255,0.13) calc(10% - 1px) 10%); }
body.portrait .power .fill { left: auto; top: 3px; bottom: 3px; right: 3px; height: auto; width: calc(var(--p, 0) * (100% - 6px)); background: linear-gradient(270deg, var(--green-bright), var(--gold) 65%, var(--red)); background-size: calc(100% / max(var(--p, 0), 0.0001)) 100%; background-position: right; }
body.portrait .power .handle { top: 50%; left: calc(100% - 3px - var(--p, 0) * (100% - 6px)); width: 24px; height: 50px; }
body.portrait .power .handle::before, body.portrait .power .handle::after { top: 6px; bottom: 6px; left: auto; right: auto; width: 3px; height: auto; }
body.portrait .power .handle::before { left: 4px; } body.portrait .power .handle::after { right: 4px; }
body.portrait .power .handle i { inset: 10px 9px; background: repeating-linear-gradient(0deg, rgba(0,0,0,0.35) 0 2px, transparent 2px 5px); }
body.portrait .power-hint { grid-column: 2; }
body.portrait .power-hint .hint-land { display: none; } body.portrait .power-hint .hint-port { display: inline; }
body.portrait .right-stack { top: auto; left: auto; right: 12px; bottom: calc(10px + var(--safe-b)); height: 110px; width: 100px; flex-direction: row; align-items: flex-end; }
body.portrait .fine-wrap { flex-direction: row; min-height: 0; height: 44px; width: auto; }
body.portrait .fine-step, body.portrait #fine { display: none; }

/* ---------- Toast ---------- */
.toast { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%) scale(0.96); padding: 10px 18px; border-radius: 12px; background: rgba(16,20,17,0.92); border: 1px solid var(--line); font: 800 15px var(--font-head); opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; z-index: 8; max-width: min(90vw, 460px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.toast.bad { border-color: rgba(240,125,115,0.6); color: #ffd9d4; }
.toast.good { border-color: rgba(217,180,93,0.7); color: var(--gold); }

/* ---------- Overlays ---------- */
.overlay { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 16px; background: rgba(4,6,5,0.72); backdrop-filter: blur(4px); }
.overlay[hidden] { display: none; }
.sheet { width: min(640px, 100%); max-height: calc(100% - 16px); overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 22px; box-shadow: 0 30px 80px rgba(0,0,0,0.6); -webkit-user-select: text; user-select: text; }
.sheet.small { width: min(400px, 100%); }
.eyebrow { margin: 0 0 4px; color: var(--green); font: 800 10px var(--font-head); letter-spacing: 1.5px; text-transform: uppercase; }
h1, h2 { font-family: var(--font-head); margin: 0 0 12px; text-wrap: balance; }
h1 { font: 900 28px/1.1 BigPoolDisplay, var(--font-head); letter-spacing: 0.3px; }
.lede { color: var(--soft); margin: -4px 0 14px; }
.levels { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin-bottom: 16px; }
.levels.compact { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.levels.compact .level span { display: none; }
.level { text-align: left; padding: 12px; border-radius: 14px; border: 1px solid var(--line); background: var(--raised); cursor: pointer; display: grid; gap: 4px; min-width: 0; }
.level b { font: 800 15px var(--font-head); }
.level span { font-size: 12px; color: var(--muted); }
.level em { font-style: normal; font-size: 11px; color: var(--gold); }
.level.on { border-color: var(--green); box-shadow: inset 0 0 0 1px var(--green); background: #14231a; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.col { display: grid; gap: 8px; margin-top: 12px; }
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line); background: var(--raised); font: 800 15px var(--font-head); text-decoration: none; color: var(--text); cursor: pointer; }
.btn.primary { background: var(--green); color: #06110d; border-color: transparent; }
.btn.gold { background: var(--gold); color: #1a1405; border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.link { background: none; border: 0; color: var(--muted); }
.btn:disabled { opacity: 0.6; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
.stats div { background: var(--raised); border-radius: 12px; padding: 10px; display: grid; }
.stats b { font: 900 22px BigPoolDisplay, var(--font-head); font-variant-numeric: tabular-nums; }
.stats span { font-size: 11px; color: var(--muted); }
.free-cta { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.free-cta p { margin: 0 0 10px; color: var(--soft); }
.share-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.share-row a, .share-row button { padding: 8px 12px; border-radius: 10px; background: var(--raised); border: 1px solid var(--line); color: var(--text); text-decoration: none; font-size: 13px; cursor: pointer; }
.opt { display: flex; gap: 10px; align-items: center; padding: 8px 0; color: var(--soft); }
.opt input { width: 18px; height: 18px; accent-color: var(--green); }
.spin-pad { position: relative; width: 200px; height: 200px; margin: 6px auto 16px; border-radius: 50%; touch-action: none; cursor: crosshair;
  background: radial-gradient(circle at 36% 30%, #fff, #ece8db 50%, #aaa597); box-shadow: 0 10px 30px rgba(0,0,0,0.5), inset 0 0 0 1px rgba(0,0,0,0.2); }
.spin-pad::before, .spin-pad::after { content: ""; position: absolute; background: rgba(0,0,0,0.12); }
.spin-pad::before { left: 50%; top: 12%; bottom: 12%; width: 1px; }
.spin-pad::after { top: 50%; left: 12%; right: 12%; height: 1px; }
.spin-pad [data-spin-dot] { width: 22px; height: 22px; margin: -11px 0 0 -11px; }
.rules { padding-left: 18px; color: var(--soft); display: grid; gap: 8px; margin: 0 0 16px; }

/* Shared help button (from /pool/js/help-button.js) sits clear of the HUD. */
.table-help { position: fixed; right: calc(14px + var(--safe-r)); bottom: calc(14px + var(--safe-b)); z-index: 6; }

@media (max-height: 420px) and (orientation: landscape) {
  .plate { padding: 4px 10px 6px 4px; gap: 6px; }
  .avatar { width: 28px; height: 28px; font-size: 12px; }
  /* Short landscape: once groups are set, the ball chips replace the subtitle so plates stay one height. */
  .who:has(.rack:not(:empty)) .sub { display: none; }
  .rack { margin-top: 3px; gap: 2px; min-height: 13px; }
  .chip { width: 13px; height: 13px; font-size: 7px; }
  .plate .left { font-size: 15px; }
  .power, .right-stack { top: 58px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ---------- Table & cue picker ---------- */
.swatches { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 10px; margin-bottom: 8px; scroll-snap-type: x proximity; }
.swatch { flex: none; width: 92px; border-radius: 12px; border: 1px solid var(--line); background: var(--raised); padding: 6px; cursor: pointer; display: grid; gap: 5px; scroll-snap-align: start; text-align: center; }
.swatch .art { height: 56px; border-radius: 8px; background-size: 140px; background-position: center; position: relative; overflow: hidden; }
.swatch .art::after { content: ""; position: absolute; inset: 11px 13px; border-radius: 3px; background: var(--cloth); box-shadow: inset 0 0 8px rgba(0,0,0,0.5); }
.swatch span { font-size: 11px; color: var(--soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.swatch.on { border-color: var(--green); box-shadow: inset 0 0 0 1px var(--green); }
.swatches.cues .swatch { width: 150px; }
.swatches.cues .art { height: 34px; background-color: #0f3b26; background-repeat: no-repeat; background-size: 140px 9px; }
.swatches.cues .art::after { display: none; }

/* ---------- Funded modes (Vault, Faucet, Quick AI) ---------- */
[hidden] { display: none !important; }
.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
.money { display: inline-flex; gap: 6px; align-items: center; margin-left: 6px; padding: 2px 10px; border-radius: 999px; background: rgba(16,20,17,0.86); border: 1px solid rgba(217,180,93,0.45); font: 800 11px var(--font-head); color: var(--soft); white-space: nowrap; }
.money i { font-style: normal; color: var(--muted); }
.money [data-hud-prize] { color: var(--gold); }
body.portrait .money { margin-left: 0; }
.funded-end { margin: 4px 0 14px; padding: 12px 14px; border-radius: 12px; background: var(--raised); border: 1px solid var(--line); }
.funded-end p { margin: 0; color: var(--soft); }
.funded-end.failed { border-color: rgba(240,125,115,0.6); }
.funded-end.failed p { color: #ffd9d4; margin-bottom: 10px; }
#vault-boot { z-index: 12; background: rgba(4,6,5,0.88); }
#vault-boot .sheet { text-align: center; }
#vault-boot:not(.failed) h2::after { content: ""; display: block; width: 28px; height: 28px; margin: 14px auto 0; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--green); animation: bp-spin 0.9s linear infinite; }
#vault-boot.failed h2 { color: #ffd9d4; }
#vault-boot .row { justify-content: center; }
@keyframes bp-spin { to { transform: rotate(360deg); } }

/* Short landscape screens: tighter spin label so the fine-aim wheel keeps its height. */
@media (orientation: landscape) and (max-height: 430px) {
  .spin-btn small { display: none; }
  .fine-wrap { min-height: 90px; }
}
