:root {
  --paper: #f5f1e9;
  --paper-deep: #e9e2d7;
  --ink: #17252b;
  --ink-soft: #647277;
  --line: #d8d1c5;
  --line-strong: #8b938e;
  --teal: #0c6b68;
  --teal-deep: #075150;
  --teal-soft: #d7e9e5;
  --coral: #d46f59;
  --coral-soft: #f1d7cb;
  --white: #fffdf9;
  --shadow: 0 14px 35px rgba(28, 37, 38, 0.07);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-width: 320px;
  min-height: 100%;
  background: var(--paper);
  -webkit-tap-highlight-color: transparent;
}

button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }

.app-shell {
  width: min(100%, 620px);
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) 20px calc(28px + env(safe-area-inset-bottom));
}

.topbar, .board-heading, .section-heading, .tools-row, .status-strip, .app-footer {
  display: flex;
  align-items: center;
}

.topbar { justify-content: space-between; margin-bottom: 30px; }

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

.brand-mark {
  width: 35px;
  height: 35px;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--teal);
  color: var(--teal);
  font-family: Georgia, serif;
  font-size: 23px;
  line-height: 1;
}

.brand strong, .brand small { display: block; }
.brand strong { font-size: 14px; letter-spacing: .02em; }
.brand small { margin-top: 2px; color: var(--ink-soft); font-size: 10px; letter-spacing: .07em; }

.icon-button, .new-game-button, .tool-button, .number-key, .difficulty-button, .text-button {
  border: 0;
  cursor: pointer;
}

.icon-button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  display: grid;
  place-items: center;
  font-size: 16px;
  letter-spacing: -3px;
  padding-right: 5px;
  transition: border-color .2s, background .2s, transform .2s;
}

.icon-button:active, .new-game-button:active, .tool-button:active, .number-key:active { transform: scale(.96); }
.icon-button:hover { border-color: var(--teal); background: var(--white); }

.intro { margin-bottom: 26px; }
.eyebrow, .section-kicker, .modal-kicker {
  color: var(--coral);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .18em;
}

.eyebrow { display: flex; gap: 7px; align-items: center; }
.eyebrow span { width: 18px; height: 1px; background: var(--coral); }
.intro h1 { margin: 9px 0 8px; max-width: 460px; font-family: Georgia, "Songti SC", serif; font-size: clamp(31px, 8vw, 49px); font-weight: 500; letter-spacing: -.04em; line-height: 1.1; }
.intro h1 em { color: var(--teal); font-style: normal; }
.intro p { margin: 0; color: var(--ink-soft); font-size: 13px; line-height: 1.65; }

.status-strip {
  justify-content: space-between;
  min-height: 68px;
  padding: 13px 17px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  margin-bottom: 23px;
}

.status-item { min-width: 85px; }
.status-item--center { text-align: center; }
.status-item--right { text-align: right; }
.status-label { display: block; margin-bottom: 4px; color: var(--ink-soft); font-size: 10px; letter-spacing: .08em; }
.status-item strong { color: var(--ink); font-size: 21px; font-weight: 650; letter-spacing: .03em; }
.status-item strong small { color: var(--ink-soft); font-size: 11px; font-weight: 500; }

.difficulty-section { margin-bottom: 26px; }
.section-heading { justify-content: space-between; margin-bottom: 10px; color: var(--ink); font-size: 12px; font-weight: 700; letter-spacing: .07em; }
.clue-note, .pencil-status { color: var(--ink-soft); font-size: 10px; font-weight: 500; letter-spacing: .03em; }
.segmented-control { display: grid; grid-template-columns: repeat(4, 1fr); padding: 3px; border: 1px solid var(--line); background: var(--paper-deep); }
.difficulty-button { min-height: 37px; border: 1px solid transparent; background: transparent; color: var(--ink-soft); font-size: 12px; font-weight: 600; transition: color .2s, background .2s, box-shadow .2s; }
.difficulty-button.is-active { background: var(--white); border-color: rgba(23, 37, 43, .07); box-shadow: 0 2px 6px rgba(23, 37, 43, .08); color: var(--teal-deep); }
.difficulty-button:focus-visible, .number-key:focus-visible, .tool-button:focus-visible, .icon-button:focus-visible, .new-game-button:focus-visible, .primary-button:focus-visible { outline: 2px solid var(--coral); outline-offset: 2px; }

.board-section { margin-bottom: 17px; }
.board-heading { justify-content: space-between; align-items: flex-end; margin-bottom: 12px; }
.board-heading h2 { margin: 3px 0 0; font-family: Georgia, "Songti SC", serif; font-size: 22px; font-weight: 500; letter-spacing: -.02em; }
.new-game-button { display: inline-flex; align-items: center; gap: 5px; min-height: 34px; padding: 0 1px 2px 9px; background: transparent; color: var(--teal); font-size: 12px; font-weight: 700; }
.new-game-button span { font-size: 20px; font-weight: 400; line-height: 1; }

.board-wrap { position: relative; }
.sudoku-board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  width: 100%;
  aspect-ratio: 1;
  border: 2px solid var(--ink);
  background: var(--ink);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--white);
  color: var(--teal-deep);
  cursor: pointer;
  font-size: clamp(20px, 6vw, 31px);
  font-weight: 550;
  line-height: 1;
  transition: background .13s, color .13s;
}

.cell:nth-child(9n) { border-right: 0; }
.cell:nth-child(n+73) { border-bottom: 0; }
.cell:nth-child(3n):not(:nth-child(9n)) { border-right: 2px solid var(--line-strong); }
.cell:nth-child(n+19):nth-child(-n+27), .cell:nth-child(n+46):nth-child(-n+54) { border-bottom: 2px solid var(--line-strong); }
.cell.is-related { background: #eef3f0; }
.cell.is-same { background: var(--teal-soft); color: var(--teal-deep); }
.cell.is-selected { background: #b7d9d4; color: var(--teal-deep); }
.cell.is-given { color: var(--ink); font-weight: 700; }
.cell.is-mistake { background: var(--coral-soft); color: #9b3c2e; animation: nudge .24s ease-in-out; }
.cell.is-hinted { color: var(--coral); }
.cell:focus-visible { z-index: 1; outline: 2px solid var(--coral); outline-offset: -3px; }

.note-grid { display: grid; grid-template-columns: repeat(3, 1fr); width: 74%; height: 74%; place-items: center; color: var(--ink-soft); font-size: clamp(7px, 2vw, 10px); font-weight: 650; line-height: 1; }
.note-grid span { display: grid; place-items: center; width: 100%; height: 100%; }
.board-helper { display: flex; align-items: center; gap: 7px; margin: 10px 1px 0; color: var(--ink-soft); font-size: 10px; }
.helper-dot { width: 6px; height: 6px; background: var(--coral); border-radius: 50%; }

.pause-overlay { position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; background: rgba(23, 37, 43, .78); }
.pause-overlay[hidden], .modal-backdrop[hidden] { display: none; }
.pause-card { display: grid; justify-items: center; gap: 7px; padding: 26px 24px; color: var(--white); text-align: center; }
.pause-card strong { margin-top: 3px; font-family: Georgia, serif; font-size: 22px; font-weight: 500; }
.pause-card > span:not(.pause-glyph) { color: rgba(255, 253, 249, .72); font-size: 12px; }
.pause-glyph { width: 48px; height: 48px; display: grid; place-items: center; padding-right: 5px; border: 1px solid rgba(255, 253, 249, .5); color: var(--white); font-size: 20px; letter-spacing: -4px; }

.tools-row { justify-content: space-between; gap: 10px; margin-bottom: 27px; }
.tool-button { flex: 1; min-height: 43px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; border-bottom: 1px solid var(--line); background: transparent; color: var(--ink-soft); font-size: 11px; font-weight: 600; transition: color .2s, border-color .2s, background .2s; }
.tool-button:hover, .tool-button.is-active { border-color: var(--teal); color: var(--teal-deep); }
.tool-button.is-active { background: var(--teal-soft); }
.tool-icon { color: var(--teal); font-size: 19px; font-weight: 400; line-height: 1; }
.tool-button small { min-width: 17px; height: 17px; display: grid; place-items: center; margin-left: -1px; border-radius: 50%; background: var(--paper-deep); color: var(--ink-soft); font-size: 9px; }

.keypad-section { padding-top: 2px; }
.keypad { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.number-key { min-height: 53px; border: 1px solid var(--line); background: var(--white); color: var(--ink); font-family: Georgia, "Songti SC", serif; font-size: 22px; font-weight: 500; box-shadow: 0 2px 0 rgba(23, 37, 43, .03); transition: transform .13s, background .13s, border-color .13s; }
.number-key:hover { border-color: var(--teal); background: #fbfaf6; }
.number-key.is-used { color: var(--ink-soft); background: var(--paper-deep); }
.number-key--erase { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; color: var(--coral); font-family: inherit; font-size: 18px; }
.number-key--erase small { color: var(--ink-soft); font-family: inherit; font-size: 9px; }

.app-footer { justify-content: center; gap: 6px; margin-top: 25px; color: var(--ink-soft); font-size: 10px; }
.footer-mark { color: var(--coral); font-size: 14px; line-height: 0; }
.text-button { padding: 0; margin-left: 3px; background: transparent; color: var(--teal); font-size: 10px; text-decoration: underline; text-underline-offset: 2px; }

.toast { position: fixed; z-index: 20; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); max-width: calc(100% - 40px); padding: 10px 16px; border: 1px solid rgba(255, 253, 249, .18); background: var(--ink); color: var(--white); font-size: 12px; opacity: 0; pointer-events: none; transform: translate(-50%, 12px); transition: opacity .2s, transform .2s; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

.modal-backdrop { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 20px; background: rgba(23, 37, 43, .68); }
.modal-card { width: min(100%, 340px); padding: 34px 25px 25px; border-top: 4px solid var(--coral); background: var(--paper); box-shadow: 0 25px 70px rgba(0, 0, 0, .2); text-align: center; }
.celebration-icon { width: 44px; height: 44px; display: grid; place-items: center; margin: 0 auto 16px; border: 1px solid var(--teal); color: var(--teal); font-size: 20px; }
.modal-card h2 { margin: 8px 0 7px; font-family: Georgia, "Songti SC", serif; font-size: 27px; font-weight: 500; }
.modal-card p { margin: 0; color: var(--ink-soft); font-size: 12px; }
.modal-card p strong { color: var(--ink); }
.modal-stats { display: flex; justify-content: center; gap: 38px; margin: 22px 0 24px; }
.modal-stats span { display: grid; gap: 3px; }
.modal-stats strong { font-size: 20px; font-weight: 650; }
.modal-stats small { color: var(--ink-soft); font-size: 10px; }
.primary-button { min-height: 44px; padding: 0 25px; border: 1px solid var(--teal-deep); background: var(--teal); color: var(--white); cursor: pointer; font-size: 12px; font-weight: 700; transition: background .2s, transform .13s; }
.primary-button:hover { background: var(--teal-deep); }
.primary-button:active { transform: scale(.97); }

@keyframes nudge { 0%, 100% { transform: translateX(0); } 35% { transform: translateX(-3px); } 70% { transform: translateX(3px); } }

@media (min-width: 560px) {
  .app-shell { padding-left: 35px; padding-right: 35px; }
  .topbar { margin-bottom: 36px; }
  .intro { margin-bottom: 32px; }
  .number-key { min-height: 58px; }
}

@media (max-height: 700px) and (max-width: 559px) {
  .app-shell { padding-top: calc(12px + env(safe-area-inset-top)); }
  .topbar { margin-bottom: 18px; }
  .intro { margin-bottom: 16px; }
  .intro h1 { font-size: 29px; }
  .status-strip { min-height: 58px; margin-bottom: 17px; }
  .difficulty-section { margin-bottom: 17px; }
  .board-heading h2 { font-size: 19px; }
  .tools-row { margin-bottom: 17px; }
  .number-key { min-height: 47px; }
  .app-footer { margin-top: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
