:root {
  --ink: #18304a;
  --ink-soft: #486074;
  --paper: #f7f3e9;
  --card: #fffdf8;
  --line: #dfd6c5;
  --blue: #245c7c;
  --teal: #1d8a7d;
  --teal-pale: #e5f4ef;
  --orange: #e68342;
  --orange-pale: #fff1df;
  --berry: #b94e54;
  --shadow: 0 17px 40px rgba(25, 48, 74, 0.1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background-color: var(--paper);
  background-image: radial-gradient(circle at 16% 3%, rgba(253, 206, 126, 0.2), transparent 23rem), radial-gradient(circle at 93% 12%, rgba(75, 173, 161, 0.14), transparent 26rem);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(230, 131, 66, 0.45); outline-offset: 2px; }

.app-shell { max-width: 1400px; margin: 0 auto; padding: 38px 26px 52px; }
.page-header { display: flex; justify-content: space-between; gap: 24px; align-items: start; margin-bottom: 22px; }
.kicker { margin: 0 0 5px; color: var(--teal); font-size: 0.7rem; letter-spacing: 0.15em; font-weight: 800; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-family: Georgia, "Songti SC", serif; font-size: clamp(2rem, 4vw, 3.15rem); letter-spacing: 0.025em; }
h2 { margin: 0; font-size: 1.38rem; }
h3 { margin: 0; font-size: 1rem; }
.page-intro { color: var(--ink-soft); margin-bottom: 0; }
.rules-chip { color: #8c4a18; background: rgba(255, 241, 223, 0.76); border: 1px solid #f2cfaa; border-radius: 999px; padding: 9px 13px; font-size: 0.84rem; white-space: nowrap; }

.settings-card, .game-card, .math-panel { background: rgba(255, 253, 248, 0.9); border: 1px solid var(--line); box-shadow: var(--shadow); }
.settings-card { display: flex; align-items: center; flex-wrap: wrap; gap: 13px 18px; border-radius: 17px; padding: 15px 18px; margin-bottom: 19px; }
.settings-title { display: flex; align-items: center; gap: 9px; margin-right: 4px; }
.settings-title small { display: block; margin-top: 2px; color: var(--ink-soft); font-size: 0.73rem; }
.section-index { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; color: white; background: var(--ink); font-size: 0.7rem; font-weight: 700; }
.settings-card label, .move-inputs label { display: flex; align-items: center; gap: 7px; color: var(--ink-soft); font-size: 0.84rem; white-space: nowrap; }
input[type="number"], select { min-width: 72px; padding: 7px 9px; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 8px; }
select { min-width: 116px; }
.primary-button { padding: 10px 14px; color: white; background: var(--ink); border: 1px solid var(--ink); border-radius: 8px; font-weight: 800; transition: transform 160ms ease, background 160ms ease; }
.primary-button:hover:not(:disabled) { background: var(--blue); transform: translateY(-1px); }
.primary-button:disabled { cursor: not-allowed; opacity: 0.5; }

.switch-label { margin-left: auto; color: var(--teal) !important; font-weight: 800; }
.switch-label input { position: absolute; opacity: 0; }
.switch-track { width: 35px; height: 20px; border-radius: 99px; background: #aebdc3; position: relative; transition: background 180ms ease; }
.switch-track::after { content: ""; position: absolute; width: 14px; height: 14px; left: 3px; top: 3px; border-radius: 50%; background: white; transition: transform 180ms ease; }
.switch-label input:checked + .switch-track { background: var(--teal); }
.switch-label input:checked + .switch-track::after { transform: translateX(15px); }

.main-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 19px; align-items: start; }
.main-layout.with-math { grid-template-columns: minmax(520px, 1fr) minmax(365px, 0.72fr); }
.game-card, .math-panel { border-radius: 18px; }
.game-card { padding: 23px; }
.card-heading, .math-header { display: flex; justify-content: space-between; align-items: start; gap: 14px; }
.turn-badge { padding: 8px 11px; color: #11685f; background: var(--teal-pale); border: 1px solid #c8e6de; border-radius: 999px; font-size: 0.82rem; font-weight: 800; }
.turn-badge.ai { color: #8d4618; background: var(--orange-pale); border-color: #f5d1ae; }
.turn-badge.over { color: #753d42; background: #f9e6e6; border-color: #efc4c6; }
.rule-strip { display: flex; align-items: center; gap: 8px; margin: 20px 0 17px; padding: 10px 12px; color: #5a6b76; background: #f5f1e8; border-left: 4px solid var(--orange); font-size: 0.88rem; }
.rule-symbol { font-size: 1.25rem; color: var(--orange); }

.piles { display: grid; grid-template-columns: 1fr 1fr; gap: 17px; }
.pile { min-height: 276px; overflow: hidden; padding: 15px; border: 1px solid #d8e4e2; border-radius: 14px; background: linear-gradient(180deg, #f9fdfc, #ecf7f4); }
.pile-b { border-color: #eadac8; background: linear-gradient(180deg, #fffcf7, #fff3e5); }
.pile-topline { display: flex; justify-content: space-between; align-items: center; }
.pile-count { display: grid; place-items: center; min-width: 37px; height: 29px; padding: 0 8px; color: white; border-radius: 99px; background: var(--teal); font-weight: 800; }
.pile-b .pile-count { background: var(--orange); }
.stones { display: flex; flex-wrap: wrap-reverse; align-content: end; justify-content: center; gap: 7px; min-height: 220px; padding: 22px 3px 4px; }
.stone { flex: 0 0 auto; width: 29px; height: 29px; border: 0; border-radius: 50%; background: radial-gradient(circle at 33% 29%, #e5fbf5 0 9%, #55b8ac 11% 44%, #1d857b 47%); box-shadow: inset -4px -5px 0 rgba(10, 92, 83, 0.22), 0 3px 4px rgba(19, 70, 69, 0.16); transition: transform 130ms ease; }
.pile-b .stone { background: radial-gradient(circle at 33% 29%, #fff5d8 0 9%, #f5b266 11% 44%, #e17b32 47%); box-shadow: inset -4px -5px 0 rgba(152, 69, 17, 0.2), 0 3px 4px rgba(135, 67, 23, 0.16); }
.stone:hover:not(:disabled) { transform: translateY(-3px) scale(1.06); }
.stone:disabled { cursor: default; opacity: 0.55; }

.move-card { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px 20px; margin-top: 17px; padding: 16px; border: 1px dashed #d4c3a9; border-radius: 13px; background: #fffcf6; }
.move-card h3 { font-size: 1rem; }
.move-inputs { display: flex; align-items: center; flex-wrap: wrap; gap: 9px; }
.move-inputs input { width: 59px; min-width: 0; }
.move-help { flex-basis: 100%; margin: 0; color: var(--ink-soft); font-size: 0.8rem; }
.move-help.error { color: var(--berry); font-weight: 700; }

.history-section { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 16px; }
.history-heading { display: flex; align-items: baseline; gap: 10px; }
.history-list { display: grid; gap: 8px; max-height: 210px; margin: 12px 0 0; padding: 0; overflow: auto; list-style: none; }
.history-list li { display: flex; align-items: start; gap: 8px; padding: 9px 10px; border-radius: 9px; background: #f7f5ef; }
.history-marker { display: block; width: 9px; height: 9px; margin-top: 5px; border-radius: 50%; background: var(--teal); }
.history-list li.ai .history-marker { background: var(--orange); }
.history-list strong { font-size: 0.88rem; }
.history-list p { margin: 2px 0 0; color: var(--ink-soft); font-size: 0.77rem; }
.history-empty { color: var(--ink-soft); font-size: 0.85rem; }

.math-panel { padding: 20px; background: #fbfaf5; }
.icon-button { display: grid; place-items: center; width: 31px; height: 31px; padding: 0; color: var(--ink-soft); background: transparent; border: 1px solid var(--line); border-radius: 50%; font-size: 1.4rem; line-height: 1; }
.discovery-tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; margin: 18px 0; padding-bottom: 9px; border-bottom: 1px solid var(--line); }
.tab-button { padding: 7px 2px; color: var(--ink-soft); background: transparent; border: 0; border-bottom: 3px solid transparent; font-size: 0.79rem; font-weight: 800; }
.tab-button.active { color: var(--teal); border-bottom-color: var(--teal); }
.prompt-card, .question-card, .derivation-card, .proof-summary { padding: 13px; border-radius: 10px; }
.prompt-card { border: 1px solid #f2d7b7; background: var(--orange-pale); }
.prompt-card span, .question-card strong { color: #a75a20; font-size: 0.72rem; letter-spacing: 0.08em; font-weight: 900; }
.prompt-card p, .question-card p, .derivation-card p { margin: 4px 0 0; line-height: 1.62; font-size: 0.86rem; }
.graph-title { display: flex; justify-content: space-between; gap: 10px; margin: 17px 0 6px; font-size: 0.78rem; }
.graph-title span { color: var(--ink-soft); font-size: 0.69rem; }
.coordinate-graph { display: block; width: 100%; padding: 7px; border: 1px solid var(--line); border-radius: 11px; background: #fffefa; }
.math-note { margin: 10px 0 0; color: var(--ink-soft); font-size: 0.79rem; line-height: 1.65; }
.exploration-board { margin: 14px 0; padding: 11px; border: 1px solid #cde4df; border-radius: 11px; background: #f4faf8; }
.exploration-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.exploration-heading strong { color: #17685f; font-size: 0.88rem; }
.exploration-heading span { display: block; margin-top: 2px; color: var(--ink-soft); font-size: 0.7rem; }
.secondary-button { padding: 6px 8px; color: #17685f; background: #fff; border: 1px solid #a9d6ce; border-radius: 7px; font-size: 0.73rem; font-weight: 800; white-space: nowrap; }
.secondary-button:hover { background: var(--teal-pale); }
.exploration-graph { margin-top: 10px; cursor: crosshair; }
.sieve-steps { display: grid; gap: 8px; margin: 13px 0; }
.sieve-step { display: grid; grid-template-columns: 25px 1fr; gap: 9px; align-items: center; padding: 9px; border-radius: 9px; background: #f4f8f7; font-size: 0.79rem; line-height: 1.45; }
.sieve-step .step-number { display: grid; place-items: center; width: 24px; height: 24px; color: white; background: var(--teal); border-radius: 50%; font-size: 0.7rem; font-weight: 900; }
.sieve-step b { color: #17685f; }
.difference-table, .ratio-table { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; margin: 13px 0; }
.derivation-pair-table { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 12px 0; }
.derivation-pair { padding: 7px 4px; color: #17685f; text-align: center; background: #eef7f4; border-radius: 7px; font-size: 0.75rem; font-weight: 800; }
.data-chip { padding: 8px 5px; text-align: center; background: #eef7f4; border-radius: 8px; font-size: 0.73rem; }
.data-chip b { display: block; color: var(--teal); margin-top: 3px; font-size: 0.88rem; }
.question-card { margin-top: 13px; background: #f0f5f6; border-left: 4px solid var(--blue); }
.complement-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 13px; }
.complement-grid div { padding: 10px; border-radius: 8px; background: var(--teal-pale); }
.complement-grid div + div { background: var(--orange-pale); }
.complement-grid span { color: #17685f; font-size: 0.72rem; font-weight: 900; }
.complement-grid div + div span { color: #a75a20; }
.complement-grid p { margin: 5px 0 0; line-height: 1.55; font-size: 0.79rem; }
.derivation-card { margin-top: 13px; background: #f3f6f8; }
.formula, .formula-stack { margin: 10px 0; padding: 10px 12px; color: #f9eacb; background: #20394d; border-radius: 8px; font-family: Consolas, "Courier New", monospace; font-size: 0.9rem; line-height: 1.7; }
.formula-stack div + div { border-top: 1px solid rgba(255, 255, 255, 0.2); }
.proof-summary { margin-top: 13px; color: #155e57; background: var(--teal-pale); border: 1px solid #cbe8e1; font-size: 0.86rem; line-height: 1.65; }
.beatty-proof { display: grid; gap: 1px; margin: 12px 0; overflow: hidden; border: 1px solid #d7e3df; border-radius: 10px; }
.beatty-proof p { margin: 0; padding: 10px 11px; background: #f4faf8; font-size: 0.81rem; line-height: 1.6; }
.inline-formula { padding: 2px 4px; color: #f9eacb; background: #20394d; border-radius: 4px; font-family: Consolas, "Courier New", monospace; font-size: 0.76rem; }

@media (max-width: 1050px) { .main-layout.with-math { grid-template-columns: minmax(0, 1fr); } .math-panel { max-width: 760px; } }
@media (max-width: 720px) { .app-shell { padding: 25px 14px 38px; } .page-header { display: block; } .rules-chip { display: inline-block; margin-top: 13px; } .settings-card { align-items: start; display: grid; grid-template-columns: 1fr 1fr; } .settings-title, .settings-card .primary-button, .switch-label { grid-column: 1 / -1; } .switch-label { margin-left: 0; } .game-card, .math-panel { padding: 16px; } .piles { gap: 10px; } .pile { min-height: 230px; padding: 11px; } .stones { min-height: 175px; gap: 5px; padding-top: 15px; } .stone { width: 24px; height: 24px; } .move-card { display: block; } .move-inputs { margin-top: 13px; } .card-heading { align-items: center; } }
@media (max-width: 420px) { .settings-card { grid-template-columns: 1fr; } .piles { grid-template-columns: 1fr; } .pile { min-height: 156px; } .stones { min-height: 100px; } .turn-badge { font-size: 0.72rem; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.001ms !important; } }
