:root {
  --paper: #f3eee2;
  --paper-deep: #ebe3d3;
  --ink: #2d2a25;
  --muted: #8d877b;
  --line: #d7cfbd;
  --green: #78945b;
  --green-dark: #5f7947;
  --rose: #b88c78;
  --surface: rgba(247, 242, 231, .82);
  --option-bg: rgba(255,255,255,.25);
  --option-selected: rgba(120, 148, 91, .10);
  --button-text: #fffdf7;
  --shadow: 0 18px 60px rgba(64, 55, 40, 0.10);
}

:root[data-theme="dark"] {
  --paper: #171b18;
  --paper-deep: #20251f;
  --ink: #e8e1d2;
  --muted: #aaa99e;
  --line: #3a4037;
  --green: #9bb779;
  --green-dark: #88a565;
  --rose: #c7977f;
  --surface: rgba(25, 30, 26, .91);
  --option-bg: rgba(239, 231, 213, .035);
  --option-selected: rgba(155, 183, 121, .12);
  --button-text: #162016;
  --shadow: 0 18px 60px rgba(0, 0, 0, .30);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: #ddd8ce;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  min-height: 100svh;
  color: var(--ink);
  background:
    radial-gradient(circle at 88% 8%, rgba(120, 148, 91, .10), transparent 31%),
    radial-gradient(circle at 4% 72%, rgba(184, 140, 120, .08), transparent 34%),
    var(--paper);
  font-family: "Songti SC", "STSong", "Noto Serif SC", "Times New Roman", serif;
  -webkit-font-smoothing: antialiased;
}

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

.test-shell {
  width: min(100%, 680px);
  min-height: 100vh;
  min-height: 100svh;
  margin: 0 auto;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.intro-panel,
.question-panel,
.verify-panel {
  min-height: 100vh;
  min-height: 100svh;
  padding: max(28px, env(safe-area-inset-top)) 24px max(28px, env(safe-area-inset-bottom));
}

.intro-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  border-top: 7px solid var(--green);
}

.edition-line {
  position: absolute;
  top: max(25px, env(safe-area-inset-top));
  left: 24px;
  right: 24px;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 11px;
  letter-spacing: .16em;
}

.overline,
.scene-label {
  margin: 0 0 22px;
  color: var(--green-dark);
  font-size: 13px;
  letter-spacing: .28em;
}

.intro-panel h1 {
  margin: 0;
  font-size: clamp(34px, 10vw, 54px);
  font-weight: 600;
  line-height: 1.48;
  letter-spacing: .08em;
}

.ornament {
  margin: 30px 0 28px;
  color: var(--green);
  letter-spacing: .5em;
}

.intro-copy {
  margin: 0;
  color: #59554d;
  font-size: 16px;
  line-height: 2.08;
  letter-spacing: .04em;
}

.test-note {
  display: flex;
  justify-content: center;
  gap: 0;
  margin: 32px 0;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: .08em;
}

.test-note span { padding: 0 11px; }
.test-note span + span { border-left: 1px solid var(--line); }

.primary-button {
  display: block;
  width: 100%;
  min-height: 54px;
  border: 0;
  border-radius: 2px;
  color: var(--button-text);
  background: var(--green-dark);
  box-shadow: 0 9px 24px rgba(95, 121, 71, .20);
  font: inherit;
  font-size: 15px;
  letter-spacing: .14em;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.primary-button:active { transform: translateY(1px); }
.primary-button:disabled { opacity: .35; box-shadow: none; cursor: default; }

.fine-print {
  margin: 16px 0 0;
  color: #aaa294;
  font-size: 11px;
  letter-spacing: .08em;
}

.local-record {
  width: 100%;
  margin-top: 22px;
  padding: 16px 0 2px;
  border-top: 1px solid var(--line);
}

.local-record-label {
  margin: 0 0 9px;
  color: var(--rose);
  font-size: 10px;
  letter-spacing: .18em;
}

.local-action {
  display: block;
  width: 100%;
  min-height: 40px;
  margin-top: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 2px;
  color: var(--ink);
  background: var(--option-bg);
  font: inherit;
  font-size: 12px;
  letter-spacing: .08em;
  line-height: 1.5;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.entertainment-note {
  margin: 21px 4px 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.75;
  letter-spacing: .035em;
}

.question-panel {
  display: flex;
  flex-direction: column;
}

.progress-header {
  position: relative;
  padding: 2px 0 17px;
}

.back-button {
  position: absolute;
  left: 0;
  top: -8px;
  width: auto;
  height: 42px;
  padding: 0 6px 0 0;
  border: 0;
  color: var(--green-dark);
  background: transparent;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .08em;
  cursor: pointer;
}

.theme-toggle {
  position: absolute;
  right: 0;
  top: -8px;
  height: 42px;
  padding: 0 0 0 8px;
  border: 0;
  color: var(--muted);
  background: transparent;
  font: inherit;
  font-size: 11px;
  letter-spacing: .06em;
  cursor: pointer;
}

.progress-meta {
  display: flex;
  justify-content: center;
  gap: 14px;
  padding: 0 82px;
  color: var(--muted);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 11px;
  letter-spacing: .12em;
}

.progress-track {
  height: 2px;
  margin-top: 14px;
  overflow: hidden;
  background: var(--line);
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--green);
  transition: width .35s ease;
}

.chapter-card {
  margin: 26px 0 8px;
  padding: 14px 16px;
  border-left: 3px solid var(--rose);
  color: var(--rose);
  background: rgba(255,255,255,.23);
  font-size: 12px;
  letter-spacing: .23em;
}

.question-content {
  flex: 1;
  padding-top: clamp(46px, 10vh, 88px);
}

.chapter-card:not([hidden]) + .question-content { padding-top: 30px; }

.scene-label {
  margin-bottom: 19px;
  color: var(--rose);
  font-size: 12px;
}

.question-content h2 {
  margin: 0 0 34px;
  font-size: clamp(22px, 6.2vw, 28px);
  font-weight: 500;
  line-height: 1.75;
  letter-spacing: .035em;
}

.options {
  display: grid;
  gap: 13px;
}

.option-button {
  position: relative;
  width: 100%;
  min-height: 68px;
  padding: 16px 18px 16px 50px;
  border: 1px solid var(--line);
  border-radius: 2px;
  color: var(--ink);
  background: var(--option-bg);
  font: inherit;
  font-size: 14px;
  line-height: 1.65;
  letter-spacing: .025em;
  text-align: left;
  cursor: pointer;
  transition: border-color .18s ease, background .18s ease, transform .18s ease;
}

.option-button::before {
  content: attr(data-letter);
  position: absolute;
  left: 17px;
  top: 18px;
  color: var(--green);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 14px;
  font-style: italic;
}

.option-button.selected {
  border-color: var(--green);
  background: var(--option-selected);
  box-shadow: inset 3px 0 0 var(--green);
  transform: translateX(2px);
}

.verify-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  border-top: 7px solid var(--green);
}

.verify-index {
  position: absolute;
  top: max(25px, env(safe-area-inset-top));
  left: 24px;
  right: 24px;
  display: flex;
  justify-content: space-between;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 10px;
  letter-spacing: .15em;
}

.verify-sigil {
  margin: 7px 0 27px;
  color: var(--green);
  font-size: 22px;
}

.verify-panel h2 {
  margin: 0;
  font-size: clamp(28px, 8vw, 42px);
  font-weight: 500;
  line-height: 1.55;
  letter-spacing: .08em;
}

.verify-copy {
  margin: 25px 0 34px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.9;
  letter-spacing: .03em;
}

.code-label {
  margin-bottom: 11px;
  color: var(--rose);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 10px;
  letter-spacing: .22em;
}

.code-input {
  width: min(100%, 270px);
  height: 66px;
  padding: 0 12px 0 25px;
  border: 1px solid var(--line);
  border-radius: 2px;
  outline: none;
  color: var(--ink);
  background: var(--option-bg);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 28px;
  letter-spacing: .48em;
  text-align: center;
  transition: border-color .2s ease, box-shadow .2s ease;
}

.code-input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px var(--option-selected);
}

.code-input.invalid {
  border-color: var(--rose);
  animation: code-shake .22s linear 2;
}

.code-input.valid {
  border-color: var(--green);
}

.code-message {
  min-height: 20px;
  margin: 11px 0 8px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .08em;
}

.code-message.error { color: var(--rose); }
.code-message.success { color: var(--green); }

.verify-button {
  width: min(100%, 270px);
  min-height: 50px;
  margin-top: 3px;
}

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

.text-button {
  margin-top: 18px;
  border: 0;
  color: var(--muted);
  background: transparent;
  font: inherit;
  font-size: 12px;
  letter-spacing: .12em;
  text-decoration: underline;
  text-underline-offset: 4px;
  cursor: pointer;
}

[hidden] { display: none !important; }

@media (min-width: 681px) {
  body { padding: 28px 0; }
  .test-shell,
  .intro-panel,
  .question-panel,
  .verify-panel { min-height: calc(100vh - 56px); }
  .intro-panel,
  .question-panel,
  .verify-panel { padding-left: 58px; padding-right: 58px; }
  .edition-line { left: calc(50% - 282px); right: calc(50% - 282px); top: 58px; }
}

@media (max-height: 720px) {
  .question-content { padding-top: 26px; }
  .question-content h2 { margin-bottom: 22px; font-size: 20px; }
  .options { gap: 9px; }
  .option-button { min-height: 58px; padding-top: 12px; padding-bottom: 12px; }
  .option-button::before { top: 14px; }
}

:root[data-theme="dark"] .intro-copy { color: #c9c3b7; }
:root[data-theme="dark"] .fine-print { color: #777e75; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
