:root {
  color-scheme: light;
  --ink: #293c48;
  --muted: #70808a;
  --paper: #fbf7ef;
  --paper-deep: #f1eadd;
  --blue: #56798a;
  --blue-dark: #334f5e;
  --blue-soft: #dce8e8;
  --rust: #bd6d51;
  --gold: #d6a85f;
  --line: rgba(41, 60, 72, 0.18);
  --shadow: 0 28px 80px rgba(52, 55, 49, 0.14);
}

* { box-sizing: border-box; }

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--paper-deep);
}

body {
  min-height: 100svh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 8%, rgba(181, 121, 87, 0.15), transparent 27%),
    radial-gradient(circle at 91% 20%, rgba(84, 123, 139, 0.16), transparent 28%),
    linear-gradient(145deg, #eee5d5 0%, #f7f2e9 43%, #e8e7dc 100%);
  font-family: "Avenir Next", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

button, a { font: inherit; }
button { color: inherit; }

button:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(189, 109, 81, 0.42);
  outline-offset: 3px;
}

.paper-texture {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.23;
  background-image:
    repeating-linear-gradient(0deg, transparent 0 7px, rgba(43, 60, 68, 0.025) 8px),
    repeating-linear-gradient(90deg, transparent 0 11px, rgba(43, 60, 68, 0.018) 12px);
  mix-blend-mode: multiply;
}

.topbar {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 22px 0 8px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  color: #6f7b7b;
}

.topbar p {
  margin: 0;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.2em;
}

.home-link {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #617078;
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
}

.home-link span {
  transition: transform 180ms ease;
}

.home-link:hover span { transform: translateX(-3px); }

.soundless-mark {
  justify-self: end;
  width: 34px;
  aspect-ratio: 1;
  border: 1px solid rgba(41, 60, 72, 0.18);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.32);
  color: #7a675e;
  font-family: Georgia, "Songti SC", serif;
  cursor: default;
}

.page-shell {
  width: min(1120px, calc(100% - 40px));
  min-height: calc(100svh - 116px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(260px, 0.72fr) minmax(520px, 1.28fr);
  align-items: center;
  gap: clamp(36px, 7vw, 90px);
  padding: 22px 0 32px;
}

.intro-panel { padding: 20px 0; }

.eyebrow {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 18px;
  color: #8a7065;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.eyebrow span {
  width: 28px;
  height: 1px;
  background: var(--rust);
}

.intro-panel h1 {
  margin: 0;
  color: #2a414e;
  font-family: Georgia, "Songti SC", "STSong", serif;
  font-size: clamp(46px, 5.5vw, 72px);
  font-weight: 500;
  line-height: 1.08;
  letter-spacing: -0.045em;
}

.intro-panel h1 em {
  color: var(--rust);
  font-style: normal;
}

.intro-copy {
  max-width: 390px;
  margin: 22px 0 26px;
  color: var(--muted);
  font-family: Georgia, "Songti SC", serif;
  font-size: 15px;
  line-height: 1.9;
}

.difficulty-card {
  max-width: 390px;
  padding: 15px;
  border: 1px solid rgba(45, 66, 76, 0.12);
  border-radius: 18px;
  background: rgba(255, 252, 245, 0.5);
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.65);
}

.difficulty-heading {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 0 2px 10px;
}

.difficulty-heading span {
  font-size: 12px;
  font-weight: 800;
}

.difficulty-heading small {
  color: #909793;
  font-size: 10px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  padding: 4px;
  border-radius: 13px;
  background: rgba(57, 77, 84, 0.08);
}

.segmented button {
  padding: 8px 7px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #738087;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}

.segmented button[aria-pressed="true"] {
  color: #314c5a;
  background: #fffaf1;
  box-shadow: 0 4px 12px rgba(55, 63, 60, 0.11);
}

.rules-card {
  max-width: 390px;
  margin-top: 15px;
  padding: 13px 15px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-left: 2px solid rgba(189, 109, 81, 0.55);
  background: rgba(255, 250, 241, 0.35);
}

.rules-icon {
  display: grid;
  place-items: center;
  width: 34px;
  aspect-ratio: 1;
  border-radius: 50%;
  color: var(--rust);
  background: rgba(189, 109, 81, 0.09);
}

.rules-card strong {
  display: block;
  margin-bottom: 3px;
  font-size: 11px;
}

.rules-card p {
  margin: 0;
  color: #78847f;
  font-family: Georgia, "Songti SC", serif;
  font-size: 11px;
  line-height: 1.55;
}

.keyboard-tip {
  margin: 20px 0 0;
  color: #8b918e;
  font-size: 10px;
}

kbd {
  padding: 2px 5px;
  border: 1px solid rgba(45, 64, 71, 0.17);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.35);
  font-family: inherit;
}

.game-card {
  width: min(610px, 100%);
  justify-self: end;
  padding: clamp(17px, 2.3vw, 27px);
  border: 1px solid rgba(50, 68, 75, 0.15);
  border-radius: 30px;
  background: rgba(251, 248, 240, 0.88);
  box-shadow: var(--shadow), inset 0 1px rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(18px);
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 13px;
}

.game-kicker {
  display: block;
  margin-bottom: 3px;
  color: #9a877c;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.game-header h2 {
  margin: 0;
  color: #3c525b;
  font-family: Georgia, "Songti SC", serif;
  font-size: clamp(15px, 2vw, 19px);
  font-weight: 600;
}

.game-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.game-meta > span {
  min-width: 46px;
  text-align: right;
}

.game-meta small,
.game-meta b {
  display: block;
}

.game-meta small {
  margin-bottom: 1px;
  color: #9b9c95;
  font-size: 8px;
  letter-spacing: 0.08em;
}

.game-meta b {
  color: #435b66;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}

.icon-button {
  width: 34px;
  aspect-ratio: 1;
  border: 1px solid rgba(47, 68, 78, 0.12);
  border-radius: 50%;
  background: #f0ede4;
  color: #62727a;
  font-size: 11px;
  font-weight: 900;
  cursor: pointer;
}

.board-wrap {
  position: relative;
  padding: clamp(6px, 1vw, 9px);
  border-radius: 18px;
  background: #36505c;
  box-shadow: 0 14px 32px rgba(43, 59, 65, 0.17);
}

.sudoku-board {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  aspect-ratio: 1;
  overflow: hidden;
  border: 2px solid #304852;
  border-radius: 11px;
  background: #fffdf8;
}

.sudoku-cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 0;
  display: grid;
  place-items: center;
  border: 0;
  border-right: 1px solid rgba(50, 72, 82, 0.18);
  border-bottom: 1px solid rgba(50, 72, 82, 0.18);
  background: rgba(255, 253, 248, 0.98);
  color: #467082;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, transform 120ms ease;
}

.sudoku-cell:nth-child(9n) { border-right: 0; }
.sudoku-cell:nth-child(n + 73) { border-bottom: 0; }
.sudoku-cell:nth-child(9n + 3),
.sudoku-cell:nth-child(9n + 6) { border-right: 2px solid #516b76; }
.sudoku-cell:nth-child(n + 19):nth-child(-n + 27),
.sudoku-cell:nth-child(n + 46):nth-child(-n + 54) { border-bottom: 2px solid #516b76; }

.sudoku-cell.related { background: #edf3f1; }
.sudoku-cell.same-value { background: #d9e7e6; }
.sudoku-cell.selected {
  z-index: 2;
  color: #294b5b;
  background: #c9dddd;
  box-shadow: inset 0 0 0 2px #537b87;
}

.sudoku-cell.given { color: #2d3d45; }
.sudoku-cell.error {
  color: #a94636;
  background: #f6d8cf;
  animation: cell-shake 300ms ease;
}
.sudoku-cell.hinted .cell-number { animation: hint-pop 600ms ease; }

.cell-number {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(17px, 3.05vw, 29px);
  line-height: 1;
}

.given .cell-number { font-weight: 700; }

.cell-notes {
  position: absolute;
  inset: 8%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
}

.cell-notes i {
  display: grid;
  place-items: center;
  color: #6d8791;
  font-family: "Avenir Next", sans-serif;
  font-size: clamp(6px, 1vw, 10px);
  font-style: normal;
  line-height: 1;
}

@keyframes cell-shake {
  25% { transform: translateX(-3px); }
  50% { transform: translateX(3px); }
  75% { transform: translateX(-2px); }
}

@keyframes hint-pop {
  0% { transform: scale(0.25); opacity: 0; color: var(--gold); }
  65% { transform: scale(1.25); }
  100% { transform: scale(1); opacity: 1; }
}

.board-cover {
  position: absolute;
  inset: clamp(6px, 1vw, 9px);
  z-index: 5;
  display: grid;
  place-items: center;
  align-content: center;
  padding: 28px;
  border-radius: 11px;
  color: #f6f2e9;
  background: rgba(45, 65, 74, 0.95);
  text-align: center;
  backdrop-filter: blur(8px);
}

.board-cover[hidden] { display: none; }
.board-cover > span { font-size: 34px; }
.board-cover h3 {
  margin: 10px 0 5px;
  font-family: Georgia, "Songti SC", serif;
  font-size: 27px;
  font-weight: 500;
}
.board-cover > p {
  margin: 0 0 18px;
  color: rgba(246, 242, 233, 0.7);
  font-size: 12px;
}
.board-cover > button {
  padding: 10px 18px;
  border: 0;
  border-radius: 999px;
  background: #f8f0e2;
  color: #39525e;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}

.victory-cover {
  background:
    radial-gradient(circle at 50% 18%, rgba(221, 176, 95, 0.25), transparent 28%),
    rgba(42, 63, 72, 0.97);
}

.victory-cover .victory-star { color: #e7bd73; font-size: 46px; }
.victory-cover > p { margin: 6px 0 3px; font-size: 10px; letter-spacing: 0.1em; }

.victory-stats {
  display: flex;
  gap: 34px;
  margin: 13px 0 19px;
}

.victory-stats small,
.victory-stats b { display: block; }
.victory-stats small { color: rgba(247, 241, 230, 0.6); font-size: 8px; }
.victory-stats b { margin-top: 2px; font-size: 16px; }

.tool-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  margin-top: 12px;
}

.tool-row button {
  position: relative;
  min-height: 50px;
  padding: 7px 5px;
  border: 1px solid rgba(50, 71, 80, 0.1);
  border-radius: 13px;
  background: #f1eee5;
  color: #65757a;
  cursor: pointer;
  transition: transform 150ms ease, background 150ms ease;
}

.tool-row button:hover:not(:disabled) { transform: translateY(-1px); background: #e9eee8; }
.tool-row button:disabled { opacity: 0.38; cursor: default; }
.tool-row button.active { color: #35586a; background: #dce9e8; }
.tool-row span, .tool-row b { display: block; }
.tool-row span { margin-bottom: 2px; font-size: 17px; line-height: 1; }
.tool-row b { font-size: 9px; }
.tool-row i {
  position: absolute;
  top: 5px;
  right: 7px;
  min-width: 16px;
  padding: 1px 4px;
  border-radius: 999px;
  color: #fffaf0;
  background: #84999d;
  font-size: 7px;
  font-style: normal;
}

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

.number-pad button {
  position: relative;
  aspect-ratio: 0.95;
  border: 0;
  border-radius: 11px;
  background: #e2ebe7;
  color: #426375;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(18px, 2.6vw, 25px);
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease;
}

.number-pad button:hover:not(:disabled) { transform: translateY(-2px); background: #d3e3df; }
.number-pad button:disabled { opacity: 0.34; cursor: default; }
.number-pad button.completed { color: #7c8e88; }
.number-pad small {
  position: absolute;
  right: 5px;
  bottom: 3px;
  font-family: sans-serif;
  font-size: 7px;
}

.new-game-button {
  display: block;
  margin: 11px auto 0;
  padding: 4px 8px;
  border: 0;
  border-bottom: 1px solid rgba(69, 91, 99, 0.24);
  background: transparent;
  color: #7d8989;
  font-size: 10px;
  cursor: pointer;
}

footer {
  padding: 0 20px 22px;
  color: #8c918c;
  font-family: Georgia, "Songti SC", serif;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-align: center;
}

@media (max-width: 840px) {
  .topbar { width: min(100% - 28px, 650px); }
  .page-shell {
    width: min(100% - 28px, 650px);
    grid-template-columns: 1fr;
    gap: 16px;
    padding-top: 10px;
  }
  .intro-panel { padding: 18px 4px 2px; }
  .intro-panel h1 br { display: none; }
  .intro-panel h1 { font-size: clamp(39px, 11vw, 58px); }
  .intro-copy { max-width: 540px; margin: 13px 0 16px; }
  .difficulty-card, .rules-card { max-width: none; }
  .rules-card, .keyboard-tip { display: none; }
  .game-card { justify-self: center; }
}

@media (max-width: 520px) {
  .topbar { grid-template-columns: 1fr 1fr; padding-top: 14px; }
  .topbar p { display: none; }
  .page-shell { min-height: 0; }
  .intro-panel { padding-top: 8px; }
  .eyebrow { margin-bottom: 10px; }
  .intro-copy { font-size: 13px; line-height: 1.65; }
  .difficulty-card { padding: 10px; border-radius: 14px; }
  .game-card { padding: 12px; border-radius: 20px; }
  .game-header { margin: 0 2px 10px; }
  .game-header h2 { max-width: 180px; font-size: 14px; }
  .game-meta { gap: 6px; }
  .game-meta > span { min-width: 39px; }
  .board-wrap { border-radius: 14px; }
  .tool-row button { min-height: 45px; }
  .number-pad { gap: 3px; }
  .number-pad button { border-radius: 8px; }
}

@media (max-height: 760px) and (min-width: 841px) {
  .page-shell { padding-top: 8px; align-items: start; }
  .intro-panel { padding-top: 50px; }
  .game-card { max-width: 540px; }
}

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