:root {
  --bg:       #141420;
  --surface:  #1e1e30;
  --surface2: #272740;
  --border:   #3a3a5c;
  --accent:   #2e8a57;
  --accent-rgb: 46,138,87;
  --accent-h: #3aad6e;
  --text:     #ddddf0;
  --muted:    #8888aa;
  --a:        #5a8fd4;
  --a-dark:   #2d5a8e;
  --b:        #d4935a;
  --b-dark:   #8e5a2d;
  --c:        #8fbf6a;
  --c-dark:   #4f7a38;
  --danger:   #c04f4f;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 17px;
  min-height: 100vh;
}

#app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1rem 1rem 3rem;
}

h1 { font-size: 1.9rem; text-align: center; margin-bottom: 1rem; }
h2 { font-size: 1.2rem; margin-bottom: 0.75rem; }
h3 { font-size: 1rem; color: var(--muted); margin-bottom: 0.6rem; font-weight: 600; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
}

/* ── Buttons ─────────────────────────────────────────────────────────── */
button {
  cursor: pointer;
  border: none;
  border-radius: 9px;
  font-family: inherit;
  font-size: 1rem;
  color: var(--text);
  padding: 0.55rem 1rem;
  min-height: 48px;
  transition: filter 0.12s, transform 0.08s;
}
button:active  { transform: scale(0.96); }
button:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }
button:not(:disabled):hover { filter: brightness(1.15); }

.btn-primary  { background: var(--accent); }
.btn-ghost    { background: var(--surface2); border: 1px solid var(--border); }
.btn-danger   { background: var(--danger); }
.btn-a        { background: var(--a-dark); }
.btn-b        { background: var(--b-dark); }
.btn-c        { background: var(--c-dark); }
.btn-sm       { font-size: 0.85rem; min-height: 36px; padding: 0.3rem 0.7rem; }
.btn-lg       { font-size: 1.25rem; min-height: 64px; padding: 1rem 1.2rem; width: 100%; }
.btn-round    { border-radius: 50%; width: 48px; min-height: 48px; padding: 0; font-size: 1.4rem; display:inline-flex; align-items:center; justify-content:center; }

.btn-game {
  background: var(--surface2);
  border: 2px solid var(--border);
  font-size: 1.1rem;
  font-weight: 700;
  min-height: 100px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}
.btn-game.active {
  border-color: var(--accent);
  background: rgba(var(--accent-rgb),0.18);
  color: var(--accent-h);
}

/* ── Inputs ──────────────────────────────────────────────────────────── */
input[type="text"] {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  padding: 0.55rem 0.8rem;
  min-height: 46px;
  margin-bottom: 0.75rem;
}
input[type="text"]:focus { outline: none; border-color: var(--accent); }
input[type="text"]::placeholder { color: var(--muted); }

/* ── Layout ──────────────────────────────────────────────────────────── */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0.9rem; }
.grid2-flat { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.6rem; }

/* ── Player slots ────────────────────────────────────────────────────── */
.player-slot {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--surface2);
  border-radius: 9px;
  padding: 0.55rem 0.75rem;
  min-height: 48px;
  margin-bottom: 0.5rem;
}
.player-slot .name { flex: 1; font-weight: 600; }
.player-slot.empty { color: var(--muted); font-style: italic; background: transparent; border: 1px dashed var(--border); }
.badge {
  font-size: 0.7rem;
  background: var(--accent);
  border-radius: 5px;
  padding: 0.15rem 0.45rem;
  color: #fff;
  white-space: nowrap;
}

/* ── Player pills ────────────────────────────────────────────────────── */
.pills { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-top: 0.4rem; }
.pill {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0.35rem 0.85rem;
  font-size: 0.9rem;
  min-height: 40px;
  cursor: pointer;
}
.pill:hover { border-color: var(--accent); }

/* ── Score cards ─────────────────────────────────────────────────────── */
.score-card {
  border-radius: 14px;
  padding: 1.25rem 1rem;
  text-align: center;
  border: 2px solid;
}
.score-card .sc-name  { font-size: 1.7rem; font-weight: 700; margin-bottom: 0.25rem; }
.score-card .sc-wins  { font-size: 6rem; font-weight: 800; line-height: 1; margin-bottom: 0.4rem; }
.sc-wins-row { display: flex; align-items: center; justify-content: center; gap: 0.5rem; }
.sc-players { display: flex; gap: 0.5rem; margin-bottom: 0.5rem; }
.player-box {
  flex: 1;
  border-radius: 10px;
  padding: 0.6rem 0.5rem;
  text-align: center;
}
.player-box.shooting {
  background: rgba(255,255,255,0.1);
  border: 2px solid rgba(255,255,255,0.4);
}
.player-box.bench {
  background: transparent;
  border: 2px dashed rgba(255,255,255,0.15);
  opacity: 0.6;
}
.player-box .pb-label { font-size: 0.75rem; color: var(--muted); margin-bottom: 0.2rem; }
.player-box .pb-name  { font-size: 1.6rem; font-weight: 800; line-height: 1.1; }
.sc-swap {
  width: 100%; margin-top: 0.4rem;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  font-size: 0.9rem; min-height: 40px;
}

/* ── 8-ball extras ───────────────────────────────────────────────────── */
.ss-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.ss-team { display: flex; flex-direction: column; gap: 0.4rem; }
.ss-btn {
  background: var(--surface2);
  border: 2px solid var(--border);
  font-size: 0.95rem;
  font-weight: 600;
  min-height: 52px;
  border-radius: 9px;
}
.ss-btn.active { border-color: var(--accent); background: rgba(var(--accent-rgb),0.2); }

/* ── Straight pool extras ────────────────────────────────────────────── */
.sp-grid     { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.sp-controls { display: flex; align-items: center; justify-content: center; gap: 0.75rem; margin-top: 0.4rem; }
.sp-score    { font-size: 2.2rem; font-weight: 800; min-width: 2.5ch; text-align: center; }

/* ── Bottom action row ───────────────────────────────────────────────── */
.bottom-row { display: flex; flex-wrap: wrap; gap: 0.7rem; }
.bottom-row button { flex: 1; min-width: 120px; }

/* ── Play mode ───────────────────────────────────────────────────────── */
.play-overlay {
  position: fixed; inset: 0; z-index: 999;
  background: var(--bg);
  display: flex; flex-direction: column;
  padding: 1.5vh 1.5vw 1vh;
}
.play-next-chip {
  text-align: center; font-size: clamp(0.8rem, 1.8vw, 1.4rem);
  font-weight: 600; opacity: 0.6; padding: 0.3vh 0; letter-spacing: 0.03em;
}
.play-close {
  position: absolute; top: 1vh; left: 1vw; z-index: 1000;
  background: rgba(128,128,128,0.25); border: none; border-radius: 50%;
  width: clamp(2.5rem, 5vw, 4rem); height: clamp(2.5rem, 5vw, 4rem);
  font-size: clamp(1.2rem, 2.5vw, 2rem); line-height: 1; cursor: pointer;
  color: var(--text); display: flex; align-items: center; justify-content: center;
}
.play-overlay .play-cards {
  flex: 1; display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr;
  gap: 1.5vw; min-height: 0;
}
.play-overlay .play-cards.cols-3 {
  grid-template-columns: 1fr 1fr 1fr;
}
.play-overlay .score-card {
  border-radius: 2vw;
  display: flex; flex-direction: column;
  align-items: center;
  padding: 2vh 2vw;
  border-width: 3px;
  height: 100%; box-sizing: border-box; overflow: hidden;
}
.play-overlay .score-card .sc-name  { font-size: clamp(1.8rem, 5.5vw, 6rem); margin-bottom: 1vh; flex-shrink: 0; line-height: 1.15; }
.play-overlay .play-ball            { flex-shrink: 0; margin-bottom: 1vh; }
.play-overlay .play-ball img        { width: min(16vw, 22vh); height: min(16vw, 22vh); display: block; }
img[src*="billiard-ball"] { filter: none !important; }
/* Balls sit at the 5 points of a true pentagon (one up top, two upper
   sides, two lower sides), positioned with real trig around a fixed
   radius --R and sized off cqmin — the smaller of the CARD's own width
   and height, via container queries, not the viewport. That's the part
   that matters: a viewport-relative unit (vw/vh/vmin) doesn't know
   whether this card is one of three side-by-side or the only one on
   screen, so the same ball size that looks right in one layout can
   overflow or collide with itself in a narrower one. cqmin scales with
   whatever box the balls actually have to live in, and since both the
   ball size (--ct-ball) and the pentagon's radius (--R) scale together
   off the same unit, the ratio between "how big the balls are" and
   "how far apart their centers sit" never changes — so they can't
   start overlapping each other at some sizes and not others. */
.cutthroat-balls {
  container-type: size;
  /* Spacing --R is set equal to the ball size (a 1:1 ratio — adjacent
     balls end up ~18% of a ball-width apart, a real visible gap).
     With that ratio fixed, the pentagon's full bounding box works out
     to 2.902 x ballSize wide (the row-2 side balls are the widest
     point) and 2.809 x ballSize tall (top ball to bottom row). THE TWO
     NUMBERS TO TWEAK are the 31cqw/32cqh below — each is "how much of
     the card's width/height this pentagon may use"; raise either for
     bigger balls, lower for smaller. min() takes whichever is more
     restrictive, so it's always sized to fit both dimensions. */
  --ct-ball: clamp(4rem, min(31cqw, 32cqh), 12rem);
  --R: var(--ct-ball);
  position: relative;
  flex: 1; width: 100%; min-height: 0; margin-bottom: 1vh;
}
.ct-ball {
  position: absolute;
  background: none; border: none; padding: 0; min-height: 0;
  width: var(--ct-ball); height: var(--ct-ball);
  transform: translate(-50%, -50%);
  transition: none;
  cursor: pointer;
}
/* Override button:active's scale — it replaces (not adds to) the
   translate() used to center each ball on its pentagon point, causing
   a visible jump that can make a touchscreen tap register as cancelled
   instead of a click. */
.ct-ball:active { transform: translate(-50%, -50%); }
/* top/left = container center (50%) offset by --R at angles 72° apart,
   starting straight up (0,1) and going clockwise. */
.ct-ball:nth-child(1) { top: calc(50% - var(--R));            left: 50%;                      }
.ct-ball:nth-child(2) { top: calc(50% - var(--R) * 0.309);    left: calc(50% + var(--R) * 0.951); }
.ct-ball:nth-child(3) { top: calc(50% + var(--R) * 0.809);    left: calc(50% + var(--R) * 0.588); }
.ct-ball:nth-child(4) { top: calc(50% + var(--R) * 0.809);    left: calc(50% - var(--R) * 0.588); }
.ct-ball:nth-child(5) { top: calc(50% - var(--R) * 0.309);    left: calc(50% - var(--R) * 0.951); }
.ct-ball img { width: 100%; height: 100%; display: block; }
.ct-ball.hit img { filter: grayscale(1) brightness(0.5) !important; }
.ct-ball.hit::after {
  content: ''; position: absolute; left: 6%; right: 6%; top: 50%;
  height: 3px; background: rgba(255,255,255,0.9); border-radius: 2px;
  transform: translateY(-50%) rotate(-25deg);
}
.play-win-btn { display: none; }
/* Shared pill styling for the bottom-of-card slot: either the "Win"
   button (green) or, once a Cutthroat player is eliminated, a
   non-interactive red pill in the exact same spot. */
.play-overlay .play-win-btn,
.eliminated-pill {
  display: flex; align-items: center; justify-content: center;
  width: 80%; margin-top: auto; margin-bottom: 1vh; flex-shrink: 0;
  color: #fff;
  font-size: clamp(1.2rem, 3.5vw, 3rem); font-weight: 900;
  letter-spacing: 0.04em;
  min-height: unset; padding: 1.2vh 2vw;
  border-radius: 999px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.4);
}
.play-overlay .play-win-btn { background: var(--accent); }
.eliminated-pill { background: var(--danger); text-transform: uppercase; }
.play-toolbar {
  position: relative;
  display: flex; justify-content: center; align-items: center;
  gap: 1.5vw; padding-top: 0.8vh; flex-shrink: 0;
}
.play-toolbar button {
  background: transparent; border: 1px solid var(--border);
  color: var(--muted); font-size: clamp(1.3rem, 3vw, 2.2rem);
  font-weight: 700;
  min-height: clamp(3.5rem, 9vh, 6.5rem);
  padding: 0.5vh 3vw; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  opacity: 0.7;
}
.play-toolbar button:hover { opacity: 1; }
.break-badge {
  font-size: clamp(1.1rem, 2.6vw, 2rem);
  font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase;
  background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.3);
  border-radius: 20px; padding: 0.25em 0.9em; margin-bottom: 0.5vh;
  display: inline-block;
}
.play-timer, .play-swap {
  position: absolute; top: 50%; transform: translateY(-50%);
  background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.3);
  border-radius: 999px; padding: 0.4em 1.1em;
  font-size: clamp(1.2rem, 2.6vw, 1.9rem); font-weight: 700;
  color: var(--text);
  cursor: pointer; user-select: none;
}
.play-timer { right: 1.5vw; font-variant-numeric: tabular-nums; }
.play-swap  { left: 1.5vw; }


/* ── Custom confirm dialog ───────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 2rem 1.75rem 1.5rem;
  max-width: 340px; width: 90%;
  text-align: center;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}
.modal p { font-size: 1.15rem; font-weight: 600; margin-bottom: 1.25rem; line-height: 1.4; }
.modal .modal-btns { display: flex; gap: 0.75rem; }
.modal .modal-btns button { flex: 1; }

/* ── Game header ─────────────────────────────────────────────────────── */
.game-header { text-align: center; margin-bottom: 1rem; }
.game-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0.25rem 0.75rem 0.25rem 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

/* ── Summary ─────────────────────────────────────────────────────────── */
.summary-card { border-radius: 14px; padding: 1.5rem; text-align: center; border: 2px solid; }
.big-score    { font-size: 3.5rem; font-weight: 800; line-height: 1; margin: 0.4rem 0; }
.big-msg      { font-size: 1.4rem; text-align: center; margin: 0.75rem 0; }
.action-stack { display: flex; flex-direction: column; gap: 0.7rem; }

/* ── Utilities ───────────────────────────────────────────────────────── */
.label   { font-size: 0.78rem; color: var(--muted); margin-bottom: 0.25rem; }
.muted   { color: var(--muted); }
.center  { text-align: center; }
.mt-sm   { margin-top: 0.6rem; }
.mt-1    { margin-top: 1rem; }
.mb-sm   { margin-bottom: 0.6rem; }
.divider { border: none; border-top: 1px solid var(--border); margin: 0.85rem 0; }
.row     { display: flex; gap: 0.5rem; align-items: center; }
.flex1   { flex: 1; }

@media (max-width: 520px) {
  .grid2     { grid-template-columns: 1fr; }
  .grid3     { grid-template-columns: 1fr; }
  .grid2-flat { grid-template-columns: 1fr 1fr; }
  h1 { font-size: 1.5rem; }
}
