:root {
  --paper: #f3eee4;
  --paper-2: #fffaf2;
  --ink: #1d2a28;
  --ink-soft: #4b5b57;
  --line: #e0d5c4;
  --teal: #2b6f64;
  --teal-2: #1e574e;
  --clay: #c45c26;
  --ok: #2f7d4a;
  --bad: #b4413c;
  --warn: #b7811d;
  --shadow: 0 18px 40px rgba(40, 32, 20, 0.08);
  --serif: "Songti SC", "Source Han Serif SC", "Noto Serif SC", "STSong", serif;
  --sans: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 8% -8%, #f4d9a8 0%, transparent 50%),
    radial-gradient(800px 380px at 96% 8%, #cfe8df 0%, transparent 46%),
    radial-gradient(700px 360px at 70% 100%, #f3cbb8 0%, transparent 42%),
    linear-gradient(180deg, #fbf6ee, var(--paper));
}
#app { position: relative; z-index: 1; }

.home-bg-photo {
  display: none;
}
body.page-home .home-bg-photo {
  display: block;
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: auto;
  max-width: min(48vw, 767px);
  object-fit: cover;
  object-position: center 20%;
  z-index: 0;
  pointer-events: none;
}
body.page-home #homeView {
  max-width: 780px;
  margin-left: max(22px, 4vw);
  margin-right: calc(min(48vw, 767px) + 16px);
  padding-right: 12px;
}
body.page-home .topbar {
  background: rgba(255, 250, 242, 0.72);
}

.hidden { display: none !important; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 250, 242, 0.78);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  cursor: pointer;
}
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--teal);
  color: #fff;
  font-family: var(--serif);
  font-size: 22px;
}
.brand-title { font-family: var(--serif); font-size: 20px; letter-spacing: 0.08em; }
.brand-sub { color: var(--ink-soft); font-size: 12px; }
.top-stats { color: var(--ink-soft); font-size: 13px; }
.top-end {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}
.sync-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-soft);
  white-space: nowrap;
}
.sync-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #c5b9a6;
  flex-shrink: 0;
}
.sync-chip.is-ok .sync-dot { background: var(--ok); }
.sync-chip.is-syncing .sync-dot { background: var(--warn); }
.sync-chip.is-error .sync-dot { background: var(--bad); }
.sync-msg { max-width: 9em; overflow: hidden; text-overflow: ellipsis; }
.sync-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 3px 10px;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
}
.sync-btn:hover { background: #e7f4f0; color: var(--teal-2); }
.sync-id { color: var(--teal-2); }

.view { min-height: calc(100vh - 76px); }

#homeView {
  max-width: 1120px;
  margin: 0 auto;
  padding: 36px 22px 88px;
}
.hero {
  margin-bottom: 28px;
  position: relative;
}
.hero-kicker {
  display: inline-block;
  font-size: 12px;
  letter-spacing: 0.18em;
  color: var(--teal-2);
  background: #e4f3ee;
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 10px;
}
.hero h1 {
  font-family: var(--serif);
  font-size: 42px;
  font-weight: 500;
  margin: 0 0 10px;
  letter-spacing: 0.04em;
  line-height: 1.2;
}
.hero h1 em {
  font-style: normal;
  color: var(--clay);
}
.hero p { margin: 0 0 14px; color: var(--ink-soft); line-height: 1.7; max-width: 36em; }
.hero-tags { display: flex; flex-wrap: wrap; gap: 8px; }
.htag {
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--ink-soft);
}
.htag-a { background: var(--teal); border-color: var(--teal); color: #fff; font-weight: 600; }
.htag-b { background: transparent; border-color: #ddd2c4; color: #9a8b78; }

.pdf-downloads {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
}
.pdf-label {
  font-size: 12px;
  color: var(--ink-soft);
  margin-right: 4px;
}
.pdf-dl {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid transparent;
}
.pdf-hint {
  background: var(--teal);
  color: #fff;
}
.pdf-hint:hover { background: var(--teal-2); }
.pdf-plain {
  background: #fff;
  color: var(--teal-2);
  border-color: #c5d8d2;
}
.pdf-plain:hover { background: #e7f4f0; }

.subject-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 22px;
  margin-bottom: 22px;
}
.deck {
  border-radius: 24px;
  padding: 20px 18px 18px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255,255,255,0.6);
  position: relative;
  overflow: hidden;
}
.deck::before {
  content: "";
  position: absolute;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  right: -50px;
  top: -60px;
  opacity: 0.35;
  pointer-events: none;
}
.deck-dao {
  background: linear-gradient(165deg, #f4fffb 0%, #eef7f3 40%, #fffaf2 100%);
}
.deck-dao::before { background: #8ed4c2; }
.deck-ren {
  background: linear-gradient(165deg, #fff7f0 0%, #fcefe4 42%, #fffaf2 100%);
}
.deck-ren::before { background: #f0b089; }

.deck-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
  margin-bottom: 14px;
  position: relative;
}
.deck-mascot {
  width: 56px;
  height: 56px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-size: 26px;
  color: #fff;
  box-shadow: 0 8px 18px rgba(40, 32, 20, 0.12);
  animation: bob 3.6s ease-in-out infinite;
}
.deck-dao .deck-mascot { background: linear-gradient(145deg, #3b8f80, #1e574e); }
.deck-ren .deck-mascot { background: linear-gradient(145deg, #e07a3a, #b04a18); }
@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}
.deck-copy h2 {
  font-family: var(--serif);
  margin: 0 0 4px;
  font-size: 26px;
  font-weight: 500;
}
.deck-copy p { margin: 0; color: var(--ink-soft); font-size: 13px; }
.deck-stats { display: flex; align-items: center; gap: 10px; }
.ring {
  --p: 0;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--teal-2);
  position: relative;
  background: conic-gradient(var(--teal) calc(var(--p) * 1%), #e7dccb 0);
}
.ring::before {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  background: #f3fbf7;
}
.ring span { position: relative; z-index: 1; }
.deck-ren .ring {
  color: #8a4b1f;
  background: conic-gradient(var(--clay) calc(var(--p) * 1%), #ead7c6 0);
}
.deck-ren .ring::before { background: #fff6ef; }
.deck-nums b { display: block; font-size: 16px; }
.deck-nums span { color: var(--ink-soft); font-size: 11px; }

.deck-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
  position: relative;
}
.lg {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
}
.lg-a { background: var(--teal); color: #fff; font-weight: 600; }
.lg-b { background: transparent; color: #9a8b78; border: 1px solid #e0d5c4; }
.go-all {
  margin-left: auto;
  border: 0;
  background: transparent;
  color: var(--teal-2);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  font-weight: 600;
}
.deck-ren .go-all { color: #8a4b1f; }
@media (prefers-reduced-motion: reduce) {
  .deck-mascot { animation: none; }
  .pill-main { transition: none; }
}

.chap-flow {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  position: relative;
  align-items: center;
}
.chap-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.pill-main {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 0;
  cursor: pointer;
  font-family: inherit;
  color: #fff;
  background: var(--accent, var(--teal));
  border-radius: 999px;
  padding: 8px 12px 8px 10px;
  box-shadow: 0 6px 14px color-mix(in srgb, var(--accent, var(--teal)) 28%, transparent);
  transition: transform 0.15s ease, filter 0.15s ease;
}
.pill-main:hover { transform: translateY(-2px); filter: brightness(1.06); }
.pill-ico { font-size: 16px; line-height: 1; }
.pill-name { font-size: 14px; font-weight: 600; letter-spacing: 0.02em; }
.pill-a {
  min-width: 1.25em;
  height: 1.25em;
  padding: 0 5px;
  border-radius: 99px;
  background: rgba(255,255,255,0.22);
  font-size: 11px;
  font-weight: 700;
  display: grid;
  place-items: center;
}
.pill-b {
  border: 0;
  background: transparent;
  color: #b3a490;
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  padding: 4px 2px;
  opacity: 0.75;
}
.pill-b:hover { color: #7a6b58; opacity: 1; }
.chap-pill.no-a .pill-main {
  background: #e8dfd2;
  color: #6f6356;
  box-shadow: none;
}

.chap-pill:nth-child(6n+1) { --accent: #2b6f64; }
.chap-pill:nth-child(6n+2) { --accent: #3d6ea8; }
.chap-pill:nth-child(6n+3) { --accent: #7a5ea8; }
.chap-pill:nth-child(6n+4) { --accent: #c45c26; }
.chap-pill:nth-child(6n+5) { --accent: #3d8a5a; }
.chap-pill:nth-child(6n+6) { --accent: #b04a4a; }
.deck-ren .chap-pill:nth-child(6n+1) { --accent: #c45c26; }
.deck-ren .chap-pill:nth-child(6n+2) { --accent: #b07a2a; }
.deck-ren .chap-pill:nth-child(6n+3) { --accent: #8a4b6a; }
.deck-ren .chap-pill:nth-child(6n+4) { --accent: #3d6ea8; }
.deck-ren .chap-pill:nth-child(6n+5) { --accent: #2b6f64; }
.deck-ren .chap-pill:nth-child(6n+6) { --accent: #6a5c9a; }

.home-foot {
  text-align: center;
  color: var(--ink-soft);
  font-size: 12px;
  margin: 8px 0 0;
}

#quizView {
  display: grid;
  grid-template-columns: 280px 1fr;
}

.sidebar {
  border-right: 1px solid var(--line);
  padding: 18px 14px 40px;
  background: rgba(255, 250, 242, 0.5);
  overflow: auto;
  max-height: calc(100vh - 76px);
  position: sticky;
  top: 76px;
}
.side-title {
  font-size: 12px;
  color: var(--ink-soft);
  letter-spacing: 0.12em;
  margin: 8px 8px 10px;
}
.chap-block, .all-block {
  margin: 0 0 10px;
  padding: 8px 8px 10px;
  border-radius: 12px;
  background: rgba(255,255,255,0.35);
}
.chap-block.open {
  background: #fffaf2;
  box-shadow: inset 0 0 0 1px var(--line);
}
.chap-name {
  font-size: 12px;
  color: var(--ink);
  padding: 4px 4px 6px;
  line-height: 1.35;
}
.ab-btn {
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 8px;
  padding: 7px 10px;
  margin-bottom: 4px;
  cursor: pointer;
  font-family: inherit;
  background: transparent;
  color: var(--ink);
}
.ab-btn small { float: right; opacity: 0.7; }
.ab-btn.ab-a {
  background: #e7f4f0;
  font-weight: 600;
}
.ab-btn.ab-b {
  color: #8d8173;
  font-weight: 400;
}
.ab-btn.ab-a:hover { background: var(--teal); color: #fff; }
.ab-btn.ab-b:hover { background: #f3efe8; color: #6f6356; }
.ab-btn[disabled] { opacity: 0.35; cursor: default; }
.ab-btn.ab-a.active { background: var(--teal); color: #fff; }
.ab-btn.ab-b.active { background: #d9d0c4; color: #5c5348; }

.ab-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  margin: -4px 0 14px;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
}
.ab-banner strong { font-size: 15px; letter-spacing: 0.04em; }
.ab-banner.is-a {
  background: #e7f3ef;
  color: var(--teal-2);
}
.ab-banner.is-b {
  background: #f8ece1;
  color: #8a4b1f;
}
.ab-banner-actions {
  margin-left: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}
.ab-switch {
  border: 0;
  border-radius: 999px;
  padding: 4px 12px;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  background: rgba(255,255,255,0.7);
  color: inherit;
}
.ab-switch:hover { background: #fff; }
#btnReclassHere {
  font-weight: 600;
  background: #fff;
}
.progress-mini {
  height: 4px;
  background: #e7dccb;
  border-radius: 99px;
  margin-top: 6px;
  overflow: hidden;
}
.progress-mini span {
  display: block;
  height: 100%;
  background: var(--teal);
}

.stage { padding: 22px 20px 64px; max-width: none; }
.crumb { color: var(--ink-soft); font-size: 13px; margin-bottom: 12px; }

.card {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 22px 20px 18px;
  box-shadow: var(--shadow);
  overflow-x: auto;
}

.mmap-canvas {
  min-height: 220px;
  padding: 8px 6px 18px;
}

.mmap {
  display: flex;
  flex-direction: row;
  align-items: center;
}
.mmap-col {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  position: relative;
  padding-left: 22px;
}
.mmap-col::before {
  content: "";
  position: absolute;
  left: 0;
  top: 22px;
  bottom: 22px;
  width: 2px;
  background: #cbb89a;
}
.mmap-col > .mmap::before {
  content: "";
  width: 22px;
  height: 2px;
  background: #cbb89a;
  flex-shrink: 0;
  margin-left: -22px;
}

.box {
  border-radius: 12px;
  padding: 10px 12px;
  min-width: 108px;
  max-width: 260px;
  line-height: 1.45;
  position: relative;
}
.box.given {
  background: #f3ebe0;
  border: 1.5px solid #d9cbb6;
  font-weight: 600;
}
.box.given.lv1 {
  background: var(--teal);
  color: #fff;
  border-color: var(--teal-2);
  font-family: var(--serif);
  font-size: 15px;
  max-width: 140px;
}
.box.given.lv2 {
  background: #e7f2ef;
  color: var(--teal-2);
  border-color: #b7d4cc;
  max-width: 180px;
}
.box.given.lv3 {
  background: #fff;
  border-color: var(--teal);
  color: var(--teal-2);
  font-family: var(--serif);
  font-size: 16px;
  min-width: 92px;
  max-width: 200px;
}
.box.given.lv4,
.box.given.lv5,
.box.given.lv6 {
  background: #fffaf3;
  border: 1.5px solid #d4c4ae;
  color: var(--ink);
  font-weight: 600;
  font-size: 13px;
  max-width: 240px;
}

.box.fill {
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 1px 0 2px;
  min-height: 0;
  min-width: 132px;
  max-width: 260px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  cursor: text;
}
.blank-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}
.node-prefix {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--clay);
  font-weight: 600;
  letter-spacing: 0.04em;
}
.node-clue {
  flex-shrink: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--teal);
  letter-spacing: 0.02em;
  line-height: 1.4;
}
.node-edit {
  display: block;
  flex: 1;
  min-width: 72px;
  min-height: 1.35em;
  outline: none;
  font-size: 14px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
  padding: 0 2px 1px;
  border: 0;
  border-bottom: 1.5px solid #b59a78;
  background: transparent;
}
.box.fill:hover .node-edit,
.box.fill:focus-within .node-edit {
  border-bottom-color: var(--teal);
}
.box.fill.has-text .node-edit { border-bottom-color: #8f7a5c; }
.box.fill.ok .node-edit { border-bottom-color: var(--ok); }
.box.fill.mid .node-edit { border-bottom-color: var(--warn); }
.box.fill.bad .node-edit { border-bottom-color: var(--bad); }
.box.fill.revealed {
  max-width: 420px;
  min-width: 180px;
}
.box.fill.revealed .node-edit {
  color: var(--teal-2);
  font-weight: 600;
  cursor: default;
}
.btn-understand {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: #fff;
  background: var(--teal);
}
.btn-understand:hover { background: var(--teal-2); }
.btn-understand svg { display: block; }
.btn-understand[hidden] { display: none !important; }

.explain-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.explain-modal.hidden,
.explain-modal[hidden] {
  display: none !important;
}
.explain-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(29, 42, 40, 0.38);
}
.explain-panel {
  position: relative;
  z-index: 1;
  width: min(520px, 100%);
  max-height: min(78vh, 640px);
  overflow: auto;
  background: #fffaf2;
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 22px 22px 18px;
}
.explain-close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: #efe6d6;
  color: var(--ink);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.explain-path {
  margin: 0 36px 8px 0;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.5;
}
.explain-title {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 500;
  margin: 0 36px 10px 0;
  color: var(--teal-2);
}
.explain-body {
  font-size: 14px;
  line-height: 1.7;
  color: var(--ink);
}
.explain-body p { margin: 0 0 10px; }
.explain-k {
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--clay);
  margin: 12px 0 6px !important;
}
.explain-body ul {
  margin: 0 0 12px;
  padding-left: 1.2em;
}
.explain-body li { margin: 0 0 4px; }
.node-edit:empty::before {
  content: attr(data-placeholder);
  color: #c0b09a;
}

.hint-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  color: var(--ink-soft);
  font-size: 13px;
  margin-bottom: 14px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
button.btn {
  border: 0;
  border-radius: 999px;
  padding: 9px 16px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
}
.btn-primary { background: var(--teal); color: #fff; }
.btn-ghost { background: #efe6d6; color: var(--ink); }
.btn-warn { background: #f3e1c8; color: #7a4c12; }

.action-bar {
  position: sticky;
  bottom: 12px;
  z-index: 6;
  margin-top: 14px;
  padding: 12px 14px;
  background: rgba(255, 250, 242, 0.95);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}
.check-summary {
  display: none;
  margin-top: 8px;
  font-size: 13px;
  color: var(--teal-2);
}
.check-summary.show { display: block; }

.node-feedback {
  margin-top: 4px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--ink-soft);
  word-break: break-word;
}
.node-feedback.ok { color: var(--ok); }
.node-feedback.mid { color: var(--warn); }
.node-feedback.bad { color: var(--bad); }
.node-feedback.answer { color: var(--teal-2); }

.answer-box {
  margin-top: 18px;
  padding: 14px 16px;
  background: #f6f1e6;
  border-radius: 12px;
  border: 1px solid #eadfcf;
}
.answer-box h3 {
  margin: 0 0 8px;
  font-size: 13px;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  font-weight: 600;
}
.ans-line {
  padding-left: calc(var(--d) * 16px);
  line-height: 1.7;
  font-size: 14px;
}
.score-tag {
  display: inline-block;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 99px;
  margin-left: 6px;
}
.score-tag.ok { background: #d9f0e0; color: var(--ok); }
.score-tag.mid { background: #f8e7c4; color: var(--warn); }
.score-tag.bad { background: #f8d7d5; color: var(--bad); }

.pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
  color: var(--ink-soft);
  font-size: 13px;
}

@media (max-width: 860px) {
  body.page-home .home-bg-photo {
    position: relative;
    width: 100%;
    max-width: none;
    height: 320px;
    object-fit: cover;
    object-position: center 22%;
  }
  body.page-home #homeView {
    max-width: none;
    margin-left: auto;
    margin-right: auto;
    padding-right: 22px;
  }
  .subject-grid { grid-template-columns: 1fr; }
  #quizView { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .hero h1 { font-size: 30px; }
  .stage, .card { padding: 18px; }
  .deck-head { grid-template-columns: auto 1fr; }
  .deck-stats { grid-column: 1 / -1; }
  .go-all { margin-left: 0; }
  .topbar { padding: 12px 16px; gap: 10px; }
  .sync-msg { display: none; }
}
