/* One centered play column: header, mode bar, the board, controls, then the rules.
   Light and dark follow the phone's setting. Dark uses BettrBall's colors. */
:root {
  --bg: #f3f5f2;
  --surface: #ffffff;
  --text: #0f1712;
  --muted: #5b6a61;
  --line: #d6ddd8;
  --grid: #1b2420;
  --thin: rgba(27, 36, 32, 0.22);
  --accent: #14a862;
  --accent-ink: #04210f;
  --bad: #e5383b;
  --bad-tint: rgba(229, 56, 59, 0.18);
  --halo: rgba(255, 255, 255, 0.9);
  --mark: #1b2420;
  --shadow: rgba(15, 23, 18, 0.12);
  /* Region colors; puzzle.js PALETTE_SIZE must match the count */
  --r1: #e9f28c; --r2: #dcdcdc; --r3: #c4b9a3; --r4: #b6e0a2; --r5: #bea6e6;
  --r6: #ffc88f; --r7: #ff8a6e; --r8: #96bdff; --r9: #f7a8d3; --r10: #8fded5;
  --display: "Bricolage Grotesque", "Arial Rounded MT Bold", system-ui, sans-serif;
  --body: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0e13; --surface: #111821; --text: #e8eef5; --muted: #8a99ab; --line: #233042;
    --grid: #05080b; --thin: rgba(5, 8, 11, 0.35); --accent: #1fd17a; --accent-ink: #04210f;
    --bad: #e0202a; --bad-tint: rgba(255, 90, 95, 0.22); --halo: rgba(255, 255, 255, 0.92); --mark: #0b1014; --shadow: rgba(0, 0, 0, 0.5);
    --r1: #cfd96f; --r2: #b9bec4; --r3: #a99d87; --r4: #95c681; --r5: #a48ed0;
    --r6: #e8ad72; --r7: #e9765c; --r8: #7ea5e8; --r9: #dc8db9; --r10: #73c4ba;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg); color: var(--text); font-family: var(--body); font-size: 15px; line-height: 1.5;
  padding-top: max(20px, env(safe-area-inset-top, 0px));
  padding-bottom: max(40px, env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  touch-action: manipulation;
  -webkit-user-select: none; user-select: none;
}
.app { max-width: 520px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }

header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand svg { width: 38px; height: 38px; }
.brand h1 { font-family: var(--display); font-weight: 800; font-size: 26px; letter-spacing: -0.02em; margin: 0; line-height: 1; }
.brand h1 span { color: var(--accent); }
.timer { font-family: var(--display); font-weight: 600; font-size: 22px; font-variant-numeric: tabular-nums; color: var(--muted); }
.timer.done { color: var(--accent); }

.bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; min-height: 38px; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.seg button {
  font: 600 13px var(--body); color: var(--muted); background: none; border: 0; border-radius: 999px;
  padding: 6px 13px; cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--text); color: var(--bg); }
.label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; }

.board-wrap { position: relative; }
.board {
  display: grid; width: 100%; aspect-ratio: 1; max-width: 100%;
  border: 3px solid var(--grid); border-radius: 6px; overflow: hidden;
  touch-action: none;
  box-shadow: 0 10px 30px var(--shadow);
}
.cell {
  position: relative; display: grid; place-items: center; cursor: pointer;
  border-top: 1px solid var(--thin); border-left: 1px solid var(--thin);
  -webkit-tap-highlight-color: transparent;
}
/* Thick lines where two color regions meet */
.cell.tt { border-top: 3px solid var(--grid); }
.cell.tl { border-left: 3px solid var(--grid); }
.cell.r0 { border-top: 0; }
.cell.c0 { border-left: 0; }
.cell svg { width: 82%; height: 82%; pointer-events: none; }
.cell .x { width: 30%; height: 30%; }
.cell .x path { stroke: var(--mark); stroke-width: 3.2; stroke-linecap: round; }
/* Red X with a light halo so it reads on every region color, red and orange included */
.cell.bad::after {
  content: ""; position: absolute; inset: 0; margin: 28%; pointer-events: none;
  background:
    linear-gradient(to top right, transparent calc(50% - 1.5px), var(--bad) calc(50% - 1.5px), var(--bad) calc(50% + 1.5px), transparent calc(50% + 1.5px)),
    linear-gradient(to bottom right, transparent calc(50% - 1.5px), var(--bad) calc(50% - 1.5px), var(--bad) calc(50% + 1.5px), transparent calc(50% + 1.5px)),
    linear-gradient(to top right, transparent calc(50% - 3.5px), var(--halo) calc(50% - 3.5px), var(--halo) calc(50% + 3.5px), transparent calc(50% + 3.5px)),
    linear-gradient(to bottom right, transparent calc(50% - 3.5px), var(--halo) calc(50% - 3.5px), var(--halo) calc(50% + 3.5px), transparent calc(50% + 3.5px));
}
.cell.bad.has-x .x { display: none; }
.cell.bad-logo { background-image: linear-gradient(var(--bad-tint), var(--bad-tint)); }
.cell.bad-logo::after { content: ""; position: absolute; inset: 3px; border: 3px solid var(--bad); border-radius: 6px; pointer-events: none; }
.cell.pop svg.logo { animation: pop 0.22s ease-out; }
@keyframes pop { from { transform: scale(0.5); } to { transform: scale(1); } }
.board.won .cell svg.logo { animation: win 0.6s ease-out both; }
@keyframes win { 0% { transform: scale(1); } 40% { transform: scale(1.25) rotate(-8deg); } 100% { transform: scale(1); } }
.cell:focus-visible { outline: 3px solid var(--text); outline-offset: -3px; z-index: 1; }

.status { min-height: 22px; font-size: 14px; color: var(--muted); text-align: center; }
.status.err { color: var(--bad); font-weight: 600; }

.controls { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.btn {
  font: 600 14px var(--body); color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 8px; cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn:focus-visible, .seg button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: 0.4; cursor: default; }

.rules { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; }
.rules h2 { font-family: var(--display); font-size: 18px; margin: 0 0 8px; }
.rules ul { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.rules .key { display: inline-flex; align-items: center; gap: 6px; vertical-align: middle; }
.rules .key svg { width: 18px; height: 18px; }

/* Start screen: the board keeps its size but shows nothing until the player starts */
.board.covered { background: var(--surface); }
.board.covered > .cell { visibility: hidden; }
.start { position: absolute; inset: 0; display: grid; place-items: center; padding: 16px; }
.start-card { display: grid; gap: 12px; text-align: center; max-width: 280px; width: 100%; }
.start-card svg { width: 72px; height: 72px; margin: 0 auto; }
.start-card h3 { font-family: var(--display); font-weight: 800; font-size: 28px; margin: 0; }
.start-card p { margin: 0; color: var(--muted); }
.start-card .btn { font-size: 16px; padding: 14px; }

.win {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 16px;
  background: color-mix(in srgb, var(--bg) 55%, transparent);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
}
.win-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 22px;
  text-align: center; box-shadow: 0 20px 50px var(--shadow); max-width: 300px; width: 100%;
  display: grid; gap: 10px; animation: rise 0.35s ease-out;
}
@keyframes rise { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }
.win-card svg { width: 56px; height: 56px; margin: 0 auto; }
.win-card h3 { font-family: var(--display); font-weight: 800; font-size: 26px; margin: 0; }
.win-card p { margin: 0; color: var(--muted); }
.win-card .t { font-family: var(--display); font-size: 40px; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; line-height: 1.1; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }

/* ---------- Leagues tab ---------- */
.play { display: contents; }
.leagues { display: flex; flex-direction: column; gap: 16px; }
.lg-card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; display: grid; gap: 10px; }
.lg-card h2, .lg-head h2 { font-family: var(--display); font-weight: 800; font-size: 22px; margin: 0; letter-spacing: -0.01em; text-wrap: balance; }
.lg-card h3 { font-family: var(--display); font-size: 17px; margin: 4px 0 0; }
.lg-card p { margin: 0; }
.lg-eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 700; }
.lg-daily { border-color: var(--accent); box-shadow: 0 6px 20px var(--shadow); }
.lg-done { font-size: 18px; }
.lg-done b { font-family: var(--display); color: var(--accent); font-size: 26px; font-variant-numeric: tabular-nums; }
.lg-fine { font-size: 13px; color: var(--muted); margin: 0; }
.lg-note { background: color-mix(in srgb, var(--accent) 14%, transparent); border-radius: 8px; padding: 8px 10px; }
.lg-msg { font-size: 14px; margin: 0; min-height: 0; }
.lg-msg:empty { display: none; }
.lg-msg.err { color: var(--bad); font-weight: 600; }
.lg-msg.ok { color: var(--accent); font-weight: 600; }
.lg-loading { color: var(--muted); text-align: center; padding: 24px 0; }
.lg-section { display: grid; gap: 10px; }
.lg-h { font-family: var(--display); font-size: 18px; margin: 0; }
.lg-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.lg-actions .btn { flex: 1 1 140px; }
.btn.danger { color: var(--bad); }
.lg-link { background: none; border: 0; padding: 0; font: 600 14px var(--body); color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; justify-self: start; }
.lg-link.danger { color: var(--bad); }
.lg-back { background: none; border: 0; padding: 0; font: 600 14px var(--body); color: var(--muted); cursor: pointer; justify-self: start; align-self: flex-start; }
.lg-tabs { justify-self: start; }

.lg-form { display: grid; gap: 10px; }
.lg-form label { display: grid; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
.lg-form input:not([type="radio"]), .lg-form select {
  font: 500 16px var(--body); color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; width: 100%; min-width: 0;
}
.lg-form input:focus-visible, .lg-form select:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
.lg-inline { grid-template-columns: 1fr auto; align-items: end; }
.lg-inline label { grid-column: 1 / -1; }
.lg-inline .btn { grid-column: auto; }
.lg-choice { border: 0; padding: 0; margin: 0; display: grid; gap: 8px; }
.lg-choice legend { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.lg-choice label { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; cursor: pointer; }
.lg-choice label:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.lg-choice input { margin-top: 3px; accent-color: var(--accent); }
.lg-choice b { display: block; }

.lg-list, .lg-people, .lg-matchups { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.lg-row { width: 100%; text-align: left; display: grid; gap: 2px; background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; cursor: pointer; font: inherit; }
.lg-row:hover { border-color: var(--muted); }
.lg-row-name { font-weight: 700; font-size: 16px; }
.lg-row-meta { font-size: 13px; color: var(--muted); }
.lg-head { display: grid; gap: 6px; }
.lg-season-pick { font-size: 13px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.lg-season-pick select { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; }

.lg-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.lg-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 14px; }
.lg-table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 700; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.lg-table td { padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.lg-table tr:last-child td { border-bottom: 0; }
.lg-table tr.me td { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.lg-table tr.win td:first-child { font-weight: 700; }
.lg-week td:first-child { white-space: normal; }
.lg-pen { color: var(--bad); }
.lg-dim { color: var(--muted); }
.lg-badge { display: inline-block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--accent-ink); background: var(--accent); border-radius: 999px; padding: 1px 7px; vertical-align: 1px; }

.lg-matchups li { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.lg-matchups b { font-variant-numeric: tabular-nums; margin-left: 4px; }
.lg-matchups .won { font-weight: 700; color: var(--accent); }
.lg-vs { color: var(--muted); font-size: 12px; text-transform: uppercase; }
.lg-people li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.lg-people li:last-child { border-bottom: 0; }
.lg-code { font-family: var(--display); font-size: 24px; letter-spacing: 0.12em; }
.lg-url { word-break: break-all; }
.lg-preview { border-top: 1px solid var(--line); padding-top: 12px; display: grid; gap: 8px; }
.lg-week th, .lg-week td { padding-left: 6px; padding-right: 6px; font-size: 13px; }
.lg-week td:first-child { min-width: 64px; }

/* ---------- Admin tab ---------- */
.ad-top { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.ad-nav { flex-wrap: wrap; }
.ad-meta { display: flex; gap: 10px; align-items: center; font-size: 13px; color: var(--muted); }
.ad-refresh { padding: 6px 12px; font-size: 13px; }
.ad-count { display: inline-block; font-size: 11px; font-weight: 700; background: var(--line); color: var(--text); border-radius: 999px; padding: 0 6px; margin-left: 2px; }
.ad-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.ad-tile { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: grid; gap: 2px; align-content: start; min-width: 0; }
.ad-tile-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.ad-tile-value { font-family: var(--display); font-weight: 800; font-size: 26px; font-variant-numeric: tabular-nums; }
.ad-tile-sub { font-size: 12px; color: var(--muted); }
.ad-table td { vertical-align: top; }
.ad-wrap { white-space: normal !important; min-width: 120px; }
.ad-sub { font-size: 12px; color: var(--muted); }
.ad-click { cursor: pointer; }
.ad-click:hover td { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.ad-subrow td { white-space: normal; background: var(--bg); }
.ad-chip { display: inline-block; border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; margin: 3px 6px 3px 0; font-size: 13px; }
.ad-code { letter-spacing: 0.08em; }
.app:has(#admin:not([hidden])) { max-width: 1000px; }
.win-card .win-hints { font-weight: 600; color: var(--accent); }
.win-card .win-hints.used { color: var(--muted); }
.win-card .win-hints:empty { display: none; }
