/* Solodoku — pastel puzzle UI. Slate neutrals, System/Light/Dark. */

:root {
  --bg: #f7f1ec;
  --surface: #ffffff;
  --surface-2: #f1e9e2;
  --text: #4a3f3a;
  --text-muted: #9b8d85;
  --accent: #8b6f5e;
  --primary: #3b82f6;
  --danger: #e11d48;
  --ok: #10b981;
  --shadow: 0 2px 10px rgba(90, 70, 60, .10);
  --radius: 18px;
  --cell-filter: none;
  /* overridden per-device in JS (applyFont, main.js) from the font/fontSize
     settings — kept as real custom properties, not inline styles per
     element, so every rule that already references font-family/size
     inherits the current choice for free. */
  --font-family: ui-rounded, "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-size: 16px;
}
.dark {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #283548;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --accent: #cbd5e1;
  --shadow: 0 2px 12px rgba(0, 0, 0, .45);
  /* keep saturation up in dark mode — muddy cells make regions hard to tell apart */
  --cell-filter: brightness(.85) saturate(.95);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; user-select: none; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-family);
  font-size: var(--font-size);
  min-height: 100vh;
}

.icon { display: inline-flex; width: 22px; height: 22px; }
.icon svg { width: 100%; height: 100%; }

/* ---------- header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(8px);
}
.topbar-left { display: flex; align-items: center; gap: 10px; position: relative; }
.topbar-fill { flex: 1; }
.app-logo { color: var(--accent); width: 30px; height: 30px; }
.app-name { font-weight: 800; letter-spacing: .12em; cursor: pointer; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border: none; border-radius: 50%;
  background: var(--surface); color: var(--text); cursor: pointer;
  box-shadow: var(--shadow); font-size: 15px;
}
.icon-btn:active { transform: scale(.94); }

.menu-dropdown {
  position: absolute; top: 46px; left: 0; z-index: 60;
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow);
  padding: 6px; min-width: 170px; display: flex; flex-direction: column;
}
.menu-dropdown.hidden { display: none; }
.menu-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border: none; background: none; color: var(--text);
  font: inherit; border-radius: 10px; cursor: pointer; text-align: left;
}
.menu-item:hover { background: var(--surface-2); }

/* ---------- screens ---------- */
.screen { max-width: 560px; margin: 0 auto; padding: 8px 14px 20px; }
.screen-head { display: flex; align-items: center; gap: 12px; margin: 8px 0 14px; }
.screen-head h2 { margin: 0; font-size: 20px; }
.muted { color: var(--text-muted); }
.small { font-size: 13px; }

.home { display: flex; flex-direction: column; gap: 14px; }
.card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 18px; cursor: pointer;
  display: flex; flex-direction: column; gap: 6px;
  position: relative;
  min-height: 140px;
}
/* .card:active { transform: scale(.985); } */
.card-title { font-weight: 700; font-size: 17px; }
.pill {
  align-self: flex-start; padding: 4px 12px; border-radius: 999px;
  background: var(--surface-2); font-size: 13px; font-weight: 600;
}
.pill.done { background: color-mix(in srgb, var(--ok) 18%, var(--surface-2)); color: var(--ok); }
.progress-track { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.progress-fill { height: 100%; border-radius: 3px; background: var(--ok); }
/* No fixed deadline once "no limit" is active, so a percentage-of-timeout
   fill is meaningless — swap to an indeterminate sliding bar instead. */
.progress-fill.indeterminate { width: 30% !important; animation: progress-indeterminate 1.2s ease-in-out infinite; }
@keyframes progress-indeterminate {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(333%); }
}
.random-card { cursor: default; }
.random-sizes { display: flex; gap: 8px; flex-wrap: wrap; }
.random-diffs { display: flex; gap: 6px; flex-wrap: wrap; }
.play-card, .daily-card, .random-card { cursor: default; }
/* Daily's content (title, date, one status line) is much shorter than the
   campaign/random cards (which need 140px for their extra pill/button
   rows) — the shared min-height left a lot of visibly empty space below. */
.daily-card { min-height: 0; }
.play-main { display: block; }
.play-left { display: flex; flex-direction: column; gap: 6px; padding-right: 48px; }
.play-left .card-title { white-space: nowrap; }
.play-btn {
  position: absolute;
  top: 16px;
  right: 18px;
  width: 40px; height: 40px; border-radius: 50%; border: none;
  background: var(--primary); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 3px 10px color-mix(in srgb, var(--primary) 45%, transparent);
}
.play-btn:active { transform: scale(.93); }
.play-icon { width: 22px; height: 22px; }
.play-icon svg { width: 100%; height: 100%; }
.title-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pill-inline {
  padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); font-size: 12px; font-weight: 600;
  color: var(--text-muted);
}
.very-small { font-size: 11.5px; }
/* label sits on its own line above its pill row, not squeezed in beside it */
.picker-label { display: block; margin-bottom: 6px; }
.jump-row {
  display: flex; gap: 6px; flex-wrap: wrap;
  margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--surface-2);
}
.jump-row .picker-label { flex-basis: 100%; margin-bottom: 0; }
.jump-row .btn.current { outline: 2px solid var(--primary); }
/* selection pills must not bounce: the press just re-renders, so a scale
   animation reads as an unrelated twitch */
.diff-btn, .size-btn { transition: none; }
.diff-btn:active, .size-btn:active { transform: none; }

.level-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 8px;
}
.level-btn {
  aspect-ratio: 1; border: none; border-radius: 12px;
  background: var(--surface); box-shadow: var(--shadow); color: var(--text);
  font: inherit; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.level-btn.solved { background: color-mix(in srgb, var(--ok) 20%, var(--surface)); color: var(--ok); }
.small-check { width: 18px; height: 18px; }

/* ---------- game ---------- */
.game { display: flex; flex-direction: column; gap: 12px; padding-bottom: 90px; }
.game-titles { flex: 1; display: flex; flex-direction: column; }
.game-titles h2 { margin: 0; font-size: 18px; }
.game-stats { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.timer { font-variant-numeric: tabular-nums; color: var(--text-muted); font-size: 14px; }
.item-count { font-weight: 700; }

.rules-strip { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.rule-chip {
  background: var(--surface); border-radius: 10px; box-shadow: var(--shadow);
  padding: 6px 10px; font-size: 12.5px; color: var(--text-muted);
}

.board-wrap {
  position: relative;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 10px;
}
.board {
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  gap: 3px;
  touch-action: none;
  user-select: none;
}
.cell {
  aspect-ratio: 1; border-radius: 6px;
  filter: var(--cell-filter);
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
/* absolutely positioned: glyphs can never change the cell's size */
.glyph {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: var(--cell-font, 20px); line-height: 1; pointer-events: none;
}
.glyph.marker-x { color: rgba(60, 45, 40, .45); font-weight: 700; font-size: calc(var(--cell-font, 20px) * .72); }
/* markers must read as "background noise", never as items: fully
   desaturated, faint, and smaller than the item glyphs */
.glyph.marker-themed { filter: grayscale(1) opacity(.3); font-size: calc(var(--cell-font, 20px) * .8); }
.cell.error { outline: 3px solid var(--danger); outline-offset: -3px; z-index: 1; }
/* hint-verified cells: untouchable, marked a shade firmer than player X's */
.cell.locked { cursor: default; }
.cell.locked .glyph.marker-x { color: rgba(60, 45, 40, .68); }
.cell.locked .glyph.marker-themed { filter: grayscale(1) opacity(.45); }
.cell.hint { outline: 3px solid var(--primary); outline-offset: -3px; animation: pulse .6s ease-in-out 3; z-index: 1; }
.cell.wrong { outline: 3px solid var(--danger); outline-offset: -3px; animation: pulse .6s ease-in-out 3; z-index: 1; }
@keyframes pulse { 50% { transform: scale(.92); } }
.cell.shake { animation: shake .45s ease-in-out; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}

.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; font-size: 14px;
  box-shadow: var(--shadow); z-index: 40; max-width: 90vw; text-align: center;
}
.toast.hidden { display: none; }
.toast .swatch {
  display: inline-block; width: 13px; height: 13px; border-radius: 4px;
  margin-right: 7px; vertical-align: -1px; border: 1px solid rgba(255, 255, 255, .5);
}

.game-actions {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 18px; z-index: 30;
}
.fab {
  width: 56px; height: 56px; border-radius: 50%; border: none;
  background: var(--surface); color: var(--text); box-shadow: 0 4px 14px rgba(90, 70, 60, .22);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  position: relative;
}
.fab:active { transform: scale(.92); }
.fab-badge {
  position: absolute; top: -4px; right: -4px;
  min-width: 20px; height: 20px; border-radius: 10px; padding: 0 5px;
  background: var(--danger); color: #fff; font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.fab-badge:empty { display: none; }

.win-overlay {
  position: absolute; inset: 0; border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 55%, transparent);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; z-index: 20;
}
.win-card {
  background: var(--surface); border-radius: 24px; box-shadow: var(--shadow);
  padding: 26px 34px; text-align: center; display: flex; flex-direction: column; gap: 8px;
}
.win-card h2 { margin: 0; }
.win-emoji { font-size: 34px; }
.win-actions { display: flex; gap: 10px; justify-content: center; margin-top: 8px; }

/* ---------- buttons / modals ---------- */
.btn {
  border: none; border-radius: 12px; padding: 10px 18px;
  background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; box-shadow: var(--shadow);
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost-danger {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent);
  box-shadow: none; font-weight: 700; letter-spacing: .03em;
}
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; }
.tutorial-dots { display: flex; gap: 8px; justify-content: center; margin: 4px 0 14px; }
.tutorial-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--surface-2); border: none; padding: 0; cursor: pointer; }
.tutorial-dot.active { background: var(--primary); }
.tutorial-list { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 10px; }
.field-label { font-weight: 600; font-size: 13.5px; margin-bottom: -4px; }
.sync-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 18px; border-radius: 14px;
  background: color-mix(in srgb, var(--ok) 12%, var(--surface-2));
}
.sync-banner-status {
  display: flex; align-items: center; gap: 8px;
  color: var(--ok); font-weight: 800; letter-spacing: .05em; text-transform: uppercase; font-size: 15px;
}
.pill-link { cursor: pointer; }
.pill-link:hover { background: color-mix(in srgb, var(--primary) 15%, var(--surface-2)); }
.levels-section { margin-bottom: 18px; }
.levels-head { display: flex; align-items: baseline; justify-content: space-between; margin: 10px 2px 8px; }
.levels-head h3 { margin: 0; font-size: 15px; }
.level-btn.current { outline: 3px solid var(--primary); }
.level-btn.attempted { background: color-mix(in srgb, var(--primary) 14%, var(--surface)); }
.diff-btn.current { outline: 2px solid var(--primary); }

/* level grid lives in its own scrolling card sized to the viewport, so the
   grid scrolls internally and the page itself never scrolls (mobile friendly).
   dvh tracks mobile browser chrome; the offset covers topbar + head + pills. */
.levels-screen { display: flex; flex-direction: column; }
.levels-scroll {
  cursor: default; margin-top: 12px;
  flex: 1; min-height: 0;
  max-height: calc(100dvh - 210px); overflow-y: auto;
}
/* Stats screen: informational cards, not the home screen's clickable ones */
.stats-screen { display: flex; flex-direction: column; gap: 14px; }
.stats-screen .card { cursor: default; min-height: 0; gap: 10px; }
.stat-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.stat-label-group { display: flex; flex-direction: column; gap: 1px; }
.stat-label { color: var(--text-muted); font-size: 14px; }
.stat-caption { color: var(--text-muted); font-size: 11.5px; opacity: .75; }
.stat-value { font-weight: 700; flex: none; }
.stat-pack-row { display: flex; align-items: center; gap: 10px; }
.stat-pack-name { flex: none; width: 70px; font-weight: 600; font-size: 14px; }
.stat-pack-bar { flex: 1; }

/* Wraps to a second row rather than a horizontally-scrolling one-liner —
   a scroll container hides content off-screen with no visible affordance
   on some devices (14x14 was getting cut off at the edge); wrapping
   keeps every size visible at once, same as the difficulty pills above it. */
.random-sizes { display: flex; gap: 8px; flex-wrap: wrap; padding: 3px; margin: -3px; }
.size-btn { color: #33302a; flex: none; border: 2px solid transparent; }
.size-btn.current { border-color: var(--primary); box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 35%, transparent); }
.gen-status { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 17px; margin: 0; }

/* skip / reveal secondary actions */
.game-secondary { display: flex; gap: 10px; justify-content: center; }
.ghost-btn { background: none; box-shadow: none; color: var(--text-muted); font-size: 13px; padding: 6px 10px; }
.ghost-btn:hover { color: var(--text); }

/* permanent mistake ring: immune to undo, survives resume */
.cell.mistake { box-shadow: inset 0 0 0 3px var(--danger); }
.level-btn.app-solved { background: var(--surface-2); color: var(--text-muted); }

/* test mode */
.board-wrap:has(.board.testing) { outline: 3px dashed var(--primary); outline-offset: -3px; }
.cell.tentative { outline: 2px dashed color-mix(in srgb, var(--primary) 75%, transparent); outline-offset: -2px; }
.cell.tentative .glyph { opacity: .75; }
.fab-apply { background: var(--ok); color: #fff; }
.fab-discard { background: var(--danger); color: #fff; }

.backdrop {
  position: fixed; inset: 0; z-index: 100;
  backdrop-filter: blur(10px);
  background: rgba(255, 255, 255, .30);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 60px 16px 16px;
}
.dark .backdrop { background: rgba(15, 23, 42, .60); }
.modal {
  background: var(--surface); border-radius: 24px; box-shadow: var(--shadow);
  width: 100%; max-width: 460px; max-height: 82vh; overflow: auto;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px 8px;
}
.modal-title { font-weight: 800; letter-spacing: .18em; font-size: 14px; }
.modal-body { padding: 8px 20px 22px; display: flex; flex-direction: column; gap: 14px; }

.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.setting-row label { font-weight: 600; font-size: 14.5px; }
/* Item/Marker rows: space-between right-aligns the whole controls group,
   so the gap (and therefore where the dropdowns start) varies with how
   wide their selected options' text happens to be -- "Plain X" vs "Stars"
   made the two rows misalign even with identical label widths. Dropping
   space-between for just these two rows fixes it: a fixed label width
   plus flex-start means the controls always start right after the label,
   regardless of content width. The toggle rows below (Auto-X, Catch
   mistakes, etc.) keep space-between -- their long descriptive labels are
   meant to push the checkbox to the far right, not sit at a fixed width. */
.setting-row.theme-row { justify-content: flex-start; }
.setting-row.theme-row label { flex: none; width: 60px; }
.setting-controls { display: flex; gap: 8px; align-items: center; }
.select {
  font: inherit; padding: 8px 10px; border-radius: 10px;
  border: 1px solid var(--surface-2); background: var(--surface); color: var(--text);
  max-width: 160px;
}
input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--primary); }
input[type="range"] { accent-color: var(--primary); width: 120px; }
.font-size-value { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 13px; width: 34px; text-align: right; flex: none; }

.rules-list { display: flex; flex-direction: column; gap: 16px; width: 100%; text-align: left; }
.rule-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.rule-text { flex: 1; font-size: 14px; color: var(--text-muted); line-height: 1.4; }
.rule-graphic { flex: none; width: 64px; height: 64px; }
.mini-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); gap: 2px;
  width: 100%; height: 100%;
}
.mini-cell {
  background: var(--surface-2); border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; color: var(--text);
}
.mini-cell.hl { background: color-mix(in srgb, var(--primary) 20%, var(--surface-2)); }
.mini-cell.hl-region { background: #a091e6; filter: var(--cell-filter); }
.mini-cell.hl-region-2 { background: #eda45f; filter: var(--cell-filter); }
.mini-cell.err { outline: 2px solid var(--danger); outline-offset: -2px; z-index: 1; }

.about-hero { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 12px 0 6px; text-align: center; }
.about-logo {
  width: 72px; height: 72px; color: var(--accent);
}
.about-name { font-size: 22px; font-weight: 800; letter-spacing: .2em; }
.about-version { font-size: 12px; font-weight: 700; color: var(--text-muted); }
.about-desc { max-width: 300px; color: var(--text-muted); margin: 4px 0 0; }

.data-actions { display: flex; flex-direction: column; gap: 10px; }

/* cloud sync indicator */
.cloud-dot { width: 24px; height: 24px; margin-right: 6px; }
.cloud-dot.ok { color: #10b981; }
.cloud-dot.warn { color: #f59e0b; }
.hidden { display: none !important; }

/* Data HUD */
.seg-control {
  display: flex; gap: 4px; background: var(--surface-2);
  border-radius: 12px; padding: 4px; flex-wrap: wrap;
}
.seg-pill {
  flex: 1; border: none; background: none; color: var(--text-muted);
  font: inherit; font-size: 12.5px; font-weight: 600;
  padding: 7px 6px; border-radius: 9px; cursor: pointer; white-space: nowrap;
}
.seg-pill.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.data-body { min-height: 180px; }

.backup-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--surface-2); border-radius: 10px; padding: 8px 12px; font-size: 13px;
}
.backup-actions { display: flex; gap: 6px; }
.small-btn { padding: 6px 10px; font-size: 12.5px; }

.text-input {
  font: inherit; font-size: 13px; width: 100%;
  padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--surface-2); background: var(--surface); color: var(--text);
  resize: vertical;
  user-select: text;
}
/* masked text without type=password, so password managers stay away */
.text-input.masked { -webkit-text-security: disc; text-security: disc; }
.vault-row { display: flex; gap: 8px; align-items: center; }
.vault-row .text-input { flex: 1; }
.small-icon-btn { width: 36px; height: 36px; flex: none; }

.backup-timeline {
  display: flex; height: 110px; background: var(--surface-2);
  border-radius: 10px; overflow: hidden; margin-top: 16px;
}
.timeline-zone { flex: 1; position: relative; border-right: 1px solid var(--surface); }
.timeline-zone:last-child { border-right: none; }
.timeline-tick {
  position: absolute; top: 0; bottom: 0; width: 1px;
  background: color-mix(in srgb, var(--surface) 60%, transparent); z-index: 0;
}
.timeline-label {
  position: absolute; top: 6px; left: 6px; font-size: 9px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); z-index: 10;
  background: color-mix(in srgb, var(--surface-2) 80%, transparent); padding: 2px 4px; border-radius: 4px;
}
.timeline-label.right { left: auto; right: 6px; }
.timeline-bar {
  position: absolute; bottom: 0; width: 4px; border-radius: 2px 2px 0 0;
  transform: translateX(-50%); z-index: 20; opacity: 0.85; transition: 0.2s; cursor: pointer;
}
.timeline-bar:hover { opacity: 1; transform: translateX(-50%) scaleY(1.1); transform-origin: bottom; }
.timeline-list { max-height: 200px; overflow-y: auto; padding-right: 4px; display: flex; flex-direction: column; gap: 6px; }

@media (min-width: 700px) {
  .board-wrap { max-width: 520px; margin: 0 auto; width: 100%; }
  .home { max-width: 520px; margin: 0 auto; width: 100%; }
}
