/* Thunderlark Classics - shared styles. Mobile-first; scales up to desktop. */
:root {
  --bg: #eef3fb; --bg2: #dfe9fb; --card: #ffffff; --card2: #f3f6fc; --text: #14213d; --muted: #5b6b8c;
  --line: #d3dcee; --shadow: 0 6px 18px rgba(20, 33, 61, .10);
  --accent: #2563eb; --accent-text: #1d4ed8; --accent-ink: #ffffff; --accent-soft: #dbeafe;
  --p1: #ef4444; --p2: #2563eb; --p1-soft: #fee2e2; --p2-soft: #dbeafe;
  --good: #16a34a; --warn: #f59e0b; --bad: #dc2626;
  --board: #1d4ed8; --radius: 16px; --tap: 48px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  color-scheme: light;
}
:root[data-palette="sunset"] { --accent: #c2410c; --accent-text: #9a3412; --accent-soft: #ffedd5; --bg: #fff4ea; --bg2: #ffe3cc; --board: #c2410c; }
:root[data-palette="forest"] { --accent: #15803d; --accent-text: #166534; --accent-soft: #dcfce7; --bg: #eef8f0; --bg2: #d6f0dc; --board: #15803d; }
:root[data-palette="berry"] { --accent: #a21caf; --accent-text: #86198f; --accent-soft: #fae8ff; --bg: #fbf0fd; --bg2: #f4d9fa; --board: #86198f; }
:root[data-theme="dark"] {
  --bg: #0f172a; --bg2: #172036; --card: #1b2540; --card2: #232f50; --text: #e8eefc; --muted: #9db0d6; --line: #34456f;
  --shadow: 0 6px 18px rgba(0, 0, 0, .4); --accent-soft: #1e3a6b; --p1-soft: #4b1d24; --p2-soft: #1e3a6b; color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #0f172a; --bg2: #172036; --card: #1b2540; --card2: #232f50; --text: #e8eefc; --muted: #9db0d6; --line: #34456f;
    --shadow: 0 6px 18px rgba(0, 0, 0, .4); --accent-soft: #1e3a6b; --p1-soft: #4b1d24; --p2-soft: #1e3a6b; color-scheme: dark;
  }
}
:root[data-theme="dark"][data-palette="sunset"], :root[data-theme="dark"][data-palette="forest"], :root[data-theme="dark"][data-palette="berry"] { --bg: #0f172a; --bg2: #172036; }
:root[data-theme="dark"][data-palette="sunset"] { --accent-soft: #5a2a0b; }
:root[data-theme="dark"][data-palette="forest"] { --accent-soft: #0f3d22; }
:root[data-theme="dark"][data-palette="berry"] { --accent-soft: #521a5a; }
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"][data-palette="sunset"] { --accent-soft: #5a2a0b; }
  :root[data-theme="auto"][data-palette="forest"] { --accent-soft: #0f3d22; }
  :root[data-theme="auto"][data-palette="berry"] { --accent-soft: #521a5a; }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font); color: var(--text); background: linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%) fixed;
  line-height: 1.4; -webkit-text-size-adjust: 100%; overscroll-behavior-y: none; touch-action: manipulation;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; }
.btn:disabled, .seg-btn:disabled, .tab:disabled { cursor: not-allowed; opacity: .55; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.2; }
p { margin: 0 0 .8em; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- app shell ---------- */
.app { max-width: 880px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; padding: 0 12px calc(20px + env(safe-area-inset-bottom)); }
.topbar { position: sticky; top: 0; z-index: 20; display: grid; grid-template-columns: var(--tap) 1fr var(--tap); align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 0 8px; margin: 0 -12px; padding-left: 12px; padding-right: 12px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); }
.topbar h1 { font-size: 1.15rem; margin: 0; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: var(--tap); height: var(--tap); border-radius: 14px; border: 1px solid var(--line); background: var(--card); box-shadow: var(--shadow); display: grid; place-items: center; font-size: 1.3rem; padding: 0; }
.icon-btn:active { transform: scale(.95); }
.icon-btn[hidden] { display: grid !important; visibility: hidden; }
.brand { display: inline-flex; align-items: center; gap: 8px; justify-content: center; }
.brand svg { width: 28px; height: 28px; }
main#view { flex: 1; padding-top: 6px; }

.btn { min-height: var(--tap); padding: 10px 18px; border-radius: 14px; border: 2px solid var(--line); background: var(--card); font-weight: 650; box-shadow: 0 2px 0 rgba(0,0,0,.06); transition: transform .08s, background .15s; }
@media (hover: hover) and (pointer: fine) { .btn:hover:not(:disabled) { background: var(--card2); } }
.btn:active:not(:disabled) { transform: translateY(1px) scale(.99); }
.btn.primary { background: var(--accent); border-color: var(--accent-text); color: var(--accent-ink); }
@media (hover: hover) and (pointer: fine) { .btn.primary:hover:not(:disabled) { filter: brightness(1.06); background: var(--accent); } }
.btn.big { width: 100%; font-size: 1.1rem; min-height: 54px; margin-top: 8px; }
.btn.small { min-height: 40px; padding: 6px 12px; font-size: .9rem; }
.row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; align-items: center; }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); max-width: 560px; margin: 8px auto; }
.field { margin: 14px 0; }
.field > label, .label { display: block; font-weight: 700; margin-bottom: 6px; font-size: .92rem; color: var(--muted); }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg-btn { flex: 1 1 auto; min-height: var(--tap); padding: 8px 12px; border-radius: 12px; border: 2px solid var(--line); background: var(--card2); font-weight: 650; }
.seg-btn.on { background: var(--accent); border-color: var(--accent-text); color: var(--accent-ink); }

input[type="text"], input[type="number"], select, textarea { font: inherit; color: var(--text); background: var(--card2); border: 2px solid var(--line); border-radius: 12px; padding: 10px 12px; min-height: var(--tap); width: 100%; }
input:focus-visible, select:focus-visible { outline: 3px solid var(--accent); border-color: var(--accent-text); }

/* ---------- hub ---------- */
.hero { text-align: center; padding: 8px 0 14px; }
.hero h2 { font-size: 1.6rem; margin-bottom: 2px; }
.hero p { color: var(--muted); margin: 0; }
.grid-games { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 620px) { .grid-games { grid-template-columns: repeat(3, 1fr); gap: 16px; } }
.game-card { position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; padding: 14px 10px 12px; min-height: 150px;
  background: var(--card); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); text-decoration: none; color: inherit; transition: transform .12s, box-shadow .12s; }
@media (hover: hover) and (pointer: fine) { .game-card:hover { transform: translateY(-3px); box-shadow: 0 10px 24px rgba(20,33,61,.16); } }
.game-card:active { transform: scale(.98); }
.game-card .gicon { width: 64px; height: 64px; }
.game-card .gname { font-weight: 800; font-size: 1.02rem; }
.game-card .gdesc { font-size: .8rem; color: var(--muted); }
.game-card .tag { margin-top: auto; font-size: .72rem; font-weight: 700; background: var(--accent-soft); color: var(--accent-text); padding: 2px 8px; border-radius: 99px; }
.unlock-slot { margin: 18px auto 4px; max-width: 560px; border: 2px dashed var(--line); border-radius: var(--radius); padding: 12px 14px; text-align: center; color: var(--muted); font-size: .9rem; }
.footer-note { text-align: center; font-size: .78rem; color: var(--muted); margin-top: 12px; }

/* ---------- game common ---------- */
.game { display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%; }
.status { min-height: 2.6em; display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 750; font-size: 1.05rem; text-align: center; }
.chip { display: inline-flex; align-items: center; justify-content: center; width: 1.5em; height: 1.5em; border-radius: 50%; font-weight: 900; color: #fff; font-size: .9em; }
.chip.p1 { background: var(--p1); } .chip.p2 { background: var(--p2); }
.scoreboard { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.score { min-width: 84px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 4px 10px; text-align: center; box-shadow: var(--shadow); }
.score-label { display: block; font-size: .72rem; color: var(--muted); font-weight: 700; }
.score-val { font-size: 1.25rem; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.x-mark { color: var(--p1); } .o-mark { color: var(--p2); }

.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(8, 15, 35, .55); display: grid; place-items: center; padding: 16px; backdrop-filter: blur(3px); }
.dialog { background: var(--card); border-radius: 22px; padding: 22px 20px; width: min(92vw, 380px); text-align: center; box-shadow: 0 20px 50px rgba(0,0,0,.35); }
.dialog .row { margin-top: 12px; }
.dialog-emoji { font-size: 3rem; line-height: 1; margin-bottom: 4px; }
.pop { animation: pop .28s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes pop { from { transform: scale(.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.cover { position: fixed; inset: 0; z-index: 60; background: linear-gradient(160deg, var(--accent), #0f172a); color: #fff; display: grid; place-items: center; text-align: center; padding: 24px; }
.cover h2 { font-size: 1.8rem; } .cover .btn { margin-top: 12px; }

/* ---------- Tic Tac Toe ---------- */
.ttt-board { display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); gap: 8px; width: min(92vw, 400px); aspect-ratio: 1; padding: 10px; background: var(--card); border-radius: 22px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.ttt-cell { border: 0; border-radius: 14px; background: var(--card2); font-size: clamp(2.4rem, 16vw, 4.4rem); font-weight: 900; display: grid; place-items: center; padding: 0; line-height: 1; }
@media (hover: hover) and (pointer: fine) { .ttt-cell:not(:disabled):hover { background: var(--accent-soft); } }
.ttt-cell.win { background: #fde68a; animation: pulse .7s ease-in-out 3; }
:root[data-theme="dark"] .ttt-cell.win { background: #6b5a14; }
.mark { display: inline-block; animation: pop .22s ease-out; font-family: "Trebuchet MS", var(--font); }
.mark.X { color: var(--p1); } .mark.O { color: var(--p2); }
@keyframes pulse { 50% { transform: scale(1.06); } }

/* ---------- Ultimate Tic Tac Toe ---------- */

/* ---------- Connect Four ---------- */
:root[data-theme="dark"] .c4-cell { background: #0b1226; }
@keyframes dropIn { from { transform: translateY(calc((var(--r) + 1.4) * -106%)); } to { transform: translateY(0); } }

/* ---------- Checkers ---------- */

/* ---------- Dots and Boxes ---------- */

/* ---------- Memory Match ---------- */
:root[data-theme="dark"] .mm-card.matched .mm-front { background: #14532d; }
@keyframes wiggle { 25% { transform: rotateY(180deg) translateX(-4px); } 75% { transform: rotateY(180deg) translateX(4px); } }

/* ---------- Simon ---------- */

/* ---------- Fleet Strike ---------- */

/* ---------- Dice ---------- */
.dice-app { width: 100%; max-width: 640px; display: flex; flex-direction: column; gap: 10px; }
.tray { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; }
.tray-dice { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; min-height: 72px; align-items: center; padding: 6px 0; }
.tray-total { text-align: center; }
.tray-total .big-num { font-size: 3rem; font-weight: 900; line-height: 1; color: var(--accent-text); }
.tray-total .detail { font-size: .85rem; color: var(--muted); word-break: break-word; }
.tray-note { text-align: center; font-weight: 700; min-height: 1.4em; }
.roll-row { display: flex; gap: 10px; }
.roll-row .btn.primary { flex: 1; font-size: 1.25rem; min-height: 58px; }
.dgroup { display: flex; flex-direction: column; align-items: center; gap: 6px; width: 100%; }
.dgroup .chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.dgroup.dim { opacity: .5; }
.dgroup .note { font-weight: 700; font-size: .85rem; color: var(--muted); }
.konst { font-size: 1.3rem; color: var(--muted); }
code { background: var(--card2); padding: 1px 5px; border-radius: 6px; font-size: .9em; }
.tabs { display: flex; gap: 6px; }
.tab { flex: 1; min-height: 44px; border: 2px solid var(--line); background: var(--card2); border-radius: 12px; font-weight: 700; }
.tab.on { background: var(--accent); border-color: var(--accent-text); color: var(--accent-ink); }
.picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.pick { background: var(--card2); border: 2px solid var(--line); border-radius: 14px; padding: 6px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.pick.has { border-color: var(--accent-text); background: var(--accent-soft); }
.pick .nm { font-weight: 800; }
.pick .sub { font-size: .65rem; color: var(--muted); margin-top: -4px; }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button { width: 36px; height: 36px; border-radius: 10px; border: 2px solid var(--line); background: var(--card); font-weight: 900; font-size: 1.1rem; padding: 0; }
.stepper b { min-width: 1.4em; text-align: center; }
.opts { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.opts label.chk { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; font-weight: 600; }
.opts input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent-text); }
.opts input[type="number"], .opts select { width: auto; min-width: 64px; }
.note { font-size: .82rem; color: var(--muted); }
.notation-hint { font-size: .8rem; color: var(--muted); }
.notation-err { color: var(--bad); font-weight: 700; min-height: 1.3em; font-size: .9rem; }
.preset-list { display: grid; gap: 8px; }
.preset { display: flex; align-items: center; gap: 8px; background: var(--card2); border: 2px solid var(--line); border-radius: 14px; padding: 8px 10px; }
.preset .pbody { flex: 1; text-align: left; border: 0; background: none; padding: 4px; min-height: 44px; }
.preset .pbody b { display: block; } .preset .pbody span { font-size: .8rem; color: var(--muted); font-family: ui-monospace, Menlo, monospace; }
.hist { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; max-height: 300px; overflow: auto; }
.hist li { display: flex; justify-content: space-between; gap: 8px; background: var(--card2); border-radius: 10px; padding: 6px 10px; font-size: .88rem; }
.hist li b { color: var(--accent-text); }
.histo { display: flex; align-items: flex-end; gap: 2px; height: 120px; padding: 6px 0 0; border-bottom: 2px solid var(--line); }
.histo .bar { flex: 1; min-width: 4px; background: var(--accent); border-radius: 4px 4px 0 0; position: relative; }
.histo .bar span { position: absolute; top: -1.2em; left: 50%; transform: translateX(-50%); font-size: .6rem; color: var(--muted); }
.histo .bar i { position: absolute; left: 0; right: 0; bottom: 0; border-top: 3px solid var(--warn); }
.histo-axis { display: flex; justify-content: space-between; font-size: .7rem; color: var(--muted); }
.stats-line { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; font-size: .85rem; margin: 8px 0; }
.help-line { font-size: .78rem; color: var(--muted); text-align: center; }
.yz { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.yz span { background: var(--accent-soft); color: var(--accent-text); font-weight: 700; padding: 2px 10px; border-radius: 99px; font-size: .8rem; }

/* ---------- settings ---------- */
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch { width: 56px; height: 56px; border-radius: 16px; border: 3px solid transparent; background: var(--sw); display: grid; place-items: center; color: #fff; font-weight: 900; padding: 0; }
.swatch.on { border-color: var(--text); box-shadow: 0 0 0 3px var(--card) inset; }
.switch { display: flex; justify-content: space-between; align-items: center; min-height: var(--tap); gap: 12px; }
.switch input { width: 28px; height: 28px; accent-color: var(--accent-text); }

@media (min-width: 700px) {
  .topbar h1 { font-size: 1.3rem; }
  .die { width: 66px; height: 66px; font-size: 1.5rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

/* dark-mode accent text colours (AA on dark cards) */
:root[data-theme="dark"] { --accent-text: #93c5fd; }
:root[data-theme="dark"][data-palette="sunset"] { --accent-text: #fdba74; }
:root[data-theme="dark"][data-palette="forest"] { --accent-text: #86efac; }
:root[data-theme="dark"][data-palette="berry"] { --accent-text: #f0abfc; }
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] { --accent-text: #93c5fd; }
  :root[data-theme="auto"][data-palette="sunset"] { --accent-text: #fdba74; }
  :root[data-theme="auto"][data-palette="forest"] { --accent-text: #86efac; }
  :root[data-theme="auto"][data-palette="berry"] { --accent-text: #f0abfc; }
}
