/* ============ THEMES ============ */
/* 1. Bakery (original) */
:root, [data-theme="bakery"] {
  --bg: #FFF7EE;
  --ink: #2B2220;
  --muted: #8A7A70;
  --accent: #F08A2C;
  --accent-d: #C2611F;
  --accent-ink: #fff;
  --board: #F3E3CF;
  --board-img: none;
  --board-edge: #EBD6BD;
  --paper: #fff;
  --line: #EADBC8;
  --card: #fff;
  --hi: #FFEBD6;
  --radius: 22px;
  --r-btn: 14px;
  --r-num: 50%;
  --num-bg: var(--accent);
  --num-ink: #fff;
  --btn-shadow: 0 4px 0 var(--accent-d);
  --btn-border: 2px solid var(--line);
  --stage-shadow: inset 0 0 0 2px var(--board-edge), 0 8px 24px rgba(120, 70, 20, .08);
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, sans-serif;
  --head: var(--font);
  --head-weight: 800;
  --head-case: none;
  --head-track: -0.3px;
  --logo-a: #F08A2C;
  --logo-b: #FFB45C;
  --logo-stroke: #C2611F;
  --logo-word: var(--accent);
}

/* 2. Neon — dark arcade */
[data-theme="neon"] {
  --bg: #090D18;
  --ink: #EAF0FF;
  --muted: #7F8AAD;
  --accent: #7CF7D4;
  --accent-d: #39B897;
  --accent-ink: #06131A;
  --board: #0E1426;
  --board-img: linear-gradient(rgba(124, 247, 212, .05) 1px, transparent 1px), linear-gradient(90deg, rgba(124, 247, 212, .05) 1px, transparent 1px);
  --board-edge: #1D2745;
  --paper: #0E1426;
  --line: #1D2745;
  --card: #10182E;
  --hi: rgba(124, 247, 212, .12);
  --radius: 18px;
  --r-btn: 12px;
  --r-num: 8px;
  --num-bg: transparent;
  --num-ink: #7CF7D4;
  --btn-shadow: 0 0 28px rgba(124, 247, 212, .35);
  --btn-border: 1px solid #26335A;
  --stage-shadow: inset 0 0 0 1px #1D2745, 0 0 60px rgba(139, 92, 255, .12);
  --font: "Space Grotesk", system-ui, sans-serif;
  --head: "Space Grotesk", system-ui, sans-serif;
  --head-weight: 700;
  --head-track: -0.5px;
  --logo-a: #8B5CFF;
  --logo-b: #FF4FA3;
  --logo-stroke: transparent;
  --logo-word: #7CF7D4;
}

/* 3. Chalk — chalkboard in a wooden frame */
[data-theme="chalk"] {
  --bg: radial-gradient(ellipse at 30% 10%, #34433A 0%, #26302B 60%, #1F2823 100%);
  --ink: #F1EFE6;
  --muted: #A9B5AC;
  --accent: #F7C948;
  --accent-d: #C99A1C;
  --accent-ink: #26302B;
  --board: #2F3B34;
  --board-img: radial-gradient(ellipse at 25% 30%, rgba(255,255,255,.06), transparent 55%), radial-gradient(ellipse at 75% 80%, rgba(255,255,255,.04), transparent 50%);
  --board-edge: #9A6A42;
  --paper: #2F3B34;
  --line: rgba(241, 239, 230, .16);
  --card: rgba(255, 255, 255, .05);
  --hi: rgba(247, 201, 72, .14);
  --radius: 10px;
  --r-btn: 12px;
  --r-num: 50%;
  --num-bg: transparent;
  --num-ink: #F7C948;
  --btn-shadow: none;
  --btn-border: 2px solid rgba(241, 239, 230, .55);
  --stage-shadow: inset 0 0 0 8px #9A6A42, inset 0 0 0 10px #6E4528, inset 0 0 30px rgba(0,0,0,.45), 0 10px 26px rgba(0,0,0,.35);
  --font: "DM Sans", system-ui, sans-serif;
  --head: "Caveat", "Patrick Hand", cursive;
  --head-weight: 700;
  --head-track: 0.3px;
  --logo-a: #F1EFE6;
  --logo-b: #F7C948;
  --logo-stroke: transparent;
  --logo-word: #F7C948;
}
[data-theme="chalk"] h1, [data-theme="chalk"] .big { font-size: 34px; }
[data-theme="chalk"] .logo span { font-size: 40px; }
[data-theme="chalk"] .target strong, [data-theme="chalk"] .countdown { font-size: 44px; }
[data-theme="chalk"] .rules li::before { box-shadow: inset 0 0 0 2px #F7C948; font-size: 22px; }
[data-theme="chalk"] .btn { font-family: var(--head); font-size: 26px; padding: 9px; }
[data-theme="chalk"] .btn.primary { box-shadow: 0 0 0 2px #26302B inset; }
[data-theme="chalk"] .stage.paper { background-image: radial-gradient(rgba(241,239,230,.12) 1.3px, transparent 1.3px); }

/* 4. Candy — soft glass */
[data-theme="candy"] {
  --bg: linear-gradient(160deg, #FDE1F2 0%, #E6E0FF 50%, #D8F2FF 100%);
  --ink: #3B2A5C;
  --muted: #8C7DAD;
  --accent: #FF5FA2;
  --accent-d: #E0428A;
  --accent-ink: #fff;
  --board: rgba(255, 255, 255, .5);
  --board-img: none;
  --board-edge: rgba(255, 255, 255, .95);
  --paper: rgba(255, 255, 255, .75);
  --line: rgba(120, 90, 180, .16);
  --card: rgba(255, 255, 255, .65);
  --hi: rgba(255, 95, 162, .14);
  --radius: 30px;
  --r-btn: 999px;
  --r-num: 50%;
  --num-bg: linear-gradient(135deg, #FF8CC0, #A98BFF);
  --num-ink: #fff;
  --btn-shadow: 0 10px 24px rgba(255, 95, 162, .35);
  --btn-border: 1.5px solid rgba(255, 255, 255, .9);
  --stage-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .95), 0 18px 40px rgba(110, 80, 180, .15);
  --font: "Fredoka", ui-rounded, system-ui, sans-serif;
  --head: "Fredoka", ui-rounded, system-ui, sans-serif;
  --head-weight: 700;
  --head-track: 0;
  --logo-a: #FF8CC0;
  --logo-b: #A98BFF;
  --logo-stroke: #fff;
  --logo-word: #FF5FA2;
}

/* 5. Riso — printed paper */
[data-theme="riso"] {
  --bg: #F4EEE1;
  --ink: #1E2850;
  --muted: #6A6F8C;
  --accent: #FF5A4E;
  --accent-d: #1E2850;
  --accent-ink: #fff;
  --board: #FBF7EC;
  --board-img: repeating-linear-gradient(0deg, transparent 0 23px, rgba(47, 91, 234, .09) 23px 24px);
  --board-edge: #1E2850;
  --paper: #FBF7EC;
  --line: rgba(30, 40, 80, .18);
  --card: #FBF7EC;
  --hi: rgba(255, 90, 78, .14);
  --radius: 6px;
  --r-btn: 6px;
  --r-num: 50%;
  --num-bg: #2F5BEA;
  --num-ink: #fff;
  --btn-shadow: 4px 4px 0 #1E2850;
  --btn-border: 2px solid #1E2850;
  --stage-shadow: inset 0 0 0 2px #1E2850, 5px 5px 0 rgba(47, 91, 234, .35);
  --font: "DM Sans", system-ui, sans-serif;
  --head: "Fraunces", Georgia, serif;
  --head-weight: 900;
  --head-track: -0.5px;
  --logo-a: #2F5BEA;
  --logo-b: #FF5A4E;
  --logo-stroke: transparent;
  --logo-word: #FF5A4E;
}

/* ============ LAYOUT ============ */
* { box-sizing: border-box; }
html { background: var(--bg); background-attachment: fixed; min-height: 100%; }
body {
  margin: 0; color: var(--ink); font-family: var(--font);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
#app { max-width: 480px; margin: 0 auto; padding: 12px 18px 60px; }

.brand { display: flex; justify-content: center; padding: 6px 0 10px; position: relative; }
.style-btn {
  position: absolute; right: 0; top: 50%; transform: translateY(-50%); width: 40px; height: 40px; border-radius: 50%;
  border: var(--btn-border); background: var(--card); color: var(--ink); cursor: pointer; display: grid; place-items: center; padding: 0;
}
.style-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.style-btn svg circle { fill: currentColor; stroke: none; }
.style-panel {
  position: absolute; right: 0; top: calc(100% - 2px); z-index: 20; width: 210px; padding: 8px;
  background: var(--card); border: var(--btn-border); border-radius: calc(var(--r-btn) + 4px);
  box-shadow: 0 14px 36px rgba(0, 0, 0, .18); backdrop-filter: blur(14px);
}
[data-theme="candy"] .style-panel { background: rgba(255, 255, 255, .92); }
.style-panel button {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; border-radius: var(--r-btn);
  background: none; color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; text-align: left;
}
.style-panel button:hover { background: var(--hi); }
.style-panel button.on { background: var(--hi); }
.style-panel button.on::after { content: "✓"; margin-left: auto; color: var(--accent); font-weight: 800; }
.style-panel .sw { width: 22px; height: 22px; border-radius: 50%; flex: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.logo { display: flex; align-items: center; gap: 8px; background: none; border: 0; cursor: pointer; color: var(--ink); }
.logo svg { width: 34px; height: 34px; }
.logo .la { fill: var(--logo-a); stroke: var(--logo-stroke); stroke-width: 3; }
.logo .lb { fill: var(--logo-b); stroke: var(--logo-stroke); stroke-width: 3; }
.logo span { font-family: var(--head); font-size: 30px; font-weight: var(--head-weight); letter-spacing: var(--head-track); text-transform: var(--head-case); }
.logo b { color: var(--logo-word); font-weight: inherit; }

.screen { display: none; animation: fade .25s ease; }
.screen.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

h1 {
  font-family: var(--head); font-weight: var(--head-weight); letter-spacing: var(--head-track);
  text-transform: var(--head-case); font-size: 22px; margin: 8px 0 12px; text-align: center;
}
.big { font-family: var(--head); font-size: 26px; font-weight: var(--head-weight); text-transform: var(--head-case); text-align: center; margin: 10px 0 4px; }
.muted { color: var(--muted); text-align: center; margin: 4px 0; }
.label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 1.5px; text-align: center; margin: 14px 0 6px; font-weight: 700; }
.error { color: #E2443A; text-align: center; min-height: 1.2em; margin: 6px 0; font-size: 14px; }
.hint { text-align: center; color: var(--muted); min-height: 1.4em; margin: 12px 0; }
.hint.bad { color: #E2443A; animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

.rules { list-style: none; counter-reset: r; padding: 0; margin: 0 0 22px; }
.rules li { counter-increment: r; position: relative; padding: 11px 0 11px 46px; line-height: 1.45; border-bottom: 1px solid var(--line); }
.rules li:last-child { border-bottom: 0; }
.rules li::before {
  content: counter(r); position: absolute; left: 0; top: 10px; width: 30px; height: 30px; border-radius: var(--r-num);
  background: var(--num-bg); color: var(--num-ink); font-weight: 800; display: grid; place-items: center; font-family: var(--head);
}
[data-theme="neon"] .rules li::before { box-shadow: inset 0 0 0 1.5px #7CF7D4, 0 0 12px rgba(124, 247, 212, .35); }

.field {
  width: 100%; font: inherit; font-size: 18px; padding: 14px 16px; border-radius: var(--r-btn);
  border: var(--btn-border); background: var(--card); color: var(--ink); outline: none; text-align: center;
}
.field:focus { border-color: var(--accent); }
[data-theme="candy"] .field, [data-theme="candy"] .btn:not(.primary), [data-theme="candy"] .stat, [data-theme="candy"] .arch-card { backdrop-filter: blur(10px); }

.btn {
  display: block; width: 100%; font: inherit; font-size: 18px; font-weight: 800; padding: 15px;
  border-radius: var(--r-btn); border: var(--btn-border); background: var(--card); color: var(--ink); cursor: pointer;
  transition: transform .08s, opacity .2s, box-shadow .2s;
  text-transform: var(--head-case); letter-spacing: calc(var(--head-track) * .5);
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); box-shadow: var(--btn-shadow); }
[data-theme="bakery"] .btn.primary:active, :root:not([data-theme]) .btn.primary:active { box-shadow: 0 1px 0 var(--accent-d); transform: translateY(3px); }
[data-theme="riso"] .btn.primary { border-color: #1E2850; }
[data-theme="riso"] .btn.primary:active { box-shadow: 1px 1px 0 #1E2850; transform: translate(3px, 3px); }
[data-theme="candy"] .btn.primary { background: linear-gradient(135deg, #FF5FA2, #A98BFF); border-color: transparent; }
.btn:disabled { opacity: .4; cursor: default; }
.link { display: block; margin: 14px auto 0; background: none; border: 0; color: var(--muted); font: inherit; text-decoration: underline; cursor: pointer; }
.row { display: flex; gap: 10px; margin-top: 14px; }

.hud { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 10px; }
.target small { display: block; color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: 1.5px; text-transform: uppercase; }
.target strong { font-family: var(--head); font-size: 32px; font-weight: var(--head-weight); letter-spacing: var(--head-track); }
[data-theme="neon"] .target strong { color: #7CF7D4; text-shadow: 0 0 18px rgba(124, 247, 212, .5); }
.by { color: var(--muted); font-size: 14px; text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }

/* live "slices today" counter */
.live {
  display: flex; align-items: center; justify-content: center; gap: 8px; margin: 0 auto 4px; width: max-content;
  padding: 6px 14px; border-radius: 999px; background: var(--card); border: var(--btn-border);
  color: var(--ink); font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums;
}
.live.small { padding: 3px 10px; font-size: 13px; margin: 0; }
.live i { width: 8px; height: 8px; border-radius: 50%; background: #2FBF71; flex: none; animation: pulse 1.6s ease-in-out infinite; }
.live b { font-family: var(--head); }
.live .bump { display: inline-block; animation: bump .5s ease; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(47,191,113,.55); } 50% { box-shadow: 0 0 0 6px rgba(47,191,113,0); } }
@keyframes bump { 30% { transform: scale(1.35); color: var(--accent); } }
.live:has(.slices:empty) { visibility: hidden; }

.stage {
  width: 100%; aspect-ratio: 1; border-radius: var(--radius); overflow: hidden;
  background-color: var(--board); background-image: var(--board-img); background-size: 24px 24px;
  box-shadow: var(--stage-shadow);
}
[data-theme="candy"] .stage { backdrop-filter: blur(14px); }
.stage.paper {
  background-color: var(--paper);
  background-image: radial-gradient(var(--line) 1.3px, transparent 1.3px);
  background-size: 22px 22px;
}
canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.after { margin-top: 6px; }
.after .btn { margin-top: 14px; }

/* target split picker */
.target-pick { display: flex; align-items: center; justify-content: center; gap: 10px; font-family: var(--head); font-weight: var(--head-weight); }
.field.num { width: 110px; font-size: 30px; font-family: var(--head); font-weight: var(--head-weight); padding: 8px; -moz-appearance: textfield; }
.field.num::-webkit-inner-spin-button, .field.num::-webkit-outer-spin-button { -webkit-appearance: none; }
.slash { font-size: 30px; color: var(--muted); }
.other { font-size: 30px; min-width: 80px; text-align: center; }
input[type=range] { width: 100%; margin: 14px 0 0; accent-color: var(--accent); }

.countdown { font-family: var(--head); font-size: 46px; font-weight: var(--head-weight); text-align: center; margin: 0 0 22px; font-variant-numeric: tabular-nums; }

/* results */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.stat { background: var(--card); border: var(--btn-border); border-radius: var(--r-btn); padding: 10px 6px; text-align: center; }
[data-theme="candy"] .stat { border-radius: 20px; }
.stat b { display: block; font-size: 20px; font-family: var(--head); }
.stat span { color: var(--muted); font-size: 12px; }
table.board { width: 100%; border-collapse: collapse; margin: 8px 0 14px; font-variant-numeric: tabular-nums; }
table.board th { text-align: left; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; padding: 6px 4px; }
table.board td { padding: 9px 4px; border-top: 1px solid var(--line); }
table.board tr.first td { font-weight: 800; }
table.board tr.me td { background: var(--hi); }
table.board td.r { width: 28px; color: var(--muted); font-weight: 800; }
.you { text-align: center; background: var(--hi); border-radius: var(--r-btn); padding: 10px; margin: 10px 0; }
.legend { text-align: center; color: var(--muted); font-size: 13px; margin: 8px 0 0; }
.legend i { display: inline-block; width: 18px; height: 3px; background: var(--win, #2F6FE0); vertical-align: middle; margin-right: 4px; }

/* archive */
.arch { display: grid; gap: 10px; margin-bottom: 16px; }
.arch-card {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; font: inherit; color: var(--ink);
  background: var(--card); border: var(--btn-border); border-radius: var(--r-btn); padding: 10px; cursor: pointer;
}
[data-theme="candy"] .arch-card { border-radius: 22px; }
.arch-card canvas { width: 64px; height: 64px; flex: none; border-radius: calc(var(--r-btn) * .6); background: var(--board); }
.arch-card b { display: block; font-family: var(--head); font-size: 17px; }
.arch-card span { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }

/* floating local tools */
.float-btn { position: fixed; left: 10px; bottom: 10px; z-index: 10; font: 700 12px system-ui; padding: 7px 10px; border-radius: 8px; border: 0; background: #2B2220; color: #fff; opacity: .7; cursor: pointer; }
.float-btn.right { left: auto; right: 10px; opacity: .9; }
.float-panel { position: fixed; left: 10px; bottom: 48px; z-index: 10; background: #fff; color: #222; border: 2px solid #222; border-radius: 12px; padding: 10px; width: 220px; font: 14px system-ui; }
.float-panel.right { left: auto; right: 10px; }
.float-panel p { margin: 0 0 6px; }
.float-panel button { display: block; width: 100%; margin: 5px 0; padding: 8px; font: inherit; border-radius: 8px; border: 1px solid #ccc; background: #f6f6f6; cursor: pointer; text-align: left; }
.float-panel button.on { background: #222; color: #fff; border-color: #222; }
[data-theme="chalk"] .stage:not(.paper) { background-size: 100% 100%; }

/* link back to the Globie home page */
.home-link { display: inline-block; margin: 2px 0 0; color: var(--muted); text-decoration: none; font-weight: 700; font-size: 14px; }
.home-link:hover { color: var(--accent); }
