:root {
  color-scheme: light;
  --bg: #eef4ef;
  --surface: #ffffff;
  --surface-soft: #f8faf8;
  --ink: #243232;
  --muted: #66706d;
  --line: #cad7d0;
  --line-strong: #233331;
  --accent: #0f766e;
  --accent-soft: #dcefed;
  --accent-warm: #d8893a;
  --danger: #c74343;
  --danger-soft: #f8dddd;
  --selected: #f5d58f;
  --same: #eef6b8;
  --shadow: 0 20px 60px rgba(29, 45, 42, 0.14);
  font-family:
    Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Noto Sans KR",
    sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.08), transparent 38%),
    linear-gradient(315deg, rgba(216, 137, 58, 0.11), transparent 42%),
    var(--bg);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  width: min(1180px, calc(100vw - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 28px 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: 52px;
  height: 52px;
  flex: 0 0 auto;
  overflow: hidden;
  border: 2px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 20px rgba(36, 50, 50, 0.12);
}

.brand-mark span {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.brand-mark span:nth-child(3n) {
  border-right: 0;
}

.brand-mark span:nth-child(n + 7) {
  border-bottom: 0;
}

.brand-mark span:nth-child(1),
.brand-mark span:nth-child(5),
.brand-mark span:nth-child(9) {
  background: var(--accent-soft);
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 3vw, 3.2rem);
  line-height: 1;
  letter-spacing: 0;
}

.brand p {
  min-height: 1.45em;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.98rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(74px, 1fr));
  gap: 10px;
  width: min(360px, 45vw);
}

.stats div {
  min-height: 64px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
}

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

.stats strong {
  display: block;
  margin-top: 4px;
  font-size: 1.25rem;
  letter-spacing: 0;
}

.game-layout {
  --board-size: 660px;
  display: grid;
  grid-template-columns: minmax(320px, var(--board-size)) minmax(260px, 340px);
  align-items: start;
  justify-content: center;
  gap: 28px;
}

.board-zone {
  width: 100%;
}

.sudoku-board {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  width: min(100%, var(--board-size));
  aspect-ratio: 1;
  overflow: hidden;
  border: 3px solid var(--line-strong);
  border-radius: 8px;
  background: var(--line-strong);
  box-shadow: var(--shadow);
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  min-width: 0;
  aspect-ratio: 1;
  margin: 0;
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface);
  cursor: pointer;
  outline: none;
  transition:
    background-color 120ms ease,
    box-shadow 120ms ease,
    color 120ms ease;
}

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

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

.cell.edge-right {
  border-right: 0;
}

.cell.edge-bottom {
  border-bottom: 0;
}

.cell:hover,
.cell:focus-visible {
  box-shadow: inset 0 0 0 3px rgba(15, 118, 110, 0.28);
  z-index: 1;
}

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

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

.cell.selected {
  background: var(--selected);
  box-shadow: inset 0 0 0 3px rgba(36, 50, 50, 0.34);
  z-index: 2;
}

.cell.error {
  background: var(--danger-soft);
  color: var(--danger);
}

.cell.fixed {
  color: var(--ink);
  font-weight: 800;
}

.cell.user-value {
  color: var(--accent);
  font-weight: 750;
}

.cell.hint-value {
  color: var(--accent-warm);
}

.value {
  font-size: clamp(1.35rem, 5.8vw, 3rem);
  line-height: 1;
}

.notes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: 72%;
  height: 72%;
  color: var(--muted);
  font-size: clamp(0.48rem, 1.55vw, 0.9rem);
  line-height: 1;
}

.notes span {
  display: grid;
  place-items: center;
  min-width: 0;
}

.control-panel {
  display: grid;
  gap: 16px;
  width: 100%;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  min-height: 46px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.segmented button {
  min-width: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
}

.segmented button.is-active {
  background: var(--ink);
  color: var(--surface);
}

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

.icon-action {
  display: grid;
  place-items: center;
  min-width: 0;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(36, 50, 50, 0.08);
}

.icon-action:hover,
.icon-action:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.icon-action:disabled {
  cursor: not-allowed;
  opacity: 0.46;
}

.icon-action svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 54px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  font-weight: 800;
}

.toggle-row input {
  width: 48px;
  height: 28px;
  margin: 0;
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #dfe8e3;
  cursor: pointer;
  transition:
    background-color 140ms ease,
    border-color 140ms ease;
}

.toggle-row input::before {
  display: block;
  width: 22px;
  height: 22px;
  margin: 2px;
  border-radius: 999px;
  background: var(--surface);
  box-shadow: 0 2px 6px rgba(36, 50, 50, 0.24);
  content: "";
  transition: transform 140ms ease;
}

.toggle-row input:checked {
  border-color: var(--accent);
  background: var(--accent);
}

.toggle-row input:checked::before {
  transform: translateX(20px);
}

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

.number-pad button {
  min-width: 0;
  min-height: 70px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--accent);
  cursor: pointer;
  font-size: 1.8rem;
  font-weight: 800;
  box-shadow: 0 8px 18px rgba(36, 50, 50, 0.08);
}

.number-pad button:hover,
.number-pad button:focus-visible {
  border-color: var(--accent);
  background: var(--accent-soft);
  outline: none;
}

.number-pad button:disabled {
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.42;
}

.message-line {
  min-height: 44px;
  padding: 12px 14px;
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
}

.complete-dialog {
  width: min(360px, calc(100vw - 36px));
  border: 0;
  border-radius: 8px;
  padding: 26px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
  text-align: center;
}

.complete-dialog::backdrop {
  background: rgba(22, 34, 32, 0.42);
}

.dialog-mark {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
}

.dialog-mark svg {
  width: 32px;
  height: 32px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.4;
}

.complete-dialog h2 {
  margin: 0;
  font-size: 1.8rem;
  letter-spacing: 0;
}

.complete-dialog p {
  margin: 10px 0 22px;
  color: var(--muted);
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.dialog-actions button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  cursor: pointer;
  font-weight: 800;
}

.dialog-actions button:last-child {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--surface);
}

@media (min-width: 901px) {
  .game-layout {
    --board-size: min(660px, calc(100vh - 170px));
  }
}

@media (max-width: 900px) {
  .app-shell {
    width: min(100vw - 24px, 680px);
    padding: 18px 0 24px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    margin-bottom: 18px;
  }

  .stats {
    width: 100%;
  }

  .game-layout {
    grid-template-columns: 1fr;
    gap: 18px;
  }

  .sudoku-board {
    width: 100%;
  }

  .control-panel {
    gap: 12px;
  }

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

  .number-pad button {
    min-height: 48px;
    font-size: 1.25rem;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100vw - 16px, 520px);
    padding-top: 12px;
  }

  .brand-mark {
    width: 44px;
    height: 44px;
  }

  .brand p {
    font-size: 0.88rem;
  }

  .stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .stats div {
    min-height: 56px;
    padding: 8px;
  }

  .stats strong {
    font-size: 1rem;
  }

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

  .action-grid {
    gap: 6px;
  }

  .icon-action {
    min-height: 46px;
  }

  .number-pad {
    gap: 5px;
  }

  .number-pad button {
    min-height: 42px;
    font-size: 1.05rem;
  }

  .value {
    font-size: clamp(1.12rem, 8vw, 1.9rem);
  }

  .notes {
    font-size: clamp(0.42rem, 2.5vw, 0.62rem);
  }
}
