:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-strong: #ffffff;
  --surface-2: #eef3fb;
  --text: #172033;
  --muted: #61708f;
  --line: #d7dfef;
  --line-strong: #9aa8c5;
  --grid-line: #cad4e8;
  --board-line: #4a5c86;
  --accent: #3f6df2;
  --accent-strong: #2b53c5;
  --accent-soft: rgba(63, 109, 242, 0.14);
  --selected: #dae6ff;
  --peer: #edf3ff;
  --same: #f3f7ff;
  --note: #6b7da3;
  --given: #0f172a;
  --user: #224cc8;
  --danger: #e14d4d;
  --danger-soft: rgba(225, 77, 77, 0.14);
  --success: #11865d;
  --success-soft: rgba(17, 134, 93, 0.12);
  --shadow: 0 18px 48px rgba(20, 31, 56, 0.08);
  --radius: 20px;
  --safe-bottom: max(14px, env(safe-area-inset-bottom));
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1424;
  --panel: rgba(19, 28, 47, 0.92);
  --panel-strong: #121a2d;
  --surface-2: #16223c;
  --text: #ecf2ff;
  --muted: #9fb0d5;
  --line: #263555;
  --line-strong: #516389;
  --grid-line: #2d3a5d;
  --board-line: #8aa4ff;
  --accent: #7fa0ff;
  --accent-strong: #a4bbff;
  --accent-soft: rgba(127, 160, 255, 0.18);
  --selected: #233256;
  --peer: #1b2743;
  --same: #17223b;
  --note: #9fb0d5;
  --given: #f8fbff;
  --user: #8fb0ff;
  --danger: #ff8787;
  --danger-soft: rgba(255, 135, 135, 0.18);
  --success: #3fd39c;
  --success-soft: rgba(63, 211, 156, 0.18);
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.3);
}

:root[data-theme="sepia"] {
  color-scheme: light;
  --bg: #f4ede1;
  --panel: rgba(255, 250, 241, 0.95);
  --panel-strong: #fffaf1;
  --surface-2: #f6ecdd;
  --text: #402f1f;
  --muted: #7c6756;
  --line: #dbcbb7;
  --line-strong: #aa927b;
  --grid-line: #d7c7b4;
  --board-line: #77583e;
  --accent: #b56b3d;
  --accent-strong: #8e522c;
  --accent-soft: rgba(181, 107, 61, 0.14);
  --selected: #f7e5d7;
  --peer: #fbf2e8;
  --same: #fdf7ef;
  --note: #7c6756;
  --given: #3b2b1d;
  --user: #8e522c;
  --danger: #bb4c36;
  --danger-soft: rgba(187, 76, 54, 0.12);
  --success: #4a8f5b;
  --success-soft: rgba(74, 143, 91, 0.12);
  --shadow: 0 18px 48px rgba(86, 58, 30, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    color-scheme: dark;
    --bg: #0d1424;
    --panel: rgba(19, 28, 47, 0.92);
    --panel-strong: #121a2d;
    --surface-2: #16223c;
    --text: #ecf2ff;
    --muted: #9fb0d5;
    --line: #263555;
    --line-strong: #516389;
    --grid-line: #2d3a5d;
    --board-line: #8aa4ff;
    --accent: #7fa0ff;
    --accent-strong: #a4bbff;
    --accent-soft: rgba(127, 160, 255, 0.18);
    --selected: #233256;
    --peer: #1b2743;
    --same: #17223b;
    --note: #9fb0d5;
    --given: #f8fbff;
    --user: #8fb0ff;
    --danger: #ff8787;
    --danger-soft: rgba(255, 135, 135, 0.18);
    --success: #3fd39c;
    --success-soft: rgba(63, 211, 156, 0.18);
    --shadow: 0 18px 48px rgba(0, 0, 0, 0.3);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(127, 160, 255, 0.1), transparent 36%),
    radial-gradient(circle at bottom right, rgba(63, 211, 156, 0.06), transparent 28%),
    var(--bg);
  color: var(--text);
}

button,
select,
input {
  font: inherit;
}

button,
select {
  border: 1px solid var(--line);
  background: var(--panel-strong);
  color: var(--text);
  border-radius: 14px;
  min-height: 48px;
  padding: 0.75rem 0.95rem;
  transition: background-color 120ms ease, border-color 120ms ease, transform 120ms ease, box-shadow 120ms ease;
}

button {
  font-weight: 700;
  cursor: pointer;
  box-shadow: none;
}

button:hover,
select:hover {
  border-color: var(--line-strong);
}

button:active {
  transform: translateY(1px);
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 3px solid var(--accent-soft);
  outline-offset: 1px;
}

button.primary {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}

button.toggle.active,
.segmented button.active,
.numpad button.selected {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}

button.subtle {
  background: transparent;
}

.app {
  width: min(1200px, 100%);
  margin: 0 auto;
  padding: 22px clamp(14px, 2.8vw, 28px) var(--safe-bottom);
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(260px, 0.9fr);
  gap: 16px;
  align-items: stretch;
  margin-bottom: 16px;
}

.brand,
.summary-strip,
.board-shell,
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.brand {
  border-radius: var(--radius);
  padding: 18px 20px;
}

.brand h1 {
  margin: 0.2rem 0 0.35rem;
  font-size: clamp(1.7rem, 4vw, 2.5rem);
  line-height: 1.05;
}

.brand p {
  margin: 0;
  color: var(--muted);
  max-width: 62ch;
}

.eyebrow {
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 800;
}

.summary-strip {
  border-radius: var(--radius);
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.summary-card {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  display: grid;
  gap: 6px;
  min-height: 96px;
  align-content: center;
}

.summary-card strong {
  font-size: clamp(1.1rem, 2.6vw, 1.45rem);
}

.summary-label {
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 800;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  margin-bottom: 16px;
}

.field {
  display: grid;
  gap: 6px;
}

.field.compact {
  min-width: min(100%, 180px);
}

.field span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  align-items: start;
}

.board-shell {
  border-radius: 24px;
  padding: 16px;
}

.board-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 14px;
  align-items: start;
  margin-bottom: 14px;
}

.board-head-copy {
  display: grid;
  gap: 6px;
}

.puzzle-meta {
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 700;
}

.status-line {
  min-height: 1.4em;
  font-weight: 700;
}

.status-line.info {
  color: var(--text);
}

.status-line.warn {
  color: var(--danger);
}

.status-line.success {
  color: var(--success);
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.board {
  width: min(100%, 720px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  aspect-ratio: 1 / 1;
  border: 3px solid var(--board-line);
  border-radius: 18px;
  overflow: hidden;
  background: var(--panel-strong);
  touch-action: manipulation;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  border: none;
  border-right: 1px solid var(--grid-line);
  border-bottom: 1px solid var(--grid-line);
  border-radius: 0;
  min-height: 0;
  padding: 0;
  background: var(--panel-strong);
  color: var(--text);
  font-weight: 800;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.cell.thick-right {
  border-right: 3px solid var(--board-line);
}

.cell.thick-bottom {
  border-bottom: 3px solid var(--board-line);
}

.cell.given .value {
  color: var(--given);
}

.cell.user .value {
  color: var(--user);
}

.cell.selected {
  background: var(--selected);
}

.cell.peer {
  background: var(--peer);
}

.cell.same-value {
  box-shadow: inset 0 0 0 999px var(--same);
}

.cell.conflict {
  box-shadow: inset 0 0 0 999px var(--danger-soft);
}

.cell.mistake .value {
  color: var(--danger);
}

.cell.hint {
  box-shadow: inset 0 0 0 3px var(--accent);
  z-index: 1;
}

.value {
  font-size: clamp(1.4rem, 5vw, 2.65rem);
  line-height: 1;
}

.notes {
  position: absolute;
  inset: 5px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  font-size: clamp(0.52rem, 1.8vw, 0.88rem);
  line-height: 1;
  color: var(--note);
  font-weight: 700;
}

.note {
  display: grid;
  place-items: center;
  opacity: 0.92;
}

.note.active-digit {
  color: var(--accent);
  font-weight: 900;
}

.side-panel {
  display: grid;
  gap: 12px;
  position: sticky;
  top: 14px;
}

.card {
  border-radius: 20px;
  padding: 15px;
}

.card h2 {
  margin: 0;
  font-size: 1rem;
}

.card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.micro-copy {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.numpad {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.numpad button {
  position: relative;
  min-height: 58px;
  padding: 0.45rem;
  font-size: 1.15rem;
}

.numpad .count {
  position: absolute;
  right: 8px;
  top: 6px;
  font-size: 0.72rem;
  font-weight: 800;
  color: currentColor;
  opacity: 0.72;
}

.settings-grid {
  display: grid;
  gap: 12px;
}

.switch {
  display: flex;
  gap: 10px;
  align-items: start;
  color: var(--text);
  font-weight: 700;
}

.switch input {
  inline-size: 18px;
  block-size: 18px;
  margin-top: 2px;
  accent-color: var(--accent);
}

details.card {
  overflow: hidden;
}

details.card summary {
  cursor: pointer;
  font-weight: 800;
  list-style: none;
}

details.card summary::-webkit-details-marker {
  display: none;
}

details.card summary::after {
  content: "▾";
  float: right;
  color: var(--muted);
}

details[open].card summary::after {
  content: "▴";
}

.stats-panel {
  margin-top: 12px;
  display: grid;
  gap: 14px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.stat-chip {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  display: grid;
  gap: 5px;
}

.stat-chip strong {
  font-size: 1.1rem;
}

.stat-chip span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.stats-table th,
.stats-table td {
  padding: 8px 0;
  text-align: left;
  border-bottom: 1px solid var(--line);
}

.stats-table th {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.hint-card {
  margin-top: 14px;
  border: 1px solid var(--accent-soft);
  background: color-mix(in srgb, var(--accent-soft) 75%, var(--panel-strong));
  border-radius: 18px;
  padding: 14px;
}

.hint-card.hidden {
  display: none;
}

.hint-title {
  font-weight: 900;
  margin-bottom: 6px;
}

.hint-text {
  color: var(--text);
  line-height: 1.45;
}

.support-copy p {
  color: var(--muted);
  margin: 12px 0 14px;
}

.badge-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.badge {
  padding: 0.45rem 0.7rem;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 0.84rem;
  font-weight: 800;
}

.empty-state {
  color: var(--muted);
  margin: 12px 0 2px;
}

@media (max-width: 1040px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .side-panel {
    position: static;
  }
}

@media (max-width: 760px) {
  .app {
    padding-inline: 12px;
  }

  .topbar {
    grid-template-columns: 1fr;
  }

  .summary-strip {
    grid-template-columns: repeat(3, 1fr);
  }

  .toolbar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .toolbar > * {
    min-width: 0;
  }

  .toolbar .field {
    grid-column: 1 / -1;
  }

  .quick-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .numpad button {
    min-height: 54px;
  }
}

@media (max-width: 520px) {
  .summary-strip {
    grid-template-columns: 1fr;
  }

  .segmented {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }
}
