:root {
  --bg: #09122b;
  --panel: #0f1b38;
  --panel-soft: #1a2745;
  --line: #394760;
  --line-strong: #6f7f9f;
  --text: #eef2ff;
  --muted: #aab6d1;

  --cell-a: #0d1834;
  --cell-b: #0f1b39;
  --fixed: #3c4a63;
  --related: #314766;
  --same: #224f3a;
  --selected: #3f6fbf;
  --duplicate: #6f2323;
  --notes: #c8d4ff;

  --primary: #4f8cff;
  --warn: #f59e0b;
  --danger: #b23434;
  --good: #16a34a;
}

body.light {
  --bg: #eef3ff;
  --panel: #ffffff;
  --panel-soft: #e8edf7;
  --line: #c8d2e4;
  --line-strong: #71809a;
  --text: #18263e;
  --muted: #5a6880;

  --cell-a: #fbfdff;
  --cell-b: #f4f7fc;
  --fixed: #dfe6f2;
  --related: #dce9ff;
  --same: #ddf6e5;
  --selected: #90b9ff;
  --duplicate: #ffd8d8;
  --notes: #3358aa;

  --primary: #4f8cff;
  --warn: #e8a11d;
  --danger: #cf4a4a;
  --good: #16a34a;
}

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

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  overflow-x: hidden;
}

#app {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px 22px;
}

.topbar {
  margin-bottom: 20px;
}

h1 {
  margin: 0 0 6px 0;
  font-size: 38px;
  line-height: 1.05;
  font-weight: 800;
}

.meta {
  font-size: 17px;
  color: var(--muted);
  margin-bottom: 4px;
}

.status {
  min-height: 24px;
  font-size: 16px;
  color: var(--muted);
  margin-bottom: 14px;
}

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

.soft-btn,
button {
  border: 0;
  border-radius: 18px;
  background: var(--panel-soft);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}

.soft-btn {
  min-height: 56px;
  padding: 14px 18px;
  font-size: 16px;
}

.main-layout {
  display: grid;
  grid-template-columns: minmax(540px, 1fr) 320px;
  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;
}

.board {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  border: 3px solid var(--line-strong);
  background: var(--line);
}

.ink-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 20;
  touch-action: none;
  pointer-events: auto;
}

.cell {
  position: relative;
  border: 1px solid var(--line);
  background: var(--cell-a);
  overflow: hidden;
  user-select: none;
}

.cell.alt {
  background: var(--cell-b);
}

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

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

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

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

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

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

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

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

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

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

.cell-value {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(20px, 2.2vw, 34px);
  font-weight: 600;
  color: var(--text);
  z-index: 2;
}

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

.cell-value.incorrect {
  color: #ff5252;
}

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

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

.side-panel {
  width: 320px;
}

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

.panel-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 8px;
}

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

button {
  min-height: 78px;
  padding: 12px 10px;
  font-size: 18px;
  line-height: 1.05;
}

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

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

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

button.done {
  box-shadow: inset 0 0 0 3px var(--good);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 8, 23, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 100;
}

.hidden {
  display: none;
}

.modal {
  width: min(92vw, 460px);
  background: var(--panel);
  border-radius: 18px;
  padding: 18px;
  color: var(--text);
}

.modal h2 {
  margin-top: 0;
}

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

.modal-actions button {
  min-height: 56px;
  padding: 12px 16px;
  border-radius: 14px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  font-size: 16px;
}

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

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

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