:root {
  --bg: #0a0f15;
  --panel: rgba(22, 31, 42, .78);
  --panel-b: rgba(255, 255, 255, .08);
  --ink: #eaf1f7;
  --mute: #8fa1b3;
  --gold: #f4c24f;
  --gold2: #ffdf8e;
  --teal: #38d6b0;
  --red: #ff5d5d;
  --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);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overflow: hidden;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-user-select: none; user-select: none; overscroll-behavior: none; touch-action: none; }
body { background: radial-gradient(1200px 700px at 50% 35%, #15222f 0%, #0a0f15 70%); }

#app { position: fixed; inset: 0; display: flex; flex-direction: column;
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l); }

/* ---------- HUD ---------- */
#hud { display: grid; grid-template-columns: 1fr minmax(120px, 1.2fr) 1fr auto; gap: 10px; align-items: stretch;
  padding: 8px 10px 4px; }
.player { background: var(--panel); border: 1px solid var(--panel-b); border-radius: 14px; padding: 6px 10px;
  display: flex; flex-direction: column; gap: 3px; min-width: 0; backdrop-filter: blur(8px);
  transition: border-color .25s, box-shadow .25s, background .25s; }
.player.right { align-items: flex-end; text-align: right; }
.player.active { border-color: rgba(244, 194, 79, .75); box-shadow: 0 0 0 1px rgba(244, 194, 79, .35), 0 0 22px rgba(244, 194, 79, .25); background: rgba(34, 44, 56, .88); }
.pname { display: flex; align-items: center; gap: 7px; font-weight: 700; font-size: 14px; letter-spacing: .02em; }
.pname .pn { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pname .dot { width: 8px; height: 8px; border-radius: 50%; background: #3b4a5a; flex: none; transition: .25s; }
.player.active .dot { background: var(--gold); box-shadow: 0 0 10px var(--gold); }
.pgroup { font-size: 11px; color: var(--mute); text-transform: uppercase; letter-spacing: .09em; font-weight: 600; }
.tray { display: flex; gap: 3px; flex-wrap: nowrap; min-height: 18px; }
.player.right .tray { justify-content: flex-end; }
.bi { width: 17px; height: 17px; border-radius: 50%; position: relative; flex: none; display: grid; place-items: center;
  font-size: 8.5px; font-weight: 800; color: #111; box-shadow: inset -2px -3px 4px rgba(0,0,0,.35), inset 1px 1px 3px rgba(255,255,255,.55), 0 1px 2px rgba(0,0,0,.5);
  transition: opacity .3s, transform .3s; }
.bi::after { content: attr(data-n); width: 9px; height: 9px; border-radius: 50%; background: #fff; display: grid; place-items: center; line-height: 1; font-size: 6.5px; }
.bi.stripe { background-image: linear-gradient(#f4f1e8 0 27%, var(--c) 27% 73%, #f4f1e8 73%) !important; }
.bi.gone { opacity: .22; transform: scale(.82); filter: grayscale(.6); }

#center { display: flex; align-items: center; justify-content: center; text-align: center; padding: 0 6px; }
#status { font-size: 14px; font-weight: 600; line-height: 1.25; color: var(--ink); text-wrap: balance; min-height: 2.5em; display: grid; place-items: center; }
#status small { display: block; color: var(--mute); font-weight: 500; font-size: 12px; margin-top: 2px; }
.iconbtn { width: 42px; border-radius: 14px; border: 1px solid var(--panel-b); background: var(--panel); color: var(--ink);
  display: grid; place-items: center; cursor: pointer; backdrop-filter: blur(8px); }
.iconbtn:active { transform: scale(.96); }

/* ---------- stage ---------- */
#stage { flex: 1; min-height: 0; display: flex; flex-direction: row; padding: 0 8px 8px; gap: 8px; }
#tableWrap { position: relative; flex: 1; min-width: 0; min-height: 0; border-radius: 16px; overflow: hidden; touch-action: none; }
#tableWrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#cOver { touch-action: none; cursor: crosshair; }
#toast { position: absolute; left: 50%; top: 14px; transform: translate(-50%, -20px); opacity: 0; pointer-events: none;
  background: rgba(10, 15, 21, .86); border: 1px solid rgba(244, 194, 79, .55); color: var(--gold2); padding: 9px 18px; border-radius: 999px;
  font-weight: 700; font-size: 15px; letter-spacing: .02em; box-shadow: 0 8px 28px rgba(0,0,0,.5); text-align: center; max-width: 92%;
  transition: opacity .25s, transform .25s; backdrop-filter: blur(6px); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { border-color: rgba(255, 93, 93, .7); color: #ffb3b3; }

/* ---------- controls ---------- */
#controls { width: 196px; display: flex; flex-direction: column; gap: 10px; align-items: stretch; padding: 4px 0; flex: none; }
#spinWrap { display: flex; flex-direction: column; align-items: center; gap: 4px; }
#spin { width: 104px; height: 104px; touch-action: none; cursor: pointer; border-radius: 50%; }
.lbl { font-size: 10px; letter-spacing: .16em; color: var(--mute); font-weight: 700; }
#mid { display: flex; flex-direction: column; gap: 9px; flex: 1; justify-content: center; }
#powerRow { display: flex; align-items: center; gap: 8px; }
#power { position: relative; flex: 1; height: 38px; border-radius: 19px; background: #0d141b; border: 1px solid var(--panel-b);
  box-shadow: inset 0 2px 8px rgba(0,0,0,.6); touch-action: none; cursor: pointer; outline: none; overflow: hidden; }
#power:focus-visible { box-shadow: 0 0 0 2px var(--gold); }
#powerFill { position: absolute; left: 0; top: 0; bottom: 0; width: 45%; border-radius: 19px;
  background: linear-gradient(90deg, #2fd6a3 0%, #e8d34d 55%, #ff6b4a 100%); background-size: 196px 100%; }
#powerKnob { position: absolute; top: 3px; bottom: 3px; width: 6px; margin-left: -3px; left: 45%; border-radius: 3px; background: #fff; box-shadow: 0 0 10px rgba(255,255,255,.8); }
.ticks { position: absolute; inset: 0; background: repeating-linear-gradient(90deg, transparent 0 calc(10% - 1px), rgba(0,0,0,.25) calc(10% - 1px) 10%); pointer-events: none; }
#powerPct { width: 34px; text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; font-size: 15px; color: var(--gold2); }
#fine { height: 34px; border-radius: 17px; background: var(--panel); border: 1px solid var(--panel-b); display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px; color: var(--mute); font-size: 11px; font-weight: 700; letter-spacing: .14em; touch-action: none; cursor: ew-resize; }
#fine .arrow { font-size: 12px; color: var(--teal); }
#fine.on { border-color: var(--teal); color: var(--ink); }
#smallBtns { display: flex; gap: 6px; }
.chip { flex: 1; border: 1px solid var(--panel-b); background: var(--panel); color: var(--ink); border-radius: 12px; padding: 7px 6px; font-size: 12px; font-weight: 600; cursor: pointer; }
.chip[aria-pressed="true"] { border-color: rgba(56, 214, 176, .6); color: var(--teal); }
.chip:active { transform: scale(.97); }
.shoot { height: 58px; border: 0; border-radius: 16px; cursor: pointer; font-weight: 900; letter-spacing: .18em; font-size: 18px; color: #2b1d00;
  background: linear-gradient(180deg, #ffe08f 0%, #f4c24f 55%, #d9a02f 100%); box-shadow: 0 6px 0 #9b6e16, 0 12px 24px rgba(0,0,0,.45); transition: transform .08s, box-shadow .08s, filter .2s; }
.shoot:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 2px 0 #9b6e16, 0 6px 14px rgba(0,0,0,.45); }
.shoot:disabled { filter: grayscale(.9) brightness(.55); cursor: not-allowed; box-shadow: 0 6px 0 #4a3a1a; }

/* ---------- portrait ---------- */
@media (max-aspect-ratio: 1/1) {
  #hud { grid-template-columns: 1fr 1fr auto; grid-template-areas: "p0 p1 m" "c c c"; gap: 6px 8px; padding: 6px 8px 2px; }
  #p0 { grid-area: p0; } #p1 { grid-area: p1; } #btnMenu { grid-area: m; } #center { grid-area: c; padding: 0; }
  #status { min-height: 2.3em; font-size: 13px; }
  #stage { flex-direction: column; padding: 0 6px 6px; gap: 6px; }
  #controls { width: auto; display: grid; grid-template-columns: 96px 1fr 100px; align-items: center; gap: 10px; padding: 0 2px; }
  #spin { width: 88px; height: 88px; }
  #mid { gap: 7px; }
  .shoot { height: 88px; border-radius: 18px; font-size: 16px; letter-spacing: .12em; }
  #smallBtns { gap: 5px; }
  .chip { padding: 6px 2px; font-size: 11px; }
}
@media (max-height: 520px) and (min-aspect-ratio: 1/1) {
  #hud { padding: 4px 8px 2px; gap: 8px; }
  .player { padding: 4px 8px; }
  .pgroup { display: none; }
  #controls { width: 170px; gap: 6px; }
  #spin { width: 78px; height: 78px; }
  .shoot { height: 46px; font-size: 15px; }
  #mid { gap: 6px; } #power { height: 32px; } #fine { height: 28px; }
}
@media (max-width: 420px) { .bi { width: 14px; height: 14px; } .bi::after { width: 7px; height: 7px; font-size: 5.5px; } .pname { font-size: 13px; } }

/* ---------- modal ---------- */
#modal { position: fixed; inset: 0; background: rgba(4, 8, 12, .66); backdrop-filter: blur(10px); display: grid; place-items: center; z-index: 50; padding: 16px; transition: opacity .25s; }
#modal.hidden { opacity: 0; pointer-events: none; }
.card { width: min(440px, 100%); max-height: 92dvh; overflow: auto; background: linear-gradient(180deg, #1b2735, #121b26); border: 1px solid var(--panel-b); border-radius: 22px; padding: 22px; box-shadow: 0 30px 80px rgba(0,0,0,.6); }
.card h1 { margin: 0 0 4px; font-size: 34px; letter-spacing: .06em; font-weight: 900; background: linear-gradient(90deg, var(--gold2), var(--gold)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.card h2 { margin: 0 0 6px; font-size: 22px; }
.card p { color: var(--mute); line-height: 1.5; margin: 8px 0; font-size: 14px; }
.card .row { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.btn { flex: 1; min-width: 130px; padding: 13px 14px; border-radius: 14px; border: 1px solid var(--panel-b); background: #223044; color: var(--ink); font-weight: 700; font-size: 15px; cursor: pointer; }
.btn:hover { background: #2a3b53; }
.btn.primary { background: linear-gradient(180deg, #ffe08f, #f4c24f); color: #2b1d00; border: 0; }
.btn.primary:hover { filter: brightness(1.06); }
.seg { display: flex; border: 1px solid var(--panel-b); border-radius: 12px; overflow: hidden; margin-top: 8px; }
.seg button { flex: 1; padding: 10px 6px; background: transparent; color: var(--mute); border: 0; font-weight: 700; cursor: pointer; font-size: 13px; }
.seg button.on { background: #2b3d55; color: var(--gold2); }
.label { margin-top: 14px; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--mute); font-weight: 700; }
.rules { text-align: left; font-size: 13px; color: #c3cfdb; line-height: 1.55; }
.rules li { margin-bottom: 4px; }
.rules b { color: var(--gold2); }
.kbd { display: inline-block; padding: 1px 6px; border-radius: 5px; background: #0d141b; border: 1px solid var(--panel-b); font-size: 12px; }
