/* =====================================================================
   Snooker — fixed "snooker hall" theme.
   Same full-height app frame as the other arcade pages (frosted top bar,
   chunky buttons, hard-shadow stage, card overlays) with a darker, older
   room than the pool table: near-black green baize, mahogany, brass, cream.
   Deliberately ignores the center's light/dark mode; no glass.css.
   ===================================================================== */
:root {
  --sn-room:   #07130f;   /* page top */
  --sn-room2:  #0b1f18;   /* page mid */
  --sn-room3:  #101d16;   /* page bottom */
  --sn-felt:   #0b5c3d;   /* canvas baize */
  --sn-felt2:  #073d29;
  --sn-rail:   #3f2314;   /* wooden rail */
  --sn-rail2:  #6a3c20;
  --sn-brass:  #d7a84c;
  --sn-brass2: #f0cf85;
  --sn-cream:  #f4eddc;
  --sn-ink:    #14171d;
  --sn-red:    #c8322b;
  --sn-line:   rgba(9, 16, 12, .9);
}

html, body { height: 100%; }
body.sn-page {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background:
    radial-gradient(80% 42% at 50% 0%, rgba(215, 168, 76, .14), transparent 62%),
    linear-gradient(180deg, var(--sn-room) 0%, var(--sn-room2) 56%, var(--sn-room3) 100%);
  color: var(--sn-cream);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
body.sn-page *,
body.sn-page *::before,
body.sn-page *::after { box-sizing: border-box; }

/* ---------- App frame ---------- */
.c-app {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- Top bar ---------- */
.c-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px 18px;
  flex-wrap: wrap;
  padding: 12px clamp(12px, 3vw, 28px);
  padding-top: max(12px, env(safe-area-inset-top));
  background: rgba(255, 255, 255, .06);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 2px solid rgba(215, 168, 76, .42);
  z-index: 20;
}
.c-bar__brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.c-bar__brand svg { filter: drop-shadow(0 2px 0 rgba(0, 0, 0, .4)); }
.c-bar__title {
  margin: 0;
  font-size: clamp(19px, 3.4vw, 26px);
  font-weight: 800;
  letter-spacing: .03em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--sn-cream);
  text-shadow: 2px 2px 0 rgba(0, 0, 0, .35);
}
.c-bar__stats { display: flex; align-items: center; gap: 8px 18px; margin-left: auto; }
.c-bar__controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stat { font-size: 14px; font-weight: 700; letter-spacing: .03em; white-space: nowrap; color: rgba(244, 237, 220, .74); }
.stat b { color: var(--sn-brass2); font-size: 16px; }

/* ---------- Buttons (chunky arcade style) ---------- */
.c-btn {
  appearance: none;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: .03em;
  text-transform: uppercase;
  text-decoration: none;
  display: inline-block;
  padding: 9px 16px;
  border-radius: 12px;
  border: 2px solid var(--sn-line);
  background: var(--sn-cream);
  color: var(--sn-ink);
  box-shadow: 0 3px 0 rgba(0, 0, 0, .42);
  transition: transform .06s ease, background .15s ease, box-shadow .15s ease;
}
.c-btn:hover { background: #fff8e6; border-color: var(--sn-brass); }
.c-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0, 0, 0, .42); }
.c-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(215, 168, 76, .52); }
.c-btn--primary {
  background: linear-gradient(140deg, #e7bd68, var(--sn-brass));
  border-color: var(--sn-line);
  color: var(--sn-ink);
}
.c-btn--primary:hover { background: linear-gradient(140deg, #f3d58f, #dfb45c); }

/* ---------- Table / board column ---------- */
.c-table {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(8px, 1.8vh, 18px) clamp(8px, 2vw, 20px);
}
.sn-board {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(96vw, calc((100vh - 250px) * 1.8462), 1000px);
  width: min(96vw, calc((100dvh - 250px) * 1.8462), 1000px);
}

/* ---------- Score strips ---------- */
.sn-players {
  display: flex;
  align-items: stretch;
  gap: 8px;
}
.sn-side {
  flex: 1 1 0;
  min-width: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "name score"
    "sub  score";
  align-items: center;
  gap: 0 10px;
  padding: 7px 12px 8px;
  border-radius: 12px;
  border: 1px solid rgba(215, 168, 76, .26);
  background: rgba(255, 255, 255, .05);
  transition: border-color .18s ease, background .18s ease, box-shadow .18s ease;
}
.sn-side.is-turn {
  border-color: var(--sn-brass);
  background: rgba(215, 168, 76, .12);
  box-shadow: 0 0 0 1px rgba(215, 168, 76, .28), 0 0 20px rgba(215, 168, 76, .14);
}
.sn-side__name {
  grid-area: name;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--sn-cream);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sn-side--cpu .sn-side__name { color: #ffb3a8; }
.sn-side__score {
  grid-area: score;
  font-size: 27px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: .02em;
  color: var(--sn-brass2);
  font-variant-numeric: tabular-nums;
}
.sn-side__sub {
  grid-area: sub;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: rgba(244, 237, 220, .55);
  white-space: nowrap;
}
.sn-side.is-turn .sn-side__sub { color: var(--sn-brass2); }
.sn-side--right { text-align: right; }
.sn-side--right .sn-side__name { text-align: right; }

.sn-mid {
  flex: 0 0 auto;
  align-self: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}
.sn-turn {
  min-width: 110px;
  padding: 7px 12px;
  border-radius: 999px;
  text-align: center;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--sn-ink);
  background: linear-gradient(140deg, var(--sn-brass2), var(--sn-brass));
  border: 1px solid var(--sn-line);
  box-shadow: 0 2px 0 rgba(0, 0, 0, .35);
  white-space: nowrap;
}
.sn-turn.is-cpu { background: linear-gradient(140deg, #ffb3a8, #d9685b); }
.sn-on {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 9px 2px 6px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: rgba(244, 237, 220, .82);
  background: rgba(0, 0, 0, .28);
  border: 1px solid rgba(244, 237, 220, .18);
  white-space: nowrap;
}
.sn-on__dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--sn-red);
  border: 1px solid rgba(0, 0, 0, .5);
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, .45);
}
.sn-on__dot.is-any {
  background: conic-gradient(#e9c534, #2e8b4f, #8a5a2b, #2f6bd8, #e78ba6, #1b1e26, #e9c534);
}

/* ---------- Stage ---------- */
.sn-stage {
  position: relative;
  aspect-ratio: 960 / 520;
  border-radius: 16px;
  overflow: hidden;
  background: var(--sn-felt2);
  border: 3px solid #24130b;
  box-shadow: 0 9px 0 rgba(0, 0, 0, .42), 0 22px 46px rgba(0, 0, 0, .52);
  touch-action: none;
  cursor: crosshair;
}
#screen {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

/* ---------- Power meter (overlaid, only while aiming) ---------- */
.sn-power {
  position: absolute;
  left: 50%;
  bottom: 9px;
  z-index: 3;
  width: min(44%, 340px);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 9px 4px 11px;
  border-radius: 999px;
  background: rgba(5, 12, 9, .74);
  border: 1px solid rgba(244, 237, 220, .22);
  transform: translateX(-50%);
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s ease;
}
.sn-power.is-on { opacity: 1; }
.sn-power__label {
  flex: none;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: rgba(244, 237, 220, .7);
}
.sn-power__track {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, .16);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .5);
}
.sn-power__fill {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #57d68c, #f0cf85 58%, #e8615a);
  transition: width .05s linear;
}

/* ---------- Tournament replay prompt ---------- */
.sn-prompt {
  position: absolute;
  top: 10px;
  left: 50%;
  z-index: 6;
  transform: translateX(-50%);
  max-width: min(92%, 470px);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 8px 14px;
  border-radius: 12px;
  background: rgba(8, 20, 15, .93);
  border: 1px solid rgba(215, 168, 76, .6);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .45);
}
.sn-prompt[hidden] { display: none; }
.sn-prompt__text {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
  color: var(--sn-cream);
}
.sn-prompt__actions { display: flex; gap: 6px; flex: none; }
.sn-prompt .c-btn { padding: 7px 10px; font-size: 11px; }

/* ---------- Ready / game-over overlays ---------- */
/* The overlay scrolls, never the card: a too-tall card on a short phone
   stage stays reachable and no scrollbar sits inside the panel. */
.sn-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: rgba(3, 10, 7, .48);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  touch-action: manipulation;
}
.sn-overlay[hidden] { display: none; }
.sn-card {
  touch-action: manipulation;
  margin: auto;
  max-width: 340px;
  text-align: center;
  padding: 16px 20px 15px;
  border-radius: 16px;
  background: linear-gradient(160deg, #fbf5e5, var(--sn-cream));
  border: 2px solid var(--sn-line);
  box-shadow: 0 7px 0 rgba(0, 0, 0, .3), 0 20px 44px rgba(0, 0, 0, .48);
  color: var(--sn-ink);
  animation: snPop .3s ease;
}
@keyframes snPop { from { transform: scale(.9); opacity: 0; } }
.sn-card__big svg {
  width: 58px;
  height: 58px;
  display: block;
  margin: 0 auto;
}
.sn-card h2 {
  margin: 4px 0 5px;
  font-size: 21px;
  font-weight: 800;
  letter-spacing: .03em;
  text-transform: uppercase;
  color: var(--sn-ink);
  text-shadow: 2px 2px 0 rgba(255, 255, 255, .55);
}
.sn-card p { margin: 0 0 11px; color: #5f5541; font-size: 13px; line-height: 1.5; }
.sn-card .c-btn { font-size: 13px; }
.sn-card .c-btn[hidden] { display: none; }
.c-win__actions { display: flex; gap: 9px; justify-content: center; flex-wrap: wrap; }

/* ---------- Rule-set picker (on the ready card) ---------- */
.sn-rules {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin: 0 0 12px;
}
.sn-rules__btn {
  appearance: none;
  cursor: pointer;
  font: inherit;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 7px 9px;
  border-radius: 10px;
  border: 2px solid rgba(20, 23, 29, .22);
  background: rgba(255, 255, 255, .5);
  color: var(--sn-ink);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
  transition: border-color .15s ease, background .15s ease;
}
.sn-rules__btn small {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  line-height: 1.3;
  color: #6d6350;
}
.sn-rules__btn:hover { border-color: rgba(215, 168, 76, .85); }
.sn-rules__btn.is-on {
  border-color: var(--sn-ink);
  background: linear-gradient(140deg, #f3d58f, #e2b85f);
}
.sn-rules__btn.is-on small { color: #4a412f; }
.sn-rules__btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(215, 168, 76, .55); }

/* ---------- Hint line ---------- */
.sn-hint {
  margin: 0;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .02em;
  color: rgba(244, 237, 220, .58);
}
.sn-hint b { color: var(--sn-brass2); font-weight: 800; }
.sn-hint kbd, .sn-card kbd, .c-modal kbd {
  display: inline-block;
  min-width: 18px;
  padding: 1px 6px;
  margin: 0 1px;
  font: 700 12px/1.5 ui-monospace, "Segoe UI", monospace;
  text-align: center;
  color: var(--sn-ink);
  background: var(--sn-cream);
  border: 1px solid var(--sn-line);
  border-radius: 6px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, .35);
}

/* ---------- Rules modal (overlay scrolls, never a boxed inner scrollbar) -- */
.c-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.c-modal[hidden] { display: none; }
.c-modal__backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 8, 6, .68);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
.c-modal__panel {
  position: relative;
  z-index: 1;
  margin: auto;
  width: min(92vw, 480px);
  background: linear-gradient(160deg, #123528, #071d15);
  color: #e9f3ea;
  border-radius: 16px;
  border: 2px solid rgba(215, 168, 76, .72);
  box-shadow: 0 8px 0 rgba(0, 0, 0, .35), 0 24px 60px rgba(0, 0, 0, .65);
}
.c-modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(215, 168, 76, .35);
}
.c-modal__head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #fff;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, .3);
}
.c-modal__x {
  appearance: none;
  border: 0;
  background: none;
  color: #e9f3ea;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}
.c-modal__x:hover { color: var(--sn-brass2); }
.c-modal__body { padding: 8px 20px 4px; font-size: 14px; line-height: 1.55; }
.c-modal__body h3 {
  margin: 16px 0 6px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--sn-brass2);
}
.c-modal__body ul { margin: 0; padding-left: 20px; }
.c-modal__body li { margin: 4px 0; }
.c-modal__body b { color: var(--sn-brass2); }
.c-modal__lead { margin: 12px 0; }
.c-modal__note {
  margin: 14px 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(215, 168, 76, .3);
  font-size: 13px;
  color: #d9e8dd;
}
.c-modal__foot { display: flex; justify-content: flex-end; padding: 12px 20px 16px; }
.c-modal .c-btn { border-color: rgba(255, 255, 255, .72); box-shadow: 0 3px 0 rgba(0, 0, 0, .35); }
.c-modal .c-btn--primary { border-color: var(--sn-line); }

/* ---------- Responsive ---------- */
@media (max-width: 760px), (max-height: 620px) {
  .c-bar { gap: 5px 12px; padding: 7px clamp(10px, 3vw, 18px); padding-top: max(7px, env(safe-area-inset-top)); }
  .c-bar__brand { gap: 8px; }
  .c-bar__title { font-size: 16px; }
  .c-bar__stats { gap: 4px 12px; margin-left: auto; }
  .stat { font-size: 12px; }
  .stat b { font-size: 13px; }
  .c-btn { padding: 8px 10px; font-size: 12px; }
  .c-bar__controls { gap: 6px; }
  .c-bar__controls .c-btn { padding: 9px 10px; white-space: nowrap; }
  .sn-board { width: min(97vw, calc((100vh - 220px) * 1.8462), 1000px); width: min(97vw, calc((100dvh - 220px) * 1.8462), 1000px); }
  .sn-side { padding: 5px 8px 6px; }
  .sn-side__name { font-size: 11px; }
  .sn-side__score { font-size: 22px; }
  .sn-side__sub { font-size: 10px; }
  .sn-turn { min-width: 92px; padding: 6px 8px; font-size: 9px; }
  .sn-on { font-size: 9px; }
  .sn-hint { font-size: 11px; }
  .sn-card { padding: 12px 14px 11px; }
  .sn-card__big svg { width: 44px; height: 44px; }
  .sn-card h2 { font-size: 18px; }
  .sn-card p { font-size: 12px; margin-bottom: 9px; }
  .sn-rules__btn small { display: none; }
  .sn-rules { margin-bottom: 9px; }
}
@media (max-width: 700px) {
  .c-bar__controls { flex: 1 1 100%; flex-wrap: nowrap; }
  .c-bar__controls .c-btn { flex: 1 1 auto; min-width: 0; padding: 9px 6px; overflow: hidden; text-overflow: ellipsis; }
}
@media (max-width: 560px) {
  .sn-players { flex-wrap: wrap; gap: 5px; }
  .sn-mid { order: -1; flex: 1 1 100%; flex-direction: row; justify-content: center; gap: 8px; }
  .sn-side { flex: 1 1 0; }
  .sn-hint { display: none; }
  .sn-prompt { flex-direction: column; align-items: stretch; gap: 6px; }
  .sn-prompt__text { text-align: center; }
  .sn-prompt__actions { justify-content: center; }
}
@media (max-width: 380px) {
  .c-bar { gap: 5px 8px; }
  .c-bar__title { font-size: 15px; }
  .stat { font-size: 11px; }
  .stat b { font-size: 12px; }
  .c-bar__controls { gap: 4px; }
  .c-bar__controls .c-btn { font-size: clamp(10px, 3.2vw, 12px); padding: 9px 4px; letter-spacing: .01em; }
}

@media (prefers-reduced-motion: reduce) {
  .c-btn, .sn-card, .sn-power, .sn-side { transition: none; animation: none; }
}
