:root {
  color-scheme: light dark;
  --bg: #e7ecec;
  --surface: #f8faf9;
  --surface-muted: #dbe3e3;
  --ink: #17262a;
  --ink-muted: #526469;
  --steel: #42636c;
  --line: #9eafb2;
  --line-strong: #23383e;
  --amber: #c87a18;
  --amber-soft: #f0d5ae;
  --peer: #dce8ea;
  --same: #c3d9dc;
  --error: #a53532;
  --error-bg: #f1d3cf;
  --page-width: 1160px;
  font-family: Arial, "Noto Sans TC", "PingFang TC", sans-serif;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
}

button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }
button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 3px solid var(--amber);
  outline-offset: 3px;
}

.site-header, main, footer {
  width: min(var(--page-width), calc(100% - 40px));
  margin-inline: auto;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 68px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 36px;
  aspect-ratio: 1;
  place-items: center;
  border: 2px solid var(--line-strong);
  border-radius: 3px;
  color: var(--surface);
  background: var(--line-strong);
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 1.15rem;
  font-weight: 800;
}

.brand-name {
  display: grid;
  gap: 1px;
  font-size: .98rem;
  font-weight: 800;
  letter-spacing: .02em;
}

.brand-name small {
  color: var(--ink-muted);
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: .62rem;
  font-weight: 600;
  letter-spacing: .08em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 20px;
}

.quiet-state {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--ink-muted);
  font-size: .76rem;
}

.quiet-state span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--amber) 18%, transparent);
}

.quiet-button, .text-button {
  border: 0;
  color: var(--ink);
  background: transparent;
  cursor: pointer;
}

.quiet-button {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 3px;
  font-size: .8rem;
  font-weight: 700;
}

.quiet-button:hover { border-color: var(--line-strong); }

.game-intro {
  display: grid;
  gap: 28px;
  align-items: end;
  padding: 34px 0 25px;
  border-bottom: 1px solid var(--line);
}

.game-intro > *, .game-layout > * { min-width: 0; }

.puzzle-context {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 0 0 8px;
  color: var(--ink-muted);
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: .72rem;
}

.puzzle-context span + span::before {
  margin-right: 8px;
  color: var(--line);
  content: "/";
}

h1, h2, p { margin-top: 0; }

h1 {
  margin-bottom: 8px;
  font-size: clamp(2rem, 4vw, 3.35rem);
  font-weight: 850;
  line-height: 1.05;
  letter-spacing: -.045em;
}

.intro {
  margin-bottom: 0;
  color: var(--ink-muted);
  font-size: .94rem;
  line-height: 1.65;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: 0;
  border: 1px solid var(--line);
  background: var(--surface-muted);
}

.stats div {
  min-width: 0;
  padding: 11px 14px 10px;
  border-left: 1px solid var(--line);
}

.stats div:first-child { border-left: 0; }

.stats dt {
  margin-bottom: 5px;
  color: var(--ink-muted);
  font-size: .68rem;
}

.stats dd {
  margin: 0;
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: .95rem;
  font-weight: 800;
  white-space: nowrap;
}

.game-layout {
  display: grid;
  gap: clamp(24px, 4vw, 50px);
  align-items: start;
  padding-top: 26px;
}

.board-column { max-width: 700px; }

.puzzle-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 34px;
  margin-bottom: 8px;
}

.puzzle-meta p { margin-bottom: 0; }

.board-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-muted);
  font-size: .74rem;
  font-weight: 800;
  letter-spacing: .06em;
}

.board-label span {
  width: 13px;
  height: 3px;
  background: var(--amber);
}

.text-button {
  padding: 5px 0;
  border-bottom: 1px solid currentColor;
  color: var(--ink-muted);
  font-size: .74rem;
  font-weight: 700;
}

.text-button:hover { color: var(--ink); }

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

.cell {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  padding: 0;
  place-items: center;
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  background: var(--surface);
  cursor: pointer;
}

.cell::after {
  position: absolute;
  z-index: 1;
  inset: 2px;
  border: 0 dashed color-mix(in srgb, var(--steel) 78%, transparent);
  border-top-width: var(--cage-top, 0);
  border-right-width: var(--cage-right, 0);
  border-bottom-width: var(--cage-bottom, 0);
  border-left-width: var(--cage-left, 0);
  content: "";
  pointer-events: none;
}

.cell[data-col="2"], .cell[data-col="5"] { border-right: 2px solid var(--line-strong); }
.cell[data-row="2"], .cell[data-row="5"] { border-bottom: 2px solid var(--line-strong); }
.cell[data-col="8"] { border-right: 0; }
.cell[data-row="8"] { border-bottom: 0; }
.cage-top { --cage-top: 1px; }
.cage-right { --cage-right: 1px; }
.cage-bottom { --cage-bottom: 1px; }
.cage-left { --cage-left: 1px; }
.cell.peer { background: var(--peer); }
.cell.same-number { background: var(--same); }
.cell.selected { background: var(--amber-soft); }
.cell.conflict { color: var(--error); background: var(--error-bg); }

.value {
  position: relative;
  z-index: 2;
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: clamp(1.08rem, 4.7vw, 2rem);
  font-weight: 700;
}

.cage-sum {
  position: absolute;
  z-index: 3;
  top: 4px;
  left: 6px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: clamp(.44rem, 1.5vw, .65rem);
  font-weight: 800;
  line-height: 1;
}

.notes {
  position: absolute;
  z-index: 2;
  inset: 6px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  color: var(--ink-muted);
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: clamp(.38rem, 1.4vw, .6rem);
}

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

.status {
  min-height: 42px;
  margin: 10px 0 0;
  padding: 11px 13px 9px;
  border-left: 4px solid var(--amber);
  color: var(--ink-muted);
  background: var(--surface-muted);
  font-size: .82rem;
  line-height: 1.45;
  text-align: left;
}

.controls {
  padding: 18px;
  border: 1px solid var(--line);
  border-top: 4px solid var(--steel);
  border-radius: 4px;
  background: var(--surface-muted);
}

.control-label {
  margin-bottom: 9px;
  color: var(--ink-muted);
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: .67rem;
  font-weight: 800;
  letter-spacing: .08em;
}

.tool-label { margin-top: 22px; }

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

.number-pad button, .tool-grid button {
  min-width: 0;
  min-height: 52px;
  border: 1px solid var(--line);
  border-bottom: 3px solid var(--steel);
  border-radius: 3px;
  color: var(--ink);
  background: var(--surface);
  cursor: pointer;
}

.number-pad button {
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 1.2rem;
  font-weight: 800;
}

.number-pad button:hover, .tool-grid button:hover { border-color: var(--steel); }
.number-pad button:active, .tool-grid button:active {
  transform: translateY(1px);
  border-bottom-width: 1px;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 7px;
}

.tool-grid button {
  display: grid;
  grid-template-columns: 20px auto;
  gap: 6px;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 8px;
  font-size: .78rem;
}

.tool-grid button span {
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 1rem;
}

.tool-grid button[aria-pressed="true"] {
  border-color: var(--line-strong);
  color: var(--surface);
  background: var(--line-strong);
}

.rules {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--ink-muted);
  font-size: .82rem;
  line-height: 1.65;
}

.rules summary {
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
}

.rules ul { padding-left: 1.2rem; }

.shortcuts {
  margin: 18px 0 0;
  color: var(--ink-muted);
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: .64rem;
  line-height: 1.55;
}

.ad-slot {
  display: grid;
  min-height: 96px;
  margin-top: 10rem;
  place-items: center;
  border: 1px dashed var(--line);
  color: var(--ink-muted);
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: .68rem;
}

.resources {
  max-width: 700px;
  padding: 64px 0 74px;
  border-bottom: 1px solid var(--line);
}

.section-label {
  margin-bottom: 10px;
  color: var(--steel);
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .08em;
}

.resources h1, .resources h2 {
  max-width: 20ch;
  margin-bottom: 12px;
  font-size: clamp(1.6rem, 3.8vw, 2.45rem);
  font-weight: 850;
  line-height: 1.15;
  letter-spacing: -.035em;
}

.resources p {
  color: var(--ink-muted);
  line-height: 1.75;
}

.resources a { color: var(--steel); }

footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
  padding: 22px 0 36px;
  color: var(--ink-muted);
  font-size: .76rem;
}

footer p { margin: 0; }
footer a { color: inherit; }

@media (min-width: 780px) {
  .game-intro { grid-template-columns: 1fr 330px; }
  .game-layout { grid-template-columns: minmax(0, 700px) minmax(250px, 1fr); }
  .controls { position: sticky; top: 18px; }
}

@media (max-width: 779px) {
  .site-header, main, footer { width: min(100% - 24px, var(--page-width)); }
  .site-header { min-height: 60px; }
  .game-intro { padding-top: 24px; }
  .game-layout { width: min(100%, 640px); margin-inline: auto; }
  .board-column { max-width: none; }
  .controls { padding: 14px; border-top-width: 3px; }
  .number-pad { grid-template-columns: repeat(9, 1fr); gap: 4px; }
  .number-pad button { min-height: 44px; border-bottom-width: 2px; font-size: .98rem; }
  .tool-label { margin-top: 17px; }
  .tool-grid { grid-template-columns: repeat(4, 1fr); gap: 4px; }
  .tool-grid button {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1px;
    min-height: 50px;
    padding: 4px 2px;
    font-size: .7rem;
  }
  .rules { margin-top: 18px; }
  .shortcuts { display: none; }
}

@media (max-width: 420px) {
  .header-actions { gap: 9px; }
  .quiet-state { font-size: .68rem; }
  .quiet-state span { width: 7px; height: 7px; }
  .quiet-button { min-height: 32px; padding-inline: 9px; }
  .brand-mark { width: 32px; }
  .brand-name { font-size: .88rem; }
  .game-intro { gap: 18px; }
  h1 { font-size: 2rem; }
  .stats div { padding-inline: 9px; }
  .board { border-width: 2px; }
  .cell::after { inset: 1px; }
  .cage-sum { top: 2px; left: 3px; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111a1d;
    --surface: #1c292c;
    --surface-muted: #253438;
    --ink: #e4ecec;
    --ink-muted: #a4b4b7;
    --steel: #8eaeb6;
    --line: #53666a;
    --line-strong: #b8c8ca;
    --amber: #e09a3b;
    --amber-soft: #5b4427;
    --peer: #253c42;
    --same: #315059;
    --error: #ffaaa3;
    --error-bg: #562f31;
  }

  .brand-mark { color: #111a1d; background: var(--line-strong); }
  .tool-grid button[aria-pressed="true"] { color: #111a1d; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
