:root {
  --paper: #e8e1d5;
  --paper-light: #f7f2e8;
  --ink: #1c2924;
  --muted: #6e756c;
  --moss: #59634b;
  --wine: #8d4038;
  --sun: #d7a74d;
  --line: #1c29242b;
  --serif: "Iowan Old Style", "Baskerville", "Songti SC", "STSong", serif;
  --sans: "Avenir Next", "Helvetica Neue", "PingFang SC", sans-serif;
}
* { box-sizing: border-box; }
html { background: var(--paper); }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: var(--sans);
  background:
    radial-gradient(circle at 12% 12%, #fff8 0 1px, transparent 1.5px),
    linear-gradient(120deg, #eee9df, var(--paper) 48%, #ddd5c8);
  background-size: 23px 23px, 100% 100%;
}
body::before { position: fixed; inset: 0; z-index: 10; pointer-events: none; content: ""; opacity: .2; background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.15'/%3E%3C/svg%3E"); mix-blend-mode: multiply; }
button, a { color: inherit; }
button { font-family: inherit; }
.page-shell { width: min(1180px, calc(100% - 64px)); margin: 0 auto; padding: 28px 0 52px; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.wordmark { display: inline-flex; align-items: center; gap: 10px; font-size: 1rem; font-weight: 700; text-decoration: none; }
.wordmark img { width: 30px; height: 30px; border-radius: 8px; }
.back-link { color: var(--muted); font-size: .72rem; font-weight: 700; letter-spacing: .13em; text-decoration: none; text-transform: uppercase; }
.back-link::before { content: "← "; }
.game-layout { display: grid; grid-template-columns: minmax(280px, .7fr) minmax(440px, .95fr); gap: clamp(58px, 9vw, 128px); align-items: center; min-height: calc(100vh - 82px); padding: 48px 5%; }
.eyebrow { margin: 0 0 18px; color: var(--wine); font-size: .66rem; font-weight: 700; letter-spacing: .2em; text-transform: uppercase; }
h1 { margin: 0; font-family: var(--serif); font-size: clamp(5.5rem, 11vw, 10rem); font-weight: 400; letter-spacing: -.08em; line-height: .76; }
.lede { max-width: 27rem; margin: 38px 0 30px; color: var(--muted); font-family: var(--serif); font-size: clamp(1.15rem, 2vw, 1.45rem); line-height: 1.65; }
.level-panel { padding: 19px 0 23px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.level-panel > p { margin: 0 0 12px; color: var(--muted); font-size: .62rem; font-weight: 700; letter-spacing: .15em; text-transform: uppercase; }
.level-switcher { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 4px; border: 1px solid var(--line); border-radius: 12px; background: #f4f0e899; }
.level-switcher button { min-height: 40px; border: 0; border-radius: 8px; color: var(--muted); font-size: .76rem; font-weight: 700; background: transparent; cursor: pointer; }
.level-switcher button[aria-pressed="true"] { color: #fff9ef; background: var(--wine); box-shadow: 0 6px 14px #6e2e282b; }
.assist-settings { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.assist-settings label { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; min-height: 39px; padding: 0 8px 0 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 9px; font-size: .64rem; font-weight: 700; background: #f7f3eb99; }
.assist-settings select { min-width: 76px; height: 30px; padding: 0 5px; border: 0; border-radius: 6px; outline: 0; color: var(--ink); font-size: .7rem; font-weight: 700; background: #e7e0d4; }
.assist-settings select:focus-visible { box-shadow: 0 0 0 3px #8d403829; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin-top: 18px; }
.stats div { display: grid; gap: 4px; }
.stats span { color: var(--muted); font-size: .56rem; font-weight: 700; letter-spacing: .13em; text-transform: uppercase; }
.stats strong { font-family: var(--serif); font-size: 1.18rem; }
.stats b { color: var(--wine); font: inherit; }
.stats i { font: inherit; font-style: normal; }
.puzzle-station { width: min(100%, 530px); justify-self: center; }
.board-wrap { position: relative; padding: 10px; border: 1px solid #26362f54; background: #26362f; box-shadow: 0 26px 50px #263d373b; transform: rotate(.25deg); }
.sudoku-board { display: grid; grid-template-columns: repeat(9, 1fr); aspect-ratio: 1; overflow: hidden; border: 2px solid #1c2924; background: #1c2924; }
.cell { position: relative; display: grid; place-items: center; min-width: 0; padding: 0; border: 0 solid #8c918b; border-right-width: 1px; border-bottom-width: 1px; color: var(--wine); font-family: var(--serif); font-size: clamp(1.15rem, 4vw, 2rem); font-weight: 700; background: var(--paper-light); cursor: pointer; }
.cell:nth-child(9n) { border-right: 0; }
.cell:nth-child(n+73) { border-bottom: 0; }
.cell[data-column="2"], .cell[data-column="5"] { border-right: 3px solid #27362f; }
.cell[data-row="2"], .cell[data-row="5"] { border-bottom: 3px solid #27362f; }
.cell.given { color: var(--ink); background: #eee8dc; cursor: default; }
.cell.peer { background: #ebe3d3; }
.cell.match { background: #e5cf9d; }
.cell.selected { z-index: 1; color: #fff; background: var(--moss); box-shadow: inset 0 0 0 2px #d7a74d; }
.cell.error { color: #fff; background: #a94f42; animation: shake .25s ease; }
.notes { position: absolute; inset: 3px; display: grid; grid-template-columns: repeat(3, 1fr); align-items: center; color: var(--muted); font: 700 clamp(.42rem, 1.2vw, .68rem)/1 var(--sans); }
.notes i { font-style: normal; text-align: center; }
.game-overlay { position: absolute; inset: 10px; z-index: 5; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #fff9ed; background: #26362fe8; backdrop-filter: blur(5px); text-align: center; }
.game-overlay[hidden] { display: none; }
.game-overlay p { margin: 0 0 7px; font-family: var(--serif); font-size: clamp(2.6rem, 8vw, 4.8rem); }
.game-overlay span { color: #d9dfd8; }
.game-overlay button { margin-top: 22px; padding: 12px 20px; border: 0; border-radius: 9px; font-weight: 800; background: var(--sun); cursor: pointer; }
.number-pad { display: grid; grid-template-columns: repeat(9, 1fr); gap: 5px; margin-top: 14px; }
.number-pad button { position: relative; min-width: 0; aspect-ratio: 1; border: 1px solid var(--line); border-radius: 9px; color: var(--ink); font-family: var(--serif); font-size: clamp(1rem, 3vw, 1.45rem); font-weight: 700; background: #f5f1e9c4; cursor: pointer; }
.number-pad button:disabled { opacity: .3; cursor: default; }
.tool-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 8px; }
.tool-row button { min-height: 48px; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); font-size: .7rem; font-weight: 700; background: #f5f1e9a8; cursor: pointer; }
.tool-row button span { display: block; margin-bottom: 2px; color: var(--ink); font-size: 1rem; }
.tool-row button[aria-pressed="true"] { color: #fff; border-color: var(--wine); background: var(--wine); }
.tool-row button[aria-pressed="true"] span { color: #fff; }
.tool-row b { display: inline-grid; place-items: center; min-width: 17px; height: 17px; border-radius: 50%; color: #fff; font-size: .58rem; background: var(--wine); }
.tool-row button:disabled { opacity: .42; cursor: default; }
.game-status { min-height: 1.4em; margin: 12px 2px 0; color: var(--muted); font-size: .72rem; }
@keyframes shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
@media (max-width: 880px) {
  .page-shell { width: min(100% - 28px, 600px); padding-top: 18px; }
  .game-layout { grid-template-columns: 1fr; gap: 32px; min-height: auto; padding: 54px 1px 62px; }
  .game-intro { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 24px; align-items: end; }
  .eyebrow, .lede { grid-column: 1 / -1; }
  h1 { font-size: clamp(5.5rem, 26vw, 8rem); }
  .lede { margin: 8px 0 0; }
  .level-panel { padding: 0; border: 0; }
  .stats { align-self: center; margin: 0; }
}
@media (max-width: 500px) {
  .game-intro { display: block; }
  .lede { margin-top: 17px; }
  .level-panel { margin-top: 22px; }
  .assist-settings { grid-template-columns: 1fr; }
  .stats { margin-top: 16px; }
  .board-wrap { padding: 7px; }
  .game-overlay { inset: 7px; }
  .tool-row button { min-height: 45px; font-size: .64rem; }
}
@media (prefers-reduced-motion: reduce) { .cell.error { animation: none; } }
