/* =========================================================
   Family Tambola — styles
   ========================================================= */
:root {
  --bg: #150a26;
  --bg2: #2a1150;
  --panel: rgba(255, 255, 255, 0.06);
  --panel-solid: #221141;
  --stroke: rgba(255, 255, 255, 0.12);
  --text: #f6f0ff;
  --muted: #b9a9d6;
  --gold: #ffd23f;
  --gold-deep: #f5a623;
  --pink: #ff5d8f;
  --green: #38d39f;
  --accent: #8a5cff;
  --accent-2: #ff7ac6;
  --danger: #ff6b6b;
  --ball-grad: radial-gradient(circle at 32% 28%, #fff6d8 0%, #ffd23f 38%, #f5a623 70%, #d97706 100%);
  --shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
  --radius: 20px;
  --font-en: 'Poppins', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-fun: 'Baloo 2', var(--font-en);
  --font-hi: 'Noto Sans Devanagari', var(--font-en);
}

[data-theme="light"] {
  --bg: #fff4e6;
  --bg2: #ffe3c7;
  --panel: rgba(120, 60, 10, 0.06);
  --panel-solid: #fff;
  --stroke: rgba(90, 40, 0, 0.14);
  --text: #34122b;
  --muted: #8a5a4a;
  --accent: #7a3cff;
  --shadow: 0 14px 34px rgba(120, 60, 10, 0.18);
  /* darker accents so gold/pink/green TEXT stays readable on light backgrounds */
  --gold: #a8650a;
  --gold-deep: #855000;
  --accent-2: #d6336c;
  --green: #0c8f6e;
}
[data-theme="light"] .win-winner { color: var(--danger); }
[data-theme="light"] .win-en { color: var(--text); }
[data-theme="light"] .total-field input,
[data-theme="light"] .win-set input { color: var(--gold-deep); }
[data-theme="light"] .ball-num { color: #5b2a00; }

* { box-sizing: border-box; }

/* The hidden attribute must always win, even over `display:grid/flex` rules
   (modals, drawers, toast all rely on toggling [hidden]). */
[hidden] { display: none !important; }

/* Disable pull-to-refresh / overscroll bounce (esp. mobile drag-down). */
html, body { margin: 0; padding: 0; overscroll-behavior: none; }
html { overflow-x: hidden; }

body {
  font-family: var(--font-en);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 12% -8%, var(--bg2), transparent 60%),
    radial-gradient(1000px 700px at 110% 10%, #3a0f5e, transparent 55%),
    var(--bg);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* Subtle festive shimmer behind everything */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(2px 2px at 20% 30%, rgba(255, 210, 63, 0.5), transparent),
    radial-gradient(2px 2px at 70% 60%, rgba(255, 122, 198, 0.4), transparent),
    radial-gradient(2px 2px at 85% 20%, rgba(138, 92, 255, 0.4), transparent),
    radial-gradient(1.5px 1.5px at 40% 80%, rgba(56, 211, 159, 0.4), transparent);
  background-size: 600px 600px, 500px 500px, 700px 700px, 550px 550px;
  pointer-events: none;
  opacity: 0.5;
  z-index: 0;
}

/* ===================== HEADER ===================== */
.app-header {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px clamp(12px, 4vw, 28px);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo {
  font-size: 2.1rem;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.4));
  animation: wiggle 4s ease-in-out infinite;
}
@keyframes wiggle { 0%,100%{transform:rotate(-8deg)} 50%{transform:rotate(10deg)} }
.brand-text h1 {
  font-family: var(--font-fun);
  font-weight: 800;
  font-size: clamp(1.3rem, 4.5vw, 2rem);
  margin: 0;
  line-height: 1;
  background: linear-gradient(90deg, var(--gold), var(--accent-2), var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tagline { margin: 2px 0 0; color: var(--muted); font-size: 0.78rem; }

.header-controls { display: flex; align-items: center; gap: 8px; }

.seg {
  display: inline-flex;
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: 999px;
  padding: 3px;
}
.seg-btn {
  border: 0; background: transparent; color: var(--muted);
  font-family: var(--font-en); font-weight: 600; font-size: 0.82rem;
  padding: 9px 14px; border-radius: 999px; cursor: pointer; transition: .2s;
}
.seg-btn.is-active { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; box-shadow: 0 4px 12px rgba(138, 92, 255, .45); }

.icon-btn {
  width: 44px; height: 44px; display: grid; place-items: center;
  border-radius: 50%; border: 1px solid var(--stroke); background: var(--panel);
  color: var(--text); cursor: pointer; font-size: 1.1rem; transition: transform .15s, background .2s;
}
.icon-btn:hover { transform: translateY(-2px); }
.icon-btn[aria-pressed="false"] { opacity: .45; }

/* ===================== GAME BAR ===================== */
.gamebar {
  position: relative; z-index: 2;
  display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; align-items: center;
  padding: 2px clamp(12px, 4vw, 28px) 8px;
}
.chip {
  background: var(--panel); border: 1px solid var(--stroke); color: var(--text);
  border-radius: 999px; padding: 7px 13px; font-size: .8rem; cursor: pointer;
  font-family: var(--font-en); font-weight: 600; display: inline-flex; align-items: center; gap: 6px;
  max-width: 60vw; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.chip:hover { background: rgba(255,255,255,.12); }
.chip.named { color: var(--gold); }

/* ===================== LAYOUT (3 columns, fit-to-screen) ===================== */
.layout {
  position: relative; z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr) clamp(160px, 18vw, 224px);
  gap: clamp(10px, 1.4vw, 16px);
  padding: 0 clamp(12px, 4vw, 28px) 12px;
  max-width: 1180px; margin: 0 auto;
  align-items: stretch;
}
#callerCard { order: 1; }
#boardCard  { order: 2; }
#winningsRail { order: 3; }

.caller-card, .board-card {
  background: linear-gradient(180deg, var(--panel), transparent), var(--panel-solid);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(10px, 1.4vw, 16px);
  backdrop-filter: blur(8px);
  min-width: 0;
}

/* On wide screens, lock the playfield to one screen height (no page scroll at all). */
@media (min-width: 900px) {
  /* lock ONLY the game page to one screen; other pages (rules, etc.) scroll normally */
  body[data-page="game"] { overflow: hidden; height: 100dvh; }
  .layout { height: calc(100dvh - 118px); grid-template-rows: minmax(0, 1fr); }
  .layout > * { min-height: 0; height: 100%; }
  /* board-card centres a square-celled board sized (in px, by JS) to fit the area */
  .board-card { display: flex; flex-direction: column; overflow: hidden; align-items: center; }
  .board-card .board-head { width: 100%; flex: 0 0 auto; }
  .board-card .board { width: var(--board-size, 100%); margin: auto; min-height: 0; }
  .board-card .cell { font-size: clamp(.6rem, 1.5vh, 1rem); }
  .caller-card { overflow: hidden; display: flex; flex-direction: column; justify-content: center; }
  .winnings-rail { height: 100%; }
  /* the ball flexes to fill leftover height, so the caller always fits (no scroll/clip) */
  .ball-stage { flex: 1 1 auto; min-height: 60px; }
  .ball { width: auto; height: 100%; max-height: min(26vh, 138px); aspect-ratio: 1 / 1; max-width: 100%; }
  .ball-shadow { display: none; }
}

/* Tablet / phone: single column — board on top, caller sticky below it. */
@media (max-width: 899px) {
  .layout { display: flex; flex-direction: column; gap: 10px; }
  #boardCard { order: 1; }
  #callerCard { order: 2; position: sticky; top: 4px; z-index: 6; }
  #winningsRail { order: 3; }
}

/* ===================== CALLER ===================== */
.caller-top { display: flex; justify-content: center; gap: 10px; margin-bottom: 2px; }
.stat-pill {
  display: flex; flex-direction: row; align-items: baseline; gap: 5px;
  background: var(--panel); border: 1px solid var(--stroke);
  border-radius: 999px; padding: 3px 12px; min-width: 0;
}
.stat-pill span { font-family: var(--font-fun); font-weight: 800; font-size: 1.05rem; color: var(--gold); line-height: 1; }
.stat-pill small { color: var(--muted); font-size: 0.6rem; text-transform: uppercase; letter-spacing: .06em; }

.ball-stage { display: grid; place-items: center; margin: 4px 0 2px; position: relative; }
.ball {
  position: relative;
  width: clamp(100px, 17vh, 158px);
  height: clamp(100px, 17vh, 158px);
  border-radius: 50%;
  background: var(--ball-grad);
  display: grid; place-items: center;
  box-shadow: inset 0 -12px 26px rgba(160, 80, 0, .55), inset 0 10px 20px rgba(255,255,255,.55), 0 18px 40px rgba(0,0,0,.5);
  transition: transform .15s;
}
.ball-num {
  font-family: var(--font-fun);
  font-weight: 800;
  font-size: clamp(2.4rem, 9vh, 4.4rem);
  color: #5b2a00;
  text-shadow: 0 2px 0 rgba(255,255,255,.4);
  line-height: 1;
}
.ball-shine {
  position: absolute; top: 14%; left: 18%;
  width: 34%; height: 24%; border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,.9), transparent 70%);
  filter: blur(2px);
}
.ball-shadow {
  width: clamp(110px, 28vw, 150px); height: 18px; margin-top: 6px;
  border-radius: 50%; background: rgba(0,0,0,.4); filter: blur(8px);
}
.ball.shuffling { animation: shake .35s linear; }
.ball.reveal { animation: pop .55s cubic-bezier(.18,1.5,.4,1); }
@keyframes shake {
  0%,100%{transform:translateX(0) rotate(0)}
  25%{transform:translateX(-7px) rotate(-6deg)}
  75%{transform:translateX(7px) rotate(6deg)}
}
@keyframes pop {
  0%{transform:scale(.3) rotate(-25deg);opacity:.2}
  60%{transform:scale(1.12) rotate(6deg)}
  100%{transform:scale(1) rotate(0)}
}

.calls { text-align: center; margin-top: 5px; min-height: 42px; }
.call-en {
  font-family: var(--font-fun); font-weight: 700;
  font-size: clamp(1.1rem, 4vw, 1.6rem); color: var(--gold);
}
.call-hi {
  font-family: var(--font-hi); font-weight: 700;
  font-size: clamp(1.1rem, 4.5vw, 1.7rem); color: var(--accent-2); margin-top: 2px;
}

.commentary { text-align: center; min-height: 30px; margin: 4px 0 8px; }
.commentary p { margin: 3px 0; }
.line-en { font-size: clamp(.92rem, 2.6vw, 1.05rem); color: var(--text); }
.line-hi { font-family: var(--font-hi); font-size: clamp(.95rem, 3vw, 1.12rem); color: var(--text); }
.line-roman { font-size: .82rem; color: var(--muted); font-style: italic; }

/* language visibility — only the number TITLES follow the toggle.
   The commentary lines are now used only by the (always-Hindi) Masala. */
body[data-lang="en"] .call-hi { display: none; }
body[data-lang="hi"] .call-en { display: none; }

/* ===================== BUTTONS ===================== */
.actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.btn {
  font-family: var(--font-fun); font-weight: 700;
  border: 0; border-radius: 14px; padding: 13px 22px; font-size: 1rem;
  cursor: pointer; color: #fff; transition: transform .12s, box-shadow .2s, filter .2s;
  display: inline-flex; align-items: center; gap: 8px; user-select: none;
}
.btn:active { transform: translateY(2px) scale(.98); }
.btn-sm { padding: 9px 14px; font-size: .85rem; border-radius: 11px; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 26px rgba(138,92,255,.5);
  font-size: 1.15rem; padding: 15px 30px;
}
.btn-primary:hover { filter: brightness(1.08); transform: translateY(-2px); }
.btn-primary:disabled { filter: grayscale(.7) brightness(.7); cursor: not-allowed; transform: none; }
.btn-ghost { background: var(--panel); border: 1px solid var(--stroke); color: var(--text); }
.btn-ghost:hover { background: rgba(255,255,255,.12); }
.btn-masala { background: linear-gradient(135deg, #ff7a3c, #ff3c6e); box-shadow: 0 8px 20px rgba(255,80,90,.4); }

.sub-actions { display: flex; align-items: center; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
.auto-wrap { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; color: var(--muted); font-weight: 600; font-size: .9rem; }
.auto-wrap input { display: none; }
.switch { width: 42px; height: 24px; border-radius: 999px; background: var(--stroke); position: relative; transition: .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: .2s; }
.auto-wrap input:checked + .switch { background: var(--green); }
.auto-wrap input:checked + .switch::after { transform: translateX(18px); }
.auto-wrap input:checked ~ .auto-label { color: var(--green); }
.speed-select {
  background: var(--panel); color: var(--text); border: 1px solid var(--stroke);
  border-radius: 10px; padding: 11px 12px; font-family: var(--font-en); font-weight: 600; cursor: pointer;
}

/* visible keyboard focus everywhere */
:focus-visible {
  outline: 3px solid var(--green);
  outline-offset: 2px;
  border-radius: 8px;
}
.btn:focus-visible, .icon-btn:focus-visible, .seg-btn:focus-visible { outline-offset: 3px; }

/* ===================== RECENT ===================== */
.recent { display: flex; align-items: center; gap: 7px; margin-top: 8px; flex-wrap: wrap; justify-content: center; }
.recent-label { color: var(--muted); font-size: .7rem; }
.recent-balls { display: flex; gap: 5px; flex-wrap: wrap; }
.mini-ball {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--ball-grad); color: #5b2a00; cursor: pointer;
  display: grid; place-items: center; font-family: var(--font-fun); font-weight: 800; font-size: .78rem;
  box-shadow: 0 3px 7px rgba(0,0,0,.35); animation: pop .4s ease;
}
.mini-ball.latest { outline: 3px solid var(--green); }

/* ===================== BOARD ===================== */
.board-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; flex-wrap: wrap; gap: 8px; }
.board-head h2 { font-family: var(--font-fun); margin: 0; font-size: 1.3rem; }
.board-head h2 small { color: var(--muted); font-weight: 500; font-size: .85rem; }
.board-tools { display: flex; gap: 8px; }
.board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);   /* 9 cols x 10 rows, numbered top-to-bottom */
  gap: clamp(3px, 1vw, 7px);
}
.cell {
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  background: var(--panel);
  border: 1px solid var(--stroke);
  display: grid; place-items: center;
  font-family: var(--font-fun); font-weight: 700;
  font-size: clamp(.7rem, 2.4vw, 1rem);
  color: var(--muted);
  cursor: default; transition: transform .15s, background .25s, color .25s;
}
.cell.called {
  background: var(--ball-grad); color: #5b2a00; cursor: pointer;
  box-shadow: 0 4px 10px rgba(0,0,0,.35); border-color: transparent;
  animation: cellPop .45s cubic-bezier(.18,1.5,.4,1);
}
.cell.current { outline: 3px solid var(--green); animation: currentPulse 1.2s ease-in-out infinite; }
@keyframes cellPop { 0%{transform:scale(.4);opacity:.3} 100%{transform:scale(1);opacity:1} }
@keyframes currentPulse { 0%,100%{box-shadow:0 0 0 0 rgba(56,211,159,.6)} 50%{box-shadow:0 0 0 7px rgba(56,211,159,0)} }
.board-hint { color: var(--muted); font-size: .78rem; text-align: center; margin: 12px 0 0; }

/* ===================== AD ZONE ===================== */
.ad-zone {
  max-width: 1180px; margin: 10px auto 0; padding: 0 clamp(12px,4vw,28px);
  min-height: 0; text-align: center; position: relative; z-index: 1;
}
.ad-zone.show { min-height: 100px; padding-top: 8px; padding-bottom: 8px; }
.ad-label { display: none; color: var(--muted); font-size: .68rem; letter-spacing: .12em; text-transform: uppercase; }
.ad-zone.show .ad-label { display: block; margin-bottom: 4px; }

/* ===================== FOOTER ===================== */
.app-footer {
  position: relative; z-index: 1;
  text-align: center; color: var(--muted); font-size: .82rem;
  padding: 18px 12px 30px; display: flex; flex-direction: column; gap: 6px; align-items: center;
}
.link-btn { background: none; border: 0; color: var(--accent-2); cursor: pointer; text-decoration: underline; font-size: .8rem; }

/* ===================== HISTORY DRAWER ===================== */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 40; animation: fade .2s ease; }
@keyframes fade { from{opacity:0} to{opacity:1} }
.drawer {
  position: fixed; top: 0; right: 0; height: 100%;
  width: min(380px, 88vw);
  background: var(--panel-solid);
  border-left: 1px solid var(--stroke);
  box-shadow: -20px 0 50px rgba(0,0,0,.5);
  z-index: 50; transform: translateX(105%); transition: transform .32s cubic-bezier(.4,0,.2,1);
  display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 18px 6px; }
.drawer-head h2 { font-family: var(--font-fun); margin: 0; font-size: 1.3rem; }
.drawer-sub { padding: 0 18px; color: var(--muted); font-size: .82rem; margin: 0 0 6px; }
.history-list { list-style: none; margin: 0; padding: 8px 14px 24px; overflow-y: auto; flex: 1; }
.history-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px; border-radius: 12px; margin-bottom: 8px;
  background: var(--panel); border: 1px solid var(--stroke);
  animation: slideIn .3s ease;
}
@keyframes slideIn { from{opacity:0;transform:translateX(20px)} to{opacity:1;transform:translateX(0)} }
.history-item .h-num {
  flex: 0 0 auto; width: 44px; height: 44px; border-radius: 50%;
  background: var(--ball-grad); color: #5b2a00;
  display: grid; place-items: center; font-family: var(--font-fun); font-weight: 800;
}
.history-item .h-meta { min-width: 0; }
.history-item .h-order { color: var(--muted); font-size: .7rem; }
.history-item .h-call { font-weight: 600; font-size: .9rem; }
.history-item .h-call-hi { font-family: var(--font-hi); color: var(--accent-2); font-size: .88rem; }
.history-empty { color: var(--muted); text-align: center; padding: 30px 10px; }

/* ===================== CONSENT ===================== */
.consent {
  position: fixed; left: 50%; bottom: 14px; transform: translateX(-50%);
  width: min(640px, 94vw); z-index: 60;
  background: var(--panel-solid); border: 1px solid var(--stroke);
  border-radius: 16px; box-shadow: 0 20px 50px rgba(0,0,0,.55);
  animation: slideUp .4s cubic-bezier(.18,1.2,.4,1);
}
@keyframes slideUp { from{opacity:0;transform:translate(-50%,40px)} to{opacity:1;transform:translate(-50%,0)} }
.consent-inner { display: flex; align-items: center; gap: 16px; padding: 16px 18px; flex-wrap: wrap; }
.consent-text { flex: 1; min-width: 220px; }
.consent-text strong { font-family: var(--font-fun); font-size: 1.02rem; }
.consent-text p { margin: 4px 0 0; color: var(--muted); font-size: .85rem; line-height: 1.45; }
.consent-actions { display: flex; gap: 8px; margin-left: auto; }

/* ===================== CONFETTI + TOAST ===================== */
.confetti-canvas { position: fixed; inset: 0; pointer-events: none; z-index: 70; }
.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  background: var(--panel-solid); border: 1px solid var(--stroke);
  color: var(--text); padding: 12px 18px; border-radius: 12px; z-index: 65;
  box-shadow: var(--shadow); font-weight: 600; font-size: .9rem;
  animation: slideUp .3s ease; max-width: 90vw; text-align: center;
}

/* ===================== EXTRA BUTTON VARIANTS ===================== */
.btn-xs { padding: 7px 12px; font-size: .8rem; border-radius: 11px; gap: 5px; }
.btn-gold { background: linear-gradient(135deg, var(--gold), var(--gold-deep)); color: #5b2a00; box-shadow: 0 8px 20px rgba(245,166,35,.4); }
.btn-gold:hover { filter: brightness(1.06); }

/* ===================== WINNINGS RAIL ===================== */
.winnings-rail {
  background: linear-gradient(180deg, var(--panel), transparent), var(--panel-solid);
  border: 1px solid var(--stroke); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 10px; display: flex; flex-direction: column; min-width: 0; gap: 8px;
}
.rail-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 2px 2px 0; }
.rail-head strong { font-family: var(--font-fun); font-size: 1rem; }
.rail-total {
  display: flex; gap: 6px; align-items: center;
  background: var(--panel); border: 1px solid var(--stroke); border-radius: 12px; padding: 6px 8px;
}
.total-field { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; }
.total-field span { font-size: .78rem; color: var(--muted); font-weight: 700; white-space: nowrap; }
.total-field input {
  width: 100%; min-width: 0; background: transparent; border: 0; color: var(--gold);
  font-family: var(--font-fun); font-weight: 800; font-size: 1.05rem; text-align: right;
}
.total-field input:focus { outline: none; }

.winnings-list { display: flex; flex-direction: column; gap: 5px; overflow-y: auto; min-height: 0; padding-right: 2px; }
@media (min-width: 900px) { .winnings-list { flex: 1; } }

/* a single winning-item tile (button-style) */
.win-tile {
  background: var(--panel); border: 1px solid var(--stroke); border-radius: 12px;
  transition: background .2s, border-color .2s;
  flex: 0 0 auto;          /* never shrink — keeps tiles from overlapping; the list scrolls */
  box-shadow: inset 4px 0 0 var(--accent);   /* coloured accent (inset = no overflow:hidden needed) */
}
.win-tile .win-row { display: flex; align-items: center; gap: 8px; padding: 6px 10px; cursor: pointer; }
.win-chk { width: 18px; height: 18px; flex: 0 0 auto; accent-color: var(--green); display: none; }
.winnings-rail.setmode .win-chk { display: inline-block; }
.win-icon { font-size: 1.15rem; line-height: 1; flex: 0 0 auto; }
.win-names { display: flex; flex-direction: column; line-height: 1.12; min-width: 0; flex: 1; }
.win-en { font-family: var(--font-fun); font-weight: 700; font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.win-hi { font-family: var(--font-hi); color: var(--accent-2); font-size: .72rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.win-amt-badge { font-family: var(--font-fun); font-weight: 800; font-size: .8rem; color: var(--gold); flex: 0 0 auto; }
.winnings-rail.setmode .win-amt-badge { display: none; }   /* the input shows the amount in set mode */

/* tooltip help icon (hover shows the item help popup) */
.win-info {
  flex: 0 0 auto; width: 18px; height: 18px; border-radius: 50%;
  display: grid; place-items: center; font-size: .68rem; font-weight: 800;
  background: rgba(255,255,255,.12); color: var(--muted); cursor: help; border: 0;
}
.win-info:hover, .win-info:focus { background: var(--accent); color: #fff; outline: none; }

/* remove (−) button for custom items */
.win-remove {
  flex: 0 0 auto; width: 18px; height: 18px; border-radius: 50%; border: 0;
  background: rgba(255,107,107,.22); color: var(--danger); cursor: pointer; font-weight: 800; font-size: .9rem;
  display: grid; place-items: center;
}
.win-remove:hover { background: var(--danger); color: #fff; }
.win-tile.custom { border-left-color: #4cc9f0; }
.win-tile.custom .win-en::after { content: ' ✎'; opacity: .5; font-size: .7em; }

/* + Add Item */
.add-item-btn {
  margin-top: 6px; width: 100%; border: 1px dashed var(--stroke); background: var(--panel);
  color: var(--accent-2); border-radius: 10px; padding: 8px; cursor: pointer;
  font-family: var(--font-en); font-weight: 700; font-size: .82rem;
}
.add-item-btn:hover { background: rgba(255,255,255,.08); border-color: var(--accent); }
.confirm-items-btn { width: 100%; justify-content: center; margin-top: 6px; }

/* coloured-but-unclaimed tiles cycle through a few accents */
.win-tile:nth-child(6n+2) { box-shadow: inset 4px 0 0 var(--green); }
.win-tile:nth-child(6n+3) { box-shadow: inset 4px 0 0 var(--accent-2); }
.win-tile:nth-child(6n+4) { box-shadow: inset 4px 0 0 var(--gold-deep); }
.win-tile:nth-child(6n+5) { box-shadow: inset 4px 0 0 #ff7a3c; }
.win-tile:nth-child(6n+6) { box-shadow: inset 4px 0 0 #4cc9f0; }
.win-tile:hover { background: rgba(255,255,255,.07); }

/* claimed -> RED */
.win-tile.claimed { border-color: var(--danger); box-shadow: inset 4px 0 0 var(--danger); background: linear-gradient(180deg, rgba(255,107,107,.16), transparent), var(--panel); }
.win-tile.claimed .win-en { color: #c9cad3; }                       /* readable grey, not red */
[data-theme="light"] .win-tile.claimed .win-en { color: #5b5b66; }
.win-winners { padding: 0 10px 8px; display: flex; flex-direction: column; gap: 2px; }
.win-winner { font-weight: 700; color: #ff8f8f; font-size: .82rem; word-break: break-word; }
.win-winner small { color: var(--gold); font-weight: 600; }

/* set-mode amount input row */
.win-set { padding: 0 10px 9px; display: none; align-items: center; gap: 6px; }
.winnings-rail.setmode .win-set { display: flex; }
.win-set .cur { color: var(--muted); font-size: .8rem; }
.win-set input {
  width: 100%; min-width: 0; background: var(--bg); border: 1px solid var(--stroke); color: var(--gold);
  border-radius: 8px; padding: 5px 8px; font-family: var(--font-fun); font-weight: 700; text-align: right;
}
.win-tile.unsel { opacity: .45; }

/* inline claim editor (expands under a tile) */
.win-claim { padding: 0 10px 10px; display: none; flex-direction: column; gap: 6px; }
.win-tile.expanded .win-claim { display: flex; }
.winnings-rail.setmode .win-tile.expanded .win-claim { display: none; } /* no claiming while setting items */
.win-claim input {
  background: var(--bg); border: 1px solid var(--stroke); color: var(--text);
  border-radius: 8px; padding: 7px 9px; font-size: .85rem; width: 100%;
}
.win-claim input:focus { outline: none; border-color: var(--accent); }
.win-claim-actions { display: flex; gap: 6px; }
.win-claim-actions .btn { flex: 1; justify-content: center; }
.rail-hint { color: var(--muted); font-size: .72rem; text-align: center; padding: 2px 4px; }

/* host-only controls hidden in viewer mode (Phase 2) */
body.viewer .host-only { display: none !important; }

/* ===================== MODALS (login + claim) ===================== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 80;
  display: grid; place-items: center; padding: 16px; animation: fade .2s ease;
}
.modal {
  position: relative; background: var(--panel-solid); border: 1px solid var(--stroke);
  border-radius: 18px; box-shadow: 0 24px 60px rgba(0,0,0,.55);
  width: min(420px, 94vw); padding: 24px; animation: slideUp .3s cubic-bezier(.18,1.2,.4,1);
}
.modal.modal-wide { width: min(680px, 96vw); max-height: 90dvh; overflow-y: auto; }
.modal h2 { font-family: var(--font-fun); margin: 0 0 6px; font-size: 1.35rem; }
.modal-x { position: absolute; top: 12px; right: 12px; width: 38px; height: 38px; }

/* ----- Report ----- */
.report-head h2 { margin: 0 0 2px; }
.report-meta { color: var(--muted); font-size: .85rem; margin: 0 0 14px; line-height: 1.5; }
.report-meta b { color: var(--text); }
.report-section-title { font-family: var(--font-fun); font-weight: 700; margin: 16px 0 8px; font-size: 1.05rem; }
.report-winner {
  border: 1px solid var(--stroke); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px;
  background: var(--panel);
}
.report-winner .rw-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.report-winner .rw-name { font-family: var(--font-fun); font-weight: 800; font-size: 1.02rem; }
.report-winner .rw-total { color: var(--gold); font-family: var(--font-fun); font-weight: 800; white-space: nowrap; }
.report-winner .rw-items { color: var(--muted); font-size: .85rem; margin-top: 4px; line-height: 1.5; }
.report-grand { display: flex; justify-content: space-between; font-family: var(--font-fun); font-weight: 800; font-size: 1.1rem; margin-top: 6px; padding-top: 10px; border-top: 2px solid var(--stroke); }
.report-grand .rg-amt { color: var(--gold); }
.report-empty { color: var(--muted); font-style: italic; }
.report-numbers { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.report-numbers span {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--ball-grad); color: #5b2a00; font-family: var(--font-fun); font-weight: 800; font-size: .78rem;
}
.report-numbers .seq { font-size: .58rem; }
.modal-sub { color: var(--muted); font-size: .9rem; margin: 0 0 14px; line-height: 1.45; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field span { font-size: .8rem; color: var(--muted); font-weight: 600; }
.field input {
  background: var(--panel); border: 1px solid var(--stroke); border-radius: 10px;
  padding: 12px 14px; color: var(--text); font-family: var(--font-en); font-size: 1rem;
}
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(138,92,255,.25); }
#authCode { letter-spacing: .4em; text-align: center; font-size: 1.3rem; font-weight: 700; }
.modal-actions { display: flex; gap: 8px; justify-content: space-between; align-items: center; flex-wrap: wrap; }
.modal-actions .btn { flex: 1; justify-content: center; }
.modal-msg { margin: 12px 0 0; font-size: .85rem; color: var(--muted); min-height: 1.1em; }
.modal-msg.err { color: var(--danger); }
.modal #authResend { display: block; margin: 10px auto 0; }
.icon-btn.is-on { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; opacity: 1; border-color: transparent; }

/* ===================== MY GAMES DRAWER ===================== */
.games-list { padding: 8px 14px 24px; overflow-y: auto; flex: 1; }
.game-card {
  background: var(--panel); border: 1px solid var(--stroke); border-radius: 14px;
  padding: 14px; margin-bottom: 10px; animation: slideIn .3s ease;
}
.g-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.g-date { font-family: var(--font-fun); font-weight: 700; }
.g-count { color: var(--muted); font-size: .8rem; }
.g-wins { margin-top: 10px; display: flex; flex-direction: column; gap: 4px; font-size: .85rem; }
.g-win { line-height: 1.35; }
.g-prize { color: var(--gold); }
.g-none { color: var(--muted); font-style: italic; }
.games-empty { color: var(--muted); text-align: center; padding: 30px 10px; line-height: 1.5; }

/* ===================== RULES PAGE ===================== */
.rules-page { max-width: 820px; margin: 0 auto; padding: 6px clamp(12px,4vw,28px) 24px; position: relative; z-index: 1; }
.rules-card {
  background: linear-gradient(180deg, var(--panel), transparent), var(--panel-solid);
  border: 1px solid var(--stroke); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: clamp(16px,3vw,26px); margin-bottom: 16px;
}
.rules-card h2 { font-family: var(--font-fun); margin: 0 0 10px; }
.rules-card p { line-height: 1.55; }
.hi-note { font-family: var(--font-hi); color: var(--muted); }
.rules-list { line-height: 1.6; padding-left: 20px; }
.rules-list li { margin-bottom: 8px; }
.ticket-wrap { display: flex; justify-content: center; margin: 12px 0; }
.ticket-grid { display: grid; grid-template-columns: repeat(9, 1fr); gap: 4px; width: min(430px, 100%); }
.t-cell {
  aspect-ratio: 1 / 1; border-radius: 6px; display: grid; place-items: center;
  font-family: var(--font-fun); font-weight: 700; font-size: clamp(.6rem, 2.4vw, .95rem);
}
.t-cell.filled { background: var(--panel); border: 1px solid var(--stroke); color: var(--text); }
.t-cell.blank { background: transparent; border: 1px dashed var(--stroke); opacity: .5; }
.t-cell.lit { background: var(--ball-grad); color: #5b2a00; border-color: transparent; box-shadow: 0 3px 8px rgba(0,0,0,.3); }
.ticket-grid.mini { width: 176px; gap: 2px; flex: 0 0 auto; }
.ticket-grid.mini .t-cell { font-size: .5rem; border-radius: 4px; }
.pattern-grid { display: grid; gap: 14px; }
.pattern-card { display: flex; gap: 16px; align-items: center; background: var(--panel); border: 1px solid var(--stroke); border-radius: 14px; padding: 14px; }
.pattern-info h3 { font-family: var(--font-fun); margin: 0 0 6px; font-size: 1.1rem; }
.pattern-info p { margin: 2px 0; font-size: .9rem; line-height: 1.4; }
.p-hi { font-family: var(--font-hi); color: var(--accent-2); font-weight: 600; font-size: .95rem; }
@media (max-width: 520px) {
  .pattern-card { flex-direction: column; align-items: flex-start; }
  .ticket-grid.mini { width: 150px; }
}

/* ===================== SHARE CLUSTER ===================== */
.share-cluster { display: inline-flex; align-items: center; gap: 5px; background: var(--panel); border: 1px solid var(--stroke); border-radius: 999px; padding: 3px 4px 3px 12px; }
.sc-label { color: var(--muted); font-size: .72rem; font-weight: 600; }
.sc-code { font-family: var(--font-fun); font-weight: 800; color: var(--gold); letter-spacing: .08em; font-size: .95rem; }
.sc-btn { width: 30px; height: 30px; border-radius: 50%; border: 0; background: rgba(255,255,255,.08); color: var(--text); cursor: pointer; font-size: .85rem; display: grid; place-items: center; transition: .15s; }
.sc-btn:hover { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }
.share-cluster.live-off { border-color: var(--danger); }
.share-cluster.live-off .sc-code { color: var(--danger); }
.share-cluster.live-off .sc-label::before { content: '⚠️ '; }

/* ===================== VIEWER BANNER ===================== */
.viewer-banner { position: relative; z-index: 2; text-align: center; padding: 9px 14px; font-weight: 600; color: #fff; background: linear-gradient(135deg, #b91c5c, #7a3cff); }
.viewer-banner b { font-family: var(--font-fun); }
.vb-dot { opacity: .92; }
body.viewer .gamebar { justify-content: center; }

/* ===================== INFO POPUP (item help + number commentary) ===================== */
.info-pop { position: fixed; z-index: 90; width: min(280px, 86vw); background: var(--panel-solid); border: 1px solid var(--stroke); border-radius: 14px; box-shadow: 0 18px 50px rgba(0,0,0,.55); padding: 12px; animation: fade .12s ease; }
.pop-title { font-family: var(--font-fun); font-weight: 700; font-size: .95rem; margin-bottom: 6px; }
.pop-hi { font-family: var(--font-hi); color: var(--accent-2); font-weight: 600; }
.pop-num { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--ball-grad); color: #5b2a00; font-weight: 800; vertical-align: middle; }
.pop-desc { font-size: .84rem; color: var(--text); margin-top: 4px; line-height: 1.4; }
.pop-desc-hi { font-family: var(--font-hi); color: var(--muted); }
.pop-roman { font-size: .76rem; color: var(--muted); font-style: italic; margin-top: 3px; }
.pop-ticket { display: grid; grid-template-columns: repeat(9, 1fr); gap: 2px; margin: 4px 0 2px; }
.pop-ticket .pt-cell { aspect-ratio: 1 / 1; border-radius: 3px; display: grid; place-items: center; font-size: .5rem; font-weight: 700; }
.pt-cell.filled { background: var(--panel); border: 1px solid var(--stroke); color: var(--text); }
.pt-cell.blank { border: 1px dashed var(--stroke); opacity: .4; }
.pt-cell.lit { background: var(--ball-grad); color: #5b2a00; border-color: transparent; }
.win-names { cursor: help; }

/* ===================== LETTERHEAD (report) ===================== */
.lh { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; border-bottom: 3px double var(--stroke); padding-bottom: 10px; }
.lh-title { font-family: var(--font-fun); font-weight: 800; font-size: 1.1rem; color: var(--gold); }
.lh-site { color: var(--muted); font-size: .8rem; }
.lh-date { color: var(--muted); font-size: .82rem; white-space: nowrap; }
.report-game-title { text-align: center; font-family: var(--font-fun); font-size: 1.5rem; margin: 12px 0 8px; }
.report-foot { text-align: center; color: var(--muted); font-size: .74rem; margin-top: 16px; border-top: 1px solid var(--stroke); padding-top: 8px; }

/* ===================== REDUCED MOTION ===================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

/* ===================== SMALL SCREENS ===================== */
@media (max-width: 480px) {
  .brand-text h1 { font-size: 1.4rem; }
  .tagline { display: none; }
  .actions { gap: 8px; }
  .btn-primary { width: 100%; justify-content: center; }
  .consent-actions { width: 100%; }
  .consent-actions .btn { flex: 1; justify-content: center; padding: 13px 14px; }
  .icon-btn { width: 46px; height: 46px; }
}

/* Very narrow phones (e.g. iPhone SE, 320px): keep all 10 columns visible */
@media (max-width: 360px) {
  .board { gap: 2px; }
  .board-card { padding: 12px; }
  .cell { border-radius: 7px; }
}

/* Short / landscape viewports: keep the toast clear of the bottom controls */
@media (max-height: 520px) {
  .toast { top: 12px; bottom: auto; }
}

/* On phones, compress chrome + board + caller so BOTH cards fit at load */
@media (max-width: 899px) {
  /* header: smaller + tighter (single row) */
  .app-header { padding: 5px 9px; gap: 5px; flex-wrap: nowrap; }
  .brand-logo { font-size: 1.25rem; }
  .brand-text h1 { font-size: .98rem; }
  .header-controls { gap: 4px; }
  .icon-btn { width: 37px; height: 37px; font-size: .98rem; }
  .seg-btn { padding: 6px 8px; font-size: .72rem; }

  /* game bar: compact single row */
  .gamebar { padding: 0 8px 4px; gap: 4px; flex-wrap: nowrap; }
  .gamebar .btn, .gamebar .chip { font-size: .7rem; padding: 5px 7px; white-space: nowrap; }
  .gamebar .chip { max-width: 34vw; }

  #boardCard { padding: 7px 10px; }
  #boardCard .board { max-width: min(84vw, 300px); margin: 0 auto; }
  .board-head { margin-bottom: 4px; }
  .board-head h2 { font-size: .98rem; }

  /* compact caller so it sits under the board within one screen */
  #callerCard { padding: 8px 12px 10px; }
  .caller-top { margin-bottom: 2px; gap: 10px; }
  .stat-pill { padding: 3px 14px; }
  .stat-pill span { font-size: 1.1rem; }
  .ball-stage { margin: 2px 0 0; }
  .ball { width: clamp(78px, 13.5vh, 118px); height: clamp(78px, 13.5vh, 118px); }
  .ball-shadow { display: none; }
  .calls { min-height: 0; margin-top: 3px; }
  .commentary { min-height: 0; margin: 2px 0 6px; }
  .line-roman { display: none; }
  /* keep Pick + Repeat + Undo on a SINGLE compact row */
  .actions { margin: 0; flex-wrap: nowrap; gap: 7px; }
  .actions .btn-primary { width: auto; flex: 1 1 auto; font-size: 1rem; padding: 11px 16px; }
  .actions .btn-ghost { padding: 11px 14px; }
  .sub-actions { margin-top: 7px; gap: 8px; }
  .recent { display: none; }            /* board already shows called numbers */

  .winnings-list { max-height: none; }
  #winningsRail { max-height: 70vh; }
}

/* extra squeeze for short phones */
@media (max-width: 899px) and (max-height: 720px) {
  .ball { width: clamp(70px, 11.5vh, 100px); height: clamp(70px, 11.5vh, 100px); }
  #boardCard .board { max-width: min(88vw, 300px); }
  .sub-actions { margin-top: 5px; }
}

/* ===================== PRINT (report) ===================== */
@media print {
  body { background: #fff !important; color: #000 !important; }
  body > *:not(#reportBackdrop) { display: none !important; }
  #reportBackdrop { position: static !important; display: block !important; background: #fff !important; padding: 0 !important; }
  #reportBackdrop .modal { box-shadow: none !important; border: 0 !important; width: 100% !important; max-height: none !important; background: #fff !important; color: #000 !important; padding: 0 !important; animation: none !important; }
  .modal-x, #reportClose, #reportCloseBtn, #reportPrint { display: none !important; }
  .report-meta, .report-meta b, .report-section-title, .rw-name, .rw-items, .rw-total, .report-grand, .rg-amt { color: #000 !important; }
  .report-winner { border: 1px solid #999 !important; background: #fff !important; }
  .report-numbers span { background: #e8e8e8 !important; color: #000 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .lh-title, .lh-site, .lh-date, .report-game-title, .report-foot { color: #000 !important; }
  .lh { border-bottom: 3px double #000 !important; }
  .report-foot { border-top: 1px solid #999 !important; }
}
