:root {
  --bg: #f4efe6; --card: #fffdf9; --ink: #2a2420; --muted: #7b6f65; --line: #e4dbcf;
  --accent: #b4532a; --accent-soft: #f6e4d9;
  --serif: "Noto Serif SC", "Songti SC", serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1b1816; --card: #24201d; --ink: #efe7dd; --muted: #a8998b; --line: #3a332e; --accent: #e08a5f; --accent-soft: #3d2a20; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 17px/1.7 var(--sans); }

.bar { position: fixed; inset: 0 0 auto; height: 3px; background: var(--line); z-index: 2; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .5s ease; }
.lang { position: fixed; top: 14px; right: 16px; z-index: 2; background: var(--card); color: var(--ink); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 14px; font: 500 14px var(--sans); cursor: pointer; }

.stage { display: grid; min-height: 100vh; padding: 64px 16px 40px; overflow-x: hidden; }
.card { grid-area: 1 / 1; width: 100%; max-width: 640px; margin: 0 auto; align-self: start;
  background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 40px 36px 28px;
  box-shadow: 0 1px 2px rgb(0 0 0 / .04), 0 12px 32px -16px rgb(60 40 20 / .18); }
@media (max-width: 520px) { .card { padding: 28px 20px 20px; border-radius: 16px; } }

.in-r { animation: inR .5s cubic-bezier(.2, .7, .2, 1) both; }
.in-l { animation: inL .5s cubic-bezier(.2, .7, .2, 1) both; }
.out-l { animation: outL .35s ease-in both; }
.out-r { animation: outR .35s ease-in both; }
.out { pointer-events: none; }
@keyframes inR { from { transform: translateX(80px); opacity: 0; } }
@keyframes inL { from { transform: translateX(-80px); opacity: 0; } }
@keyframes outL { to { transform: translateX(-80px); opacity: 0; } }
@keyframes outR { to { transform: translateX(80px); opacity: 0; } }
/* keep a tiny duration so animationend still fires and removes the old card */
@media (prefers-reduced-motion: reduce) { .card { animation-duration: 1ms !important; } }

.sec { margin: 0 0 6px; color: var(--muted); font-size: 14px; letter-spacing: .04em; }
.no { margin: 0; color: var(--accent); font-size: 13px; font-weight: 600; letter-spacing: .12em; }
.no b { font: 700 28px/1 var(--serif); margin-right: 10px; letter-spacing: 0; }
h1, h2 { font-family: var(--serif); font-weight: 700; line-height: 1.3; margin: 8px 0 18px; outline: none; }
h1 { font-size: 34px; } h2 { font-size: 28px; }
h3 { font: 700 18px var(--serif); margin: 28px 0 8px; padding-top: 16px; border-top: 1px solid var(--line); }
.prompt { margin: 0 0 8px; font-size: 18px; }
.hint { display: block; color: var(--muted); font-size: 14px; margin: 2px 0 8px; }
.toc { margin: 20px 0; padding-left: 22px; color: var(--muted); }

.f { display: block; border: 0; padding: 0; margin: 22px 0 0; min-width: 0; }
.lab { display: block; font-weight: 600; margin-bottom: 6px; padding: 0; }
textarea, input[type=text], input[type=number], input[type=date] {
  width: 100%; font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; transition: border-color .2s, box-shadow .2s; }
textarea { resize: vertical; min-height: 110px; }
textarea:focus, input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.calc { margin: 16px 0 0; padding: 12px 14px; background: var(--accent-soft); border-radius: 12px; }
.calc b { font: 700 22px var(--serif); color: var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips label { position: relative; cursor: pointer; }
.chips input { position: absolute; opacity: 0; inset: 0; }
.chips span { display: block; padding: 6px 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg); transition: all .15s; }
.chips.scale { gap: 6px; }
.chips.scale span { width: 40px; padding: 6px 0; text-align: center; }
@media (max-width: 520px) { .chips.scale { gap: 4px; } .chips.scale span { width: 30px; font-size: 15px; } }
.chips input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.chips input:focus-visible + span { box-shadow: 0 0 0 3px var(--accent-soft); }

nav { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 32px; flex-wrap: wrap; }
nav .row { display: flex; gap: 8px; flex-wrap: wrap; }
button { font: 600 16px var(--sans); border-radius: 999px; padding: 10px 22px; cursor: pointer;
  background: var(--accent); color: #fff; border: 1px solid var(--accent); transition: transform .15s, opacity .15s; }
button:hover { transform: translateY(-1px); }
button:focus-visible { outline: 3px solid var(--accent-soft); outline-offset: 2px; }
button.ghost { background: transparent; color: var(--muted); border-color: var(--line); }

.ai { margin-top: 24px; padding: 4px 20px 20px; background: var(--accent-soft); border-radius: 16px; }
.ai h3 { border-top: 0; padding-top: 0; margin-top: 16px; }
.ai-out { white-space: pre-wrap; margin: 0 0 16px; }
button:disabled { opacity: .6; cursor: wait; transform: none; }
.sum dl { margin: 0; }
.sum dt { color: var(--muted); font-size: 14px; margin-top: 10px; }
.sum dd { margin: 2px 0 0; white-space: pre-wrap; }

@media print {
  /* dark-mode visitors still get a light, readable printout */
  :root { --bg: #fff; --card: #fff; --ink: #000; --muted: #6b6058; --line: #ddd; --accent: #b4532a; --accent-soft: #f6e4d9; }
  body { background: #fff; color: #000; }
  .bar, .lang, nav, .card.out, .ai button { display: none !important; }
  .ai { background: none; padding: 0; }
  .stage { padding: 0; min-height: 0; display: block; }
  .card { border: 0; box-shadow: none; max-width: none; padding: 0; animation: none !important; }
  h3, .sum dt { break-after: avoid; }
  .sum dd { break-inside: avoid; }
}
