/* =====================================================================
   8-Ball Pool — fixed "green room" theme.
   Same full-height app frame as the other arcade pages (frosted top bar,
   chunky buttons, hard-shadow stage, card overlays) but with a pool-hall
   palette: dark baize room, brass rail, cream ink. Deliberately ignores
   the center's light/dark mode; no glass.css is loaded.
   ===================================================================== */
:root {
  --pl-room:   #081b16;   /* page top */
  --pl-room2:  #0d2a22;   /* page mid */
  --pl-room3:  #13251d;   /* page bottom */
  --pl-felt:   #0e6b4a;   /* canvas baize */
  --pl-felt2:  #084a34;
  --pl-rail:   #4b2a18;   /* wooden rail */
  --pl-rail2:  #7a4526;
  --pl-brass:  #d7a84c;   /* accents / stats */
  --pl-brass2: #f0cf85;
  --pl-cream:  #f4eddc;   /* card surface */
  --pl-ink:    #171a21;   /* outline ink */
  --pl-red:    #d64545;
  --pl-line:   rgba(10, 18, 14, .88);
}

html, body { height: 100%; }
body.pl-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, .16), transparent 62%),
    linear-gradient(180deg, var(--pl-room) 0%, var(--pl-room2) 56%, var(--pl-room3) 100%);
  color: var(--pl-cream);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
body.pl-page *,
body.pl-page *::before,
body.pl-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, .07);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 2px solid rgba(215, 168, 76, .45);
  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(--pl-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(--pl-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(--pl-line);
  background: var(--pl-cream);
  color: var(--pl-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(--pl-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(--pl-brass));
  border-color: var(--pl-line);
  color: var(--pl-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);
}
.pl-board {
  display: flex;
  flex-direction: column;
  gap: 8px;
  /* Landscape table: 960 x 520, capped by width and by the viewport height
     left over after the bar, player strips and hint line. */
  width: min(96vw, calc((100vh - 250px) * 1.8462), 1000px);
  width: min(96vw, calc((100dvh - 250px) * 1.8462), 1000px);
}

/* ---------- Player strips ---------- */
.pl-players {
  display: flex;
  align-items: stretch;
  gap: 8px;
}
.pl-player {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 7px 12px 8px;
  border-radius: 12px;
  border: 1px solid rgba(215, 168, 76, .28);
  background: rgba(255, 255, 255, .05);
  transition: border-color .18s ease, background .18s ease, box-shadow .18s ease;
}
.pl-player.is-turn {
  border-color: var(--pl-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);
}
.pl-player__top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}
.pl-player__name {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--pl-cream);
}
.pl-player--cpu .pl-player__name { color: #ffb3a8; }
.pl-player__group {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--pl-brass2);
  white-space: nowrap;
}
.pl-player__balls {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-height: 19px;
}
.pl-pip {
  width: 19px;
  height: 19px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, .55);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 1px 1px rgba(0, 0, 0, .6);
  box-shadow: inset 0 2px 2px rgba(255, 255, 255, .32), 0 1px 1px rgba(0, 0, 0, .35);
}
.pl-pip--stripe { color: var(--pl-ink); text-shadow: none; }
.pl-pip--eight { background: #171a21; color: #fff; }
.pl-pip--empty {
  border-style: dashed;
  border-color: rgba(244, 237, 220, .28);
  background: none;
  box-shadow: none;
}

.pl-turn {
  flex: 0 0 auto;
  align-self: center;
  min-width: 94px;
  padding: 7px 10px;
  border-radius: 999px;
  text-align: center;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--pl-ink);
  background: linear-gradient(140deg, var(--pl-brass2), var(--pl-brass));
  border: 1px solid var(--pl-line);
  box-shadow: 0 2px 0 rgba(0, 0, 0, .35);
  white-space: nowrap;
}
.pl-turn.is-cpu { background: linear-gradient(140deg, #ffb3a8, #d9685b); }

/* ---------- Stage ---------- */
.pl-stage {
  position: relative;
  aspect-ratio: 960 / 520;
  border-radius: 16px;
  overflow: hidden;
  background: var(--pl-felt2);
  border: 3px solid #2a160d;
  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) ---------- */
.pl-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(6, 14, 11, .72);
  border: 1px solid rgba(244, 237, 220, .22);
  transform: translateX(-50%);
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s ease;
}
.pl-power.is-on { opacity: 1; }
.pl-power__label {
  flex: none;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: rgba(244, 237, 220, .7);
}
.pl-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);
}
.pl-power__fill {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #57d68c, #f0cf85 58%, #e8615a);
  transition: width .05s linear;
}

/* ---------- Ready / game-over overlays ---------- */
.pl-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(4, 12, 9, .46);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  touch-action: manipulation;
}
.pl-overlay[hidden] { display: none; }
.pl-card {
  touch-action: manipulation;
  max-width: 316px;
  text-align: center;
  padding: 18px 22px 16px;
  border-radius: 16px;
  background: linear-gradient(160deg, #fbf5e5, var(--pl-cream));
  border: 2px solid var(--pl-line);
  box-shadow: 0 7px 0 rgba(0, 0, 0, .3), 0 20px 44px rgba(0, 0, 0, .48);
  color: var(--pl-ink);
  animation: plPop .3s ease;
}
@keyframes plPop { from { transform: scale(.9); opacity: 0; } }
.pl-card__big svg {
  width: 64px;
  height: 64px;
  display: block;
  margin: 0 auto;
}
.pl-card h2 {
  margin: 4px 0 5px;
  font-size: 21px;
  font-weight: 800;
  letter-spacing: .03em;
  text-transform: uppercase;
  color: var(--pl-ink);
  text-shadow: 2px 2px 0 rgba(255, 255, 255, .55);
}
.pl-card p { margin: 0 0 12px; color: #5f5541; font-size: 13px; line-height: 1.5; }
.pl-card .c-btn { font-size: 13px; }
.pl-card .c-btn[hidden] { display: none; }
.c-win__actions { display: flex; gap: 9px; justify-content: center; flex-wrap: wrap; }

/* ---------- Hint line ---------- */
.pl-hint {
  margin: 0;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .02em;
  color: rgba(244, 237, 220, .58);
}
.pl-hint kbd, .pl-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(--pl-ink);
  background: var(--pl-cream);
  border: 1px solid var(--pl-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, #143b2d, #082219);
  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(--pl-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(--pl-brass2);
}
.c-modal__body ul { margin: 0; padding-left: 20px; }
.c-modal__body li { margin: 4px 0; }
.c-modal__body b { color: var(--pl-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(--pl-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; }
  .pl-board { width: min(97vw, calc((100vh - 220px) * 1.8462), 1000px); width: min(97vw, calc((100dvh - 220px) * 1.8462), 1000px); }
  .pl-player { padding: 5px 8px 6px; }
  .pl-player__name { font-size: 11px; }
  .pl-player__group { font-size: 10px; }
  .pl-pip { width: 15px; height: 15px; font-size: 7px; }
  .pl-turn { min-width: 76px; padding: 6px 8px; font-size: 9px; }
  .pl-hint { font-size: 11px; }
}
@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) {
  .pl-players { flex-wrap: wrap; gap: 5px; }
  .pl-turn { order: -1; flex: 1 1 100%; }
  .pl-player { flex: 1 1 0; }
  .pl-hint { display: none; }
}
@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, .pl-card, .pl-power, .pl-player { transition: none; animation: none; }
}
