:root {
  --ink: #18202d;
  --muted: #667085;
  --paper: #fffdf8;
  --surface: #ffffff;
  --line: #d9dde6;
  --strong-line: #303846;
  --accent: #087f8c;
  --accent-dark: #05616b;
  --accent-soft: #d9f1f3;
  --warning: #b42318;
  --success: #16723b;
  --shadow: 0 20px 60px rgba(24, 32, 45, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(135deg, rgba(8, 127, 140, 0.13), rgba(255, 255, 255, 0) 42%),
    linear-gradient(315deg, rgba(232, 111, 81, 0.13), rgba(255, 255, 255, 0) 44%),
    var(--paper);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.game-panel {
  width: min(100%, 760px);
  padding: clamp(18px, 3vw, 34px);
  border: 1px solid rgba(48, 56, 70, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

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

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 7vw, 3.6rem);
  line-height: 0.95;
}

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

.stats div {
  min-width: 82px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  text-align: right;
}

.stats span {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.stats strong {
  display: block;
  margin-top: 2px;
  font-size: 1.15rem;
}

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

.levels {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 0;
  padding: 0;
  border: 0;
}

.levels legend {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.levels input {
  position: absolute;
  opacity: 0;
}

.levels span,
.actions button,
.number-pad button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 800;
}

.levels span {
  min-width: 92px;
  padding: 0 14px;
}

.levels input:checked + span {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.levels input:focus-visible + span,
button:focus-visible,
.cell:focus-visible {
  outline: 3px solid rgba(8, 127, 140, 0.26);
  outline-offset: 2px;
}

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

.actions button {
  padding: 0 15px;
}

.actions button:hover,
.number-pad button:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.board-wrap {
  display: grid;
  place-items: center;
  margin: 6px auto 18px;
}

.board {
  display: grid;
  width: min(100%, 540px);
  aspect-ratio: 1;
  grid-template-columns: repeat(6, 1fr);
  border: 3px solid var(--strong-line);
  background: var(--strong-line);
  gap: 1px;
}

.cell {
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 0;
  background: var(--surface);
  color: var(--ink);
  font-size: clamp(1.35rem, 7vw, 2.7rem);
  font-weight: 850;
  text-align: center;
}

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

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

.cell:nth-child(n + 13):nth-child(-n + 18),
.cell:nth-child(n + 25):nth-child(-n + 30) {
  border-top: 2px solid var(--strong-line);
}

.cell.given {
  background: #eef3f8;
  color: #26364b;
}

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

.cell.related {
  background: #f5f9fa;
}

.cell.same {
  background: #e8f5ec;
}

.cell.complete-unit {
  background: #eaf8ff;
}

.cell.complete-unit.related {
  background: #e1f5ff;
}

.cell.complete-unit.selected {
  background: #d5f0ff;
}

.cell.error {
  background: #fde7e5;
  color: var(--warning);
}

.cell.correct {
  color: var(--success);
}

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

.number-pad button {
  min-width: 0;
}

.number-pad [data-number="0"] {
  grid-column: span 1;
  color: var(--warning);
}

.message {
  min-height: 1.5em;
  margin: 16px 0 0;
  color: var(--muted);
  font-weight: 700;
  text-align: center;
}

.message.win {
  color: var(--success);
}

.message.warn {
  color: var(--warning);
}

@media (max-width: 680px) {
  .shell {
    align-items: start;
    padding: 12px;
  }

  .game-panel {
    padding: 16px;
  }

  .topbar,
  .controls {
    align-items: stretch;
    flex-direction: column;
  }

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

  .stats div {
    text-align: left;
  }

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

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

  .levels span {
    min-width: 0;
    padding: 0 8px;
  }

  .number-pad {
    grid-template-columns: repeat(4, 1fr);
  }

  .number-pad [data-number="0"] {
    grid-column: span 2;
  }
}

@media (max-width: 390px) {
  .actions,
  .levels {
    grid-template-columns: 1fr;
  }
}
