:root {
  color-scheme: light;
  --ink: #202d3a;
  --muted: #5c6871;
  --paper: #eeede7;
  --line: #c7c9c7;
  --accent: #b07642;
  --white: #fafaf6;
  --mast: #202d3a;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--paper); color: var(--ink); font-size: 17px; line-height: 1.7; }
a { color: inherit; }
button, input, select, summary { font: inherit; }
button { cursor: pointer; }
a:focus-visible, button:focus-visible, summary:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.mast {
  background: var(--mast);
  color: #faf8ef;
  padding: 48px max(20px, calc((100vw - 1560px) / 2)) 32px;
  border-bottom: 4px solid var(--accent);
}
.eyebrow { letter-spacing: 0.16em; font-size: 13px; color: #e2bc8d; margin: 0; }
.mast h1 {
  font-family: "Songti SC", "STSong", "Noto Serif SC", serif;
  font-size: clamp(32px, 4vw, 56px);
  font-weight: 600;
  line-height: 1.25;
  margin: 14px 0;
}
.lede { max-width: 760px; margin: 0; color: #d7dee2; font-size: 17px; }
.tagline { margin: 14px 0 0; color: #cfac83; font-size: 14px; }
.library-note { margin: 10px 0 0; color: #c5ced4; font-size: 14px; }

.toolbar, .story-nav, .mode-row, .filter-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.toolbar { margin-top: 22px; }
.filter-row, .mode-row { width: 100%; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: #e2bc8d; }
input[type="search"], select, .mast button, .story-nav button, .scene-files a, summary {
  min-height: 44px;
}
input[type="search"], select {
  min-width: 180px;
  border: 1px solid #6c7781;
  background: #fafaf6;
  color: var(--ink);
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 16px;
}
.mast button, .story-nav button, .scene-open {
  border: 1px solid #9ca5a8;
  background: transparent;
  color: inherit;
  border-radius: 4px;
  padding: 8px 14px;
  min-height: 44px;
}
.mast button { color: #faf8ef; border-color: #6c7781; }
.mast button[aria-pressed="true"] { border-color: var(--accent); color: #f3e2cc; }
#score, #progress { margin: 0; min-height: 44px; display: flex; align-items: center; font-size: 16px; color: #f7f1e6; }

main { max-width: 1608px; margin: 0 auto; padding: 28px 24px 48px; }
#scene-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px;
}
.scene-card {
  border: 1px solid var(--line);
  background: var(--white);
  border-radius: 5px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.scene-open {
  width: 100%;
  text-align: left;
  color: var(--ink);
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 0;
  border: 0;
}
.scene-index { color: #7c5738; letter-spacing: 0.08em; font-size: 13px; }
.scene-title {
  font-family: "Songti SC", "STSong", "Noto Serif SC", serif;
  font-size: 26px;
  line-height: 1.35;
  font-weight: 600;
}
.scene-domain { color: var(--muted); font-size: 14px; }
.thumb-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 2px;
  background: #26323b;
  padding: 2px;
  border-radius: 4px;
  overflow: hidden;
}
.thumb-panel { position: relative; overflow: hidden; aspect-ratio: 2 / 3; background: #26323b; }
.thumb-panel img, .story-panel img {
  position: absolute;
  top: 0;
  height: 100%;
  width: 300%;
  max-width: none;
  object-fit: fill;
  display: block;
}
.making {
  margin: 0;
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #d5dde2;
  background: #26323b;
  font-size: 15px;
  letter-spacing: 0.08em;
}
.thumb-board .making { min-height: 120px; grid-column: 1 / -1; }
.scene-files { display: flex; flex-wrap: wrap; gap: 8px 14px; }
.scene-files a { display: inline-flex; align-items: center; font-size: 14px; color: #6d4c32; text-underline-offset: 3px; }
.empty { grid-column: 1 / -1; color: var(--muted); margin: 12px 0; }

#story { margin-top: 8px; }
.story-kicker { margin: 0; color: #7c5738; letter-spacing: 0.08em; font-size: 13px; }
#story h2 {
  font-family: "Songti SC", "STSong", "Noto Serif SC", serif;
  font-size: clamp(28px, 3vw, 40px);
  font-weight: 600;
  line-height: 1.3;
  margin: 8px 0 16px;
}
.story-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 3px;
  padding: 3px;
  max-width: 1560px;
  background: #26323b;
  border-radius: 5px;
  overflow: hidden;
}
.story-panel {
  position: relative;
  overflow: hidden;
  aspect-ratio: 2 / 3;
  background: #26323b;
}
.dialogue {
  position: absolute;
  z-index: 2;
  top: 3.5%;
  left: 5%;
  width: 90%;
  padding: 12px 15px;
  background: rgba(255, 255, 251, 0.94);
  color: #202b35;
  border: 1px solid #48535b;
  border-radius: 10px;
  box-shadow: 0 2px 8px #0002;
  font-size: 20px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.dialogue.anchor-top-right { left: auto; right: 5%; }
.dialogue.anchor-bottom-left,
.dialogue.anchor-bottom-right { top: auto; bottom: var(--bubble-bottom, 3.5%); }
.dialogue.anchor-bottom-right { left: auto; right: 5%; }
.speaker { display: block; font-size: 13px; font-weight: 700; letter-spacing: 0.04em; color: #65717a; margin-bottom: 3px; }
.line { display: block; font-size: 20px; }
.dialogue::after {
  content: "";
  position: absolute;
  bottom: -9px;
  left: var(--tail-x, 30px);
  right: auto;
  width: 16px;
  height: 16px;
  background: #fffffb;
  border-right: 1px solid #48535b;
  border-bottom: 1px solid #48535b;
  transform: rotate(45deg);
}
.dialogue.anchor-bottom-left::after,
.dialogue.anchor-bottom-right::after {
  bottom: auto;
  top: -9px;
  border-right: 0;
  border-bottom: 0;
  border-left: 1px solid #48535b;
  border-top: 1px solid #48535b;
}
.phase {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 2;
  padding: 5px 10px;
  border-radius: 3px;
  background: #202d3ad9;
  color: #fff;
  font-size: 12px;
  letter-spacing: 0.1em;
}
.hide-dialogue .dialogue { display: none; }
.reading { color: var(--muted); font-size: 15px; margin: 14px 0; }
.question-text {
  font-family: "Songti SC", "STSong", "Noto Serif SC", serif;
  font-size: 26px;
  font-weight: 600;
  line-height: 1.45;
  margin: 8px 0 14px;
}
.candidates { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.candidate {
  min-height: 44px;
  border: 1px solid #9aa3a6;
  background: var(--white);
  color: var(--ink);
  border-radius: 4px;
  padding: 10px 12px;
  font-size: 18px;
  text-align: left;
}
.candidate.is-selected { border-color: var(--accent); background: #f3eee6; }
.candidate[disabled] { opacity: 1; color: var(--ink); cursor: default; }
.hint, #feedback { color: var(--muted); font-size: 15px; min-height: 1.6em; }
.answer-details {
  border: 1px solid #bdc5c6;
  background: #f7f7f2;
  border-radius: 5px;
  margin-top: 16px;
}
.answer-details summary { padding: 12px 18px; cursor: pointer; font-weight: 600; }
.answer-details[open] summary { border-bottom: 1px solid #d3d8d7; }
.explanation { padding: 18px 22px 24px; max-width: 980px; }
.gua-name {
  font-family: "Songti SC", "STSong", "Noto Serif SC", serif;
  font-size: 28px;
  margin: 0 0 8px;
}
.meaning { font-size: 18px; margin: 0 0 12px; }
.explanation h3 { font-size: 16px; margin: 18px 0 6px; }
.explanation ul { margin: 8px 0; padding-left: 22px; }
.explanation li { margin: 4px 0; }
.limit { color: #6b7379; font-size: 15px; border-top: 1px solid #d4d8d6; padding-top: 14px; margin: 18px 0 0; }
.story-nav { margin-top: 16px; }
.story-nav button { color: var(--ink); background: transparent; }
.story-files { display: flex; flex-wrap: wrap; gap: 12px 18px; margin-top: 12px; }
.story-files a { min-height: 44px; display: inline-flex; align-items: center; color: #6d4c32; }

.foot {
  background: var(--mast);
  color: #c8d0d5;
  padding: 22px 24px 28px;
  text-align: center;
  font-size: 13px;
  line-height: 1.8;
}

@media (max-width: 820px) {
  html:not([data-preview="1"]) .mast { padding: 28px 16px; }
  html:not([data-preview="1"]) main { padding: 20px 16px 36px; }
  html:not([data-preview="1"]) .story-board { grid-template-columns: 1fr; gap: 4px; }
  html:not([data-preview="1"]) .story-panel { width: 100%; aspect-ratio: 2 / 3; }
  html:not([data-preview="1"]) .dialogue,
  html:not([data-preview="1"]) .line { font-size: 18px; }
  html:not([data-preview="1"]) .dialogue.mobile-anchor-top-left,
  html:not([data-preview="1"]) .dialogue.mobile-anchor-top-right { top: 0.5%; bottom: auto; }
  html:not([data-preview="1"]) .dialogue.mobile-anchor-bottom-left,
  html:not([data-preview="1"]) .dialogue.mobile-anchor-bottom-right { top: auto; bottom: 3.5%; }
  html:not([data-preview="1"]) .dialogue.mobile-anchor-bottom-left::after,
  html:not([data-preview="1"]) .dialogue.mobile-anchor-bottom-right::after {
    bottom: auto; top: -9px; border-right: 0; border-bottom: 0;
    border-left: 1px solid #48535b; border-top: 1px solid #48535b;
  }
  html:not([data-preview="1"]) .phase { bottom: 2px; right: 8px; padding: 2px 6px; font-size: 11px; line-height: 1.2; }
  html:not([data-preview="1"]) .question-text { font-size: 22px; }
  html:not([data-preview="1"]) .candidates { grid-template-columns: 1fr 1fr; }
  html:not([data-preview="1"]) input[type="search"],
  html:not([data-preview="1"]) select { width: 100%; }
}

html[data-preview="1"],
html[data-preview="1"] body {
  width: 1560px;
  height: 780px;
  margin: 0;
  overflow: hidden;
  background: #26323b;
}
html[data-preview="1"] .mast,
html[data-preview="1"] #scene-grid,
html[data-preview="1"] .foot,
html[data-preview="1"] .story-copy,
html[data-preview="1"] .story-kicker,
html[data-preview="1"] #story-title,
html[data-preview="1"] .reading,
html[data-preview="1"] .question-block,
html[data-preview="1"] .story-nav,
html[data-preview="1"] #score,
html[data-preview="1"] #progress,
html[data-preview="1"] .library-note { display: none !important; }
html[data-preview="1"] main { max-width: none; margin: 0; padding: 0; }
html[data-preview="1"] #story { display: block !important; margin: 0; }
html[data-preview="1"] .story-board {
  position: absolute;
  top: 0;
  left: 0;
  width: 1560px;
  height: 780px;
  max-width: none;
  margin: 0;
  padding: 0;
  gap: 0;
  border-radius: 0;
  grid-template-columns: 520px 520px 520px;
  grid-template-rows: 780px;
}
html[data-preview="1"] .story-panel {
  width: 520px !important;
  height: 780px !important;
  aspect-ratio: auto !important;
}
html[data-preview="1"] .dialogue,
html[data-preview="1"] .line { font-size: 20px; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}
