:root {
  --bg: #071023;
  --bg-soft: #0b1630;
  --panel: rgba(15, 27, 56, 0.86);
  --panel-solid: #0f1b38;
  --panel-soft: rgba(255, 255, 255, 0.065);
  --panel-lift: rgba(255, 255, 255, 0.095);

  --paper: #fbfaf5;
  --paper-line: rgba(23, 32, 54, 0.14);
  --paper-line-strong: rgba(23, 32, 54, 0.42);

  --text: #eef2ff;
  --muted: #a8b4cf;
  --muted-2: #7f8cac;

  --cell-a: #fbfaf5;
  --cell-b: #f4f1e8;
  --fixed: #ece5d7;
  --selected: #d7e7ff;
  --related: #edf4ff;
  --same: #e6f6ec;
  --duplicate: #ffe0df;
  --incorrect: #d92929;

  --ink: #151515;
  --primary: #4b86ff;
  --primary-dark: #2f64c8;
  --good: #1fa34a;
  --warn: #d79424;
  --danger: #cf4d4d;

  --radius-lg: 28px;
  --radius-md: 20px;
  --shadow-soft: 0 22px 70px rgba(0, 0, 0, 0.28);
  --shadow-board: 0 26px 90px rgba(0, 0, 0, 0.34);
}

body.light {
  --bg: #eef3ff;
  --bg-soft: #e5ecfb;
  --panel: rgba(255, 255, 255, 0.86);
  --panel-solid: #ffffff;
  --panel-soft: rgba(12, 35, 75, 0.055);
  --panel-lift: rgba(12, 35, 75, 0.085);

  --text: #15233a;
  --muted: #586881;
  --muted-2: #7a879b;

  --shadow-soft: 0 22px 70px rgba(45, 64, 98, 0.16);
  --shadow-board: 0 26px 90px rgba(45, 64, 98, 0.20);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(75, 134, 255, 0.22), transparent 34%),
    radial-gradient(circle at bottom right, rgba(31, 163, 74, 0.10), transparent 30%),
    linear-gradient(145deg, var(--bg), var(--bg-soft));
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  overflow-x: hidden;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 18px;
  min-height: 54px;
  padding: 12px 16px;
  background: var(--panel-soft);
  color: var(--text);
  font-size: 15px;
  line-height: 1.1;
  font-weight: 750;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
  transition:
    transform 0.16s ease,
    background 0.16s ease,
    box-shadow 0.16s ease,
    opacity 0.16s ease;
}

button:hover {
  background: var(--panel-lift);
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
  opacity: 0.9;
}

button.primary {
  background: linear-gradient(180deg, var(--primary), var(--primary-dark));
  color: white;
  box-shadow:
    0 12px 34px rgba(75, 134, 255, 0.28),
    inset 0 0 0 1px rgba(255, 255, 255, 0.16);
}

button.good {
  background: var(--good);
  color: white;
}

button.warn {
  background: var(--warn);
  color: white;
}

button.danger {
  background: var(--danger);
  color: white;
}

button.done {
  opacity: 0.48;
}

h1 {
  margin: 0;
  font-size: clamp(34px, 4vw, 54px);
  line-height: 0.95;
  font-weight: 850;
  letter-spacing: -0.05em;
}

h2,
h3 {
  margin: 0 0 10px 0;
  letter-spacing: -0.02em;
}

.app-shell {
  max-width: 1320px;
  margin: 0 auto;
  padding: 22px;
}

.topbar {
  margin-bottom: 22px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.app-topbar {
  padding: 4px 2px 0;
}

.brand-row {
  display: flex;
  gap: 14px;
  align-items: center;
}

.brand-mark {
  width: 54px;
  height: 54px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background:
    linear-gradient(145deg, rgba(75, 134, 255, 0.95), rgba(31, 163, 74, 0.88));
  color: white;
  font-size: 30px;
  font-weight: 900;
  box-shadow: 0 16px 40px rgba(75, 134, 255, 0.24);
}

.topbar-copy {
  min-width: 280px;
}

.topbar-actions,
.compact-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.meta {
  font-size: 16px;
  color: var(--muted);
  margin-top: 6px;
}

.status {
  min-height: 24px;
  font-size: 15px;
  color: var(--muted);
  margin-top: 10px;
}

.main-layout,
.premium-layout {
  display: grid;
  grid-template-columns: minmax(520px, 1fr) 310px;
  gap: 28px;
  align-items: start;
}

.board-section {
  min-width: 0;
}

.board-shell {
  position: relative;
  width: min(78vw, 760px);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  padding: 10px;
  border-radius: 30px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.04)),
    rgba(255, 255, 255, 0.04);
  box-shadow: var(--shadow-board);
  transition:
    box-shadow 0.24s ease,
    background 0.24s ease,
    transform 0.24s ease;
}

.board-shell.board-complete-correct {
  box-shadow:
    0 0 0 5px rgba(31, 163, 74, 0.85),
    0 0 48px rgba(31, 163, 74, 0.30),
    var(--shadow-board);
}

.board-shell.board-complete-error {
  box-shadow:
    0 0 0 5px rgba(207, 77, 77, 0.88),
    0 0 48px rgba(207, 77, 77, 0.30),
    var(--shadow-board);
}

.board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  width: 100%;
  height: 100%;
  border-radius: 20px;
  overflow: hidden;
  background: var(--paper);
  border: 3px solid var(--paper-line-strong);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.45);
}

.board-ink-canvas {
  position: absolute;
  inset: 10px;
  width: calc(100% - 20px);
  height: calc(100% - 20px);
  z-index: 20;
  background: transparent;
  touch-action: none;
  pointer-events: auto;
  border-radius: 20px;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--paper-line);
  border-bottom: 1px solid var(--paper-line);
  background: var(--cell-a);
  color: var(--ink);
  overflow: hidden;
  user-select: none;
  cursor: pointer;
  font-size: clamp(24px, 3.2vw, 42px);
  font-weight: 650;
  line-height: 1;
  transition:
    background 0.14s ease,
    color 0.14s ease,
    box-shadow 0.14s ease;
}

.cell:nth-child(3n) {
  border-right: 3px solid var(--paper-line-strong);
}

.cell:nth-child(n + 19):nth-child(-n + 27),
.cell:nth-child(n + 46):nth-child(-n + 54) {
  border-bottom: 3px solid var(--paper-line-strong);
}

.cell:nth-child(9n) {
  border-right: 0;
}

.cell:nth-child(n + 73) {
  border-bottom: 0;
}

.cell.fixed {
  background: var(--fixed);
  font-weight: 850;
}

.cell.selected {
  background: var(--selected);
  box-shadow: inset 0 0 0 3px rgba(75, 134, 255, 0.28);
}

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

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

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

.cell.incorrect,
.cell .incorrect {
  color: var(--incorrect);
}

.cell-value,
.cell-notes {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.cell-value {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(22px, 3vw, 42px);
  font-weight: 650;
  color: var(--ink);
  z-index: 2;
}

.cell-value.fixed-value {
  font-weight: 850;
}

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

.cell-notes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 5px;
  font-size: clamp(9px, 0.8vw, 12px);
  color: rgba(21, 21, 21, 0.58);
  z-index: 1;
}

.note {
  display: flex;
  align-items: center;
  justify-content: center;
}

.side-panel,
.premium-panel {
  width: 310px;
  background: var(--panel);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.panel-group {
  margin-bottom: 18px;
}

.panel-group:last-child {
  margin-bottom: 0;
}

.panel-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-bottom: 10px;
  font-weight: 800;
}

.keypad {
  display: grid;
  gap: 10px;
}

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

.keypad-digits button {
  min-height: 64px;
  font-size: 24px;
  border-radius: 20px;
}

.quick-controls,
.secondary-actions,
.settings-actions {
  display: grid;
  gap: 10px;
}

.quick-controls {
  grid-template-columns: 1fr 1fr;
}

.secondary-actions {
  grid-template-columns: 1fr 1fr;
  margin-top: 10px;
}

.card {
  background: var(--panel);
  border-radius: var(--radius-md);
  padding: 18px;
  box-shadow: var(--shadow-soft);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at center, rgba(75, 134, 255, 0.10), transparent 42%),
    rgba(3, 8, 23, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.hidden {
  display: none !important;
}

.modal,
.premium-modal {
  width: min(94vw, 560px);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent),
    var(--panel-solid);
  border-radius: 30px;
  padding: 26px;
  color: var(--text);
  box-shadow: var(--shadow-soft);
  border: 1px solid rgba(255, 255, 255, 0.10);
}

.modal-wide {
  width: min(96vw, 840px);
}

.modal h2 {
  margin-top: 0;
  margin-bottom: 8px;
  font-size: clamp(28px, 4vw, 40px);
  letter-spacing: -0.04em;
}

.modal-kicker {
  color: var(--primary);
  font-weight: 850;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.modal-copy,
.settings-copy {
  color: var(--muted);
  margin: 0 0 18px 0;
  line-height: 1.45;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.modal-actions button {
  min-height: 54px;
  padding: 12px 18px;
  border-radius: 18px;
  font-size: 15px;
}

.modal-actions-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
}

.difficulty-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 18px;
}

.difficulty-grid button {
  min-height: 76px;
  font-size: 18px;
  border-radius: 24px;
}

.completion-card {
  text-align: left;
}

.completion-stats {
  margin: 18px 0 4px;
  padding: 14px;
  border-radius: 18px;
  background: var(--panel-soft);
  color: var(--muted);
  line-height: 1.55;
}

.completion-actions {
  justify-content: flex-start;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.9fr 0.9fr;
  gap: 16px;
  align-items: start;
}

.settings-section {
  background: var(--panel-soft);
  border-radius: 22px;
  padding: 16px;
}

.settings-section h3 {
  margin-bottom: 12px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  font-size: 15px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.setting-row:last-child {
  border-bottom: 0;
}

.setting-row span {
  display: grid;
  gap: 3px;
}

.setting-row small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.setting-row input[type="checkbox"] {
  width: 48px;
  height: 28px;
  flex: 0 0 auto;
  accent-color: var(--primary);
}

.stats-block {
  margin-bottom: 14px;
  padding: 12px;
  background: var(--panel-soft);
  border-radius: 14px;
}

.writing-pad-shell {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: start;
}

.writing-pad {
  position: relative;
  width: 100%;
  aspect-ratio: 1.6 / 1;
  border-radius: 22px;
  background: var(--paper);
  overflow: hidden;
  border: 2px solid rgba(21, 21, 21, 0.12);
}

.writing-guide {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(
      to bottom,
      transparent 0,
      transparent calc(50% - 1px),
      rgba(90, 105, 135, 0.26) calc(50% - 1px),
      rgba(90, 105, 135, 0.26) calc(50% + 1px),
      transparent calc(50% + 1px),
      transparent 100%);
  z-index: 1;
}

#writingCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  z-index: 2;
  background: transparent;
}

.writing-side {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 120px;
}

.writing-side button {
  min-height: 56px;
  font-size: 15px;
}

.writing-help {
  font-size: 15px;
  color: var(--muted);
  margin-bottom: 10px;
}

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

.calibration-main,
.calibration-side {
  min-width: 0;
}

.prompt-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: 6px;
  font-weight: 800;
}

.muted {
  color: var(--muted);
  font-size: 15px;
}

.status-block {
  text-align: right;
}

.compare-grid {
  display: grid;
  grid-template-columns: 1.3fr 0.8fr;
  gap: 18px;
  align-items: stretch;
}

.compare-card {
  background: var(--panel-soft);
  border-radius: 22px;
  padding: 14px;
}

.compare-title {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 800;
}

.pad-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1.6 / 1;
  border-radius: 22px;
  overflow: hidden;
  background: var(--paper);
  border: 2px solid rgba(21, 21, 21, 0.12);
}

#pad,
#userCalCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  z-index: 5;
  display: block;
}

#userCalPadShell {
  position: relative;
}

.guide {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: rgba(80, 110, 160, 0.22);
  z-index: 2;
  pointer-events: none;
}

.guide-top { top: 22%; }
.guide-mid { top: 50%; }
.guide-bot { top: 78%; }

.prediction-box {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 22px;
  background: var(--paper);
  border: 2px solid rgba(21, 21, 21, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
}

.prediction-digit {
  color: var(--ink);
  font-size: clamp(58px, 9vw, 120px);
  font-weight: 850;
  line-height: 1;
}

.controls {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

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

.confirm-panel {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.confirm-question {
  font-size: 18px;
  font-weight: 750;
  margin-bottom: 12px;
}

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

.card-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
  margin: 18px 0;
}

.manual-panel {
  margin-top: 4px;
}

.side-tools {
  display: grid;
  gap: 10px;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.small {
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.json-box {
  margin: 0;
  max-height: 320px;
  overflow: auto;
  font-size: 12px;
  line-height: 1.45;
  background: rgba(0, 0, 0, 0.22);
  border-radius: 14px;
  padding: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}

@media (max-width: 1080px) {
  .main-layout,
  .premium-layout,
  .calibration-layout {
    grid-template-columns: 1fr;
  }

  .side-panel,
  .premium-panel {
    width: min(92vw, 760px);
    margin: 0 auto;
  }

  .board-shell {
    width: min(92vw, 760px);
  }

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

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

  .brand-mark {
    width: 46px;
    height: 46px;
    border-radius: 15px;
    font-size: 25px;
  }

  h1 {
    font-size: 34px;
  }

  .topbar {
    gap: 12px;
  }

  .compact-actions {
    width: 100%;
  }

  .compact-actions button {
    flex: 1;
  }

  .board-shell {
    padding: 7px;
    border-radius: 22px;
  }

  .board,
  .board-ink-canvas {
    border-radius: 15px;
  }

  .board-ink-canvas {
    inset: 7px;
    width: calc(100% - 14px);
    height: calc(100% - 14px);
  }

  .side-panel,
  .premium-panel {
    padding: 14px;
    border-radius: 24px;
  }

  .quick-controls,
  .secondary-actions,
  .difficulty-grid,
  .compare-grid,
  .writing-pad-shell,
  .controls-three,
  .confirm-actions,
  .modal-actions-grid {
    grid-template-columns: 1fr;
  }

  .writing-side {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .writing-side button {
    flex: 1 1 140px;
  }

  .modal,
  .premium-modal {
    padding: 20px;
    border-radius: 24px;
  }
}

/* iPad / Apple Pencil hardening */
.pad-wrap,
#pad,
#userCalCanvas,
.writing-pad,
#writingCanvas,
.board-shell,
.board,
.cell,
.board-ink-canvas,
#boardInkCanvas {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#pad,
#userCalCanvas,
#writingCanvas,
.board-ink-canvas {
  pointer-events: auto;
}



/* -------------------------------------------------------------------------- */
/* Premium play controls upgrade                                                */
/* -------------------------------------------------------------------------- */

.play-controls {
  display: grid;
  gap: 16px;
}

.play-controls .panel-group {
  margin-bottom: 0;
}

.toggle-pill {
  position: relative;
}

.toggle-pill.primary::after,
#notesBtn.primary::after,
#writeBtn.primary::after {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 14px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.18);
  pointer-events: none;
}

.action-row {
  grid-template-columns: repeat(2, 1fr);
}

.cell.selected {
  background: linear-gradient(180deg, #dceaff, #cfe1ff);
  box-shadow:
    inset 0 0 0 3px rgba(75, 134, 255, 0.42),
    inset 0 0 22px rgba(75, 134, 255, 0.16);
}

.cell.related {
  background: #edf4ff;
}

.cell.same {
  background: #dff4e8;
}

.cell-notes {
  padding: clamp(3px, 0.6vw, 7px);
  font-weight: 700;
  color: rgba(21, 21, 21, 0.62);
}

.note {
  line-height: 1;
}

/* Mobile: no-scroll play loop */
@media (max-width: 760px) {
  body {
    padding-bottom: calc(238px + env(safe-area-inset-bottom));
  }

  .app-shell {
    padding: 10px 10px 0;
  }

  .topbar {
    margin-bottom: 10px;
    align-items: center;
  }

  .topbar-copy {
    min-width: 0;
  }

  h1 {
    font-size: 32px;
    letter-spacing: -0.055em;
  }

  .meta {
    font-size: 13px;
    margin-top: 4px;
  }

  .status {
    font-size: 13px;
    min-height: 18px;
    margin-top: 6px;
  }

  .compact-actions {
    display: flex;
    gap: 8px;
    width: auto;
    margin-left: auto;
  }

  .compact-actions button {
    min-height: 42px;
    padding: 10px 12px;
    border-radius: 14px;
    font-size: 13px;
    flex: unset;
  }

  .board-shell {
    width: min(96vw, 720px);
    max-height: calc(100vh - 310px);
    padding: 6px;
    border-radius: 22px;
  }

  .board {
    border-width: 2px;
    border-radius: 16px;
  }

  .cell {
    font-size: clamp(22px, 8vw, 39px);
  }

  .cell-value {
    font-size: clamp(22px, 8vw, 39px);
  }

  .cell-notes {
    font-size: clamp(8px, 2.35vw, 12px);
    padding: 3px;
  }

  .board-ink-canvas {
    inset: 6px;
    width: calc(100% - 12px);
    height: calc(100% - 12px);
    border-radius: 16px;
  }

  .play-controls {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    z-index: 40;

    width: auto;
    margin: 0;
    padding: 12px;

    display: grid;
    grid-template-areas:
      "keypad"
      "input"
      "actions";
    gap: 10px;

    border-radius: 26px;
    background:
      linear-gradient(180deg, rgba(255,255,255,0.92), rgba(255,255,255,0.84)),
      rgba(255,255,255,0.88);
    color: #142139;
    border: 1px solid rgba(20, 33, 57, 0.08);
    box-shadow:
      0 -18px 60px rgba(20, 33, 57, 0.18),
      0 10px 26px rgba(20, 33, 57, 0.10);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
  }

  body:not(.light) .play-controls {
    background:
      linear-gradient(180deg, rgba(19, 32, 65, 0.96), rgba(12, 22, 46, 0.94)),
      var(--panel);
    color: var(--text);
    border-color: rgba(255,255,255,0.10);
  }

  .keypad-group {
    grid-area: keypad;
  }

  .input-group {
    grid-area: input;
  }

  .actions-group {
    grid-area: actions;
  }

  .play-controls .panel-title {
    display: none;
  }

  .keypad-digits {
    grid-template-columns: repeat(9, 1fr);
    gap: 6px;
  }

  .keypad-digits button {
    min-height: 48px;
    padding: 0;
    border-radius: 15px;
    font-size: 22px;
    font-weight: 850;
    background: rgba(20, 33, 57, 0.07);
    color: #142139;
    box-shadow: inset 0 0 0 1px rgba(20, 33, 57, 0.06);
  }

  body:not(.light) .keypad-digits button {
    background: rgba(255,255,255,0.075);
    color: var(--text);
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.06);
  }

  .input-toggles {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .input-toggles button {
    min-height: 42px;
    border-radius: 15px;
    font-size: 14px;
    background: rgba(20, 33, 57, 0.07);
    color: #142139;
  }

  body:not(.light) .input-toggles button {
    background: rgba(255,255,255,0.075);
    color: var(--text);
  }

  .input-toggles button.primary {
    background: linear-gradient(180deg, var(--primary), var(--primary-dark));
    color: white;
  }

  .action-row {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
  }

  .action-row button {
    min-height: 38px;
    padding: 8px 6px;
    border-radius: 14px;
    font-size: 12px;
    background: rgba(20, 33, 57, 0.06);
    color: #142139;
  }

  body:not(.light) .action-row button {
    background: rgba(255,255,255,0.065);
    color: var(--text);
  }

  .modal-backdrop {
    z-index: 100;
  }
}

/* Extra small phones */
@media (max-width: 420px) {
  body {
    padding-bottom: calc(220px + env(safe-area-inset-bottom));
  }

  .keypad-digits button {
    min-height: 42px;
    font-size: 20px;
    border-radius: 13px;
  }

  .input-toggles button {
    min-height: 38px;
  }

  .action-row button {
    min-height: 34px;
    font-size: 11px;
  }

  .board-shell {
    max-height: calc(100vh - 292px);
  }
}
@media (max-width: 760px) {
  .modal-backdrop {
    align-items: flex-start;
    justify-content: center;
    overflow-y: auto;
    padding: max(14px, env(safe-area-inset-top)) 14px max(24px, env(safe-area-inset-bottom));
    -webkit-overflow-scrolling: touch;
  }

  .modal,
  .premium-modal {
    max-height: calc(100dvh - 28px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .modal-wide {
    width: 100%;
  }

  body:has(.modal-backdrop:not(.hidden)) {
    overflow: hidden;
  }
}

/* -------------------------------------------------------------------------- */
/* Quick calibration modal                                                      */
/* -------------------------------------------------------------------------- */

.quick-calibration-modal {
  width: min(94vw, 520px);
}

.quick-calibration-pad-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1.45 / 1;
  border-radius: 24px;
  overflow: hidden;
  background: var(--paper);
  border: 2px solid rgba(21, 21, 21, 0.12);
  margin: 16px 0;
}

#quickCalCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: transparent;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.quick-calibration-result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-radius: 18px;
  background: var(--panel-soft);
  color: var(--muted);
  margin-bottom: 12px;
}

.quick-calibration-result strong {
  font-size: 38px;
  color: var(--text);
  line-height: 1;
}

.quick-calibration-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

.quick-cal-manual {
  margin-top: 12px;
  grid-template-columns: repeat(9, 1fr);
}

.quick-cal-manual button {
  min-height: 44px;
  font-size: 18px;
  border-radius: 14px;
}

@media (max-width: 760px) {
  .quick-calibration-modal {
    max-height: calc(100dvh - 28px);
  }

  .quick-calibration-pad-wrap {
    aspect-ratio: 1.25 / 1;
  }

  .quick-calibration-actions {
    grid-template-columns: 1fr;
  }

  .quick-cal-manual {
    grid-template-columns: repeat(3, 1fr);
  }
}
/* -------------------------------------------------------------------------- */
/* Homepage / SEO landing page                                                  */
/* -------------------------------------------------------------------------- */

.home-shell {
  min-height: 100vh;
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px;
  color: var(--text);
}

.home-hero-card,
.home-panel,
.home-card,
.home-cta-card {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent),
    var(--panel);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  border: 1px solid rgba(255, 255, 255, 0.10);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.home-hero-card {
  text-align: center;
  padding: clamp(34px, 7vw, 76px) 22px;
  margin-bottom: 22px;
}

.home-kicker {
  display: inline-flex;
  margin-bottom: 16px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--primary);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.home-hero-card h1 {
  margin: 0;
  font-size: clamp(46px, 12vw, 92px);
  line-height: 0.9;
  letter-spacing: -0.06em;
}

.home-subtitle {
  max-width: 760px;
  margin: 20px auto 0;
  color: var(--muted);
  font-size: clamp(18px, 3vw, 24px);
  line-height: 1.45;
}

.home-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 26px;
}

.home-button {
  min-height: 56px;
  padding: 15px 22px;
  border-radius: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  background: var(--panel-soft);
  text-decoration: none;
  font-size: 16px;
  font-weight: 850;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
  transition:
    transform 0.16s ease,
    background 0.16s ease,
    box-shadow 0.16s ease,
    opacity 0.16s ease;
}

.home-button:hover {
  background: var(--panel-lift);
  transform: translateY(-1px);
}

.home-button.primary {
  background: linear-gradient(180deg, var(--primary), var(--primary-dark));
  color: white;
  box-shadow:
    0 12px 34px rgba(75, 134, 255, 0.28),
    inset 0 0 0 1px rgba(255, 255, 255, 0.16);
}

.home-section {
  margin: 22px 0;
}

.home-section > h2 {
  margin: 0 0 14px;
  text-align: center;
  font-size: clamp(28px, 5vw, 44px);
  letter-spacing: -0.04em;
}

.home-panel,
.home-cta-card {
  padding: 24px;
  margin-bottom: 22px;
}

.home-panel h2,
.home-cta-card h2 {
  margin: 0 0 10px;
  font-size: clamp(26px, 4vw, 38px);
}

.home-panel p,
.home-card p,
.home-cta-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
  font-size: 16px;
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
}

.home-card {
  padding: 22px;
}

.home-card h3 {
  margin: 0 0 8px;
  font-size: 22px;
}

.feature-icon {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  margin-bottom: 14px;
  border-radius: 18px;
  background: var(--panel-soft);
  font-size: 26px;
}

.home-cta-card {
  text-align: center;
}

.home-cta-card .home-actions {
  margin-top: 20px;
}

@media (max-width: 760px) {
  .home-shell {
    padding: 14px;
  }

  .home-hero-card {
    padding: 38px 16px;
    border-radius: 24px;
  }

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

  .home-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .home-button {
    width: 100%;
    min-height: 54px;
  }
}

@media (max-width: 420px) {
  .home-actions {
    grid-template-columns: 1fr;
  }
}

.feature-label {
  display: inline-block;
  margin-bottom: 12px;

  padding: 6px 14px;
  border-radius: 999px;

  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);

  color: #9fb4ff;

  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

button.tool-active {
  background: var(--warn) !important;
  color: white !important;
  box-shadow:
    0 12px 34px rgba(215, 148, 36, 0.28),
    inset 0 0 0 1px rgba(255, 255, 255, 0.16);
}

.daily-leaderboard-card {
  margin-top: 64px;
  padding: 34px;
  border-radius: 30px;
  background:
    radial-gradient(circle at top, rgba(59, 130, 246, 0.16), transparent 42%),
    rgba(11, 25, 55, 0.78);
  border: 1px solid rgba(148, 163, 184, 0.18);
}

.daily-actions {
  justify-content: center;
  margin-bottom: 34px;
}

.leaderboard-panel {
  margin-top: 34px;
  padding: 26px;
  border-radius: 24px;
  background: rgba(3, 10, 28, 0.42);
  border: 1px solid rgba(148, 163, 184, 0.14);
}

.leaderboard-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-end;
  margin-bottom: 20px;
  text-align: left;
}

.leaderboard-kicker {
  color: #60a5fa;
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.leaderboard-title {
  margin: 4px 0 0;
  color: #f8fafc;
}

.leaderboard-note {
  color: #94a3b8;
  font-size: 0.9rem;
  font-weight: 700;
}

.leaderboard-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.leaderboard-card {
  padding: 18px;
  border-radius: 18px;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid rgba(148, 163, 184, 0.16);
  text-align: left;
}

.leaderboard-card h3 {
  margin: 0 0 12px;
  color: #f8fafc;
  font-size: 1.05rem;
}

.leaderboard-card ol {
  margin: 0;
  padding-left: 22px;
  color: #cbd5e1;
  font-weight: 700;
}

.leaderboard-card li {
  padding: 6px 0;
}

@media (max-width: 900px) {
  .leaderboard-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

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

  .leaderboard-header {
    display: block;
  }
}

.daily-completion-panel {
  margin-top: 18px;
  padding: 16px;
  border-radius: 18px;
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid rgba(148, 163, 184, 0.18);
}

.daily-result-message {
  color: #dbeafe;
  font-weight: 800;
  margin-bottom: 14px;
}

.leaderboard-name-area {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.leaderboard-name-area label {
  color: #cbd5e1;
  font-size: 0.9rem;
  font-weight: 800;
}

.leaderboard-name-area input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: rgba(255, 255, 255, 0.92);
  color: #020617;
  font-weight: 800;
}

.share-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.share-actions a,
.share-actions button {
  padding: 10px 14px;
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: rgba(30, 41, 59, 0.82);
  color: #f8fafc;
  font-weight: 900;
  text-decoration: none;
  cursor: pointer;
}

button.daily-disabled,
button.daily-disabled:hover {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
  background: rgba(148, 163, 184, 0.18);
  color: rgba(226, 232, 240, 0.62);
}

.brand-home-link {
  color: inherit;
  text-decoration: none;
}

.brand-home-link:hover {
  opacity: 0.88;
}

.seo-copy-section {
  margin-top: 22px;
}

.seo-copy-section .home-panel {
  max-width: 880px;
  margin: 0 auto 22px;
  text-align: center;
}

.seo-copy-section p {
  font-size: 17px;
  line-height: 1.65;
}

/* -------------------------------------------------------------------------- */
/* Homepage spacing / rhythm polish                                            */
/* -------------------------------------------------------------------------- */

.home-shell {
  max-width: 1180px;
  padding: clamp(18px, 3vw, 32px);
}

.home-shell > section {
  margin: 0 0 clamp(28px, 4vw, 44px);
}

.home-hero-card {
  padding: clamp(44px, 7vw, 76px) clamp(20px, 4vw, 40px);
  margin-bottom: clamp(32px, 5vw, 52px);
}

.home-subtitle {
  max-width: 760px;
  margin: 22px auto 0;
}

.home-actions {
  margin-top: 28px;
}

.daily-leaderboard-card {
  margin-top: 0;
  padding: clamp(24px, 4vw, 36px);
}

.daily-leaderboard-card > h2 {
  text-align: center;
  margin-bottom: 22px;
  font-size: clamp(30px, 5vw, 44px);
}

.daily-actions {
  margin-top: 0;
  margin-bottom: 30px;
}

.leaderboard-panel {
  margin-top: 0;
}

.home-section {
  margin: 0 0 clamp(28px, 4vw, 44px);
}

.home-section > h2,
.seo-copy-section > h2,
.home-cta-card > h2 {
  text-align: center;
  margin-bottom: 20px;
  font-size: clamp(30px, 5vw, 44px);
}

.feature-grid {
  gap: clamp(16px, 2vw, 22px);
}

.home-card {
  min-height: 172px;
}

.seo-copy-section {
  margin-top: 0;
}

.seo-copy-section .home-panel {
  max-width: 880px;
  margin: 0 auto;
  padding: clamp(22px, 3vw, 32px);
  text-align: center;
}

.seo-copy-section p {
  max-width: 780px;
  margin: 0 auto;
  font-size: clamp(16px, 2vw, 18px);
  line-height: 1.65;
}

.home-cta-card {
  padding: clamp(34px, 5vw, 52px);
  margin-bottom: 0;
}

.home-cta-card p {
  text-align: center;
}

@media (max-width: 760px) {
  .home-shell > section {
    margin-bottom: 28px;
  }

  .daily-leaderboard-card {
    padding: 20px;
  }

  .home-section > h2,
  .seo-copy-section > h2,
  .home-cta-card > h2 {
    font-size: 30px;
  }

  .home-card {
    min-height: auto;
  }
}

/* -------------------------------------------------------------------------- */
/* Homepage compact rhythm pass                                                */
/* -------------------------------------------------------------------------- */

.home-shell {
  max-width: 1180px;
  padding-top: 18px;
}

.home-shell > section {
  margin-bottom: 26px;
}

.home-hero-card {
  padding: 46px 36px 48px;
  margin-bottom: 26px;
}

.home-hero-card h1 {
  font-size: clamp(54px, 8vw, 86px);
}

.home-subtitle {
  margin-top: 18px;
  font-size: clamp(18px, 2.2vw, 22px);
  line-height: 1.35;
}

.home-actions {
  margin-top: 24px;
}

.home-button {
  min-height: 52px;
  padding: 13px 21px;
}

.daily-leaderboard-card {
  padding: 28px 30px;
}

.daily-leaderboard-card > h2 {
  margin-bottom: 18px;
}

.daily-actions {
  margin-bottom: 24px;
}

.leaderboard-panel {
  padding: 22px 24px;
}

.leaderboard-header {
  margin-bottom: 16px;
}

.leaderboard-card {
  padding: 15px 16px;
}

.leaderboard-card li {
  padding: 4px 0;
}

.home-section > h2,
.seo-copy-section > h2,
.home-cta-card > h2 {
  margin-bottom: 16px;
}

.home-card {
  min-height: 145px;
  padding: 20px;
}

.feature-label {
  margin-bottom: 10px;
}

.home-card h3 {
  margin-bottom: 7px;
}

.seo-copy-section {
  max-width: 1180px;
  margin-left: auto;
  margin-right: auto;
}

.seo-copy-section .home-panel {
  width: 100%;
  max-width: 100%;
  margin: 0 auto 22px;
  text-align: center;
}

.home-cta-card {
  padding: 34px 32px;
}

.home-cta-card .home-actions {
  margin-top: 18px;
}

@media (max-width: 760px) {
  .home-shell {
    padding-top: 12px;
  }

  .home-hero-card {
    padding: 34px 18px 36px;
  }

  .daily-leaderboard-card {
    padding: 20px;
  }

  .leaderboard-panel {
    padding: 18px;
  }
}

.seo-footer {
  margin-top: 40px;
  padding: 28px;
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.06), transparent),
    var(--panel);

  border: 1px solid rgba(255,255,255,0.08);
  box-shadow: var(--shadow-soft);
}

.seo-footer-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 28px;
}

.seo-footer-column h3 {
  margin-bottom: 14px;
  font-size: 18px;
}

.seo-footer-column a {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.16s ease;
}

.seo-footer-column a:hover {
  color: var(--text);
}

.seo-footer-column p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

@media (max-width: 760px) {
  .seo-footer-grid {
    grid-template-columns: 1fr;
    gap: 20px;
  }
}

.brand-icon {
  width: 26px;
  height: 26px;

  display: inline-flex;
  align-items: center;
  justify-content: center;

  font-size: 24px;
  font-weight: 950;
  line-height: 1;
}

.share-btn-x .brand-icon {
  font-size: 22px;
}

.modal-close-btn {
  position: absolute;
  top: 22px;
  right: 22px;

  width: 42px;
  height: 42px;

  border: 1px solid rgba(255,255,255,0.08);

  border-radius: 14px;

  background:
    linear-gradient(
      180deg,
      rgba(255,255,255,0.08),
      rgba(255,255,255,0.04)
    );

  color: rgba(255,255,255,0.82);

  font-size: 1rem;
  font-weight: 700;

  cursor: pointer;

  transition:
    transform 0.18s ease,
    border-color 0.18s ease,
    box-shadow 0.18s ease,
    background 0.18s ease;
}

.modal-close-btn:hover {
  transform: translateY(-1px);

  border-color: rgba(90,140,255,0.45);

  box-shadow:
    0 0 18px rgba(70,120,255,0.22);

  color: white;
}

.sudoku-rule-image {
  display: block;
  width: 100%;
  height: auto;
  margin: 16px 0 18px;
  border-radius: 18px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.16);
}

/* Contribution page */

.contribute-hero-card {
  padding-top: clamp(28px, 4vw, 48px);
  padding-bottom: clamp(28px, 4vw, 48px);
}

.contribute-hero-card h1 {
  font-size: clamp(2.35rem, 6vw, 4.5rem);
  line-height: 0.95;
  max-width: 900px;
  margin-left: auto;
  margin-right: auto;
}

.contribute-hero-card .home-subtitle {
  max-width: 760px;
  margin-left: auto;
  margin-right: auto;
}

.contribute-intro-panel {
  max-width: 820px;
  margin: 22px auto 0;
  padding: 18px 22px;
}

.contribute-shell {
  width: min(760px, calc(100% - 32px));
  margin: 0 auto;
}

.contribute-progress-wrap {
  margin-bottom: 18px;
}

.contribute-progress-top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
  font-size: 0.9rem;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.78);
}

.contribute-progress-bar {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
}

.contribute-progress-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #4b86ff, #7dd3fc);
  transition: width 220ms ease;
}

.contribute-card {
  border-radius: 28px;
  padding: clamp(18px, 3vw, 28px);
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid rgba(148, 163, 184, 0.18);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(18px);
}

.contribute-target-wrap {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 18px;
  margin-bottom: 14px;
}

.contribute-label {
  font-size: 0.9rem;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.7);
}

.contribute-target-digit {
  font-size: clamp(3.25rem, 9vw, 5.5rem);
  line-height: 0.9;
  font-weight: 950;
  letter-spacing: -0.08em;
  color: #ffffff;
}

.contribute-pad-wrap {
  width: min(440px, 100%);
  height: min(440px, calc(100vw - 64px));
  max-height: 440px;
  margin: 0 auto 18px;
  border-radius: 26px;
  background: #fffefa;
  border: 1px solid rgba(15, 23, 42, 0.14);
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.04);
}

.contribute-pad-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.contribute-card .quick-calibration-result {
  margin-top: 12px;
}

@media (max-width: 720px) {
  .contribute-progress-top {
    flex-direction: column;
    gap: 4px;
  }

  .contribute-target-wrap {
    align-items: center;
  }

  .contribute-card {
    border-radius: 24px;
  }
}

.feedback-rating-grid,
.feedback-digit-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin: 18px 0;
}

.feedback-rating-btn.active {
  outline: 2px solid rgba(125, 211, 252, 0.95);
}

.feedback-digit-grid label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  border-radius: 14px;
  background: rgba(255,255,255,0.08);
  cursor: pointer;
  font-weight: 800;
}

.feedback-comment {
  width: 100%;
  min-height: 110px;
  resize: vertical;
  margin-top: 14px;
  padding: 14px;
  border-radius: 16px;
  border: 1px solid rgba(148,163,184,0.22);
  background: rgba(15,23,42,0.72);
  color: white;
}