:root {
  --paper: #efe6d2;
  --card: #fbf6e9;
  --card-edge: #d9c9a5;
  --ink: #2a241c;
  --muted: #74654f;
  --line: #e2d5b6;
  --vermilion: #b8372b;
  --vermilion-deep: #96291f;
  --gold: #a8762a;
  --wood: #3f7d5a;
  --fire: #c1442e;
  --earth: #a8762a;
  --metal: #6f7b86;
  --water: #2b4f73;
  --song: "Songti SC", "STSong", "Noto Serif SC", "Source Han Serif SC", "SimSun", serif;
  --kai: "Kaiti SC", "STKaiti", "KaiTi", "BiauKai", var(--song);
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --panel-w: 420px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.7;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }

#stage { position: fixed; inset: 0; }
#stage canvas { display: block; touch-action: none; }

/* ---------- 顶栏 ---------- */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 18px;
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }
#brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.seal {
  display: grid; place-items: center;
  width: 44px; height: 44px; border-radius: 7px;
  background: var(--vermilion); color: #fdf3e0;
  font-family: var(--kai); font-size: 19px; font-weight: 700; line-height: 1; letter-spacing: 1px;
  box-shadow: inset 0 0 0 2px rgba(253, 243, 224, 0.55), 0 2px 0 var(--vermilion-deep);
}
.brand-text { font-family: var(--song); font-size: 21px; font-weight: 700; letter-spacing: 4px; }
#crumb { font-family: var(--song); color: var(--muted); font-size: 15px; white-space: nowrap; }
.spacer { flex: 1; }
#stars { font-family: var(--song); font-weight: 700; color: var(--gold); white-space: nowrap; }
.ghost {
  border: 1.5px solid var(--card-edge); background: rgba(251, 246, 233, 0.85); color: var(--ink);
  border-radius: 999px; padding: 5px 14px; font-size: 13px; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.ghost:hover { border-color: var(--ink); }

/* ---------- 讲解面板 ---------- */
#panel {
  position: fixed; z-index: 4;
  top: 72px; right: 18px; bottom: 18px; width: var(--panel-w);
  display: flex; flex-direction: column;
  background: var(--card);
  border: 1.5px solid var(--card-edge);
  border-radius: 14px;
  box-shadow: 0 1px 0 #fff inset, 0 18px 40px -18px rgba(70, 50, 20, 0.45);
  overflow: hidden;
}
#panel-head { padding: 18px 22px 12px; border-bottom: 1px solid var(--line); }
#panel-body { flex: 1; overflow-y: auto; padding: 16px 22px 20px; overscroll-behavior: contain; }
#panel-foot { padding: 12px 22px 16px; border-top: 1px solid var(--line); display: flex; gap: 10px; align-items: center; }
#panel-foot:empty { display: none; }

.kicker { font-size: 12.5px; letter-spacing: 2px; color: var(--vermilion); font-weight: 600; }
h1 { font-family: var(--song); font-size: 27px; line-height: 1.25; margin: 2px 0 0; letter-spacing: 1px; }
h2 { font-family: var(--song); font-size: 19px; margin: 0 0 8px; line-height: 1.4; }
h3 { font-family: var(--song); font-size: 15.5px; margin: 18px 0 6px; }
p { margin: 0 0 10px; }
ul, ol { margin: 0 0 10px; padding-left: 1.3em; }
li { margin-bottom: 3px; }
b, strong { font-weight: 650; }
small, .small { font-size: 13px; color: var(--muted); }
a { color: var(--vermilion-deep); }

.title-row { display: flex; align-items: center; gap: 12px; justify-content: space-between; }
.voice {
  flex: none; border: 1.5px solid var(--vermilion); background: transparent; color: var(--vermilion-deep);
  border-radius: 999px; padding: 4px 13px; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.voice:hover { background: #f8e4dc; }
.voice.on { background: var(--vermilion); color: #fff6e6; }
.voice.nudge { animation: nudge 1.2s ease-in-out 3; }
@keyframes nudge { 50% { box-shadow: 0 0 0 5px rgba(184, 55, 43, 0.22); } }
.dots { display: flex; gap: 6px; margin-top: 12px; }
.dots i { flex: 1; height: 4px; border-radius: 2px; background: var(--line); }
.dots i.on { background: var(--vermilion); }
.dots i.done { background: var(--gold); }

.btn {
  border: 1.5px solid var(--ink); background: transparent; border-radius: 9px;
  padding: 9px 18px; cursor: pointer; font-weight: 600; font-size: 14.5px; transition: transform 0.08s;
}
.btn:hover { background: rgba(42, 36, 28, 0.06); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--vermilion); border-color: var(--vermilion-deep); color: #fff6e6; box-shadow: 0 2px 0 var(--vermilion-deep); }
.btn.primary:hover { background: #c64234; }
.btn.small { padding: 5px 12px; font-size: 13px; border-radius: 7px; border-width: 1.2px; }
.btn[disabled] { opacity: 0.4; cursor: not-allowed; }
.btn.grow { flex: 1; }

/* 五行色 */
.el { font-family: var(--kai); font-weight: 700; padding: 0 1px; }
.el-木 { color: var(--wood); } .el-火 { color: var(--fire); } .el-土 { color: var(--earth); }
.el-金 { color: var(--metal); } .el-水 { color: var(--water); }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 9px; border-radius: 999px;
  border: 1.2px solid currentColor; font-size: 13px; font-weight: 600; line-height: 1.6; white-space: nowrap;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 10px; }
.chips .btn.small.on { background: var(--ink); color: var(--card); }

.note {
  background: #f3e9d0; border-left: 3px solid var(--gold); border-radius: 0 8px 8px 0;
  padding: 9px 12px; margin: 12px 0; font-size: 13.5px; color: #55472f;
}
.note b { color: var(--ink); }
.try {
  background: #f8e4dc; border-left: 3px solid var(--vermilion); border-radius: 0 8px 8px 0;
  padding: 9px 12px; margin: 12px 0; font-size: 14px;
}
.verse { font-family: var(--kai); font-size: 17px; line-height: 1.9; color: #4a3d2a; margin: 8px 0 12px; padding-left: 12px; border-left: 2px solid var(--line); }

#info:empty { display: none; }
#info { margin-top: 12px; padding: 12px 14px; border: 1.5px solid var(--card-edge); border-radius: 10px; background: #fffaf0; }
#info h3 { margin-top: 0; }

table { border-collapse: collapse; width: 100%; margin: 8px 0 12px; font-size: 13.5px; }
th, td { border-bottom: 1px solid var(--line); padding: 5px 6px; text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12.5px; }
td.big { font-family: var(--kai); font-size: 19px; font-weight: 700; }

/* ---------- 闯关 ---------- */
.q-prompt { font-family: var(--song); font-size: 19px; font-weight: 700; line-height: 1.5; margin: 4px 0 14px; }
.q-options { display: grid; gap: 9px; }
.q-options .btn { text-align: left; padding: 11px 14px; }
.q-options .btn.right { background: #dcebdd; border-color: var(--wood); color: #214a33; }
.q-options .btn.wrong { background: #f6dcd6; border-color: var(--fire); color: #7c2518; }
.q-feedback { margin-top: 14px; padding: 11px 13px; border-radius: 10px; font-size: 14px; }
.q-feedback.ok { background: #dcebdd; color: #214a33; }
.q-feedback.no { background: #f6dcd6; color: #7c2518; }
.q-feedback b { display: block; font-family: var(--song); font-size: 16px; }
.q-pick { color: var(--vermilion-deep); font-weight: 600; }

/* ---------- 星图首页 ---------- */
.lesson-list { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 8px; }
.lesson-list a {
  display: grid; grid-template-columns: 38px 1fr auto; gap: 10px; align-items: center;
  padding: 9px 12px; border: 1.5px solid var(--card-edge); border-radius: 10px; text-decoration: none; color: var(--ink); background: #fffaf0;
}
.lesson-list a:hover { border-color: var(--ink); }
.lesson-list a.locked { opacity: 0.5; pointer-events: none; background: transparent; }
.lesson-list a.next { border-color: var(--vermilion); box-shadow: 0 2px 0 var(--vermilion); }
.lesson-list .no { font-family: var(--kai); font-size: 23px; font-weight: 700; color: var(--vermilion); text-align: center; }
.lesson-list .name { font-family: var(--song); font-weight: 700; font-size: 16px; line-height: 1.3; }
.lesson-list .sub { font-size: 12.5px; color: var(--muted); line-height: 1.4; }
.lesson-list .got { font-size: 14px; color: var(--gold); letter-spacing: 1px; white-space: nowrap; }
details { border-top: 1px solid var(--line); padding: 10px 0 2px; }
details summary { cursor: pointer; font-family: var(--song); font-weight: 700; }
details[open] summary { margin-bottom: 8px; }
label.check { display: flex; gap: 8px; align-items: center; font-size: 13.5px; color: var(--muted); cursor: pointer; }

/* ---------- 表单 ---------- */
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; margin: 10px 0 12px; }
.form label { display: grid; gap: 3px; font-size: 12.5px; color: var(--muted); }
.form label.wide { grid-column: 1 / -1; }
.form input, .form select {
  border: 1.5px solid var(--card-edge); border-radius: 8px; padding: 7px 9px; background: #fffaf0; font-size: 15px; width: 100%; min-width: 0;
}
.form input:focus, .form select:focus { outline: 2px solid var(--vermilion); outline-offset: 1px; }
.form .row { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; }

.pillars { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 10px 0; text-align: center; }
.pillars > div { border: 1.5px solid var(--card-edge); border-radius: 9px; padding: 6px 2px 7px; background: #fffaf0; }
.pillars .cap { font-size: 12px; color: var(--muted); }
.pillars .gz { font-family: var(--kai); font-size: 25px; font-weight: 700; line-height: 1.25; }
.pillars .god { font-size: 11.5px; color: var(--muted); line-height: 1.35; }
.pillars .me { border-color: var(--vermilion); box-shadow: 0 2px 0 var(--vermilion); }

.meter { height: 12px; border-radius: 6px; background: var(--water); overflow: hidden; margin: 6px 0 4px; }
.meter i { display: block; height: 100%; background: var(--vermilion); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 8px 0 12px; font-size: 14px; }
.kv dt { color: var(--muted); white-space: nowrap; }
.kv dd { margin: 0; }
.tone-偏顺 { color: var(--wood); font-weight: 650; } .tone-偏紧 { color: var(--fire); font-weight: 650; }
.tone-平, .tone-未定 { color: var(--muted); font-weight: 650; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 12px; }
.tabs .btn.small.on { background: var(--ink); color: var(--card); }

/* ---------- 提示、弹窗 ---------- */
#hint {
  position: fixed; left: 18px; bottom: 16px; z-index: 3; font-size: 12.5px; color: var(--muted);
  background: rgba(251, 246, 233, 0.7); padding: 3px 12px; border-radius: 999px; pointer-events: none;
}
#toast {
  position: fixed; left: calc((100vw - var(--panel-w) - 18px) / 2); top: 84px; transform: translate(-50%, -12px); z-index: 6;
  background: var(--ink); color: #fbf3df; padding: 8px 18px; border-radius: 999px; font-weight: 600;
  opacity: 0; transition: opacity 0.25s, transform 0.25s; pointer-events: none; max-width: 80vw; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.ok { background: var(--wood); } #toast.no { background: var(--fire); }

#modal { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; background: rgba(42, 36, 28, 0.45); padding: 20px; }
#modal[hidden] { display: none; }
.sheet {
  width: min(480px, 100%); max-height: 90vh; overflow: auto; background: var(--card); border: 1.5px solid var(--card-edge);
  border-radius: 16px; padding: 26px 28px 22px; text-align: center; box-shadow: 0 30px 60px -20px rgba(40, 25, 5, 0.6);
  animation: rise 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
@keyframes rise { from { transform: translateY(24px) scale(0.96); opacity: 0; } }
.sheet .big-stars { font-size: 44px; letter-spacing: 8px; color: var(--gold); line-height: 1.2; }
.sheet .big-stars .off { color: var(--line); }
.sheet ul { text-align: left; margin: 14px 0 18px; }
.sheet .row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---------- 窄屏：面板变成底部抽屉 ---------- */
@media (max-width: 860px) {
  :root { --panel-w: 100vw; }
  #panel { top: auto; left: 0; right: 0; bottom: 0; width: auto; height: 50vh; border-radius: 16px 16px 0 0; border-width: 1.5px 0 0; }
  #panel-head { padding: 12px 16px 9px; }
  #panel-body { padding: 12px 16px 16px; }
  #panel-foot { padding: 9px 16px calc(10px + env(safe-area-inset-bottom)); }
  h1 { font-size: 22px; }
  #hint, #crumb, .brand-text { display: none; }
  #topbar { padding: 9px 10px; gap: 6px; }
  .ghost { padding: 5px 10px; font-size: 12.5px; }
  .seal { width: 38px; height: 38px; font-size: 16px; }
  #toast { left: 50%; top: 60px; }
}

@media (prefers-reduced-motion: reduce) {
  .sheet { animation: none; }
  .voice.nudge { animation: none; }
  #toast { transition: none; }
}
