:root {
  --bg-deep: #121d26;
  --bg-mid: #203b51;
  --panel: rgba(245, 239, 231, 0.96);
  --panel-soft: rgba(255, 249, 243, 0.92);
  --ink: #201814;
  --muted: #665851;
  --line: rgba(38, 27, 21, 0.12);
  --accent: #d39b45;
  --accent-deep: #c35d35;
  --board-line: #2d3f50;
  --cell-light: #fbf8f1;
  --cell-related: #e7eff8;
  --cell-selected: #dbe8f7;
  --cell-given: #efe7d8;
  --cell-same: #f1d7b1;
  --cell-conflict: #f7d0cf;
  --cell-hint: #d9f0da;
  --shadow: 0 22px 56px rgba(8, 10, 13, 0.34);
  --board-size: min(78vw, 612px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 16% 12%, rgba(211, 155, 69, 0.16), transparent 22%),
    radial-gradient(circle at 84% 14%, rgba(145, 180, 206, 0.18), transparent 24%),
    linear-gradient(150deg, var(--bg-deep), var(--bg-mid));
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    linear-gradient(120deg, rgba(255, 255, 255, 0.026), transparent 28%),
    linear-gradient(rgba(255, 255, 255, 0.014) 0, rgba(255, 255, 255, 0.014) 1px, transparent 1px, transparent 76px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.014) 0, rgba(255, 255, 255, 0.014) 1px, transparent 1px, transparent 76px);
  opacity: 0.34;
  pointer-events: none;
}

.sudoku-app {
  width: min(1220px, calc(100% - 28px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.sudoku-topbar,
.sudoku-controls,
.board-panel,
.keypad-card,
.insight-card,
.rules-card {
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.sudoku-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  border-radius: 24px;
}

.sudoku-topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sudoku-brand {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  text-decoration: none;
  color: var(--ink);
}

.sudoku-brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  color: #23150f;
  font-weight: 900;
}

.sudoku-brand-copy {
  display: grid;
  gap: 2px;
}

.sudoku-brand-copy strong {
  font-size: 1.04rem;
}

.sudoku-brand-copy span {
  color: var(--muted);
  font-size: 0.92rem;
}

.sudoku-return,
.sudoku-support,
.action-button,
.sudoku-cell,
.keypad-button {
  font: inherit;
}

.sudoku-return,
.sudoku-support,
.action-button,
.keypad-button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 46px;
  padding: 0 18px;
  border: 1px solid rgba(36, 25, 18, 0.12);
  border-radius: 999px;
  background: linear-gradient(145deg, #fffaf3, #ecdcc6);
  color: var(--ink);
  text-decoration: none;
  font-weight: 800;
  cursor: pointer;
  transition: transform 140ms ease, opacity 140ms ease, background 140ms ease;
}

.action-button.primary {
  background: linear-gradient(145deg, var(--accent), var(--accent-deep));
  color: #23150f;
}

.sudoku-support {
  background: linear-gradient(145deg, #ffdc42, #f0b90a);
  color: #23150f;
}

.sudoku-return:hover,
.sudoku-return:focus-visible,
.sudoku-support:hover,
.sudoku-support:focus-visible,
.action-button:hover,
.action-button:focus-visible,
.keypad-button:hover,
.keypad-button:focus-visible,
.sudoku-cell:hover,
.sudoku-cell:focus-visible {
  transform: translateY(-1px);
}

.action-button:disabled,
.sudoku-cell:disabled,
.keypad-button:disabled {
  opacity: 0.52;
  cursor: not-allowed;
  transform: none;
}

.action-button.active-toggle {
  background: linear-gradient(145deg, rgba(211, 155, 69, 0.18), rgba(33, 59, 81, 0.12));
  border-color: rgba(195, 93, 53, 0.3);
}

.sudoku-hero {
  display: grid;
  grid-template-columns: minmax(0, 0.92fr) minmax(360px, 1.08fr);
  gap: 20px;
  align-items: start;
  padding: 28px 0 18px;
}

.eyebrow {
  margin: 0 0 12px;
  color: rgba(255, 247, 235, 0.8);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.sudoku-copy h1,
.sudoku-status h2,
.rules-card h3,
.keypad-card h3,
.insight-card h3,
.result-overlay h2 {
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
}

.sudoku-copy h1 {
  margin: 0 0 14px;
  max-width: 10ch;
  color: #fff7eb;
  font-size: clamp(2.3rem, 5vw, 4.6rem);
  line-height: 0.95;
}

.sudoku-copy p:last-child {
  margin: 0;
  max-width: 60ch;
  color: rgba(255, 244, 231, 0.84);
  line-height: 1.65;
}

.sudoku-controls {
  border-radius: 30px;
  padding: 22px;
}

.sudoku-status h2 {
  margin: 0;
  font-size: clamp(1.26rem, 2.4vw, 1.82rem);
  line-height: 1.12;
}

.notice-text,
.selection-copy {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.58;
}

.setup-row {
  display: grid;
  margin-top: 18px;
}

.setup-label {
  margin: 0 0 10px;
  color: #584635;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.difficulty-select {
  min-height: 48px;
  width: 100%;
  padding: 0 14px;
  border: 1px solid rgba(36, 25, 18, 0.12);
  border-radius: 16px;
  background: #fbf4ea;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.metric-card {
  padding: 14px;
  border: 1px solid rgba(36, 25, 18, 0.1);
  border-radius: 20px;
  background: var(--panel-soft);
}

.metric-card span {
  display: block;
  margin-bottom: 6px;
  color: #786452;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.metric-card strong {
  font-size: 1.28rem;
}

.control-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 18px;
}

.sudoku-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.12fr) minmax(300px, 0.88fr);
  gap: 20px;
  align-items: start;
}

.board-panel {
  position: relative;
  border-radius: 34px;
  padding: 20px;
  background:
    radial-gradient(circle at top, rgba(255, 246, 231, 0.16), transparent 24%),
    linear-gradient(155deg, #28465d, #182733);
}

.board-shell {
  display: grid;
  place-items: center;
  padding: 14px;
  border-radius: 28px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.08), transparent 32%),
    linear-gradient(145deg, #edf3f7, #dbe5ed);
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.08),
    inset 0 -8px 14px rgba(34, 50, 63, 0.12);
}

.sudoku-board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  width: var(--board-size);
  max-width: 100%;
  aspect-ratio: 1;
  border: 4px solid var(--board-line);
  border-radius: 18px;
  overflow: hidden;
  background: white;
}

.sudoku-cell {
  position: relative;
  border: 1px solid rgba(45, 63, 80, 0.18);
  padding: 0;
  background: var(--cell-light);
  min-width: 0;
  min-height: 0;
}

.sudoku-cell.given {
  background: var(--cell-given);
}

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

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

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

.sudoku-cell.conflict {
  background: var(--cell-conflict);
}

.sudoku-cell.hinted {
  background: var(--cell-hint);
}

.sudoku-cell.box-right {
  border-right: 3px solid var(--board-line);
}

.sudoku-cell.box-bottom {
  border-bottom: 3px solid var(--board-line);
}

.cell-value {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(1.2rem, 2.8vw, 2rem);
  font-weight: 800;
  color: #17304a;
}

.sudoku-cell.given .cell-value {
  color: #1f1914;
}

.cell-notes {
  position: absolute;
  inset: 6px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 2px;
  align-items: center;
  justify-items: center;
  font-size: clamp(0.46rem, 1vw, 0.72rem);
  color: #5f6d78;
  line-height: 1;
}

.result-overlay {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(92%, 420px);
  padding: 22px 20px 18px;
  transform: translate(-50%, -50%);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(255, 249, 241, 0.97), rgba(253, 244, 232, 0.98)),
    var(--panel);
  text-align: center;
  box-shadow: 0 22px 48px rgba(12, 5, 2, 0.36);
  z-index: 5;
}

.result-overlay[hidden] {
  display: none;
}

.overlay-kicker {
  margin: 0 0 6px;
  color: #7c654f;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.result-overlay h2 {
  margin: 0 0 10px;
  font-size: clamp(1.7rem, 3vw, 2.2rem);
  line-height: 1;
}

.overlay-message {
  margin: 0 auto;
  max-width: 30ch;
  color: var(--muted);
  line-height: 1.58;
}

.overlay-stats,
.overlay-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.overlay-stats span {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  border-radius: 999px;
  background: #f4e9da;
  color: #594537;
  font-weight: 700;
}

.sudoku-sidebar {
  display: grid;
  gap: 16px;
}

.keypad-card,
.insight-card,
.rules-card {
  border-radius: 28px;
  padding: 18px;
}

.keypad-card {
  background:
    linear-gradient(165deg, rgba(255, 255, 255, 0.34), transparent 46%),
    var(--panel);
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

.keypad-card h3,
.insight-card h3,
.rules-card h3 {
  margin: 0;
  font-size: 1.26rem;
}

.card-head span {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

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

.keypad-button {
  min-height: 56px;
  border-radius: 18px;
  background: var(--panel-soft);
  font-size: 1.22rem;
}

.keypad-button.active-number {
  background: linear-gradient(145deg, rgba(211, 155, 69, 0.22), rgba(255, 249, 243, 0.96));
}

.keypad-actions {
  display: flex;
  margin-top: 14px;
}

.keypad-actions .action-button {
  width: 100%;
}

.candidate-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.candidate-pill {
  display: inline-flex;
  min-width: 34px;
  min-height: 34px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--panel-soft);
  border: 1px solid rgba(36, 25, 18, 0.08);
  font-weight: 800;
}

.rules-list {
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 10px;
}

.rules-list li {
  color: var(--muted);
  line-height: 1.58;
  padding-left: 18px;
  position: relative;
}

.rules-list li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.72em;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  transform: translateY(-50%);
}

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

  .sudoku-copy h1 {
    max-width: none;
  }
}

@media (max-width: 760px) {
  .sudoku-app {
    width: min(100%, calc(100% - 20px));
    padding-top: 14px;
  }

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

  .sudoku-topbar-actions {
    width: 100%;
    justify-content: stretch;
  }

  .sudoku-topbar-actions > * {
    flex: 1 1 0;
  }

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

  .board-panel,
  .sudoku-controls,
  .keypad-card,
  .insight-card,
  .rules-card {
    padding: 16px;
  }

  .control-row {
    flex-direction: column;
  }

  .control-row .action-button {
    width: 100%;
  }

  .sudoku-board {
    width: min(100vw - 64px, 520px);
  }
}
