:root {
  color-scheme: light;
  --canvas: #e8efec;
  --sheet: #fbfcfa;
  --ink: #17362d;
  --muted: #48675e;
  --line: #a8bdb3;
  --strong-line: #54736a;
  --jade: #17604f;
  --jade-pale: #d7eae1;
  --amber: #89520c;
  --amber-pale: #fff0cd;
  --focus: #075ac0;
  --accent: var(--focus);
  --signal: var(--jade);
  --ease-out: cubic-bezier(.2, .72, .25, 1);
  --fonts: "Avenir Next", -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--fonts);
  line-height: 1.45;
}
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}
.sudoku-shell { width: min(100% - 44px, 958px); margin: 0 auto; padding: 30px 0 37px; }
.sudoku-shell[data-mode="daily"] { --signal: var(--amber); }
.page-header {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  row-gap: 11px;
  margin-bottom: 19px;
  padding-bottom: 15px;
  border-bottom: 1px solid var(--line);
}
.hall-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  justify-self: start;
  min-height: 40px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
  text-decoration: none;
}
.hall-link span { font-size: 26px; line-height: 1; margin-top: -3px; }
.hall-link:hover { color: var(--jade); text-decoration: underline; }
.page-tools { display: flex; gap: 7px; justify-content: end; flex-wrap: wrap; }
h1 {
  margin: 0;
  font-family: "Songti SC", "Noto Serif CJK SC", "SimSun", serif;
  font-size: clamp(36px, 6.2vw, 60px);
  font-weight: 800;
  letter-spacing: -.06em;
  line-height: 1.07;
}
h2, h3, p { margin: 0; }
button, summary {
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--sheet);
  min-height: 42px;
  padding: 7px 12px;
  font-size: 14px;
  font-weight: 650;
  transition: background-color .14s var(--ease-out), border-color .14s var(--ease-out), color .12s ease-out;
}
button:not(.cell):hover:not(:disabled), summary:hover { border-color: var(--jade); color: var(--jade); }
button:disabled { color: #5c7268; opacity: .6; }
.primary, .share-button {
  color: white;
  background: var(--jade);
  border-color: var(--jade);
}
button.primary:hover:not(:disabled), button.share-button:hover:not(:disabled) { color: white; background: #0c473b; }
.modes {
  display: flex;
  gap: 3px;
  border: 1px solid var(--line);
  padding: 3px;
  border-radius: 9px;
  background: #dce7e1;
}
.modes button { flex: 1; border-color: transparent; min-height: 37px; background: transparent; color: var(--muted); }
.modes button[aria-pressed="true"] { background: var(--sheet); border-color: #bdcec4; color: var(--signal); }
.notice { margin: 0 0 13px; padding: 9px 12px; background: var(--amber-pale); color: #704506; border-radius: 6px; font-size: 14px; }

.play {
  display: grid;
  grid-template-columns: minmax(0, 554px) minmax(255px, 1fr);
  grid-template-areas: "meta settings" "board controls" "footer controls";
  grid-template-rows: auto auto 1fr;
  column-gap: clamp(24px, 4.1vw, 53px);
  row-gap: 12px;
  align-items: start;
}
.board-meta { grid-area: meta; display: grid; grid-template-rows: 1fr auto; align-self: stretch; align-items: center; gap: 7px; }
.board-meta strong { font-size: 15px; }
.board-meta #progress-count { margin-left: 8px; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
progress { width: 100%; height: 3px; border: 0; appearance: none; background: #c5d6ce; }
progress::-webkit-progress-bar { background: #c5d6ce; }
progress::-webkit-progress-value { background: var(--signal); transition: width .23s var(--ease-out); }
progress::-moz-progress-bar { background: var(--signal); }

.board-stage { grid-area: board; min-width: 0; position: relative; }
.board {
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  grid-template-rows: repeat(9, minmax(0, 1fr));
  overflow: hidden;
  border: 2px solid var(--strong-line);
  border-radius: 4px;
  background: var(--sheet);
  isolation: isolate;
}
.board-effects {
  position: absolute;
  inset: 2px;
  overflow: hidden;
  pointer-events: none;
}
.selection-cursor {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  width: calc(100% / 9);
  height: calc(100% / 9);
  transform: translate3d(var(--select-x, 0%), var(--select-y, 0%), 0);
  box-shadow: inset 0 0 0 2px var(--jade);
}
.selection-cursor.adjacent { transition: transform .14s var(--ease-out); }
.board-stage.showing-hint .selection-cursor { opacity: .65; }
.win-sweep {
  position: absolute;
  inset: -65% -30%;
  opacity: 0;
  background: linear-gradient(134deg, transparent 42%, #b0edcd66 48%, #fcffefbd 50%, #b0edcd66 52%, transparent 58%);
}
.board-row { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); }
.grid-slot { min-width: 0; min-height: 0; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.grid-slot:nth-child(3n):not(:last-child) { border-right: 2px solid var(--strong-line); }
.board-row:nth-child(3n):not(:last-child) .grid-slot { border-bottom: 2px solid var(--strong-line); }
.grid-slot:last-child { border-right: 0; }
.board-row:last-child .grid-slot { border-bottom: 0; }
.board .cell {
  display: grid;
  place-items: center;
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  color: var(--jade);
  background: var(--sheet);
  font-size: clamp(20px, 5.3vw, 35px);
  font-variant-numeric: lining-nums tabular-nums;
  font-weight: 600;
  line-height: 1;
  touch-action: manipulation;
  transition: background-color .16s var(--ease-out), color .12s ease-out;
}
.cell.given { color: var(--ink); font-weight: 600; }
.cell.peer { background: #e9f1ed; }
.cell.match { background: #cfebdf; }
.cell.selected { background: #bce0d2; }
.cell.conflict { color: #95332c; background: #f9ded8; }
.cell:focus-visible { z-index: 1; outline-offset: -3px; }
.cell:active:not(:disabled) { transform: none; }
.cell-value, .cell-notes { z-index: 1; }
.cell-wash, .cell-echo {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}
.cell-wash { background: #74d8a836; box-shadow: inset 0 0 0 1.5px #44a08073; }
.cell.conflict .cell-wash { background: #e8786338; box-shadow: inset 0 0 0 1.5px #c64f42a3; }
.cell.hint-answer .cell-wash { background: #f6b74c40; box-shadow: inset 0 0 0 2px #a2651e91; }
.cell-echo { display: grid; place-items: center; color: var(--jade); z-index: 1; }
.cell.daily-target::before {
  position: absolute;
  content: "";
  width: 6px;
  height: 6px;
  border: 1px solid #89520c;
  border-radius: 50%;
  background: #e0a446;
  top: 4px;
  right: 4px;
}
.cell.daily-target:not(.selected):not(.conflict):not(.hint-answer) { background: #fff4dd; }
.cell.hint-area:not(.conflict) { background: #f9eed5; }
.cell.hint-proof { box-shadow: inset 0 0 0 2px #ab6b19; }
.cell.hint-focus::after, .cell.hint-excluded:not(.hint-candidates)::after {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px dashed #966323;
  pointer-events: none;
}
.cell.hint-excluded:not(.hint-candidates)::after { inset: 22%; opacity: .7; border: 0; background: linear-gradient(135deg, transparent 47%, #a0743f 48% 51%, transparent 52%); }
.cell.hint-answer {
  background: #ffde98;
  box-shadow: inset 0 0 0 2px var(--amber);
}
.cell-notes {
  position: absolute;
  inset: 8%;
  display: grid;
  grid-template: repeat(3, minmax(0, 1fr)) / repeat(3, minmax(0, 1fr));
  place-items: center;
  color: var(--muted);
  font-weight: 650;
  font-size: clamp(8px, 2.3vw, 13px);
}
.cell-notes .mark-proof, .cell-notes .mark-excluded { color: #804a09; font-weight: 800; }
.cell-notes .mark-excluded { text-decoration: line-through; }

.mode-settings { grid-area: settings; min-width: 0; }
.mode-settings h2 { margin-bottom: 6px; font-size: 13px; font-weight: 750; color: var(--muted); }
.mode-settings p { font-size: 14px; }
#daily-heading { color: var(--amber); }
.levels, .actions { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 6px; }
.levels button { padding-inline: 5px; min-height: 36px; background: transparent; }
.levels button[aria-pressed="true"], .actions button[aria-pressed="true"] {
  border-color: var(--jade);
  background: var(--jade-pale);
  color: #114b3e;
}
.controls { grid-area: controls; display: grid; gap: 11px; min-width: 0; }
.actions button { padding-inline: 2px; white-space: nowrap; }
.actions span { margin-right: 1px; }
.keypad { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.keypad button {
  padding-inline: 0;
  min-height: 51px;
  font-size: 23px;
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  touch-action: manipulation;
}
.keypad button:active:not(:disabled) { background: var(--jade-pale); }
.keypad[data-notes="true"] button:not(:disabled) {
  color: var(--jade);
  background: #edf7f1;
  border-style: dashed;
}
.hint-panel, .outcome { background: var(--sheet); border: 1px solid var(--line); border-radius: 8px; padding: 11px; }
.hint-panel { transition: background-color .18s var(--ease-out), border-color .18s var(--ease-out); }
.hint-panel[data-active="true"] { border-color: #ae7935; background: #fffaf0; }
.hint-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.hint-header h2, .outcome h2 { font-size: 15px; font-weight: 750; }
.hint-header p, .control-footer p, .outcome p { color: var(--muted); font-size: 12px; margin-top: 3px; }
.hint-header button { flex-shrink: 0; padding-inline: 8px; color: #774707; background: var(--amber-pale); border-color: #cead78; }
.hint-content { margin-top: 10px; padding-top: 9px; border-top: 1px solid #e6d0aa; font-size: 14px; line-height: 1.55; }
.hint-actions { display: flex; gap: 7px; justify-content: end; margin-top: 7px; }
.hint-actions button, .control-footer button, .control-footer summary { min-height: 35px; padding-block: 4px; }
.outcome { border-color: var(--signal); }
.outcome button { margin-top: 9px; }
.control-footer { display: flex; justify-content: space-between; align-items: start; position: relative; gap: 8px; }
.control-footer details { flex: 1; }
.control-footer summary { cursor: pointer; width: fit-content; margin-left: auto; background: transparent; font-size: 13px; }
.control-footer p { padding: 2px 4px; }
.board-footer { grid-area: footer; display: flex; flex-wrap: wrap; gap: 4px 12px; justify-content: space-between; color: var(--muted); font-size: 12px; }
.board-footer code { color: var(--ink); font-size: 12px; user-select: all; overflow-wrap: anywhere; }

dialog {
  width: min(440px, calc(100% - 30px));
  max-height: calc(100% - 30px);
  border: 1px solid var(--strong-line);
  border-radius: 10px;
  padding: 16px;
  color: var(--ink);
  background: var(--sheet);
  box-shadow: 0 14px 45px #12291e42;
}
dialog::backdrop { background: #102c23a0; }
.dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.dialog-header h2 { font-size: 22px; }
.dialog-header button { font-size: 23px; line-height: 1; }
dialog h3 { font-size: 16px; }
dialog p, dialog label { font-size: 14px; color: var(--muted); }
dialog p { margin: 4px 0 7px; }
dialog input { width: 100%; min-height: 44px; border: 1px solid var(--strong-line); border-radius: 5px; padding: 5px 9px; color: var(--ink); background: white; font-size: 16px; }
.share-options > div { padding: 10px 0; border-top: 1px solid var(--line); }
.share-options button { margin: 2px 1px 2px 0; }
#open-form { display: grid; gap: 8px; }
#open-form button { justify-self: end; min-width: 85px; }
.error { color: #982f27; }
.window-placeholder { background: var(--sheet); color: var(--ink); border-color: var(--line); }
.window-placeholder p { margin: 6px 0 13px; color: var(--muted); }
.window-status { color: var(--muted); }

@media (min-width: 741px) and (max-height: 820px) {
  .sudoku-shell { width: min(100% - 44px, 875px); padding-top: 18px; }
  .play { grid-template-columns: minmax(0, 480px) minmax(255px, 1fr); column-gap: 34px; }
  h1 { font-size: 47px; }
}
@media (max-width: 740px) {
  .sudoku-shell { width: min(100% - 28px, 534px); padding: 12px 0 25px; }
  .page-header { row-gap: 8px; margin-bottom: 9px; padding-bottom: 8px; }
  .page-tools button { min-height: 38px; padding: 5px 8px; font-size: 13px; }
  .modes button { padding: 4px 8px; min-height: 32px; font-size: 13px; }
  .play { grid-template-columns: minmax(0, 1fr); grid-template-areas: "settings" "meta" "board" "controls" "footer"; gap: 8px; }
  #classic-settings, #daily-settings { display: flex; align-items: center; gap: 10px; }
  .mode-settings h2 { margin: 0; white-space: nowrap; }
  .mode-settings .levels { flex: 1; }
  .levels button { min-height: 33px; }
  .board-meta { gap: 5px; }
  .controls { gap: 8px; }
  .keypad { grid-template-columns: repeat(9, minmax(0,1fr)); gap: 3px; }
  .keypad button { min-height: 44px; font-size: 21px; border-radius: 5px; }
  .hint-panel { padding: 8px; }
}
@media (max-width: 365px) {
  .sudoku-shell { width: calc(100% - 22px); }
  .keypad { grid-template-columns: repeat(5,minmax(0,1fr)); gap: 4px; }
  .actions button { font-size: 13px; }
}

.sudoku-shell.compact {
  width: min(100% - 16px, 424px);
  padding: 8px 0 10px;
}
.sudoku-shell.compact-in-page {
  position: fixed;
  z-index: 5;
  top: 8px;
  right: 9px;
  max-height: calc(100dvh - 16px);
  overflow: auto;
  padding: 9px;
  background: var(--canvas);
  border: 1px solid var(--strong-line);
  border-radius: 10px;
  box-shadow: 0 12px 42px #182d2542;
}
body:has(.compact-in-page) .window-placeholder { display: none; }
.compact :is(.page-header, .mode-settings, .board-meta, .board-footer, .control-footer, #result-detail, #result-extra, #next-game) {
  display: none;
}
.compact .play {
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto;
  grid-template-areas: "board" "controls";
  gap: 6px;
}
.compact .board-stage {
  width: min(100%, max(173px, calc(100dvh - 105px)));
  justify-self: center;
}
.compact .board .cell { font-size: clamp(16px, 4.8vw, 25px); }
.compact .controls { gap: 6px; }
.compact .actions { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 3px; }
.compact .actions span { display: none; }
.compact .actions .window-button { grid-column: -2; }
.compact .actions #hint { color: #774707; background: var(--amber-pale); border-color: #cead78; }
.compact .keypad { grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 3px; }
.compact .keypad button { font-size: 17px; min-height: 32px; border-radius: 5px; padding: 4px 0; }
.compact .actions button, .compact .hint-actions button { min-height: 31px; font-size: 12px; padding: 4px 2px; }
.compact .actions button { white-space: normal; overflow-wrap: anywhere; }
.compact .hint-panel:not([data-active="true"]) { display: none; }
.compact :is(.hint-panel, .outcome) { padding: 6px 8px; }
.compact .hint-content { font-size: 12px; margin-top: 5px; padding-top: 5px; }
@media (max-width: 600px) and (any-pointer: coarse) {
  .sudoku-shell:not(.compact) #game-window { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
