:root {
  color-scheme: light;
  --ink: #202124;
  --muted: #65707a;
  --paper: #f3f0e9;
  --panel: #fffdfa;
  --line: #d9d3c8;
  --accent: #2f80a8;
  --accent-dark: #1f5d7b;
  --warn: #d95043;
  --ok: #4f8d5f;
  --circle: #7355a4;
  --shadow: 0 22px 50px rgba(44, 36, 24, 0.15);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(47, 128, 168, 0.16), transparent 34%),
    linear-gradient(225deg, rgba(232, 184, 79, 0.18), transparent 44%),
    var(--paper);
  color: var(--ink);
}

button,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 14px;
  min-height: 100vh;
  padding: 14px;
}

.game-panel,
.lesson-panel {
  background: rgba(255, 253, 250, 0.9);
  border: 1px solid rgba(217, 211, 200, 0.92);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.game-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 20px 22px 12px;
  flex-wrap: wrap;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 1.45rem;
  font-weight: 800;
}

h2 {
  font-size: 1.05rem;
  font-weight: 800;
  margin-bottom: 6px;
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.select-control {
  display: inline-flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
}

.select-control select {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  font-weight: 600;
  color: var(--ink);
}

.controls button {
  background: var(--accent);
  color: white;
  border-radius: 6px;
  padding: 8px 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
  transition: background 120ms ease;
}

.controls button:hover {
  background: var(--accent-dark);
}

.controls button.secondary {
  background: transparent;
  color: var(--accent-dark);
  border: 1px solid var(--accent);
}

.controls button.secondary:hover {
  background: rgba(47, 128, 168, 0.1);
}

.status-strip {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 22px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: rgba(243, 240, 233, 0.6);
  font-size: 0.9rem;
  color: var(--muted);
}

.status-strip strong {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  font-size: 1rem;
}

.board-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px;
  min-height: 0;
}

.nc-board {
  display: grid;
  grid-template-columns: repeat(var(--nc-cols, 8), minmax(40px, 60px));
  gap: 4px;
  font-variant-numeric: tabular-nums;
}

.nc-board.is-solved .nc-cell.is-kept,
.nc-board.is-solved .nc-cell.is-circled {
  background: rgba(79, 141, 95, 0.18);
  border-color: var(--ok);
}

.nc-corner {
  /* empty top-left */
}

.nc-target {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--muted);
  padding: 4px 2px;
  border-radius: 4px;
  transition: color 140ms ease, background 140ms ease;
}

.nc-target.is-match {
  color: var(--ok);
  background: rgba(79, 141, 95, 0.12);
}

.nc-target.is-over {
  color: var(--warn);
  background: rgba(217, 80, 67, 0.08);
}

.nc-current {
  font-weight: 800;
}

.nc-slash {
  opacity: 0.5;
}

.nc-goal {
  font-weight: 700;
  color: var(--ink);
}

.nc-target.is-match .nc-goal,
.nc-target.is-over .nc-goal {
  color: inherit;
}

.nc-cell {
  aspect-ratio: 1 / 1;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  position: relative;
  transition: background 110ms ease, border-color 110ms ease, color 110ms ease, transform 80ms ease;
}

.nc-cell:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.nc-cell.is-kept {
  /* default */
}

.nc-cell.is-crossed {
  color: var(--muted);
  background: rgba(217, 211, 200, 0.4);
  text-decoration: line-through;
  text-decoration-color: var(--warn);
  text-decoration-thickness: 2px;
  opacity: 0.65;
}

.nc-cell.is-circled {
  color: var(--circle);
  border-color: var(--circle);
  background: rgba(115, 85, 164, 0.08);
  box-shadow: inset 0 0 0 2px var(--circle);
}

.legend {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 22px 18px;
  font-size: 0.78rem;
  color: var(--muted);
  flex-wrap: wrap;
}

.legend kbd {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 2px 6px;
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--ink);
}

.legend-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 5px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
}

.legend-dot.legend-kept {
  /* default style */
}

.legend-dot.legend-crossed {
  color: var(--muted);
  background: rgba(217, 211, 200, 0.4);
  text-decoration: line-through;
  text-decoration-color: var(--warn);
  text-decoration-thickness: 2px;
}

.legend-dot.legend-circled {
  color: var(--circle);
  border-color: var(--circle);
  box-shadow: inset 0 0 0 2px var(--circle);
}

.lesson-panel {
  padding: 22px;
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--ink);
}

.lesson-panel p {
  margin: 0 0 10px;
}

.lesson-panel em {
  color: var(--accent-dark);
  font-style: normal;
  font-weight: 700;
}

@media (max-width: 880px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr);
  }
  .lesson-panel {
    order: -1;
  }
}

/* ---------- Print worksheet ---------- */

.print-sheet {
  display: none;
}

@media print {
  body {
    background: #fff;
    color: #000;
  }
  .app-shell {
    display: none !important;
  }
  .print-sheet {
    display: block;
    padding: 0.3in;
    color: #000;
    font-family: Georgia, "Times New Roman", serif;
  }
  .print-header h1 {
    margin: 0 0 2px;
    font-size: 20pt;
    font-weight: 700;
    letter-spacing: 0.02em;
  }
  .print-sub {
    margin: 0 0 8px;
    font-size: 9pt;
    font-style: italic;
    color: #555;
  }
  .print-instr {
    margin: 0 0 12px;
    font-size: 9pt;
    line-height: 1.3;
    max-width: 100%;
  }
  .print-puzzles {
    display: grid;
    grid-template-columns: repeat(var(--print-cols, 1), 1fr);
    grid-template-rows: repeat(var(--print-rows, 1), auto);
    gap: 0.2in;
  }
  .print-puzzle {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }
  .print-puzzle-label {
    font-size: 8pt;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #666;
  }
  .print-grid {
    display: grid;
    grid-template-columns: var(--print-cell-size, 0.5in) repeat(calc(var(--nc-print-cols, 8) - 1), var(--print-cell-size, 0.5in));
    gap: 0;
  }
  .print-target,
  .print-cell {
    width: var(--print-cell-size, 0.5in);
    height: var(--print-cell-size, 0.5in);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11pt;
    font-variant-numeric: tabular-nums;
    font-weight: 500;
  }
  .print-target {
    font-weight: 600;
    color: #000;
    padding: 2px;
    text-align: center;
  }
  .print-cell {
    border: 1px solid #000;
    background: #fff;
  }
  @page {
    margin: 0.35in;
  }
}

