:root {
  --ink: #16120e;
  --paper: #f4efe6;
  --paper-deep: #e9dfd1;
  --gold: #8a641e;
  --cinnabar: #9e3f2d;
  --jade: #3f6f62;
  --muted: #71685e;
  --line: rgba(66, 50, 33, 0.18);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: 'Noto Serif SC', 'Source Han Serif SC', 'Microsoft YaHei', sans-serif;
  line-height: 1.85;
}
a { color: inherit; }
button, input { font: inherit; }
select { font: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.site-header {
  position: sticky;
  z-index: 20;
  top: 0;
  min-height: 60px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: rgba(244, 239, 230, 0.94);
  backdrop-filter: blur(16px);
}

.site-header-inner {
  width: min(1120px, calc(100% - 32px));
  margin: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
}

.brand { text-decoration: none; font-size: 18px; font-weight: 700; }
.brand span { margin-left: 8px; color: var(--muted); font-size: 12px; font-weight: 400; }
.site-nav { display: flex; align-items: center; gap: 20px; }
.site-nav a { color: var(--muted); text-decoration: none; font-size: 13px; }
.site-nav a:hover { color: var(--cinnabar); }
.nav-primary {
  padding: 7px 12px;
  color: #fff !important;
  background: var(--cinnabar);
  border-radius: 4px;
}

.page-hero {
  min-height: 330px;
  display: flex;
  align-items: end;
  color: #f7eddf;
  background:
    linear-gradient(rgba(15, 11, 8, 0.2), rgba(15, 11, 8, 0.78)),
    radial-gradient(circle at 72% 30%, var(--accent, #8a641e), transparent 38%),
    #18130f;
  border-bottom: 4px solid var(--accent, var(--gold));
}

.page-hero-inner {
  width: min(900px, calc(100% - 32px));
  margin: 0 auto;
  padding: 58px 0 48px;
}

.eyebrow { margin-bottom: 12px; color: #d8bd88; font-size: 12px; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 14px; font-size: clamp(38px, 6vw, 72px); line-height: 1.18; font-weight: 500; }
.page-lead { max-width: 720px; margin-bottom: 0; color: rgba(247, 237, 223, 0.8); font-size: 16px; }

.container { width: min(900px, calc(100% - 32px)); margin: auto; }
.content-layout { padding: 50px 0 80px; }
.story-meta { display: flex; flex-wrap: wrap; gap: 10px 22px; margin-bottom: 36px; color: var(--muted); font-size: 13px; }
.story-copy { font-size: 18px; line-height: 2; }
.story-copy p { margin-bottom: 1.3em; }
.story-quote {
  margin: 36px 0;
  padding: 22px 26px;
  border-left: 4px solid var(--accent, var(--gold));
  background: rgba(255, 255, 255, 0.54);
  font-size: 20px;
}
.quote-from { margin-top: 8px; color: var(--muted); font-size: 13px; text-align: right; }

.source-status {
  margin-top: 42px;
  padding: 22px 24px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.34);
}
.source-status h2 { margin-bottom: 8px; font-size: 16px; }
.source-status p { margin-bottom: 0; color: var(--muted); font-size: 14px; }

.actions { margin: 34px 0; display: flex; flex-wrap: wrap; gap: 10px; }
.button {
  min-height: 42px;
  padding: 9px 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  background: transparent;
  border: 1px solid rgba(66, 50, 33, 0.28);
  border-radius: 4px;
  text-decoration: none;
  cursor: pointer;
}
.button.primary { color: #fff; background: var(--cinnabar); border-color: var(--cinnabar); }
.button:hover { border-color: var(--cinnabar); }

.related { margin-top: 42px; padding-top: 28px; border-top: 1px solid var(--line); }
.related h2 { font-size: 20px; }
.tag-list { display: flex; flex-wrap: wrap; gap: 9px; }
.tag { padding: 6px 12px; color: var(--jade); border: 1px solid rgba(63, 111, 98, 0.28); border-radius: 4px; text-decoration: none; font-size: 13px; }

.section { padding: 52px 0; border-bottom: 1px solid var(--line); }
.section:last-child { border-bottom: 0; }
.section h2 { margin-bottom: 12px; font-size: 27px; font-weight: 500; }
.section-intro { max-width: 700px; color: var(--muted); }
.stat-line { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.stat { padding: 24px 18px; border-right: 1px solid var(--line); }
.stat:last-child { border-right: 0; }
.stat strong { display: block; color: var(--cinnabar); font-size: 29px; font-weight: 500; }
.stat span { color: var(--muted); font-size: 12px; }

.story-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); }
.story-item { min-height: 150px; padding: 20px; display: block; background: var(--paper); text-decoration: none; }
.story-item:hover { background: #fffaf1; }
.story-item h2, .story-item h3 { margin-bottom: 6px; font-size: 18px; }
.story-item p { margin-bottom: 0; color: var(--muted); font-size: 12px; line-height: 1.65; }
.story-item .item-era { margin-bottom: 10px; color: var(--cinnabar); }

.story-filters {
  margin-bottom: 18px;
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 150px 140px auto;
  gap: 8px;
}
.story-filters input,
.story-filters select,
.filter-clear {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.48);
  border: 1px solid var(--line);
  border-radius: 4px;
}
.story-filters input:focus,
.story-filters select:focus { outline: 2px solid rgba(158, 63, 45, 0.35); outline-offset: 1px; }
.filter-clear { width: auto; cursor: pointer; white-space: nowrap; }
.filter-clear:hover { color: var(--cinnabar); border-color: var(--cinnabar); }
.story-results-head { margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; gap: 16px; color: var(--muted); font-size: 12px; }
.story-results-head a { color: var(--jade); text-decoration: none; }
.story-empty { padding: 54px 20px; color: var(--muted); border: 1px solid var(--line); text-align: center; }
.dynasty-index { margin: 30px 0 0; padding-top: 24px; border-top: 1px solid var(--line); }

.dynasty-filter { margin-bottom: 26px; display: flex; flex-wrap: wrap; gap: 8px; }
.dynasty-filter a { padding: 5px 10px; color: var(--muted); border: 1px solid var(--line); border-radius: 3px; text-decoration: none; font-size: 12px; }
.dynasty-filter a:hover { color: var(--cinnabar); border-color: var(--cinnabar); }

.route-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
}
.route-card {
  min-height: 280px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  background: var(--paper);
}
.route-card:hover { background: #fffaf1; }
.route-card h2 { margin-bottom: 10px; font-size: 24px; font-weight: 500; }
.route-card p { color: var(--muted); font-size: 14px; line-height: 1.75; }
.route-meta { margin-bottom: 16px; display: flex; flex-wrap: wrap; gap: 7px 14px; color: var(--cinnabar); font-size: 12px; }
.route-question { margin-top: auto; padding-top: 18px; border-top: 1px solid var(--line); font-size: 14px; }
.route-card .actions { margin: 18px 0 0; }
.progress-row { margin-top: 18px; display: flex; align-items: center; gap: 12px; }
.progress-track { flex: 1; height: 5px; overflow: hidden; background: var(--paper-deep); border-radius: 3px; }
.progress-fill { width: 0; height: 100%; background: var(--accent, var(--cinnabar)); transition: width 0.3s; }
.progress-value { min-width: 42px; color: var(--muted); font-size: 12px; text-align: right; }

.route-detail-head { padding: 34px 0; border-bottom: 1px solid var(--line); }
.route-detail-head .actions { margin-bottom: 0; }
.route-steps { position: relative; padding: 12px 0 12px 38px; }
.route-steps::before { content: ''; position: absolute; top: 28px; bottom: 28px; left: 13px; width: 1px; background: var(--line); }
.route-step { position: relative; padding: 22px 0; border-bottom: 1px solid var(--line); }
.route-step:last-child { border-bottom: 0; }
.route-step::before { content: ''; position: absolute; top: 31px; left: -30px; width: 10px; height: 10px; background: var(--paper); border: 2px solid var(--muted); border-radius: 50%; }
.route-step.complete::before { background: var(--jade); border-color: var(--jade); }
.route-step-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.route-step-index { color: var(--cinnabar); font-size: 12px; }
.route-step h2 { margin: 3px 0 6px; font-size: 24px; font-weight: 500; }
.route-step p { margin-bottom: 0; color: var(--muted); }
.step-status { padding: 3px 8px; color: var(--muted); border: 1px solid var(--line); border-radius: 3px; font-size: 11px; white-space: nowrap; }
.route-step.complete .step-status { color: var(--jade); border-color: rgba(63,111,98,0.35); }

.quiz-section { padding: 46px 0 70px; border-top: 1px solid var(--line); }
.quiz-section h2 { margin-bottom: 8px; font-size: 28px; font-weight: 500; }
.quiz-intro { color: var(--muted); }
.quiz-question { margin: 30px 0; padding-bottom: 28px; border-bottom: 1px solid var(--line); }
.quiz-question legend { margin-bottom: 14px; font-size: 18px; }
.quiz-option { min-height: 44px; padding: 9px 12px; display: flex; align-items: center; gap: 10px; cursor: pointer; }
.quiz-option:hover { background: rgba(255,255,255,0.48); }
.quiz-option input { accent-color: var(--cinnabar); }
.quiz-result { margin-top: 28px; }
.quiz-score { margin-bottom: 22px; color: var(--cinnabar); font-size: 38px; }
.quiz-feedback { margin: 10px 0; padding: 14px 16px; border-left: 3px solid var(--line); background: rgba(255,255,255,0.4); }
.quiz-feedback strong, .quiz-feedback span { display: block; }
.quiz-feedback span { margin-top: 4px; color: var(--muted); font-size: 13px; }
.quiz-feedback.correct { border-left-color: var(--jade); }
.quiz-feedback.incorrect { border-left-color: var(--cinnabar); }
.quiz-summary { margin-left: 10px; color: var(--muted); font-size: 13px; }

.auth-shell { width: min(500px, calc(100% - 32px)); margin: auto; padding: 46px 0 80px; }
.auth-form { display: grid; gap: 18px; }
.auth-field span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 13px; }
.auth-field input { width: 100%; min-height: 46px; padding: 9px 12px; color: var(--ink); background: rgba(255,255,255,0.54); border: 1px solid var(--line); border-radius: 4px; }
.auth-field input:focus { outline: 2px solid rgba(158,63,45,0.35); outline-offset: 1px; }
.auth-field small { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.auth-links { margin-top: 20px; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px 20px; color: var(--muted); font-size: 13px; }
.auth-links a { color: var(--jade); text-decoration: none; }
.auth-message { margin-bottom: 22px; padding: 13px 15px; border-left: 3px solid var(--gold); background: rgba(255,255,255,0.5); font-size: 13px; }
.auth-message.success { border-left-color: var(--jade); }
.auth-message.error { border-left-color: var(--cinnabar); }
.auth-note { margin-top: 18px; color: var(--muted); font-size: 12px; }
.recovery-result { margin: 22px 0; padding: 20px; border: 1px solid rgba(34,92,78,0.32); background: rgba(255,255,255,0.46); }
.recovery-result h2 { margin: 0 0 8px; font-size: 20px; }
.recovery-result p { color: var(--muted); font-size: 13px; }
.recovery-code { display: block; margin: 18px 0; padding: 14px 10px; overflow-wrap: anywhere; color: var(--ink); background: rgba(255,255,255,0.72); border: 1px solid var(--line); font: 700 19px/1.4 ui-monospace, SFMono-Regular, Consolas, monospace; text-align: center; letter-spacing: 0; user-select: all; }
.account-security { margin-top: 36px; padding-top: 28px; border-top: 1px solid var(--line); }
.account-security h2 { font-size: 20px; }
.account-panel { padding: 24px; border: 1px solid var(--line); background: rgba(255,255,255,0.34); }
.account-email { margin: 2px 0 20px; font-size: 22px; overflow-wrap: anywhere; }
.danger-zone { margin-top: 44px; padding-top: 30px; border-top: 1px solid var(--line); }
.danger-zone h2 { font-size: 20px; }
.danger-zone .button { color: var(--cinnabar); }
.admin-inbox { width: min(760px, calc(100% - 32px)); margin: auto; padding: 46px 0 80px; }
.admin-correction { margin-top: 18px; padding: 20px; border: 1px solid var(--line); background: rgba(255,255,255,0.34); }
.admin-correction h2 { margin: 6px 0; font-size: 22px; }
.admin-correction-meta { color: var(--muted); font-size: 12px; }
.admin-correction a { color: var(--jade); }
.admin-correction dl { display: grid; grid-template-columns: 90px 1fr; gap: 8px 14px; margin: 16px 0 0; font-size: 13px; line-height: 1.7; }
.admin-correction dt { color: var(--muted); }
.admin-correction dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }

.site-footer { padding: 34px 0; color: var(--muted); background: var(--paper-deep); font-size: 12px; }
.footer-inner { width: min(900px, calc(100% - 32px)); margin: auto; display: flex; justify-content: space-between; gap: 24px; }
.footer-links { display: flex; flex-wrap: wrap; gap: 14px; }
.footer-links a { text-decoration: none; }

@media (max-width: 760px) {
  .site-header-inner { min-height: 58px; }
  .brand { white-space: nowrap; font-size: 16px; }
  .brand span, .site-nav a:not(.nav-primary):not([data-account-link]) { display: none; }
  .site-nav { gap: 8px; }
  .site-nav [data-account-link] { max-width: 62px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .nav-primary { padding: 7px 9px; white-space: nowrap; }
  .page-hero { min-height: 300px; }
  .page-hero-inner { padding: 52px 0 40px; }
  h1 { font-size: 42px; }
  .story-copy { font-size: 16px; }
  .story-grid { grid-template-columns: 1fr; }
  .story-filters { grid-template-columns: 1fr 1fr; }
  .story-search { grid-column: 1 / -1; }
  .filter-clear { grid-column: 1 / -1; }
  .route-grid { grid-template-columns: 1fr; }
  .route-card { min-height: 0; padding: 22px 18px; }
  .route-steps { padding-left: 30px; }
  .route-steps::before { left: 9px; }
  .route-step::before { left: -26px; }
  .route-step h2 { font-size: 21px; }
  .route-step-head { gap: 10px; }
  .stat-line { grid-template-columns: 1fr 1fr; }
  .stat:nth-child(2) { border-right: 0; }
  .stat:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .footer-inner { display: block; }
  .footer-links { margin-top: 10px; }
}

@media (max-width: 330px) {
  .site-header-inner { width: calc(100% - 20px); gap: 8px; }
  .site-nav [data-account-link] { display: none; }
  .nav-primary { font-size: 12px !important; }
  .page-hero { min-height: 260px; }
  .page-hero-inner { padding-top: 40px; }
  h1 { font-size: 36px; }
}
