/* ==========================================================================
   App3 — styles
   Theming via CSS custom properties on [data-theme]. Mobile-first layout.
   ========================================================================== */

:root,
[data-theme="light"] {
  --bg: #f4f5fb;
  --bg-grad: radial-gradient(1200px 600px at 10% -10%, #e0e7ff 0%, transparent 60%),
             radial-gradient(900px 500px at 110% 0%, #fce7f3 0%, transparent 55%);
  --surface: #ffffff;
  --surface-2: #f1f3f9;
  --surface-3: #e6e9f2;
  --text: #171a2b;
  --muted: #646a85;
  --border: #e2e5ef;
  --primary: #6366f1;
  --primary-2: #8b5cf6;
  --primary-soft: #eef0ff;
  --on-primary: #ffffff;
  --success: #16a34a;
  --success-soft: #dcfce7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warning: #d97706;
  --shadow: 0 1px 2px rgba(20, 24, 50, .05), 0 6px 20px rgba(20, 24, 50, .06);
  --shadow-lg: 0 20px 50px rgba(20, 24, 50, .18);
  --radius: 16px;
  --radius-sm: 10px;
  --chart-1: #6366f1;
  --chart-2: #22c55e;
  --sd-given: #171a2b;
  --sd-user: #4f46e5;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0e1020;
  --bg-grad: radial-gradient(1200px 600px at 10% -10%, rgba(99, 102, 241, .18) 0%, transparent 60%),
             radial-gradient(900px 500px at 110% 0%, rgba(236, 72, 153, .12) 0%, transparent 55%);
  --surface: #171a2e;
  --surface-2: #1f2340;
  --surface-3: #2a2f52;
  --text: #eceefe;
  --muted: #9aa0c3;
  --border: #2b3052;
  --primary: #818cf8;
  --primary-2: #a78bfa;
  --primary-soft: #262b55;
  --on-primary: #0e1020;
  --success: #4ade80;
  --success-soft: rgba(74, 222, 128, .14);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, .14);
  --warning: #fbbf24;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, .5);
  --chart-1: #818cf8;
  --chart-2: #4ade80;
  --sd-given: #eceefe;
  --sd-user: #a5b4fc;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg-grad), var(--bg);
  background-attachment: fixed;
  min-height: 100vh;
  transition: background-color .3s ease;
}
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .75rem; }
a { color: var(--primary); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; border-radius: 6px; }

.skip-link { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; border-radius: 8px; z-index: 100; }
.skip-link:focus { left: 8px; }

/* ---------------------------------------------------------------- topbar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 10px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 1.2rem; color: var(--text); text-decoration: none; }
.brand-mark {
  display: grid; place-items: center; width: 32px; height: 32px; border-radius: 10px;
  color: #fff; background: linear-gradient(135deg, var(--primary), var(--primary-2)); font-size: 16px;
}
.nav { display: flex; gap: 4px; margin-left: 8px; }
.nav a {
  display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 999px;
  color: var(--muted); text-decoration: none; font-weight: 600; font-size: .92rem;
  transition: background .2s, color .2s;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.nav-ico { font-size: 1rem; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.level-pill {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px;
  background: var(--surface-2); color: var(--text); text-decoration: none; font-weight: 700; font-size: .85rem;
}
.level-pill.pulse { animation: pulse .9s ease; }
.mini-bar { width: 64px; height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.mini-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), var(--primary-2)); transition: width .6s ease; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 1.05rem; cursor: pointer;
  transition: transform .15s, background .2s;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { transform: scale(.94); }

/* ------------------------------------------------------------- layout */
.container {
  max-width: 1120px; margin: 0 auto; padding: 20px 16px 96px;
  animation: fadeUp .35s ease both;
  outline: none;
}
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}
section.card, .container > .card { margin-bottom: 16px; }
.page-title { margin: 4px 0 16px; }
.section-title { margin: 24px 0 12px; }
.section-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.two-col { display: grid; grid-template-columns: 1fr; gap: 16px; }
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* ------------------------------------------------------------- controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; font-size: .95rem;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: transform .12s ease, background .2s, box-shadow .2s, opacity .2s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px) scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; border-color: transparent; box-shadow: 0 6px 16px rgba(99, 102, 241, .3); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn.danger.primary { background: var(--danger); color: #fff; box-shadow: none; }
.btn.small { padding: 6px 12px; font-size: .85rem; border-radius: 10px; }
.btn.active { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }

.input, .select {
  font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 12px; min-width: 0;
}
.input:focus, .select:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px var(--primary-soft); }

.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.slider { position: absolute; inset: 0; background: var(--surface-3); border-radius: 999px; transition: background .2s; cursor: pointer; }
.slider::before { content: ""; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(20px); }
.switch input:focus-visible + .slider { outline: 3px solid var(--primary); outline-offset: 2px; }

.chip { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .75rem; font-weight: 700; letter-spacing: .02em; }
.diff-easy { --d: #16a34a; }
.diff-medium { --d: #2563eb; }
.diff-hard { --d: #ea580c; }
.diff-expert { --d: #dc2626; }
.chip[class*="diff-"] { color: var(--d); background: color-mix(in srgb, var(--d) 14%, transparent); }

.progress { height: 10px; background: var(--surface-3); border-radius: 999px; overflow: hidden; flex: 1; min-width: 80px; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--primary), var(--primary-2)); border-radius: 999px; transition: width .8s cubic-bezier(.2, .8, .2, 1); }

.stat-tile { background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px; text-align: center; }
.stat-value { font-size: 1.35rem; font-weight: 800; }
.stat-label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }

.mode-icon {
  display: inline-grid; place-items: center; width: 52px; height: 52px; border-radius: 16px; font-size: 1.6rem;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.12); flex: none;
}
.mode-icon.sm { width: 38px; height: 38px; border-radius: 12px; font-size: 1.15rem; }
.mode-icon.xs { width: 26px; height: 26px; border-radius: 8px; font-size: .85rem; vertical-align: middle; }

.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 48px; color: var(--muted); }
.spinner { width: 20px; height: 20px; border: 3px solid var(--surface-3); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
.notice { background: var(--surface-2); border-left: 4px solid var(--warning); padding: 12px 14px; border-radius: 8px; }
.empty { text-align: center; padding: 24px 0; }

/* ------------------------------------------------------------- home */
.hero { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; margin-bottom: 16px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--primary) 10%, var(--surface)), var(--surface)); }
.hero-level {
  width: 96px; height: 96px; border-radius: 28px; flex: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: #fff; background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 12px 30px rgba(99, 102, 241, .35);
}
.hero-level-num { font-size: 2.3rem; font-weight: 900; line-height: 1; }
.hero-level-cap { font-size: .7rem; letter-spacing: .2em; font-weight: 700; opacity: .85; }
.hero-main { flex: 1; min-width: 240px; }
.xp-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 6px 0 14px; }
.hero-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }

.daily-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.daily-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: var(--surface-2); border-radius: 12px; transition: transform .2s; }
.daily-item:hover { transform: translateX(2px); }
.daily-item.done { opacity: .75; }
.daily-text { flex: 1; display: flex; flex-direction: column; gap: 2px; align-items: flex-start; }
.daily-check { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--success-soft); color: var(--success); font-weight: 900; }
.daily.complete { border-color: color-mix(in srgb, var(--success) 50%, var(--border)); }
.daily-done { margin: 12px 0 0; font-weight: 600; }
.streak { text-align: right; display: flex; flex-direction: column; }
.streak-num { font-size: 1.4rem; font-weight: 800; }

.mode-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
.mode-card {
  position: relative; text-align: left; font: inherit; color: inherit; cursor: pointer;
  display: flex; flex-direction: column; gap: 8px; overflow: hidden;
  transition: transform .2s ease, box-shadow .2s ease, border-color .2s;
}
.mode-card::after {
  content: ""; position: absolute; inset: auto -40px -60px auto; width: 160px; height: 160px; border-radius: 50%;
  background: var(--accent); opacity: .08; transition: transform .4s ease;
}
.mode-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
.mode-card:hover::after { transform: scale(1.3); }
.mode-card p { margin: 0; flex: 1; }
.mode-stats { color: var(--muted); }
.mode-play { font-weight: 700; color: var(--accent); }

/* ------------------------------------------------------------- picker */
.diff-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.diff-btn {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 14px; text-align: left;
  border-radius: 14px; border: 2px solid color-mix(in srgb, var(--d) 30%, var(--border));
  background: color-mix(in srgb, var(--d) 6%, var(--surface)); color: var(--text); font: inherit; cursor: pointer;
  transition: transform .15s, border-color .2s, background .2s;
}
.diff-btn:hover { transform: translateY(-2px); border-color: var(--d); }
.diff-name { font-weight: 800; color: var(--d); font-size: 1.05rem; }
.diff-meta { font-weight: 600; }

/* ------------------------------------------------------------- modal */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px;
  background: rgba(10, 12, 30, .5); opacity: 0; transition: opacity .2s ease;
}
.modal-overlay.in { opacity: 1; }
.modal {
  width: min(520px, 100%); max-height: calc(100vh - 32px); overflow: auto;
  background: var(--surface); border-radius: 20px; box-shadow: var(--shadow-lg); padding: 22px;
  transform: translateY(16px) scale(.97); transition: transform .25s cubic-bezier(.2, .9, .3, 1.2);
}
.modal-overlay.in .modal { transform: none; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }

.results { text-align: center; }
.results-emoji { font-size: 3.2rem; animation: pop .6s cubic-bezier(.2, .9, .3, 1.4) both; }
.results-sub { font-weight: 700; font-size: 1.1rem; }
.results-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 12px 0; }
.xp-breakdown { list-style: none; padding: 0; margin: 0 0 10px; text-align: left; }
.xp-breakdown li { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px dashed var(--border); }
.levelup-line { font-weight: 700; color: var(--primary); animation: pop .5s both; }

/* ------------------------------------------------------------- toasts */
.toasts { position: fixed; z-index: 60; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 10px; align-items: flex-end; pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; gap: 10px; align-items: flex-start; max-width: min(380px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-left: 4px solid var(--primary);
  border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow-lg); cursor: pointer;
  opacity: 0; transform: translateX(30px); transition: opacity .3s, transform .3s cubic-bezier(.2, .9, .3, 1.2);
}
.toast.in { opacity: 1; transform: none; }
.toast.out { opacity: 0; transform: translateY(10px); }
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.xp { border-left-color: var(--primary-2); }
.toast-icon { font-size: 1.3rem; }
.toast-body { display: flex; flex-direction: column; }
.toast-title { font-size: .95rem; }
.toast.achievement {
  border: none; color: #fff; padding: 14px 18px; align-items: center;
  background: linear-gradient(135deg, #f59e0b, #ec4899 55%, #8b5cf6);
  transform: translateY(40px) scale(.8);
}
.toast.achievement.in { transform: none; animation: achGlow 1.6s ease .3s; }
.toast.achievement .muted { color: rgba(255,255,255,.85); }
.ach-name { font-size: 1.1rem; font-weight: 800; }
.badge-burst { position: relative; width: 56px; height: 56px; flex: none; display: grid; place-items: center; }
.badge-burst::before {
  content: ""; position: absolute; inset: -6px; border-radius: 50%;
  background: conic-gradient(from 0deg, rgba(255,255,255,.0), rgba(255,255,255,.7), rgba(255,255,255,0) 30%, rgba(255,255,255,.7) 60%, rgba(255,255,255,0) 80%);
  animation: spin 2.4s linear infinite;
}
.badge-icon {
  position: relative; width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; font-size: 1.7rem;
  background: rgba(255,255,255,.95); animation: badgeIn .8s cubic-bezier(.2, .9, .3, 1.5) both .15s;
}

/* ------------------------------------------------------------- game screen */
.game-header { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; padding: 12px 14px; border-top: 4px solid var(--accent); }
.game-header .back { font-size: 1.2rem; padding: 6px 12px; }
.game-title { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 180px; }
.game-title h1 { font-size: 1.2rem; margin: 0; }
.game-sub { display: flex; gap: 8px; align-items: center; }
.game-actions { display: flex; align-items: center; gap: 8px; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; padding: 8px 12px; background: var(--surface-2); border-radius: 10px; min-width: 64px; text-align: center; }
.hint-count { display: inline-grid; place-items: center; min-width: 20px; height: 20px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-size: .75rem; padding: 0 5px; }
.game-area { animation: fadeUp .3s ease both; }
.kbd-help { margin-top: 8px; }

/* ------------------------------------------------------------- sudoku */
.sudoku-wrap { display: flex; flex-direction: column; gap: 16px; align-items: center; }
.sudoku-board {
  --size: min(92vw, 470px);
  width: var(--size); height: var(--size);
  display: grid; grid-template-columns: repeat(9, 1fr); grid-template-rows: repeat(9, 1fr);
  background: var(--surface); border: 3px solid var(--text); border-radius: 12px; overflow: hidden;
  box-shadow: var(--shadow); user-select: none; -webkit-user-select: none;
}
.sd-cell {
  display: grid; place-items: center; font-size: calc(var(--size) / 17); font-weight: 600;
  border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
  cursor: pointer; color: var(--sd-user); transition: background .12s; position: relative;
}
.sd-cell:nth-child(9n) { border-right: none; }
.sd-cell:nth-last-child(-n+9) { border-bottom: none; }
.sd-cell.br { border-right: 2px solid var(--text); }
.sd-cell.bb { border-bottom: 2px solid var(--text); }
.sd-cell.given { color: var(--sd-given); font-weight: 800; }
.sd-cell.peer { background: var(--surface-2); }
.sd-cell.same { background: color-mix(in srgb, var(--primary) 22%, var(--surface)); }
.sd-cell.selected { background: color-mix(in srgb, var(--primary) 35%, var(--surface)); }
.sd-cell.conflict { color: var(--danger); background: var(--danger-soft); }
.sd-cell.flash { animation: flash 1.2s ease; }
.sudoku-board.solved .sd-cell { animation: solvedWave .8s ease both; }
.sd-notes { display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; height: 100%; padding: 2px; }
.sd-notes span { font-size: calc(var(--size) / 42); color: var(--muted); display: grid; place-items: center; line-height: 1; font-weight: 600; }
.sudoku-side { width: min(92vw, 470px); display: flex; flex-direction: column; gap: 12px; }
.sd-tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.sd-pad { display: grid; grid-template-columns: repeat(9, 1fr); gap: 6px; }
.sd-num {
  display: flex; flex-direction: column; align-items: center; padding: 8px 0 4px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: 1.3rem; font-weight: 700; cursor: pointer;
  transition: transform .1s, background .2s;
}
.sd-num:hover { background: var(--primary-soft); }
.sd-num:active { transform: scale(.94); }
.sd-num small { font-size: .65rem; color: var(--muted); font-weight: 600; }
.sd-num.done { opacity: .4; }
.sd-info { text-align: center; }

/* ------------------------------------------------------------- memory */
.mem-wrap { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.mem-grid {
  display: grid; grid-template-columns: repeat(var(--cols), 1fr); gap: 10px;
  width: min(100%, calc(var(--cols) * 104px)); perspective: 1000px;
}
.mem-card { aspect-ratio: 1; border: none; padding: 0; background: none; cursor: pointer; border-radius: 14px; }
.mem-inner { position: relative; display: block; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform .45s cubic-bezier(.3, .8, .3, 1.1); }
.mem-card.flipped .mem-inner, .mem-card.matched .mem-inner { transform: rotateY(180deg); }
.mem-face {
  position: absolute; inset: 0; display: grid; place-items: center; border-radius: 14px;
  backface-visibility: hidden; -webkit-backface-visibility: hidden; box-shadow: var(--shadow);
}
.mem-back { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: rgba(255,255,255,.75); font-size: 1.6rem; font-weight: 900; }
.mem-front { background: var(--surface); border: 2px solid var(--border); transform: rotateY(180deg); padding: 14%; }
.mem-front .fig { width: 100%; height: 100%; }
.mem-card.matched .mem-front { border-color: var(--success); background: var(--success-soft); animation: matchPop .4s ease; }
.mem-card.matched { cursor: default; }
.mem-card.hint-glow .mem-back { box-shadow: 0 0 0 4px var(--warning), 0 0 24px var(--warning); animation: pulse 0.8s ease infinite; }
.mem-card.peek .mem-front { border-color: var(--warning); }

/* ------------------------------------------------------------- logic grid */
.lg-wrap { display: grid; grid-template-columns: 1fr; gap: 16px; align-items: start; }
.lg-grid-scroll { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); }
.lg-table { border-collapse: collapse; margin: 0 auto; user-select: none; -webkit-user-select: none; }
.lg-table th, .lg-table td { padding: 0; }
.lg-cat { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 4px; border-left: 2px solid var(--text); }
.lg-colhead { height: 84px; vertical-align: bottom; padding-bottom: 6px !important; font-size: .8rem; font-weight: 600; }
.lg-colhead.gstart { border-left: 2px solid var(--text); }
.vert { writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; display: inline-block; }
.lg-cat-row { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); border-top: 2px solid var(--text); width: 26px; }
.lg-rowhead { text-align: right; padding: 0 8px !important; font-size: .85rem; font-weight: 600; white-space: nowrap; }
tbody tr:first-child .lg-rowhead, .lg-table tr.gend + tr .lg-rowhead { border-top: 2px solid var(--text); }
.lg-cell {
  width: 34px; height: 34px; min-width: 34px; text-align: center; font-weight: 800; font-size: 1rem;
  border: 1px solid var(--border); cursor: pointer; transition: background .12s;
}
.lg-cell.gstart { border-left: 2px solid var(--text); }
tr.gend .lg-cell { border-bottom: 2px solid var(--text); }
tbody tr:first-child .lg-cell, tr.gend + tr .lg-cell { border-top: 2px solid var(--text); }
.lg-cell:last-child { border-right: 2px solid var(--text); }
.lg-cell:hover { background: var(--primary-soft); }
.lg-cell.no { color: var(--danger); }
.lg-cell.yes { color: var(--success); background: var(--success-soft); }
.lg-cell.flash { animation: flash 1.4s ease; }
.lg-void { border: none; }
.lg-table.solved .lg-cell.yes { animation: matchPop .5s ease; }
.lg-side h3 { margin-bottom: 8px; }
.lg-clues { margin: 0 0 12px; padding-left: 1.4rem; display: grid; gap: 6px; }
.lg-clues li { cursor: pointer; padding: 2px 4px; border-radius: 6px; transition: opacity .2s; }
.lg-clues li:hover { background: var(--surface-2); }
.lg-clues li.used { text-decoration: line-through; opacity: .45; }
.lg-controls { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.switch-label { display: flex; align-items: center; gap: 6px; font-size: .9rem; cursor: pointer; }

/* ------------------------------------------------------------- quiz */
.quiz { max-width: 760px; margin: 0 auto; }
.quiz.anim-in { animation: fadeUp .35s ease both; }
.quiz-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.quiz-progress { display: flex; gap: 6px; list-style: none; padding: 0; margin: 0; }
.quiz-progress li { width: 22px; height: 6px; border-radius: 999px; background: var(--surface-3); transition: background .3s; }
.quiz-progress li.cur { background: var(--primary); }
.quiz-progress li.ok { background: var(--success); }
.quiz-progress li.bad { background: var(--danger); }
.quiz-prompt { font-size: 1.2rem; margin-bottom: 14px; }
.quiz-stimulus { display: flex; justify-content: center; margin-bottom: 16px; }
.quiz-options { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.quiz-options.figs.n5, .quiz-options.figs.n6, .quiz-options.figs.n8, .quiz-options.figs.n9 { grid-template-columns: repeat(3, 1fr); }
.quiz-options.figs.n4 { grid-template-columns: repeat(2, 1fr); }
.quiz-options.nums { grid-template-columns: repeat(2, 1fr); }
.quiz-opt {
  position: relative; display: grid; place-items: center; min-height: 64px; padding: 12px;
  border: 2px solid var(--border); border-radius: 14px; background: var(--surface-2); color: var(--text);
  font: inherit; cursor: pointer; transition: transform .12s, border-color .2s, background .2s, opacity .2s;
}
.quiz-opt:hover:not(:disabled) { border-color: var(--primary); transform: translateY(-2px); }
.quiz-opt .fig { width: 100%; max-width: 92px; aspect-ratio: 1; height: auto; }
.quiz-opt.correct { border-color: var(--success); background: var(--success-soft); animation: matchPop .4s ease; }
.quiz-opt.wrong { border-color: var(--danger); background: var(--danger-soft); animation: shake .4s ease; }
.quiz-opt.eliminated { opacity: .2; filter: grayscale(1); }
.quiz-opt:disabled { cursor: default; }
.opt-key { position: absolute; top: 6px; left: 8px; font-size: .7rem; color: var(--muted); font-weight: 700; }
.seq-opt { font-size: 1.4rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.quiz-form { display: flex; gap: 8px; grid-column: 1 / -1; }
.quiz-input { flex: 1; font: inherit; font-size: 1.3rem; font-weight: 700; padding: 10px 14px; border-radius: 12px; border: 2px solid var(--border); background: var(--surface-2); color: var(--text); min-width: 0; }
.quiz-input:focus { outline: none; border-color: var(--primary); }
.quiz-input.correct { border-color: var(--success); background: var(--success-soft); }
.quiz-input.wrong { border-color: var(--danger); background: var(--danger-soft); }
.shake { animation: shake .4s ease; }
.quiz-bottom { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; min-height: 44px; flex-wrap: wrap; }
.quiz-feedback { flex: 1; font-weight: 600; }
.quiz-feedback.ok { color: var(--success); }
.quiz-feedback.bad { color: var(--danger); }

.seq-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.seq-tile {
  min-width: 56px; padding: 12px 10px; text-align: center; border-radius: 12px; background: var(--surface-2);
  font-size: 1.3rem; font-weight: 800; font-variant-numeric: tabular-nums; border: 2px solid var(--border);
}
.seq-tile.q, .fig-tile.q { border-style: dashed; border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }

.fig-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.fig-tile { width: 72px; height: 72px; padding: 8px; border-radius: 12px; background: var(--surface-2); border: 2px solid var(--border); display: grid; place-items: center; font-size: 1.8rem; font-weight: 900; }
.fig-tile .fig { width: 100%; height: 100%; }
.fig-tile.big { width: 150px; height: 150px; padding: 14px; }
.matrix { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.matrix .fig-tile { width: 84px; height: 84px; }

/* ------------------------------------------------------------- stats / tables */
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 12px; font-family: inherit; }
.chart .bar.s1 { fill: var(--chart-1); }
.chart .bar.s2 { fill: var(--chart-2); }
.chart .line { fill: none; stroke: var(--chart-1); stroke-width: 2.5; stroke-linejoin: round; }
.chart .area { fill: var(--chart-1); opacity: .12; }
.chart .dot { fill: var(--surface); stroke: var(--chart-1); stroke-width: 2; }
.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.data-table th, .data-table td { padding: 10px 8px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table thead th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; }
.data-table tbody tr:hover { background: var(--surface-2); }
.lb-filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.lb-table tr.podium td { font-weight: 700; }

/* ------------------------------------------------------------- achievements */
.ach-summary { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.ach-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.ach { display: flex; gap: 14px; align-items: center; transition: transform .2s; }
.ach:hover { transform: translateY(-2px); }
.ach-icon { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; font-size: 1.7rem; flex: none; background: var(--surface-2); }
.ach.unlocked .ach-icon { background: linear-gradient(135deg, #fde68a, #f9a8d4); box-shadow: 0 6px 18px rgba(245, 158, 11, .35); }
.ach.locked { opacity: .6; }
.ach.locked .ach-icon { filter: grayscale(1); }
.ach h3 { margin-bottom: 2px; }
.ach p { margin: 0; }
.ach-date { color: var(--success); font-weight: 600; }

/* ------------------------------------------------------------- settings */
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.set-row:last-child { border-bottom: none; }
.set-label { font-weight: 600; }
.settings .input { width: 200px; }

/* ------------------------------------------------------------- animations */
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pop { 0% { transform: scale(.4); opacity: 0; } 70% { transform: scale(1.15); opacity: 1; } 100% { transform: scale(1); } }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.08); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
@keyframes flash { 0% { background: color-mix(in srgb, var(--warning) 60%, transparent); } 100% { background: inherit; } }
@keyframes matchPop { 0% { transform: scale(1); } 50% { transform: scale(1.08); } 100% { transform: scale(1); } }
@keyframes solvedWave { 0% { background: var(--surface); } 50% { background: var(--success-soft); } 100% { background: var(--surface); } }
@keyframes badgeIn { 0% { transform: scale(0) rotate(-180deg); } 100% { transform: scale(1) rotate(0); } }
@keyframes achGlow { 0%, 100% { box-shadow: var(--shadow-lg); } 50% { box-shadow: 0 0 0 6px rgba(245, 158, 11, .35), var(--shadow-lg); } }

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

/* ------------------------------------------------------------- responsive */
@media (min-width: 640px) {
  .tiles { grid-template-columns: repeat(3, 1fr); }
  .hero-stats { grid-template-columns: repeat(4, 1fr); }
  .mode-grid { grid-template-columns: repeat(2, 1fr); }
  .ach-grid { grid-template-columns: repeat(2, 1fr); }
  .results-grid { grid-template-columns: repeat(4, 1fr); }
  .quiz-options.nums { grid-template-columns: repeat(4, 1fr); }
  .quiz-options.figs.n4 { grid-template-columns: repeat(4, 1fr); }
  .quiz-options.figs.n8 { grid-template-columns: repeat(4, 1fr); }
  .fig-tile { width: 88px; height: 88px; }
  .matrix .fig-tile { width: 100px; height: 100px; }
}
@media (min-width: 900px) {
  .tiles { grid-template-columns: repeat(6, 1fr); }
  .mode-grid { grid-template-columns: repeat(3, 1fr); }
  .ach-grid { grid-template-columns: repeat(3, 1fr); }
  .two-col { grid-template-columns: 1fr 1fr; }
  .sudoku-wrap { flex-direction: row; align-items: flex-start; justify-content: center; }
  .sudoku-side { width: 300px; }
  .sd-pad { grid-template-columns: repeat(3, 1fr); }
  .sd-num { padding: 14px 0 6px; font-size: 1.5rem; }
  .lg-wrap { grid-template-columns: auto 340px; justify-content: center; }
  .quiz-options.figs.n5 { grid-template-columns: repeat(5, 1fr); }
  .quiz-options.figs.n6 { grid-template-columns: repeat(6, 1fr); }
  .quiz-options.figs.n5 .quiz-opt, .quiz-options.figs.n6 .quiz-opt { min-height: 0; padding: 18px 8px 8px; }
}

/* Mobile: nav becomes a bottom tab bar. */
@media (max-width: 760px) {
  /* No backdrop-filter here: it would become the containing block of the fixed nav. */
  .topbar { gap: 8px; backdrop-filter: none; -webkit-backdrop-filter: none; background: var(--surface); }
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; margin: 0; justify-content: space-around;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
  }
  .nav a { flex-direction: column; gap: 0; padding: 4px 8px; font-size: .7rem; border-radius: 10px; }
  .nav-ico { font-size: 1.2rem; }
  .mini-bar { width: 40px; }
  .toasts { bottom: 84px; left: 16px; align-items: stretch; }
  .game-actions { width: 100%; justify-content: space-between; }
  .settings .input { width: 150px; }
}
@media (max-width: 420px) {
  .brand-name { display: none; }
  .lg-cell { width: 30px; height: 30px; min-width: 30px; }
  .mem-grid { gap: 6px; }
  .sd-pad { gap: 4px; }
}

/* Music volume slider (settings) */
#set-music-vol { width: 160px; max-width: 100%; accent-color: var(--accent, #6c5ce7); }
