:root {
  --ink: #20212b;
  --muted: #6e7280;
  --paper: #f8f5ed;
  --surface: #ffffff;
  --line: #d8d6ca;
  --teal: #1d897f;
  --coral: #c95f46;
  --indigo: #4451a3;
  --amber: #d89b2b;
  --green-soft: #dff4eb;
  --amber-soft: #fbefcf;
  --red-soft: #f7ddd7;
  --shadow: 0 16px 48px rgba(32, 33, 43, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  letter-spacing: 0;
}

body {
  min-height: 100%;
  margin: 0;
  background:
    linear-gradient(90deg, rgba(29, 137, 127, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(68, 81, 163, 0.06) 1px, transparent 1px),
    var(--paper);
  background-size: 34px 34px;
}

button,
input {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition:
    transform 120ms ease,
    border-color 120ms ease,
    background 120ms ease;
}

button:hover {
  border-color: var(--teal);
  transform: translateY(-1px);
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(29, 137, 127, 0.28);
  outline-offset: 2px;
}

button.primary {
  border-color: var(--teal);
  background: var(--teal);
  color: #ffffff;
}

.app-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  max-width: 1440px;
  margin: 0 auto;
  padding: 28px clamp(16px, 3vw, 36px) 16px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--coral);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.05;
}

h1 {
  font-size: clamp(2rem, 5vw, 4.5rem);
  font-weight: 900;
}

h2 {
  font-size: 1.28rem;
  font-weight: 850;
}

.count-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.count-strip span,
.print-summary span {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  padding: 8px 12px;
  box-shadow: 0 8px 24px rgba(32, 33, 43, 0.06);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(230px, 280px) minmax(360px, 1fr) minmax(260px, 340px);
  gap: 16px;
  max-width: 1440px;
  margin: 0 auto;
  padding: 8px clamp(16px, 3vw, 36px) 32px;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
}

.catalog-panel,
.print-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px;
}

.play-panel {
  display: grid;
  gap: 18px;
  padding: clamp(16px, 3vw, 28px);
}

.section-title {
  display: grid;
  gap: 2px;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.tab.is-active {
  border-color: var(--indigo);
  background: #eceefe;
  color: var(--indigo);
  font-weight: 800;
}

.puzzle-list {
  display: grid;
  gap: 8px;
  max-height: 640px;
  overflow: auto;
  padding-right: 4px;
}

.puzzle-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  text-align: left;
}

.puzzle-item.is-active {
  border-color: var(--teal);
  background: var(--green-soft);
}

.puzzle-item span:first-child {
  font-weight: 800;
}

.badge {
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 0.72rem;
  font-weight: 850;
}

.badge.easy {
  background: var(--green-soft);
  color: #09645b;
}

.badge.medium {
  background: var(--amber-soft);
  color: #8c5d00;
}

.badge.hard {
  background: var(--red-soft);
  color: #9b3928;
}

.play-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.timer {
  min-width: 80px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 10px 12px;
  font-weight: 850;
  text-align: center;
}

.board-wrap {
  display: grid;
  justify-content: center;
}

.sudoku-board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  width: min(72vh, 100%, 620px);
  aspect-ratio: 1;
  border: 3px solid var(--ink);
  background: var(--ink);
}

.cell {
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid #9ea1a8;
  border-radius: 0;
  background: #ffffff;
  color: var(--ink);
  font-size: clamp(1rem, 3.2vw, 2rem);
  font-weight: 780;
}

.cell:nth-child(3n) {
  border-right-width: 3px;
}

.cell:nth-child(n + 19):nth-child(-n + 27),
.cell:nth-child(n + 46):nth-child(-n + 54) {
  border-bottom-width: 3px;
}

.cell:nth-child(9n) {
  border-right-width: 1px;
}

.cell.given {
  background: #edf1f7;
  color: #172031;
  font-weight: 900;
}

.cell.selected {
  background: #ddeeea;
}

.cell.related {
  background: #f3f8f7;
}

.cell.conflict,
.cell.wrong {
  background: #f7ddd7;
  color: #9b3928;
}

.cell.correct {
  background: #dff4eb;
  color: #09645b;
}

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

.keypad button {
  min-width: 0;
  font-weight: 850;
}

.keypad button:last-child {
  grid-column: span 1;
  font-size: 0.82rem;
}

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

.actions button {
  flex: 1 1 120px;
  padding: 0 14px;
  font-weight: 780;
}

.status {
  min-height: 24px;
  margin: 0;
  color: var(--muted);
  font-weight: 700;
}

.print-controls {
  display: grid;
  gap: 10px;
}

.print-controls label {
  display: grid;
  grid-template-columns: 1fr 86px;
  align-items: center;
  gap: 10px;
  font-weight: 800;
}

.print-controls input {
  min-height: 40px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  text-align: center;
}

.print-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.preview-list {
  display: grid;
  gap: 8px;
  max-height: 330px;
  overflow: auto;
}

.preview-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 10px;
  font-weight: 800;
}

.mini-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  width: 48px;
  aspect-ratio: 1;
  border: 1px solid var(--ink);
  background: #ffffff;
}

.mini-grid span {
  border-right: 1px solid rgba(32, 33, 43, 0.2);
  border-bottom: 1px solid rgba(32, 33, 43, 0.2);
}

#printArea {
  display: none;
}

.print-page {
  display: grid;
  grid-template-rows: auto 1fr 1fr;
  min-height: 100vh;
  gap: 8mm;
  background:
    radial-gradient(circle at 14px 14px, rgba(29, 137, 127, 0.16) 2px, transparent 2px),
    linear-gradient(135deg, rgba(216, 155, 43, 0.12), transparent 34%),
    #fffdf7;
  background-size: 22px 22px, auto;
  color: #1e2029;
}

.print-cover {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  border-bottom: 2px solid #1e2029;
  padding-bottom: 4mm;
}

.print-cover h2 {
  font-size: 17pt;
}

.print-cover p {
  margin: 0;
  color: #666a75;
  font-size: 8.5pt;
  font-weight: 800;
  text-transform: uppercase;
}

.print-card {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8mm;
  min-height: 0;
  border: 2px solid #1e2029;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.92);
  padding: 7mm;
  overflow: hidden;
  page-break-inside: avoid;
}

.print-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 6mm;
  background: var(--accent, #1d897f);
}

.print-card::after {
  content: "";
  position: absolute;
  right: -18mm;
  top: -18mm;
  width: 38mm;
  height: 38mm;
  border: 6px solid rgba(32, 33, 43, 0.12);
  transform: rotate(28deg);
}

.print-meta {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-width: 34mm;
  padding-left: 3mm;
}

.print-meta strong {
  font-size: 22pt;
  line-height: 1;
}

.print-meta span {
  display: inline-block;
  margin-top: 3mm;
  border: 1.5px solid #1e2029;
  border-radius: 999px;
  padding: 2mm 4mm;
  color: #1e2029;
  font-size: 8pt;
  font-weight: 900;
  text-transform: uppercase;
}

.print-meta small {
  color: #666a75;
  font-weight: 800;
}

.print-board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  width: min(100%, 96mm);
  aspect-ratio: 1;
  justify-self: center;
  align-self: center;
  border: 2.2px solid #1e2029;
  background: #1e2029;
}

.print-cell {
  display: grid;
  place-items: center;
  border: 0.65px solid #878b94;
  background: #ffffff;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 13pt;
  font-weight: 700;
}

.print-cell:nth-child(3n) {
  border-right-width: 2px;
}

.print-cell:nth-child(n + 19):nth-child(-n + 27),
.print-cell:nth-child(n + 46):nth-child(-n + 54) {
  border-bottom-width: 2px;
}

.print-cell:nth-child(9n) {
  border-right-width: 0.65px;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: minmax(220px, 300px) minmax(360px, 1fr);
  }

  .print-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .app-header {
    align-items: start;
    flex-direction: column;
  }

  .count-strip {
    justify-content: start;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .puzzle-list {
    max-height: 260px;
  }

  .sudoku-board {
    width: min(94vw, 560px);
  }

  .keypad {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .keypad button:last-child {
    grid-column: span 5;
  }
}

@media print {
  @page {
    size: A4;
    margin: 12mm;
  }

  html,
  body {
    width: auto;
    min-height: auto;
    background: #ffffff;
  }

  .screen-only {
    display: none !important;
  }

  #printArea {
    display: block;
  }

  .print-page {
    height: 273mm;
    min-height: 0;
    padding: 0;
    break-after: page;
    page-break-after: always;
  }

  .print-page:last-child {
    break-after: auto;
    page-break-after: auto;
  }
}
