:root {
  --bg: #f1ede4;
  --play-width: 620px;
  --play-width: min(620px, max(360px, calc(100dvh - 392px)));
  --paper: #fbf8f1;
  --paper-bright: #fffdf8;
  --ink: #213029;
  --ink-soft: #3d4d44;
  --muted: #78847c;
  --muted-strong: #5f6c64;
  --line: #d9d1c3;
  --line-soft: rgba(75, 84, 76, 0.12);
  --line-strong: #92998f;
  --clay: #c25b42;
  --clay-deep: #9e4531;
  --clay-soft: #f2ded5;
  --sage: #2c6f60;
  --sage-deep: #1f5247;
  --sage-soft: #e1ebe4;
  --note: #a97442;
  --note-deep: #6c4826;
  --note-soft: #f7ecd6;
  --note-wash: #fbf4e7;
  --note-line: #dcc29d;
  --gold: #d4a548;
  --gold-soft: #f3e6c6;
  --cream: #fff8ea;
  --shadow-sm: 0 8px 24px rgba(41, 49, 42, 0.06);
  --shadow-md: 0 24px 60px rgba(41, 49, 42, 0.09);
  --shadow-lg: 0 38px 90px rgba(33, 43, 36, 0.16);
  --radius-lg: 26px;
  --radius-md: 18px;
  --font-display: "Iowan Old Style", "Palatino Linotype", "Noto Serif SC", "Songti SC", "STSong", serif;
  --font-body: "Avenir Next", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 680px at 48% -14%, rgba(255, 251, 242, 0.92), transparent 70%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

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

button:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--clay);
  outline-offset: 3px;
}

button:disabled {
  cursor: default;
}

.tool-button:disabled,
.hint-action:disabled,
.coach-button:disabled,
.hint-peek:disabled {
  opacity: 0.38;
  pointer-events: none;
}

::selection {
  background: var(--gold-soft);
  color: var(--ink);
}

.ambient {
  position: fixed;
  z-index: -2;
  width: 520px;
  height: 520px;
  border-radius: 50%;
  filter: blur(4px);
  pointer-events: none;
}

.ambient--clay {
  top: -240px;
  right: -150px;
  background: radial-gradient(circle, rgba(200, 108, 79, 0.14), transparent 68%);
}

.ambient--sage {
  left: -280px;
  bottom: -220px;
  background: radial-gradient(circle, rgba(44, 111, 96, 0.11), transparent 68%);
}

.grain {
  position: fixed;
  inset: 0;
  z-index: 20;
  opacity: 0.19;
  pointer-events: none;
  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='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.16'/%3E%3C/svg%3E");
  mix-blend-mode: multiply;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border: 1px solid rgba(74, 83, 76, 0.2);
  border-bottom-color: rgba(74, 83, 76, 0.3);
  border-radius: 5px;
  background: rgba(255, 253, 247, 0.68);
  color: var(--muted-strong);
  font-family: var(--font-body);
  font-size: 9.5px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.02em;
  box-shadow: 0 1px 0 rgba(44, 55, 47, 0.06);
}

.app {
  width: min(1220px, calc(100% - 64px));
  margin: 0 auto;
  padding: 18px 0 28px;
}

/* ---------- Header ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 15px;
  border-bottom: 1px solid var(--line);
  animation: rise-in 0.55s ease both;
}

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

.brand-mark {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  width: 34px;
  height: 34px;
  padding: 5px;
  border: 1px solid var(--ink);
  border-radius: 9px;
  transform: rotate(-3deg);
  background: rgba(255, 253, 248, 0.35);
  flex: 0 0 auto;
}

.brand-mark i {
  display: block;
  border: 1px solid rgba(33, 48, 41, 0.24);
  border-radius: 1.5px;
}

.brand-mark i.is-dot {
  border-color: var(--clay);
  background: var(--clay);
  transform: rotate(3deg) scale(1.1);
}

.brand-copy {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.brand-kicker {
  color: var(--muted);
  font-size: 8px;
  font-weight: 650;
  letter-spacing: 0.17em;
  white-space: nowrap;
}

.brand-title {
  font-family: var(--font-display);
  font-size: 23px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.brand-title em {
  margin-left: 3px;
  color: var(--clay);
  font-style: normal;
  font-size: 16px;
  letter-spacing: 0.1em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 15px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: none;
  font-size: 12.5px;
  font-weight: 580;
  letter-spacing: 0.01em;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease, color 0.18s ease;
}

.button svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.55;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.button--ghost {
  color: var(--muted-strong);
}

.button--ghost:hover {
  background: rgba(255, 253, 248, 0.72);
  color: var(--ink);
  border-color: var(--line);
}

.button--dark {
  min-height: 40px;
  padding: 0 16px;
  background: var(--ink);
  color: var(--cream);
  box-shadow: 0 7px 18px rgba(32, 47, 38, 0.14);
}

.button--dark:hover {
  background: var(--sage-deep);
  transform: translateY(-1px);
}

.button--quiet {
  border-color: var(--line);
  background: var(--paper-bright);
  color: var(--ink-soft);
}

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

.button--danger {
  background: var(--clay);
  color: #fff9f0;
}

.button--danger:hover {
  background: var(--clay-deep);
}

/* ---------- Layout ---------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 386px;
  align-items: start;
  gap: 26px;
  margin-top: 18px;
}

.game-area {
  min-width: 0;
  animation: rise-in 0.65s 0.05s ease both;
}

.side-area {
  min-width: 0;
  animation: rise-in 0.65s 0.13s ease both;
}

/* ---------- Game heading ---------- */

.game-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 12px;
  padding: 0 4px;
}

.game-heading__main {
  display: grid;
  grid-template-columns: auto auto;
  grid-template-rows: auto auto;
  align-items: end;
  column-gap: 16px;
  row-gap: 0;
}

.section-kicker {
  grid-column: 1;
  grid-row: 1;
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 8.5px;
  font-weight: 680;
  letter-spacing: 0.19em;
}

.game-heading h1 {
  grid-column: 1;
  grid-row: 2;
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(30px, 3.1vw, 38px);
  font-weight: 500;
  line-height: 1.02;
  letter-spacing: 0.03em;
}

.meta-line {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 11px;
}

.meta-separator {
  width: 2px;
  height: 2px;
  border-radius: 50%;
  background: var(--line-strong);
}

.difficulty-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 21px;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--sage-soft);
  color: var(--sage-deep);
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: 0.05em;
}

.difficulty-badge::before {
  content: "";
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
}

.difficulty-badge[data-level="进阶"] {
  background: var(--gold-soft);
  color: #78561c;
}

.difficulty-badge[data-level="挑战"] {
  background: var(--clay-soft);
  color: var(--clay-deep);
}

.game-heading__side {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 2px;
}

.timer-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.56);
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.timer-chip svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.6;
  stroke-linecap: round;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255, 253, 248, 0.56);
  color: var(--muted-strong);
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}

.icon-button:hover {
  border-color: var(--line-strong);
  background: #fffdf8;
  color: var(--ink);
  transform: rotate(-18deg);
}

.icon-button svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Play card + board ---------- */

.play-card {
  padding: 14px 16px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(145deg, rgba(255, 255, 252, 0.5), transparent 42%),
    var(--paper);
  box-shadow: var(--shadow-md);
}

.play-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 31px;
  margin-bottom: 9px;
}

.progress-wrap {
  flex: 1 1 auto;
  max-width: 252px;
  min-width: 135px;
}

.progress-copy {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 10px;
}

.progress-copy strong {
  color: var(--ink-soft);
  font-size: 10px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
}

.progress-track {
  height: 3px;
  overflow: hidden;
  border-radius: 99px;
  background: #e5ded1;
}

.progress-track span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--sage), #5a9380);
  transition: width 0.45s cubic-bezier(0.22, 0.8, 0.25, 1);
}

.mobile-puzzle-label {
  display: none;
}

.play-toolbar__right {
  display: flex;
  align-items: center;
  gap: 15px;
  flex: 0 0 auto;
}

.micro-stat {
  display: flex;
  align-items: baseline;
  gap: 4px;
  color: var(--muted);
  font-size: 9.5px;
  white-space: nowrap;
}

.micro-stat strong {
  color: var(--ink-soft);
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.hint-peek {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 29px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--muted-strong);
  font-size: 10.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.hint-peek svg {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.hint-peek kbd {
  height: 16px;
  min-width: 16px;
  padding: 0 4px;
  border: none;
  background: #ece6da;
  box-shadow: none;
  font-size: 8.5px;
}

.hint-peek:hover {
  border-color: var(--gold);
  background: var(--gold-soft);
  color: #5d471e;
}

.board-key {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px 18px;
  width: min(100%, var(--play-width));
  margin: 0 auto 8px;
  color: var(--muted-strong);
  font-size: 9.8px;
  line-height: 1.5;
}

.board-key > span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.key-cage {
  width: 22px;
  height: 5px;
  border-top: 1.2px dashed rgba(128, 82, 53, 0.45);
  border-bottom: 1.2px dashed rgba(128, 82, 53, 0.45);
}

.key-sum {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 15px;
  padding: 0 3px;
  border-radius: 3px;
  background: #f5ecdc;
  color: #805534;
  font-size: 8.5px;
  font-style: normal;
  font-weight: 600;
  line-height: 1;
}

.board-mode {
  margin-left: auto;
  min-height: 20px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f7f3e9;
  color: var(--muted-strong);
  font-size: 8.8px;
  font-weight: 650;
  letter-spacing: 0.02em;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}

.board-mode i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #9eaa9f;
  transition: background 0.18s ease, box-shadow 0.18s ease;
}

.board-mode b {
  font-size: inherit;
  font-weight: inherit;
}

.board-mode.is-note-mode {
  border-color: var(--note-line);
  background: var(--note-soft);
  color: var(--note-deep);
}

.board-mode.is-note-mode i {
  background: var(--note);
  box-shadow: 0 0 0 3px rgba(139, 101, 52, 0.11);
}

.board-frame {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 1px;
}

.board {
  --cell-fill: var(--paper-bright);
  --cell-peer: #f7f3e9;
  --cell-cage: #f6efdd;
  --cell-cage-empty: #f7ded5;
  --cell-cage-filled: #f0eae1;
  --cell-same: #e5eee7;
  --cell-selected: #f4e2cf;
  --cell-grid: #d7d0c3;
  --cell-box: #2f4438;
  --cell-hover: #fbf5e9;
  --cage-sum-bg: rgba(255, 253, 248, 0.94);
  position: relative;
  display: grid;
  scroll-margin-top: 16px;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  width: min(100%, var(--play-width));
  aspect-ratio: 1;
  overflow: hidden;
  border: 2.5px solid var(--ink);
  border-radius: 6px;
  background: var(--cell-fill);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.8) inset,
    0 18px 35px -22px rgba(33, 44, 36, 0.33);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
  user-select: none;
  -webkit-user-select: none;
}

.board.is-note-mode {
  --cell-fill: #f8eed8;
  --cell-peer: #f2e6cf;
  --cell-cage: #f3e7cf;
  --cell-cage-empty: #f7d9cd;
  --cell-cage-filled: #eee3d1;
  --cell-same: #eedfc0;
  --cell-selected: #f5e2c7;
  --cell-grid: #d2c0a2;
  --cell-box: #6d5437;
  --cell-hover: #f6ecd8;
  --cage-sum-bg: rgba(251, 244, 231, 0.96);
  border-color: #705538;
  box-shadow:
    0 0 0 4px rgba(134, 98, 52, 0.11),
    0 1px 0 rgba(255, 255, 255, 0.8) inset,
    0 18px 35px -22px rgba(33, 44, 36, 0.28);
}

.cell {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--cell-grid);
  border-bottom: 1px solid var(--cell-grid);
  background: var(--cell-fill);
  cursor: pointer;
  transition: background-color 0.16s ease, border-color 0.16s ease;
}

.cell.is-col-last {
  border-right: 0;
}

.cell.is-row-last {
  border-bottom: 0;
}

.cell.box-right {
  border-right: 2.5px solid var(--cell-box);
}

.cell.box-bottom {
  border-bottom: 2.5px solid var(--cell-box);
}

.cell.is-peer {
  background: var(--cell-peer);
}

.cell.is-cage {
  background: var(--cell-cage);
}

.cell.is-cage-empty {
  background: var(--cell-cage-empty);
}

.cell.is-cage-filled {
  background: var(--cell-cage-filled);
}

.cell.is-same {
  background: var(--cell-same);
}

.cell.is-hint-unit {
  background: #faefcf;
}

.cell.is-hint-cage {
  background: #f8e9d2;
}

.cell.is-hint-target {
  z-index: 5;
  background: var(--gold-soft);
  box-shadow: inset 0 0 0 3px var(--clay);
  animation: hint-target 2.2s ease-in-out infinite;
}

.cell.is-hint-related {
  z-index: 2;
  box-shadow: inset 0 0 0 2px rgba(194, 91, 66, 0.5);
}

.cell.is-selected {
  z-index: 6;
  background: var(--cell-selected);
  box-shadow: inset 0 0 0 2.5px var(--clay);
}

.cell.is-hint-target.is-selected {
  box-shadow: inset 0 0 0 3px var(--clay);
}

.cell:hover:not(.is-hint-target):not(.is-selected) {
  background: var(--cell-hover);
}

.cell:focus-visible {
  outline: 2px solid var(--clay);
  outline-offset: -4px;
  z-index: 7;
}

.cell.is-wrong {
  background: #f5d8cf !important;
  animation: cell-shake 0.38s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

.cell.is-wrong::after {
  content: "";
  position: absolute;
  inset: 5px;
  z-index: 8;
  border: 1.5px solid rgba(194, 91, 66, 0.75);
  border-radius: 3px;
  pointer-events: none;
}

.cell-value {
  position: relative;
  z-index: 2;
  font-family: var(--font-body);
  font-size: clamp(21px, 3vw, 34px);
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: var(--ink);
  transform: translateY(1px);
}

.cell-value.is-user {
  color: var(--sage-deep);
  font-weight: 400;
}

.cell.is-given .cell-value {
  color: var(--ink);
  font-weight: 400;
}

.cell.is-col-last.box-right {
  border-right: 2.5px solid var(--cell-box);
}

.cell.is-row-last.box-bottom {
  border-bottom: 2.5px solid var(--cell-box);
}

.cell.just-placed .cell-value {
  animation: number-pop 0.26s cubic-bezier(0.2, 0.85, 0.3, 1.35);
}

.cage-label-layer {
  position: absolute;
  inset: 0;
  z-index: 7;
  overflow: hidden;
  pointer-events: none;
}

.cell-sum {
  position: absolute;
  z-index: auto;
  padding: 0 2px;
  border-radius: 3px;
  background: var(--cage-sum-bg);
  color: #805534;
  font-family: var(--font-body);
  font-size: clamp(8.5px, 0.98vw, 10px);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  letter-spacing: -0.02em;
  pointer-events: none;
}

.cell-sum.is-active {
  background: rgba(255, 251, 241, 0.98);
  color: var(--clay-deep);
  box-shadow: 0 0 0 1px rgba(194, 91, 66, 0.1);
}

.cell-notes {
  position: absolute;
  inset: 3px;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  pointer-events: none;
}

.cell.has-sum .cell-notes {
  padding-top: 6px;
}

.cell-note {
  display: grid;
  place-items: center;
  visibility: hidden;
  color: #77837a;
  font-size: clamp(6.5px, 0.8vw, 8.8px);
  font-weight: 400;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.cell-note.is-on {
  visibility: visible;
  color: var(--sage-deep);
}

.cell.is-hint-target .cell-note.is-on {
  color: var(--clay-deep);
}

.board.is-note-mode .cell-note.is-on {
  color: var(--note-deep);
  font-weight: 400;
}

.cage-overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}

.cage-line {
  fill: none;
  stroke: rgba(128, 82, 53, 0.48);
  stroke-width: 1.3;
  stroke-dasharray: 3.5 4;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.cage-active-halo {
  fill: none;
  stroke: var(--paper-bright);
  stroke-width: 6.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.cage-active-line {
  fill: none;
  stroke: var(--clay);
  stroke-width: 2.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.board.is-celebrating .cell-value {
  animation: solved-glow 1.2s ease both;
}

/* ---------- Input area ---------- */

.input-area {
  width: min(100%, var(--play-width));
  margin: 14px auto 0;
}

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

.num-key {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  height: 51px;
  padding: 0;
  border: 1px solid #ddd5c7;
  border-radius: 12px;
  background: var(--paper-bright);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(56, 64, 57, 0.04);
  transition: transform 0.14s ease, border-color 0.14s ease, background 0.14s ease, box-shadow 0.14s ease;
}

.num-key:hover:not(:disabled) {
  border-color: var(--sage);
  background: #f7fbf7;
  transform: translateY(-2px);
  box-shadow: 0 6px 15px rgba(44, 111, 96, 0.1);
}

.num-key:active:not(:disabled) {
  transform: translateY(0);
}

.num-key__digit {
  font-family: var(--font-body);
  font-size: clamp(19px, 2vw, 24px);
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.num-key__left {
  color: var(--muted);
  font-size: 7.5px;
  line-height: 1;
  letter-spacing: 0.02em;
}

.num-key.is-done {
  opacity: 0.36;
}

.num-key.is-note-mode {
  border-color: var(--note-line);
  background: var(--note-soft);
  color: var(--note-deep);
  box-shadow: inset 0 0 0 1px rgba(139, 101, 52, 0.05), 0 2px 0 rgba(56, 64, 57, 0.03);
}

.num-key.is-note-mode:hover:not(:disabled) {
  border-color: var(--note);
  background: #f2e4cc;
  transform: translateY(-2px);
  box-shadow: 0 6px 15px rgba(139, 101, 52, 0.13);
}

.num-key.is-note-mode .num-key__digit {
  color: var(--note-deep);
}

.num-key.is-note-mode .num-key__left {
  color: #997953;
}

.input-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin-top: 12px;
}

.input-tools {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.mode-switch {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #eae3d6;
}

.mode-switch__button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 25px;
  padding: 0 8px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted-strong);
  font-size: 10px;
  font-weight: 650;
  line-height: 1;
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}

.mode-switch__button svg {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.55;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mode-switch__button kbd {
  height: 15px;
  min-width: 15px;
  padding: 0 3px;
  border: none;
  background: rgba(74, 80, 73, 0.09);
  box-shadow: none;
  font-size: 7.5px;
}

#notesToggle[aria-pressed="true"] kbd {
  background: rgba(255, 255, 255, 0.16);
  color: #f4fbfc;
}

.mode-switch__button:hover:not([aria-pressed="true"]) {
  background: rgba(255, 253, 248, 0.42);
  color: var(--ink);
}

.mode-switch:has(#notesToggle[aria-pressed="true"]) {
  border-color: var(--note-line);
  background: var(--note-soft);
  box-shadow: inset 0 0 0 1px rgba(139, 101, 52, 0.06);
}

.mode-switch__button[aria-pressed="true"] {
  background: var(--paper-bright);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(41, 49, 42, 0.08);
}

#digitModeBtn[aria-pressed="true"] {
  background: var(--ink);
  color: var(--cream);
  box-shadow: 0 2px 6px rgba(33, 48, 41, 0.18);
}

#notesToggle[aria-pressed="true"] {
  background: var(--note);
  color: #fffaf0;
  box-shadow: 0 2px 6px rgba(108, 72, 38, 0.2);
}

#notesToggle[aria-pressed="true"]:hover {
  background: var(--note-deep);
}

.input-tools__divider {
  width: 1px;
  height: 16px;
  margin: 0 1px;
  background: var(--line);
  flex: 0 0 auto;
}

.tool-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 31px;
  padding: 0 9px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted-strong);
  font-size: 10.5px;
  font-weight: 560;
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease;
}

.tool-button svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.55;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tool-button kbd {
  border: none;
  background: #ece6da;
  box-shadow: none;
  color: #7a8178;
}

.tool-button:hover {
  border-color: var(--line);
  background: var(--paper-bright);
  color: var(--ink);
}

.tool-button[aria-pressed="true"] {
  border-color: rgba(44, 111, 96, 0.32);
  background: var(--sage-soft);
  color: var(--sage-deep);
}

.tool-button[aria-pressed="true"] kbd {
  background: rgba(255, 255, 255, 0.45);
  color: var(--sage-deep);
}

.selection-readout {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  flex-basis: 100%;
  gap: 7px;
  color: var(--muted);
  font-size: 11px;
  text-align: left;
  min-height: 19px;
}

.selection-readout .selection-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--line-strong);
  transition: background 0.16s ease;
}

.selection-readout.is-active {
  color: var(--ink-soft);
}

.selection-readout.is-active .selection-dot {
  background: var(--clay);
}

.selection-readout.is-note-mode {
  color: var(--note-deep);
}

.selection-readout.is-note-mode .selection-dot {
  background: var(--note);
  box-shadow: 0 0 0 3px rgba(139, 101, 52, 0.10);
}

.selection-readout.is-note-mode strong {
  color: var(--note-deep);
}

.selection-readout strong {
  color: var(--ink);
  font-weight: 650;
}

.board-note {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  margin: 13px 4px 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
}

.board-note__mark {
  color: var(--clay);
  font-size: 9px;
  line-height: 1.9;
}

/* ---------- Coach ---------- */

.coach-card {
  position: relative;
  overflow: hidden;
  scroll-margin-top: 16px;
  padding: 20px;
  border: 1px solid rgba(27, 50, 40, 0.24);
  border-radius: var(--radius-lg);
  background:
    radial-gradient(420px 200px at 100% 0, rgba(218, 173, 92, 0.15), transparent 70%),
    radial-gradient(320px 220px at -20% 100%, rgba(79, 135, 112, 0.22), transparent 70%),
    #20342b;
  color: #f7f0e2;
  box-shadow: 0 23px 50px -26px rgba(28, 46, 37, 0.6);
}

.coach-card::after {
  content: "";
  position: absolute;
  right: -38px;
  top: -46px;
  width: 130px;
  height: 130px;
  border: 1px solid rgba(241, 221, 180, 0.12);
  border-radius: 50%;
  pointer-events: none;
}

.coach-topline {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(241, 233, 214, 0.13);
}

.coach-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 620;
  letter-spacing: 0.13em;
}

.coach-glyph {
  display: grid;
  place-items: center;
  width: 21px;
  height: 21px;
  border: 1px solid rgba(242, 213, 154, 0.42);
  border-radius: 50%;
  color: #e7c67f;
  font-size: 9px;
}

.coach-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: rgba(247, 240, 226, 0.55);
  font-size: 9px;
  letter-spacing: 0.08em;
}

.coach-state i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #9bc4a5;
  box-shadow: 0 0 0 3px rgba(155, 196, 165, 0.1);
}

.coach-state.is-thinking i {
  animation: thinking-pulse 1s ease-in-out infinite;
}

.hint-idle {
  display: flex;
  gap: 17px;
  align-items: center;
  padding: 22px 2px 21px;
}

.idle-orbit {
  position: relative;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 64px;
  height: 64px;
  border: 1px solid rgba(232, 202, 142, 0.24);
  border-radius: 50%;
}

.idle-orbit::before {
  content: "";
  position: absolute;
  inset: 8px;
  border: 1px dashed rgba(232, 202, 142, 0.3);
  border-radius: 50%;
  animation: orbit-spin 24s linear infinite;
}

.idle-orbit::after {
  content: "";
  position: absolute;
  top: 5px;
  right: 9px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 12px rgba(212, 165, 72, 0.9);
}

.idle-orbit span {
  display: grid;
  place-items: center;
  width: 37px;
  height: 37px;
  border-radius: 50%;
  background: rgba(245, 237, 220, 0.08);
  color: #ead8af;
  font-family: var(--font-display);
  font-size: 21px;
  font-style: italic;
}

.hint-idle__copy h2 {
  margin: 0 0 7px;
  font-family: var(--font-display);
  color: #fbf5e9;
  font-size: 21px;
  font-weight: 500;
  line-height: 1.36;
  letter-spacing: 0.025em;
}

.hint-idle__copy p {
  margin: 0;
  color: rgba(247, 240, 226, 0.66);
  font-size: 12.5px;
  line-height: 1.75;
}

.coach-actions {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.coach-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 43px;
  padding: 0 16px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  background: #f5ead3;
  color: #263c31;
  font-size: 12.5px;
  font-weight: 650;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: transform 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}

.coach-button:hover {
  background: #fff5e1;
  transform: translateY(-1px);
  box-shadow: 0 9px 22px rgba(0, 0, 0, 0.15);
}

.coach-button:active {
  transform: translateY(0);
}

.coach-button svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.55;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.coach-button kbd {
  margin-left: auto;
  border-color: rgba(36, 54, 44, 0.16);
  background: rgba(42, 60, 49, 0.07);
  color: #4d5f53;
  box-shadow: none;
}

.coach-footnote {
  color: rgba(247, 240, 226, 0.44);
  font-size: 9.8px;
  line-height: 1.45;
  text-align: center;
}

/* Hint result */

.hint-result {
  padding: 19px 1px 18px;
  animation: hint-arrive 0.38s cubic-bezier(0.2, 0.8, 0.25, 1) both;
}

.hint-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 15px;
}

.hint-kicker {
  display: flex;
  align-items: center;
  gap: 7px;
  color: rgba(247, 240, 226, 0.55);
  font-size: 8.5px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.hint-kicker::before {
  content: "";
  width: 15px;
  height: 1px;
  background: rgba(232, 202, 142, 0.5);
}

.technique-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 21px;
  padding: 0 8px;
  border: 1px solid rgba(232, 202, 142, 0.24);
  border-radius: 999px;
  background: rgba(232, 202, 142, 0.08);
  color: #ecd19a;
  font-size: 9px;
  font-weight: 580;
  white-space: nowrap;
}

.technique-tag.is-fallback {
  border-color: rgba(255, 255, 255, 0.2);
  color: rgba(247, 240, 226, 0.7);
  background: rgba(255, 255, 255, 0.06);
}

.hint-focus {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 15px;
}

.hint-digit {
  position: relative;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 65px;
  height: 72px;
  border: 1px solid rgba(246, 229, 191, 0.33);
  border-radius: 12px;
  background:
    linear-gradient(180deg, rgba(255, 250, 235, 0.14), rgba(255, 250, 235, 0.06));
  color: #f4dfb3;
  font-family: var(--font-display);
  font-size: 43px;
  font-weight: 500;
  line-height: 1;
  box-shadow: inset 0 0 30px rgba(237, 205, 143, 0.06);
}

.hint-digit::after {
  content: "";
  position: absolute;
  right: 11px;
  bottom: 10px;
  left: 11px;
  height: 1px;
  background: rgba(232, 202, 142, 0.2);
}

.hint-focus-copy {
  min-width: 0;
}

.hint-coord {
  margin: 0 0 5px;
  color: #e9ce95;
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: 0.015em;
}

.hint-unit-caption {
  margin: 0;
  color: rgba(247, 240, 226, 0.54);
  font-size: 10px;
  line-height: 1.5;
}

.hint-summary {
  margin: 0 0 14px;
  color: rgba(251, 245, 233, 0.92);
  font-family: var(--font-display);
  font-size: 16px;
  line-height: 1.58;
  letter-spacing: 0.012em;
}

.hint-steps {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0 0 15px;
  padding: 0;
  list-style: none;
}

.hint-steps li {
  position: relative;
  padding-left: 18px;
  color: rgba(247, 240, 226, 0.72);
  font-size: 11.8px;
  line-height: 1.66;
}

.hint-steps li::before {
  content: "";
  position: absolute;
  top: 0.63em;
  left: 3px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: rgba(232, 202, 142, 0.52);
}

.candidate-strip {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 4px;
  margin-bottom: 13px;
}

.candidate-chip {
  display: grid;
  place-items: center;
  height: 28px;
  border: 1px solid rgba(247, 240, 226, 0.12);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.025);
  color: rgba(247, 240, 226, 0.26);
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
}

.candidate-chip.is-possible {
  border-color: rgba(247, 240, 226, 0.23);
  background: rgba(255, 255, 255, 0.07);
  color: rgba(247, 240, 226, 0.88);
}

.candidate-chip.is-forced {
  border-color: rgba(232, 202, 142, 0.64);
  background: rgba(232, 202, 142, 0.19);
  color: #f4dfb2;
  box-shadow: 0 0 0 1px rgba(232, 202, 142, 0.11);
  font-size: 13px;
}

.candidate-chip.is-excluded {
  text-decoration: line-through;
  text-decoration-thickness: 1px;
  text-decoration-color: rgba(247, 240, 226, 0.28);
}

.combo-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  margin: 0 0 14px;
  color: rgba(247, 240, 226, 0.5);
  font-size: 9.5px;
  line-height: 1.5;
}

.combo-pill {
  display: inline-flex;
  align-items: center;
  min-height: 21px;
  padding: 0 7px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.055);
  color: rgba(247, 240, 226, 0.72);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
}

.equation-card {
  margin: 0 0 14px;
  padding: 10px 12px;
  border: 1px solid rgba(232, 202, 142, 0.18);
  border-radius: 9px;
  background: rgba(232, 202, 142, 0.07);
  color: #ecd8ac;
  font-family: var(--font-display);
  font-size: 16px;
  letter-spacing: 0.04em;
  text-align: center;
}

.hint-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 7px;
  margin-bottom: 10px;
}

.hint-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid rgba(247, 240, 226, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.045);
  color: rgba(247, 240, 226, 0.78);
  font-size: 11px;
  font-weight: 580;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.hint-action:hover {
  border-color: rgba(232, 202, 142, 0.4);
  background: rgba(232, 202, 142, 0.1);
  color: #f3e1bb;
}

.hint-action--primary {
  border-color: rgba(245, 234, 211, 0.15);
  background: #f2e6cf;
  color: #243a2f;
}

.hint-action--primary:hover {
  border-color: transparent;
  background: #fff4de;
  color: #1b3328;
}

.hint-stale {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 9px;
  margin-top: 3px;
  color: rgba(247, 240, 226, 0.46);
  font-size: 9.5px;
}

.hint-stale button {
  padding: 0;
  border: 0;
  border-bottom: 1px solid rgba(232, 202, 142, 0.4);
  background: none;
  color: #d8bd87;
  font-size: 9.5px;
  cursor: pointer;
}

.hint-done {
  padding: 22px 3px 20px;
  text-align: center;
}

.hint-done .done-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  margin: 0 auto 12px;
  border: 1px solid rgba(211, 223, 196, 0.3);
  border-radius: 50%;
  background: rgba(161, 189, 155, 0.12);
  color: #c7dfbd;
  font-size: 18px;
}

.hint-done h3 {
  margin: 0 0 7px;
  font-family: var(--font-display);
  color: #f6eedf;
  font-size: 19px;
  font-weight: 500;
}

.hint-done p {
  margin: 0;
  color: rgba(247, 240, 226, 0.55);
  font-size: 10.5px;
  line-height: 1.65;
}

/* ---------- Notebook ---------- */

.notebook-card {
  margin-top: 17px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--paper);
  box-shadow: var(--shadow-sm);
}

.notebook-topline {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 17px 0;
  border-bottom: 1px solid var(--line);
}

.tabs {
  display: flex;
  align-items: center;
  gap: 3px;
}

.tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 8px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 580;
  cursor: pointer;
  transition: color 0.16s ease;
}

.tab::after {
  content: "";
  position: absolute;
  right: 7px;
  bottom: -1px;
  left: 7px;
  height: 2px;
  border-radius: 9px 9px 0 0;
  background: transparent;
  transition: background 0.16s ease;
}

.tab.is-active {
  color: var(--ink);
}

.tab.is-active::after {
  background: var(--clay);
}

.tab-count {
  display: inline-grid;
  place-items: center;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 99px;
  background: #e9e2d6;
  color: var(--muted-strong);
  font-size: 8.5px;
  font-variant-numeric: tabular-nums;
}

.notebook-rule {
  flex: 1;
  height: 1px;
}

.notebook-panel {
  display: none;
}

.notebook-panel.is-active {
  display: block;
}

#logPanel {
  position: relative;
  height: 358px;
}

.log-list {
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 7px 17px 20px;
  scrollbar-width: thin;
  scrollbar-color: #d1c8b9 transparent;
}

.log-list::-webkit-scrollbar {
  width: 4px;
}

.log-list::-webkit-scrollbar-thumb {
  border-radius: 9px;
  background: #d1c8b9;
}

.log-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 36px;
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1.7;
  text-align: center;
}

.log-entry {
  position: relative;
  padding: 11px 0 11px 19px;
  border-bottom: 1px solid rgba(89, 94, 84, 0.07);
}

.log-entry:last-child {
  border-bottom: 0;
}

.log-entry::before {
  content: "";
  position: absolute;
  top: 16px;
  left: 2px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #b9b3a7;
  box-shadow: 0 0 0 3px var(--paper);
}

.log-entry::after {
  content: "";
  position: absolute;
  top: 25px;
  bottom: -11px;
  left: 4.25px;
  width: 1px;
  background: rgba(93, 100, 90, 0.1);
}

.log-entry:last-child::after {
  display: none;
}

.log-entry--coach::before {
  background: var(--gold);
}

.log-entry--success::before {
  background: var(--sage);
}

.log-entry--warn::before {
  background: var(--clay);
}

.log-entry--system::before {
  background: #9faea2;
}

.log-entry__top {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 4px;
}

.log-time {
  color: #a19d92;
  font-size: 9px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
}

.log-label {
  color: var(--muted);
  font-size: 9px;
  font-weight: 620;
  letter-spacing: 0.04em;
}

.log-label--coach {
  color: #9a752a;
}

.log-label--success {
  color: var(--sage);
}

.log-label--warn {
  color: var(--clay-deep);
}

.log-entry__body {
  color: var(--ink-soft);
  font-size: 11.8px;
  line-height: 1.66;
  overflow-wrap: anywhere;
}

.log-entry__body strong {
  color: var(--ink);
  font-weight: 650;
}

.log-entry--coach .log-entry__body {
  color: #424f45;
}

.log-entry__meta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 5px;
  color: var(--muted);
  font-size: 9px;
}

.log-entry__meta i {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--gold);
}

.log-entry__formula {
  display: inline-block;
  margin-top: 5px;
  padding: 3px 7px;
  border-radius: 5px;
  background: #f0eadf;
  color: #66573f;
  font-family: var(--font-display);
  font-size: 11.5px;
  letter-spacing: 0.025em;
}

/* Manual */

#manualPanel {
  height: 358px;
  overflow-y: auto;
  padding: 16px 17px 22px;
  scrollbar-width: thin;
  scrollbar-color: #d1c8b9 transparent;
}

#manualPanel::-webkit-scrollbar {
  width: 4px;
}

#manualPanel::-webkit-scrollbar-thumb {
  border-radius: 9px;
  background: #d1c8b9;
}

.manual-intro {
  margin-bottom: 13px;
  padding: 0 2px;
}

.manual-intro span {
  display: block;
  margin-bottom: 6px;
  color: #9a927f;
  font-size: 8px;
  font-weight: 650;
  letter-spacing: 0.17em;
}

.manual-intro p {
  margin: 0;
  color: var(--muted);
  font-size: 11.3px;
  line-height: 1.65;
}

.manual-list {
  border-top: 1px solid var(--line-soft);
}

.manual-item {
  border-bottom: 1px solid var(--line-soft);
}

.manual-item summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 0;
  list-style: none;
  cursor: pointer;
}

.manual-item summary::-webkit-details-marker {
  display: none;
}

.manual-index {
  color: #b1a58f;
  font-family: var(--font-display);
  font-size: 11px;
  font-style: italic;
}

.manual-summary {
  display: flex;
  align-items: baseline;
  gap: 7px;
  flex: 1;
  min-width: 0;
}

.manual-summary strong {
  color: var(--ink-soft);
  font-size: 12.3px;
  font-weight: 630;
}

.manual-summary small {
  color: #9c9d93;
  font-family: var(--font-display);
  font-size: 9.5px;
  font-style: italic;
}

.manual-plus {
  position: relative;
  width: 12px;
  height: 12px;
  flex: 0 0 auto;
}

.manual-plus::before,
.manual-plus::after {
  content: "";
  position: absolute;
  top: 5.5px;
  left: 1px;
  width: 10px;
  height: 1px;
  background: #a29e90;
  transition: transform 0.2s ease;
}

.manual-plus::after {
  transform: rotate(90deg);
}

.manual-item[open] .manual-plus::after {
  transform: rotate(0);
}

.manual-body {
  padding: 0 1px 14px 26px;
  animation: soft-open 0.2s ease both;
}

.manual-body p {
  margin: 0 0 10px;
  color: var(--muted-strong);
  font-size: 11.4px;
  line-height: 1.7;
}

.manual-body p:last-child {
  margin-bottom: 0;
}

.manual-body .manual-hint {
  margin-top: 8px;
  color: var(--muted);
  font-size: 9.8px;
}

.mini-formula {
  display: flex;
  gap: 4px;
}

.mini-formula span {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: #9a9d92;
  font-family: var(--font-display);
  font-size: 10px;
}

.mini-formula .strike {
  text-decoration: line-through;
  color: #bbb6ab;
  background: #f1ece3;
}

.mini-formula .candidate-focus {
  border-color: var(--clay);
  background: var(--clay-soft);
  color: var(--clay-deep);
  font-weight: 600;
}

.tip-callout {
  padding: 8px 10px;
  border-left: 2px solid var(--gold);
  border-radius: 0 6px 6px 0;
  background: #f6f0e2;
  color: #77674b;
  font-size: 10.5px;
  line-height: 1.6;
}

.combo-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 8px;
}

.combo-pill {
  padding: 5px 7px;
  border-radius: 5px;
  background: #efe8dc;
  color: #6b6558;
  font-size: 9px;
  line-height: 1.35;
}

.formula-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  padding: 9px 10px;
  border: 1px solid #e2d6be;
  border-radius: 7px;
  background: #f8f1e3;
  color: #72654f;
  font-size: 9.5px;
  line-height: 1.5;
}

.formula-card__minus,
.formula-card__equals {
  color: #a9977a;
  font-family: var(--font-display);
  font-size: 13px;
}

.formula-card strong {
  color: var(--clay-deep);
  font-weight: 650;
}

.shortcut-sheet {
  margin-top: 16px;
  padding-top: 13px;
  border-top: 1px solid var(--line-soft);
}

.shortcut-title {
  margin: 0 0 9px;
  color: var(--muted);
  font-size: 8.5px;
  font-weight: 650;
  letter-spacing: 0.1em;
}

.shortcut-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px 10px;
}

.shortcut-grid span {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted-strong);
  font-size: 9.8px;
  line-height: 1.4;
}

.shortcut-grid kbd {
  flex: 0 0 auto;
  height: 17px;
  font-size: 8px;
}

/* ---------- Footer ---------- */

.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-top: 25px;
  padding: 18px 4px 0;
  border-top: 1px solid var(--line);
  color: #929186;
  font-size: 9.5px;
  line-height: 1.6;
}

.footer strong {
  color: var(--muted-strong);
  font-weight: 620;
}

.footer button {
  padding: 0;
  border: 0;
  border-bottom: 1px solid transparent;
  background: none;
  color: var(--muted-strong);
  font-size: 9.5px;
  cursor: pointer;
}

.footer button:hover {
  border-bottom-color: var(--muted-strong);
}

/* ---------- Dialogs ---------- */

.dialog {
  position: fixed;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 40px);
  margin: auto;
  padding: 24px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
}

.dialog::backdrop {
  background: rgba(27, 39, 32, 0.56);
  backdrop-filter: blur(7px) saturate(0.85);
  -webkit-backdrop-filter: blur(7px) saturate(0.85);
}

.dialog[open] {
  animation: dialog-in 0.28s cubic-bezier(0.2, 0.8, 0.25, 1) both;
}

.dialog-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.dialog-kicker {
  color: #938b7c;
  font-size: 8px;
  font-weight: 680;
  letter-spacing: 0.18em;
}

.dialog-close {
  display: grid;
  place-items: center;
  width: 31px;
  height: 31px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  color: var(--muted-strong);
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.dialog-close:hover {
  background: var(--paper-bright);
  color: var(--ink);
  transform: rotate(90deg);
}

.dialog-close svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linecap: round;
}

/* Tutorial */

.tutorial-dialog {
  width: min(790px, calc(100vw - 32px));
  padding: 24px 28px 20px;
}

.tutorial-progress {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
  margin: 17px 0 0;
}

.tutorial-progress span {
  height: 2px;
  border-radius: 99px;
  background: #e0d8ca;
  transition: background 0.24s ease;
}

.tutorial-progress span.is-done {
  background: var(--clay);
}

.tutorial-stage {
  min-height: 420px;
  padding: 25px 3px 15px;
}

.lesson {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(240px, 0.95fr);
  align-items: center;
  gap: 38px;
  animation: lesson-in 0.3s ease both;
}

.lesson__copy {
  min-width: 0;
}

.lesson__eyebrow {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  color: var(--clay);
  font-size: 8.5px;
  font-weight: 680;
  letter-spacing: 0.15em;
}

.lesson__eyebrow::after {
  content: "";
  width: 26px;
  height: 1px;
  background: rgba(194, 91, 66, 0.32);
}

.lesson h2 {
  margin: 0 0 14px;
  font-family: var(--font-display);
  font-size: clamp(27px, 3.1vw, 37px);
  font-weight: 500;
  line-height: 1.28;
  letter-spacing: 0.015em;
}

.lesson__lead {
  margin: 0 0 17px;
  color: var(--muted-strong);
  font-size: 13px;
  line-height: 1.85;
}

.lesson__lead strong {
  color: var(--ink);
  font-weight: 650;
}

.lesson-note {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  padding-top: 15px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11.2px;
  line-height: 1.65;
}

.lesson-note span {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--gold-soft);
  color: #87651f;
  font-family: var(--font-display);
  font-size: 9px;
}

.lesson__visual {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 280px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background:
    radial-gradient(circle at 20% 10%, rgba(255, 255, 255, 0.75), transparent 50%),
    #f5f0e6;
}

.lesson-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: min(224px, 100%);
  aspect-ratio: 1;
  overflow: hidden;
  border: 1.5px solid var(--ink-soft);
  border-radius: 5px;
  background: rgba(255, 253, 248, 0.5);
}

.lesson-cell {
  position: relative;
  display: grid;
  place-items: center;
  border-right: 1px solid #d3cbbc;
  border-bottom: 1px solid #d3cbbc;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 25px;
}

.lesson-cell:nth-child(3n) {
  border-right: 0;
}

.lesson-cell:nth-last-child(-n + 3) {
  border-bottom: 0;
}

.lesson-cell.is-empty {
  background: var(--gold-soft);
  color: var(--clay-deep);
  font-style: italic;
  box-shadow: inset 0 0 0 2px rgba(194, 91, 66, 0.6);
}

.lesson-cell.is-cage-cell {
  background: #f1e3ca;
}

.lesson-caption {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  padding: 5px 9px;
  border: 1px solid rgba(123, 104, 74, 0.18);
  border-radius: 99px;
  background: rgba(255, 252, 245, 0.88);
  color: #7e6c4f;
  font-size: 9px;
  white-space: nowrap;
}

.lesson-grid-nine {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  width: min(246px, 100%);
  aspect-ratio: 1;
  overflow: hidden;
  border: 1.5px solid var(--ink-soft);
  border-radius: 4px;
  background: var(--paper-bright);
}

.lesson-grid-nine i {
  border-right: 1px solid rgba(110, 118, 107, 0.18);
  border-bottom: 1px solid rgba(110, 118, 107, 0.18);
}

.lesson-grid-nine i.box-r {
  border-right: 1.5px solid rgba(60, 74, 64, 0.7);
}

.lesson-grid-nine i.box-b {
  border-bottom: 1.5px solid rgba(60, 74, 64, 0.7);
}

.lesson-grid-nine i.row-tint {
  background: rgba(212, 165, 72, 0.23);
}

.lesson-grid-nine i.col-tint {
  background: rgba(44, 111, 96, 0.13);
}

.lesson-grid-nine i.box-tint {
  background: rgba(194, 91, 66, 0.1);
}

.lesson-grid-nine i.box-tint.col-tint {
  background: linear-gradient(135deg, rgba(44, 111, 96, 0.14), rgba(194, 91, 66, 0.13));
}

.cage-lesson-wrap {
  position: relative;
  width: min(230px, 100%);
}

.cage-lesson-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid #b9ae9c;
  border-radius: 5px;
  background: var(--paper-bright);
}

.cage-lesson-grid .lesson-cell {
  font-size: 28px;
}

.cage-sumtag {
  position: absolute;
  top: 5px;
  left: 7px;
  color: var(--clay-deep);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.cage-lesson-outline {
  position: absolute;
  top: -2px;
  left: -2px;
  width: 33.333%;
  height: 66.666%;
  border: 2px dashed var(--clay);
  border-radius: 5px 0 0 5px;
  pointer-events: none;
}

.lesson-formula {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.lesson-formula__row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-soft);
  font-family: var(--font-display);
  font-size: 25px;
  letter-spacing: 0.02em;
}

.lesson-formula__row span {
  color: var(--muted);
}

.lesson-formula__row strong {
  color: var(--clay-deep);
  font-weight: 500;
}

.lesson-formula__line {
  width: 74%;
  height: 1px;
  background: var(--line);
}

.lesson-formula p {
  margin: 0;
  color: var(--muted);
  font-size: 9.5px;
  line-height: 1.6;
  text-align: center;
}

.lesson-combo-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.lesson-combo {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 253, 248, 0.68);
}

.lesson-combo__sum {
  flex: 0 0 auto;
  color: var(--clay-deep);
  font-family: var(--font-display);
  font-size: 25px;
  line-height: 1;
}

.lesson-combo__meta {
  flex: 1;
}

.lesson-combo__meta strong {
  display: block;
  margin-bottom: 2px;
  color: var(--ink-soft);
  font-size: 10.5px;
  font-weight: 650;
}

.lesson-combo__meta span {
  color: var(--muted);
  font-size: 9.5px;
}

.lesson-combo__digits {
  color: var(--ink-soft);
  font-family: var(--font-display);
  font-size: 18px;
}

.lesson-shortcuts {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.lesson-shortcut {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 253, 248, 0.62);
  color: var(--ink-soft);
  font-size: 10.5px;
}

.lesson-shortcut kbd {
  flex: 0 0 auto;
  min-width: 25px;
  height: 24px;
  border-color: #d4cbbb;
  background: #fffaf0;
  color: var(--ink-soft);
  font-size: 9px;
}

.lesson-shortcut span {
  color: var(--muted);
}

.tutorial-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  padding-top: 15px;
  border-top: 1px solid var(--line);
}

.tutorial-count {
  color: var(--muted);
  font-family: var(--font-display);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.05em;
}

.tutorial-skip {
  display: block;
  margin: 12px auto 0;
  padding: 2px;
  border: 0;
  border-bottom: 1px solid transparent;
  background: none;
  color: #999488;
  font-size: 9px;
  cursor: pointer;
}

.tutorial-skip:hover {
  border-bottom-color: #aaa397;
  color: var(--muted-strong);
}

/* Puzzle book */

.puzzle-book {
  width: min(720px, calc(100vw - 32px));
  padding: 24px 26px 27px;
}

.puzzle-book__heading h2 {
  margin: 19px 0 7px;
  font-family: var(--font-display);
  font-size: 31px;
  font-weight: 500;
  line-height: 1.2;
}

.puzzle-book__heading p {
  margin: 0 0 23px;
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1.6;
}

.puzzle-groups {
  display: flex;
  flex-direction: column;
  gap: 21px;
}

.puzzle-group__title {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 8px;
  color: var(--ink-soft);
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.04em;
}

.puzzle-group__title span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--sage);
}

.puzzle-group__title[data-level="进阶"] span {
  background: var(--gold);
}

.puzzle-group__title[data-level="挑战"] span {
  background: var(--clay);
}

.puzzle-group__title small {
  color: var(--muted);
  font-size: 9px;
  font-weight: 460;
  letter-spacing: 0;
}

.puzzle-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.puzzle-option {
  position: relative;
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  min-height: 59px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(255, 253, 248, 0.5);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.16s ease, background 0.16s ease, transform 0.16s ease;
}

.puzzle-option:hover {
  border-color: #b9b8a8;
  background: var(--paper-bright);
  transform: translateX(2px);
}

.puzzle-option.is-current {
  border-color: rgba(44, 111, 96, 0.55);
  background: #f4f9f4;
  box-shadow: inset 3px 0 0 var(--sage);
}

.puzzle-option__number {
  flex: 0 0 auto;
  color: #b3a791;
  font-family: var(--font-display);
  font-size: 18px;
  font-style: italic;
  font-variant-numeric: tabular-nums;
}

.puzzle-option__main {
  flex: 1;
  min-width: 0;
}

.puzzle-option__name {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 4px;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 500;
}

.puzzle-option__meta {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 9.7px;
}

.puzzle-option__meta i {
  width: 2px;
  height: 2px;
  border-radius: 50%;
  background: var(--line-strong);
}

.puzzle-option__state {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 9.7px;
  white-space: nowrap;
}

.puzzle-option__state.is-done {
  color: var(--sage);
}

.puzzle-option__state.is-progress {
  color: #a27c30;
}

.puzzle-option__state strong {
  font-weight: 650;
}

.puzzle-tick {
  display: inline-grid;
  place-items: center;
  width: 17px;
  height: 17px;
  border: 1px solid rgba(44, 111, 96, 0.24);
  border-radius: 50%;
  background: var(--sage-soft);
  color: var(--sage-deep);
  font-size: 9px;
}

.puzzle-book__note {
  margin: 23px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 9px;
  line-height: 1.6;
  text-align: center;
}

/* Completion */

.completion-dialog {
  width: min(520px, calc(100vw - 32px));
  overflow: hidden;
  border-color: rgba(33, 52, 42, 0.25);
  border-radius: 27px;
  background:
    radial-gradient(360px 260px at 100% 0, rgba(218, 173, 92, 0.16), transparent 65%),
    #20342b;
  color: var(--cream);
  box-shadow: var(--shadow-lg);
}

.completion-dialog::backdrop {
  background: rgba(23, 33, 27, 0.7);
}

.confetti-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.completion-content {
  position: relative;
  z-index: 1;
  padding: 18px 16px 9px;
  text-align: center;
}

.completion-mark {
  display: grid;
  place-items: center;
  width: 53px;
  height: 53px;
  margin: 0 auto 15px;
  border: 1px solid rgba(237, 210, 158, 0.36);
  border-radius: 50%;
  background: rgba(237, 210, 158, 0.1);
  color: #edd29f;
  font-size: 21px;
  box-shadow: 0 0 40px rgba(218, 173, 92, 0.1);
}

.completion-dialog .dialog-kicker {
  color: rgba(235, 213, 170, 0.62);
}

.completion-dialog h2 {
  margin: 9px 0 8px;
  color: #fbf5e7;
  font-family: var(--font-display);
  font-size: 34px;
  font-weight: 500;
  line-height: 1.2;
}

.completion-lead {
  margin: 0 auto 22px;
  max-width: 320px;
  color: rgba(247, 240, 226, 0.58);
  font-size: 11px;
  line-height: 1.7;
}

.completion-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: 0 4px 24px;
  border-top: 1px solid rgba(247, 240, 226, 0.13);
  border-bottom: 1px solid rgba(247, 240, 226, 0.13);
}

.completion-stats div {
  padding: 14px 5px;
  border-right: 1px solid rgba(247, 240, 226, 0.1);
}

.completion-stats div:last-child {
  border-right: 0;
}

.completion-stats span {
  display: block;
  margin-bottom: 5px;
  color: rgba(247, 240, 226, 0.44);
  font-size: 8.5px;
}

.completion-stats strong {
  color: #edd7aa;
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.completion-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.completion-dialog .button--quiet {
  border-color: rgba(247, 240, 226, 0.16);
  background: rgba(255, 255, 255, 0.05);
  color: rgba(247, 240, 226, 0.72);
}

.completion-dialog .button--quiet:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(247, 240, 226, 0.3);
}

.completion-dialog .button--dark {
  background: #f2e6cf;
  color: #263b30;
}

.completion-dialog .button--dark:hover {
  background: #fff4de;
}

/* Confirm */

.confirm-dialog {
  width: min(420px, calc(100vw - 32px));
  text-align: center;
  padding: 28px 28px 24px;
}

.confirm-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  margin: 0 auto 11px;
  border-radius: 50%;
  background: var(--gold-soft);
  color: #8b6821;
  font-size: 20px;
}

.confirm-dialog h2 {
  margin: 0 0 7px;
  font-family: var(--font-display);
  font-size: 25px;
  font-weight: 500;
}

.confirm-dialog p {
  margin: 0 auto 19px;
  max-width: 295px;
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1.7;
}

.confirm-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
}

/* Toast */

.toast {
  position: fixed;
  z-index: 100;
  right: 50%;
  bottom: 24px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 11px 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  background: rgba(31, 46, 38, 0.96);
  color: #f6efe2;
  font-size: 11px;
  line-height: 1.55;
  text-align: center;
  box-shadow: 0 12px 35px rgba(28, 39, 31, 0.22);
  opacity: 0;
  transform: translate(50%, 12px);
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(50%, 0);
}

.toast.is-warn {
  background: #7b392b;
}

/* ---------- Animations ---------- */

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes hint-arrive {
  from {
    opacity: 0;
    transform: translateY(7px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes number-pop {
  0% {
    opacity: 0.3;
    transform: scale(0.72) translateY(2px);
  }
  75% {
    transform: scale(1.06) translateY(0);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes cell-shake {
  10%, 90% {
    transform: translateX(-1px);
  }
  20%, 80% {
    transform: translateX(2px);
  }
  30%, 50%, 70% {
    transform: translateX(-3px);
  }
  40%, 60% {
    transform: translateX(3px);
  }
}

@keyframes hint-target {
  0%, 100% {
    box-shadow: inset 0 0 0 3px rgba(194, 91, 66, 0.9);
  }
  50% {
    box-shadow: inset 0 0 0 3px rgba(194, 91, 66, 0.55), 0 0 0 5px rgba(194, 91, 66, 0.07);
  }
}

@keyframes orbit-spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes thinking-pulse {
  0%, 100% {
    opacity: 0.4;
    transform: scale(0.8);
  }
  50% {
    opacity: 1;
    transform: scale(1.1);
  }
}

@keyframes solved-glow {
  0% {
    opacity: 0.35;
    transform: scale(0.82);
  }
  50% {
    opacity: 1;
    transform: scale(1.08);
    color: var(--clay);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes dialog-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes lesson-in {
  from {
    opacity: 0;
    transform: translateX(7px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes soft-open {
  from {
    opacity: 0;
    transform: translateY(-3px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------- Responsive ---------- */

@media (max-width: 1120px) {
  .app {
    width: min(1040px, calc(100% - 44px));
  }

  .layout {
    grid-template-columns: minmax(0, 1fr) 352px;
    gap: 20px;
  }

  .play-card {
    padding: 14px 14px 15px;
  }

  .play-toolbar {
    gap: 12px;
  }

  .micro-stat:nth-child(1) {
    display: none;
  }

  .coach-card {
    padding: 18px;
  }

  .hint-idle {
    gap: 12px;
  }

  .idle-orbit {
    width: 55px;
    height: 55px;
  }

  .hint-idle__copy h2 {
    font-size: 19px;
  }
}

@media (max-width: 940px) {
  .app {
    width: min(720px, calc(100% - 40px));
  }

  .layout {
    grid-template-columns: 1fr;
    gap: 18px;
    margin-top: 18px;
  }

  .game-heading {
    display: none;
  }

  .play-toolbar__right {
    gap: 7px;
  }

  .play-toolbar__right .game-heading__side {
    gap: 6px;
    padding: 0;
  }

  .play-toolbar__right .timer-chip {
    height: 29px;
    padding: 0 9px;
    font-size: 10px;
  }

  .play-toolbar__right .timer-chip svg {
    width: 12px;
    height: 12px;
  }

  .play-toolbar__right .icon-button {
    width: 28px;
    height: 28px;
  }

  .progress-label {
    display: none;
  }

  .mobile-puzzle-label {
    display: inline-block;
    max-width: 62%;
    overflow: hidden;
    color: var(--ink-soft);
    font-size: 10px;
    font-weight: 650;
    letter-spacing: 0.015em;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .side-area {
    display: grid;
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
    align-items: start;
    gap: 16px;
  }

  .coach-card,
  .notebook-card {
    margin-top: 0;
  }

  .notebook-card {
    min-width: 0;
  }

  #logPanel,
  #manualPanel {
    height: 366px;
  }

  .board {
    width: min(100%, var(--play-width));
  }

  .footer {
    margin-top: 21px;
  }

  .grain {
    opacity: 0.13;
  }
}

@media (max-width: 760px) {
  .app {
    width: calc(100% - 28px);
    padding-top: 10px;
  }

  .topbar {
    align-items: center;
    gap: 10px;
    padding-bottom: 9px;
  }

  .brand {
    gap: 9px;
  }

  .brand-mark {
    width: 29px;
    height: 29px;
    padding: 4px;
    border-radius: 7px;
  }

  .brand-kicker {
    font-size: 6.7px;
    letter-spacing: 0.13em;
  }

  .brand-title {
    font-size: 19px;
  }

  .brand-title em {
    font-size: 13px;
  }

  .topbar-actions {
    gap: 2px;
    margin-top: 0;
  }

  .button {
    min-height: 33px;
    padding: 0 9px;
    font-size: 10.5px;
  }

  .button svg {
    width: 14px;
    height: 14px;
  }

  .button--ghost .button-label {
    display: none;
  }

  .button--ghost {
    width: 33px;
    padding: 0;
    border-radius: 50%;
  }

  .button--dark {
    min-height: 33px;
    padding: 0 11px;
    gap: 5px;
  }

  .button--dark svg {
    display: none;
  }

  .layout {
    margin-top: 12px;
  }

  /* On phones the puzzle identity moves into the progress line and the
     timer/restart controls move beside the hint button. This keeps the
     complete board above the fold instead of spending a whole row on a
     decorative heading. */
  .game-heading {
    display: none;
  }

  .play-toolbar__right {
    gap: 5px;
  }

  .play-toolbar__right .game-heading__side {
    gap: 5px;
    padding: 0;
  }

  .play-toolbar__right .timer-chip {
    height: 27px;
    padding: 0 7px;
    gap: 5px;
    font-size: 10px;
  }

  .play-toolbar__right .timer-chip svg {
    width: 12px;
    height: 12px;
  }

  .play-toolbar__right .icon-button {
    width: 27px;
    height: 27px;
  }

  .progress-label {
    display: none;
  }

  .mobile-puzzle-label {
    display: inline-block;
    max-width: 62%;
    overflow: hidden;
    color: var(--ink-soft);
    font-size: 10px;
    font-weight: 650;
    letter-spacing: 0.015em;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .play-card {
    padding: 12px;
    border-radius: 20px;
  }

  .play-toolbar {
    margin-bottom: 7px;
    gap: 9px;
  }

  .board-key {
    gap: 5px 10px;
    margin: 0 auto 7px;
    font-size: 8.8px;
  }

  .key-cage {
    width: 18px;
  }

  .board-mode {
    min-height: 18px;
    padding: 0 6px;
    font-size: 8.2px;
  }

  .progress-copy {
    margin-bottom: 5px;
    font-size: 9px;
  }

  .progress-copy strong {
    font-size: 9px;
  }

  .play-toolbar__right {
    gap: 7px;
  }

  .micro-stat {
    display: none;
  }

  .hint-peek {
    height: 27px;
    padding: 0 7px;
    font-size: 9.5px;
  }

  .hint-peek kbd {
    display: none;
  }

  .board {
    width: min(100%, var(--play-width), max(220px, calc(100dvh - 170px)));
    border-width: 2px;
  }

  .cell-sum {
    top: 1px;
    left: 2.5px;
    font-size: clamp(8px, 1.8vw, 9px);
  }

  .cell-value {
    font-size: clamp(20px, 5.5vw, 30px);
  }

  .cell-notes {
    inset: 1.5px;
  }

  .cell-note {
    font-size: clamp(6px, 1.65vw, 8px);
  }

  .input-area {
    width: min(100%, var(--play-width), max(220px, calc(100dvh - 170px)));
    margin-top: 12px;
  }

  .number-pad {
    gap: 4px;
  }

  .num-key {
    height: 43px;
    border-radius: 8px;
  }

  .num-key__digit {
    font-size: 20px;
  }

  .num-key__left {
    font-size: 6.5px;
  }

  .input-footer {
    align-items: flex-end;
    gap: 8px;
    margin-top: 8px;
  }

  .mode-switch__button {
    min-height: 24px;
    padding: 0 7px;
    gap: 3px;
    font-size: 9.5px;
  }

  .mode-switch__button svg {
    width: 12px;
    height: 12px;
  }

  .mode-switch__button kbd {
    display: none;
  }

  .input-tools__divider {
    height: 14px;
    margin: 0;
  }

  .tool-button {
    min-height: 28px;
    padding: 0 6px;
    gap: 4px;
    font-size: 9.5px;
  }

  .tool-button kbd {
    display: none;
  }

  .selection-readout {
    flex-basis: 100%;
    max-width: none;
    min-height: 18px;
    font-size: 10px;
    line-height: 1.4;
  }

  .board-note {
    margin-top: 9px;
    font-size: 9px;
  }

  .side-area {
    display: flex;
    flex-direction: column;
    gap: 14px;
  }

  .coach-card {
    padding: 17px;
    border-radius: 21px;
  }

  .hint-idle {
    padding: 18px 1px 17px;
  }

  .notebook-card {
    border-radius: 21px;
  }

  #logPanel,
  #manualPanel {
    height: 305px;
  }

  .notebook-topline {
    padding: 11px 13px 0;
  }

  .log-list {
    padding: 5px 13px 16px;
  }

  #manualPanel {
    padding: 13px;
  }

  .footer {
    display: block;
    margin: 19px 3px 0;
    padding-top: 13px;
    font-size: 8.5px;
  }

  .footer span {
    display: block;
  }

  .footer span + span {
    display: none;
  }

  /* tutorial */
  .tutorial-dialog {
    width: calc(100vw - 20px);
    max-height: calc(100dvh - 20px);
    padding: 17px 17px 15px;
    border-radius: 20px;
  }

  .tutorial-progress {
    margin-top: 12px;
  }

  .tutorial-stage {
    min-height: 0;
    padding: 18px 0 15px;
  }

  .lesson {
    grid-template-columns: 1fr;
    gap: 18px;
  }

  .lesson__visual {
    min-height: 220px;
    padding: 18px;
    order: 2;
  }

  .lesson h2 {
    font-size: 27px;
  }

  .lesson__lead {
    font-size: 11.5px;
    margin-bottom: 12px;
  }

  .lesson-note {
    padding-top: 10px;
    font-size: 9.5px;
  }

  .lesson-board {
    width: 180px;
  }

  .lesson-cell {
    font-size: 21px;
  }

  .lesson-caption {
    bottom: 9px;
    font-size: 8px;
  }

  .lesson-grid-nine {
    width: 205px;
  }

  .cage-lesson-wrap {
    width: 190px;
  }

  .lesson-formula__row {
    font-size: 22px;
  }

  .tutorial-footer {
    padding-top: 11px;
  }

  .tutorial-skip {
    margin-top: 8px;
  }

  .dialog {
    max-height: calc(100dvh - 24px);
  }

  .puzzle-book {
    width: calc(100vw - 20px);
    padding: 18px 16px 20px;
  }

  .puzzle-book__heading h2 {
    font-size: 27px;
    margin-top: 14px;
  }

  .puzzle-book__heading p {
    margin-bottom: 17px;
  }

  .puzzle-option {
    min-height: 55px;
    gap: 9px;
    padding: 8px 9px;
  }

  .puzzle-option__number {
    font-size: 15px;
  }

  .puzzle-option__name {
    font-size: 16px;
  }

  .puzzle-option__meta {
    font-size: 9px;
  }

  .puzzle-option__state {
    font-size: 9px;
  }

  .puzzle-groups {
    gap: 17px;
  }

  .completion-dialog {
    width: calc(100vw - 20px);
  }

  .completion-content {
    padding: 12px 4px 5px;
  }

  .completion-dialog h2 {
    font-size: 30px;
  }

  .completion-actions {
    flex-direction: column-reverse;
  }

  .completion-actions .button {
    width: 100%;
  }
}

@media (max-width: 430px) {
  .brand-copy .brand-kicker {
    display: none;
  }

  .brand-title {
    font-size: 18px;
  }

  .brand-title em {
    display: none;
  }

  .topbar {
    align-items: center;
  }

  .game-heading h1 {
    font-size: 31px;
  }

  .meta-line {
    font-size: 9px;
    gap: 5px;
  }

  .timer-chip svg {
    display: none;
  }

  .game-heading__side {
    gap: 4px;
  }

  .play-toolbar {
    min-height: 30px;
  }

  .progress-wrap {
    min-width: 90px;
  }

  .hint-peek {
    font-size: 0;
    gap: 0;
    width: 29px;
    padding: 0;
    justify-content: center;
  }

  .hint-peek svg {
    width: 14px;
    height: 14px;
  }

  .cell-sum {
    font-size: 8px;
    top: 1px;
    left: 2px;
  }

  .num-key {
    height: 40px;
  }

  .num-key__digit {
    font-size: 18px;
  }

  .num-key__left {
    display: none;
  }

  .tool-button span {
    display: none;
  }

  .tool-button {
    width: 28px;
    justify-content: center;
    padding: 0;
  }

  .tool-button svg {
    width: 15px;
    height: 15px;
  }

  .mode-switch__button {
    padding: 0 7px;
  }

  .mode-switch__button svg {
    display: none;
  }

  .input-tools__divider {
    display: none;
  }

  .input-footer {
    align-items: center;
    flex-wrap: wrap;
    row-gap: 4px;
  }

  .input-tools {
    width: 100%;
    gap: 4px;
  }

  .selection-readout {
    flex-basis: 100%;
    max-width: none;
    min-height: 16px;
    font-size: 9.5px;
    justify-content: flex-start;
  }

  .hint-idle__copy h2 {
    font-size: 18px;
  }

  .hint-idle__copy p {
    font-size: 11.5px;
  }

  .idle-orbit {
    width: 48px;
    height: 48px;
  }

  .idle-orbit span {
    width: 31px;
    height: 31px;
    font-size: 17px;
  }

  .coach-card {
    padding: 15px;
  }

  .hint-result {
    padding-top: 15px;
  }

  .hint-coord {
    font-size: 21px;
  }

  .hint-digit {
    width: 57px;
    height: 64px;
    font-size: 37px;
  }

  .hint-summary {
    font-size: 15px;
  }

  .puzzle-option__state {
    max-width: 67px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

@media (max-width: 360px) {
  .board-key {
    gap: 4px 7px;
    font-size: 8px;
  }

  .board-mode {
    font-size: 8px;
    padding: 0 5px;
  }

  .key-cage {
    width: 15px;
  }

  .key-sum {
    min-width: 16px;
    font-size: 8px;
  }
}

/* Landscape touch layout: the board and shared number pad sit side by side.
   Everything above the coach is kept compact so the whole board and the
   keypad remain visible without scrolling on both phones and tablets. */
@media (orientation: landscape) and (any-pointer: coarse) {
  .app {
    width: min(1240px, calc(100% - 20px));
    padding-top: 7px;
    padding-right: env(safe-area-inset-right);
    padding-bottom: 14px;
    padding-left: env(safe-area-inset-left);
  }

  .topbar {
    gap: 10px;
    padding-bottom: 7px;
  }

  .brand {
    gap: 9px;
  }

  .brand-mark {
    width: 27px;
    height: 27px;
    padding: 4px;
    border-radius: 7px;
  }

  .brand-kicker {
    display: none;
  }

  .brand-title {
    font-size: 18px;
  }

  .brand-title em {
    font-size: 13px;
  }

  .topbar-actions {
    gap: 4px;
    margin-top: 0;
  }

  .button {
    min-height: 30px;
    padding: 0 9px;
    gap: 5px;
    font-size: 10px;
  }

  .button svg {
    width: 14px;
    height: 14px;
  }

  .button--dark {
    min-height: 30px;
    padding: 0 10px;
  }

  .button--dark svg {
    display: none;
  }

  .layout {
    gap: 12px;
    margin-top: 8px;
  }

  .game-heading {
    display: none;
  }

  /* The entrance animation translates the game area. Disable it here so the
     first board measurement uses its final top and can claim every free pixel. */
  .game-area {
    animation: none;
  }

  .play-card {
    padding: 9px 10px 10px;
    border-radius: 18px;
  }

  .play-toolbar {
    min-height: 26px;
    margin-bottom: 6px;
    gap: 8px;
  }

  .progress-wrap {
    max-width: 230px;
    min-width: 90px;
  }

  .progress-copy {
    margin-bottom: 4px;
    font-size: 9px;
  }

  .progress-copy strong {
    font-size: 9px;
  }

  .progress-label {
    display: none;
  }

  .mobile-puzzle-label {
    display: inline-block;
    max-width: 62%;
    overflow: hidden;
    color: var(--ink-soft);
    font-size: 10px;
    font-weight: 650;
    letter-spacing: 0.015em;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .play-toolbar__right {
    gap: 5px;
  }

  .play-toolbar__right .game-heading__side {
    gap: 5px;
    padding: 0;
  }

  .play-toolbar__right .timer-chip {
    height: 27px;
    padding: 0 7px;
    gap: 5px;
    font-size: 10px;
  }

  .play-toolbar__right .timer-chip svg {
    width: 12px;
    height: 12px;
  }

  .play-toolbar__right .icon-button {
    width: 27px;
    height: 27px;
  }

  .micro-stat {
    display: none;
  }

  .hint-peek {
    height: 27px;
    padding: 0 7px;
    font-size: 9.5px;
  }

  .hint-peek kbd {
    display: none;
  }

  .board-key {
    display: none;
  }

  .play-body {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: clamp(10px, 2vw, 18px);
  }

  .board-frame {
    flex: 0 0 auto;
    min-width: 0;
    padding: 0;
  }

  .board {
    width: min(var(--play-width), calc(100dvh - 120px));
    max-width: 100%;
    border-width: 2px;
  }

  /* Cell typography follows the board's height here, not the viewport width:
     the board is deliberately smaller than the screen so the side pad fits. */
  .cell-sum {
    top: 1px;
    left: 2px;
    font-size: clamp(8px, 1.7dvh, 11px);
  }

  .cell-value {
    font-size: clamp(16px, 5.5dvh, 33px);
  }

  .cell-notes {
    inset: 1.5px;
  }

  .cell.has-sum .cell-notes {
    padding-top: clamp(5px, 1.4dvh, 8px);
  }

  .cell-note {
    font-size: clamp(6px, 1.55dvh, 9.5px);
  }

  .input-area {
    --sidepad-width: clamp(106px, 25dvh, 150px);
    flex: 0 0 var(--sidepad-width);
    width: var(--sidepad-width);
    min-width: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

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

  .num-key {
    width: 100%;
    height: auto;
    min-height: 0;
    aspect-ratio: 1;
    border-radius: 9px;
  }

  .num-key__left {
    display: none;
  }

  .num-key__digit {
    font-size: clamp(16px, 4.8dvh, 25px);
  }

  .input-footer {
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    flex-wrap: nowrap;
    gap: 4px;
    margin-top: 0;
  }

  .input-tools {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    gap: 4px;
  }

  .mode-switch {
    grid-column: 1 / -1;
    width: 100%;
  }

  .mode-switch__button {
    flex: 1 1 0;
    min-height: 24px;
    padding: 0 4px;
    gap: 3px;
    font-size: 9.5px;
  }

  .mode-switch__button svg {
    width: 12px;
    height: 12px;
  }

  .mode-switch__button kbd {
    display: none;
  }

  .input-tools__divider {
    display: none;
  }

  .tool-button {
    width: 100%;
    min-height: 26px;
    padding: 0 4px;
    justify-content: center;
    gap: 4px;
    font-size: 9px;
  }

  .tool-button kbd {
    display: none;
  }

  .selection-readout {
    display: none;
  }

  .board-note {
    display: none;
  }

  /* Keep transient feedback out of the board's way. The right edge of a
     landscape screen is always free once the pad sits beside the board. */
  .toast {
    right: 10px;
    bottom: 10px;
    left: auto;
    max-width: min(320px, 34vw);
    text-align: left;
    transform: translateY(12px);
  }

  .toast.is-visible {
    transform: translateY(0);
  }

  /* The tutorial is a one-time dialog, but it must also fit without
     scrolling after the phone has been rotated to landscape. */
  .tutorial-dialog {
    width: min(780px, calc(100vw - 20px));
    max-height: calc(100dvh - 16px);
    padding: 13px 18px 10px;
    border-radius: 18px;
  }

  .tutorial-dialog .dialog-close {
    width: 26px;
    height: 26px;
  }

  .tutorial-progress {
    margin-top: 9px;
    gap: 4px;
  }

  .tutorial-stage {
    min-height: 0;
    padding: 11px 0 9px;
  }

  .lesson {
    grid-template-columns: minmax(0, 1.08fr) minmax(180px, 0.92fr);
    gap: 20px;
  }

  .lesson__eyebrow {
    margin-bottom: 7px;
    font-size: 7.5px;
  }

  .lesson h2 {
    margin-bottom: 8px;
    font-size: clamp(21px, 3vw, 27px);
    line-height: 1.25;
  }

  .lesson__lead {
    margin-bottom: 8px;
    font-size: 10.5px;
    line-height: 1.62;
  }

  .lesson-note {
    padding-top: 8px;
    font-size: 9px;
    line-height: 1.5;
  }

  .lesson__visual {
    min-height: 150px;
    padding: 12px;
    border-radius: 13px;
  }

  .lesson-board {
    width: min(150px, 100%);
  }

  .lesson-cell {
    font-size: 19px;
  }

  .lesson-grid-nine {
    width: min(160px, 100%);
  }

  .cage-lesson-wrap {
    width: min(150px, 100%);
  }

  .cage-lesson-grid .lesson-cell {
    font-size: 22px;
  }

  .lesson-caption {
    bottom: 7px;
    padding: 3px 7px;
    font-size: 7.5px;
  }

  .lesson-formula__row {
    font-size: 19px;
  }

  .lesson-combo-stack {
    gap: 7px;
  }

  .lesson-combo {
    gap: 9px;
    padding: 8px 10px;
  }

  .lesson-combo__sum {
    font-size: 20px;
  }

  .lesson-shortcut {
    gap: 8px;
    padding: 7px 9px;
    font-size: 9px;
  }

  .lesson-shortcut kbd {
    min-width: 22px;
    height: 21px;
  }

  .tutorial-footer {
    padding-top: 8px;
  }

  .tutorial-footer .button {
    min-height: 29px;
  }

  .tutorial-skip {
    margin-top: 5px;
    font-size: 8.5px;
  }
}

@media (orientation: landscape) and (any-pointer: coarse) and (max-height: 460px) {
  .lesson {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .lesson__visual {
    display: none;
  }

  .lesson__lead {
    margin-bottom: 0;
  }

  .lesson-note {
    margin-top: 8px;
  }
}

/* Wide desktop: mirror the clean board-left / keypad-right arrangement
   while keeping the extra cage highlight and learning controls. */
@media (min-width: 1100px) and (orientation: landscape) and (any-pointer: fine) {
  .game-area {
    animation: none;
  }

  .play-body {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 18px;
  }

  .board-frame {
    flex: 0 0 auto;
    min-width: 0;
  }

  .board {
    max-width: 100%;
  }

  .input-area {
    --sidepad-width: clamp(180px, 14vw, 210px);
    flex: 0 0 var(--sidepad-width);
    width: var(--sidepad-width);
    min-width: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

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

  .num-key {
    width: 100%;
    height: auto;
    min-height: 0;
    aspect-ratio: 1;
    border-radius: 12px;
  }

  .num-key__digit {
    font-size: clamp(22px, 1.9vw, 28px);
  }

  .input-footer {
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    flex-wrap: nowrap;
    gap: 8px;
    margin-top: 0;
  }

  .input-tools {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    gap: 6px;
  }

  .mode-switch {
    grid-column: 1 / -1;
    width: 100%;
  }

  .mode-switch__button {
    flex: 1 1 0;
    min-height: 28px;
  }

  .input-tools__divider {
    display: none;
  }

  .tool-button {
    width: 100%;
    padding: 0 6px;
    gap: 4px;
    justify-content: center;
    white-space: nowrap;
  }

  .tool-button kbd {
    display: none;
  }

  .selection-readout {
    display: none;
  }
}

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