:root {
  color-scheme: light;
  --bg: #fbfaf8;
  --panel: #ffffff;
  --ink: #182130;
  --muted: #8b929c;
  --line: #e7e5e0;
  --shadow: 0 18px 48px rgba(24, 33, 48, 0.12);
  --shadow-soft: 0 10px 28px rgba(24, 33, 48, 0.09);
  --black: #111111;
  --empty: #bdbdbd;
  --tile-1: #d17fef;
  --tile-2: #f658b7;
  --tile-3: #8be2ed;
  --tile-4: #e4832f;
  --tile-5: #dcbea3;
  --tile-6: #f2e451;
  --tile-7: #368bdf;
  --tile-8: #ffffff;
  --tile-9: #53b45b;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  background:
    radial-gradient(circle at 50% 8%, rgba(255, 255, 255, 0.96), rgba(251, 250, 248, 0.94) 42%, #f8f5ef 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
select {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

svg {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.app-shell {
  width: min(100%, 970px);
  margin: 0 auto;
  padding: 16px 16px 34px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 74px;
  padding: 0 28px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow-soft);
}

.brand {
  display: flex;
  align-items: center;
  gap: 22px;
}

.brand h1 {
  margin: 0;
  color: var(--ink);
  font-size: 37px;
  font-weight: 850;
  line-height: 1;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}

.brand-mark span {
  border-radius: 3px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}

.brand-mark span:nth-child(1) { background: var(--tile-7); }
.brand-mark span:nth-child(2) { background: var(--tile-3); }
.brand-mark span:nth-child(3) { background: var(--tile-2); }
.brand-mark span:nth-child(4) { background: var(--tile-8); }
.brand-mark span:nth-child(5) { background: var(--tile-6); }
.brand-mark span:nth-child(6) { background: var(--tile-4); }
.brand-mark span:nth-child(7) { background: var(--tile-5); }
.brand-mark span:nth-child(8) { background: var(--tile-1); }
.brand-mark span:nth-child(9) { background: var(--tile-9); }

.primary-action {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 0 20px;
  border: 0;
  border-radius: 9px;
  background: #162131;
  color: #fff;
  cursor: pointer;
  font-size: 21px;
  font-weight: 780;
  box-shadow: 0 8px 18px rgba(22, 33, 49, 0.22);
}

.primary-action svg {
  width: 23px;
  height: 23px;
}

.board-card {
  width: fit-content;
  margin: 22px auto 20px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 23px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.sudoku-board {
  --board-size: 612px;
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  grid-template-rows: repeat(9, minmax(0, 1fr));
  width: var(--board-size);
  height: var(--board-size);
  border: 3px solid #111;
  border-radius: 5px;
  overflow: hidden;
  background: #f4f4f2;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 1px solid #b5b5b5;
  background: #f4f4f2;
  appearance: none;
}

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

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

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

.cell.given .tile {
  cursor: default;
}

.tile,
.empty-tile {
  position: absolute;
  inset: 4px;
  display: grid;
  place-items: center;
  aspect-ratio: 1 / 1;
  border: 0;
  border-radius: 8px;
  color: #050505;
  font-size: 31px;
  font-weight: 760;
  line-height: 1;
}

.tile {
  cursor: pointer;
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.16),
    inset 0 -7px 12px rgba(0, 0, 0, 0.08),
    0 2px 4px rgba(0, 0, 0, 0.14);
}

.empty-tile {
  background: linear-gradient(145deg, #c6c6c6, #b5b5b5);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

.cell.editable .empty-tile,
.cell.editable .tile {
  cursor: pointer;
}

.cell.selected::after {
  position: absolute;
  inset: 6px;
  border: 3px solid rgba(24, 33, 48, 0.5);
  border-radius: 6px;
  content: "";
  pointer-events: none;
}

.cell.conflict .tile {
  outline: 3px solid rgba(230, 30, 63, 0.75);
}

.tile.v1 { background: var(--tile-1); }
.tile.v2 { background: var(--tile-2); }
.tile.v3 { background: var(--tile-3); }
.tile.v4 { background: var(--tile-4); }
.tile.v5 { background: var(--tile-5); }
.tile.v6 { background: var(--tile-6); }
.tile.v7 { background: var(--tile-7); }
.tile.v8 { background: var(--tile-8); }
.tile.v9 { background: var(--tile-9); }

.notes {
  display: grid;
  width: 52px;
  height: 52px;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  align-items: center;
  color: rgba(24, 33, 48, 0.62);
  font-size: 12px;
  font-weight: 750;
}

.puzzle-pager {
  display: grid;
  grid-template-columns: 40px auto 40px;
  align-items: center;
  width: fit-content;
  min-height: 48px;
  margin: -4px auto 20px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow-soft);
}

.pager-button {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.pager-button:disabled {
  color: #b3b6ba;
  cursor: default;
}

.pager-button svg {
  width: 22px;
  height: 22px;
}

.pager-label {
  min-width: 118px;
  padding: 0 12px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 760;
  text-align: center;
}

.control-dock {
  display: grid;
  grid-template-columns: 132px 170px 132px 128px 128px 128px;
  align-items: center;
  justify-content: center;
  width: min(100%, 890px);
  min-height: 139px;
  margin: 0 auto;
  padding: 24px 26px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.control-block {
  display: grid;
  min-height: 88px;
  align-content: space-between;
  padding: 0 18px;
}

.control-block + .control-block {
  border-left: 1px solid #e8e6e0;
}

.control-label,
.tool-button > span {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 16px;
  font-weight: 680;
  line-height: 1;
}

.control-label svg,
.tool-button > span svg {
  width: 20px;
  height: 20px;
}

.select-like,
.select-wrap select {
  width: 112px;
  height: 49px;
  border: 1px solid #deddd8;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-size: 18px;
  text-align: center;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.select-like {
  display: flex;
  align-items: center;
  justify-content: center;
}

.select-wrap {
  position: relative;
  width: 142px;
}

.select-wrap::after {
  position: absolute;
  right: 16px;
  top: 50%;
  width: 9px;
  height: 9px;
  border-bottom: 2px solid var(--ink);
  border-right: 2px solid var(--ink);
  content: "";
  pointer-events: none;
  transform: translateY(-70%) rotate(45deg);
}

.select-wrap select {
  width: 142px;
  padding: 0 38px 0 18px;
  appearance: none;
  cursor: pointer;
  text-align: left;
}

.switch {
  position: relative;
  width: 58px;
  height: 34px;
  border: 0;
  border-radius: 999px;
  background: #c9c9c9;
  cursor: pointer;
  transition: background 0.18s ease;
}

.switch span {
  position: absolute;
  left: 3px;
  top: 3px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.22);
  transition: transform 0.18s ease;
}

.switch[aria-checked="true"] {
  background: #162131;
}

.switch[aria-checked="true"] span {
  transform: translateX(24px);
}

.tool-button {
  display: grid;
  gap: 10px;
  justify-items: center;
  border: 0;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.tool-button:disabled {
  color: #a9adb2;
  cursor: default;
}

.tool-icon {
  width: 35px;
  height: 35px;
}

.hint-count {
  display: grid;
  width: 35px;
  height: 35px;
  place-items: center;
  border-radius: 50%;
  background: #1c2636;
  color: #fff;
  font-size: 17px;
  font-weight: 800;
}

.number-popover {
  position: fixed;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(3, 44px);
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.number-popover[hidden] {
  display: none;
}

.number-popover button {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-size: 21px;
  font-weight: 800;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.16), 0 2px 4px rgba(0, 0, 0, 0.14);
}

.number-popover .clear {
  grid-column: 1 / -1;
  width: 100%;
  background: #eef0f2;
  color: var(--ink);
  box-shadow: none;
}

.status {
  min-height: 26px;
  margin-top: 16px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.status:empty {
  display: none;
}

@media (max-width: 980px) {
  .app-shell {
    width: min(100%, 720px);
  }

  .sudoku-board {
    --board-size: min(86vw, 612px);
  }

  .cell .tile,
  .cell .empty-tile {
    font-size: clamp(19px, 4.7vw, 31px);
  }

  .control-dock {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    min-height: 0;
    padding: 14px;
    gap: 0;
  }

  .control-block {
    min-height: 66px;
    padding: 0 8px;
    align-content: center;
    gap: 8px;
  }

  .control-block:nth-child(4) {
    border-left: 0;
  }

  .control-label,
  .tool-button > span {
    justify-content: center;
    gap: 6px;
    font-size: 12px;
  }

  .control-label svg,
  .tool-button > span svg {
    width: 17px;
    height: 17px;
  }

  .select-like,
  .select-wrap,
  .select-wrap select {
    width: 100%;
  }

  .select-like,
  .select-wrap select {
    height: 39px;
    border-radius: 9px;
    font-size: 15px;
  }

  .select-wrap select {
    padding: 0 28px 0 10px;
  }

  .select-wrap::after {
    right: 12px;
    width: 8px;
    height: 8px;
  }

  .switch {
    width: 46px;
    height: 28px;
    justify-self: center;
  }

  .switch span {
    width: 22px;
    height: 22px;
  }

  .switch[aria-checked="true"] span {
    transform: translateX(18px);
  }

  .tool-button {
    gap: 6px;
  }

  .tool-icon {
    display: none;
  }

  .hint-count {
    width: 28px;
    height: 28px;
    font-size: 13px;
  }
}

@media (max-width: 620px) {
  .app-shell {
    padding: 14px 10px 28px;
  }

  .topbar {
    min-height: 56px;
    padding: 0 10px;
    border-radius: 13px;
  }

  .brand {
    gap: 10px;
  }

  .brand h1 {
    font-size: 22px;
  }

  .brand-mark {
    width: 30px;
    height: 30px;
    gap: 3px;
  }

  .primary-action {
    min-height: 38px;
    padding: 0 12px;
    font-size: 14px;
  }

  .primary-action svg {
    width: 18px;
    height: 18px;
  }

  .board-card {
    width: 100%;
    margin: 14px auto;
    padding: 8px;
    border-radius: 15px;
  }

  .sudoku-board {
    --board-size: min(calc(100vw - 38px), 560px);
  }

  .tile,
  .empty-tile {
    inset: 3.5px;
    border-radius: 7px;
  }

  .puzzle-pager {
    min-height: 40px;
    margin: -4px auto 14px;
  }

  .pager-button {
    width: 34px;
    height: 34px;
  }

  .pager-button svg {
    width: 19px;
    height: 19px;
  }

  .pager-label {
    min-width: 104px;
    padding: 0 8px;
    font-size: 13px;
  }

  .control-dock {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    min-height: 0;
    padding: 12px;
    gap: 10px 0;
  }

  .control-block {
    min-height: 58px;
    padding: 0 8px;
    align-content: center;
    gap: 8px;
  }

  .clue-block,
  .control-block:nth-child(2) {
    grid-column: span 2;
    min-height: 70px;
  }

  .notes-block,
  .action-block {
    min-height: 56px;
  }

  .control-block,
  .control-block + .control-block,
  .control-block:nth-child(odd),
  .control-block:nth-child(4) {
    border-left: 0;
  }

  .control-label,
  .tool-button > span {
    justify-content: center;
    gap: 6px;
    font-size: 12px;
  }

  .control-label svg,
  .tool-button > span svg {
    width: 17px;
    height: 17px;
  }

  .select-like,
  .select-wrap,
  .select-wrap select {
    width: 100%;
  }

  .select-like,
  .select-wrap select {
    height: 39px;
    border-radius: 9px;
    font-size: 16px;
  }

  .select-wrap::after {
    right: 14px;
    width: 8px;
    height: 8px;
  }

  .switch {
    width: 46px;
    height: 28px;
    justify-self: center;
  }

  .switch span {
    width: 22px;
    height: 22px;
  }

  .switch[aria-checked="true"] span {
    transform: translateX(18px);
  }

  .tool-button {
    gap: 6px;
  }

  .tool-icon {
    display: none;
  }

  .hint-count {
    width: 28px;
    height: 28px;
    font-size: 13px;
  }
}
