:root {
  --paper: #f8f3e8;
  --paper-2: #eee1ca;
  --ink: #171310;
  --muted: #71685c;
  --line: rgba(42, 30, 22, .14);
  --red: #a61517;
  --red-2: #d33a2f;
  --gold: #b88431;
  --green: #26746b;
  --panel: rgba(255, 252, 245, .92);
  --shadow: 0 22px 70px rgba(50, 29, 15, .14);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  color: var(--ink);
  background:
    linear-gradient(120deg, rgba(255,255,255,.78), transparent 38%),
    radial-gradient(circle at 78% 8%, rgba(166,21,23,.12), transparent 28%),
    linear-gradient(145deg, #fffaf0 0%, var(--paper) 46%, var(--paper-2) 100%);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .18;
  background-image:
    linear-gradient(rgba(35, 26, 18, .09) 1px, transparent 1px),
    linear-gradient(90deg, rgba(35, 26, 18, .05) 1px, transparent 1px);
  background-size: 44px 44px;
}

.rail {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  padding: 24px 20px;
  color: #fff9ef;
  background:
    linear-gradient(180deg, rgba(24,18,15,.98), rgba(57,22,18,.95)),
    #1a1512;
  border-right: 1px solid rgba(255,255,255,.1);
}

.brand { display: grid; gap: 7px; margin-bottom: 18px; }
.brand span {
  width: fit-content;
  padding: 6px 10px;
  background: var(--red);
  color: white;
  font-size: 12px;
  font-weight: 900;
}
.brand strong { font-size: 31px; line-height: 1; letter-spacing: 0; }
.brand small { color: rgba(255,249,239,.68); font-size: 14px; }

.cover {
  display: block;
  width: 100%;
  aspect-ratio: 1055 / 1491;
  object-fit: cover;
  border: 1px solid rgba(255,249,239,.16);
  box-shadow: 0 18px 48px rgba(0,0,0,.42);
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 18px 0;
}
.stats div {
  min-height: 62px;
  display: grid;
  align-content: center;
  gap: 3px;
  padding: 9px;
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.12);
}
.stats strong { color: #ffcf79; font-size: 24px; line-height: 1; }
.stats span { color: rgba(255,249,239,.66); font-size: 12px; }

nav { display: grid; gap: 8px; padding-bottom: 18px; }
button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  color: inherit;
  font: inherit;
  letter-spacing: 0;
}
nav button {
  width: 100%;
  text-align: left;
  color: rgba(255,249,239,.8);
  background: rgba(255,255,255,.07);
}
nav button.active {
  color: white;
  background: var(--red);
  border-color: rgba(255,255,255,.2);
  font-weight: 900;
}
button:active { transform: translateY(1px); }

main {
  position: relative;
  min-width: 0;
  padding: 28px clamp(18px, 3vw, 44px) 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 18px;
  padding: clamp(24px, 3vw, 38px);
  background:
    linear-gradient(110deg, rgba(255,252,245,.95), rgba(255,252,245,.72)),
    linear-gradient(90deg, rgba(166,21,23,.12), transparent 58%);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.eyebrow { margin: 0 0 10px; color: var(--green); font-size: 13px; font-weight: 900; }
h1 { margin: 0; font-size: clamp(42px, 6vw, 86px); line-height: 1; letter-spacing: 0; }
.top-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.top-actions button, #saveNoteBtn {
  background: var(--red);
  color: white;
  border-color: var(--red);
  font-weight: 900;
}
.top-actions .ghost {
  background: transparent;
  color: var(--ink);
  border-color: rgba(23,19,16,.22);
}

.dashboard {
  display: grid;
  grid-template-columns: minmax(320px, 1.1fr) minmax(320px, .9fr);
  gap: 16px;
}

.panel {
  min-width: 0;
  padding: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 14px 42px rgba(50,29,15,.08);
}
.path-panel, .toolbox-panel { grid-column: span 2; }
.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
  color: var(--green);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}
.panel-head strong {
  max-width: 52%;
  color: var(--red);
  text-align: right;
  font-size: 12px;
}
h2 { margin: 0 0 10px; font-size: 25px; line-height: 1.22; letter-spacing: 0; }
.muted { color: var(--muted); line-height: 1.72; }

.unit-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 10px;
}
.unit-list button {
  min-height: 92px;
  display: grid;
  align-content: start;
  gap: 7px;
  text-align: left;
  background: #fffaf2;
}
.unit-list button.selected {
  color: white;
  background: linear-gradient(135deg, var(--red), #6d1513);
  border-color: var(--red);
}
.unit-list strong { font-size: 15px; line-height: 1.35; }
.unit-list span { color: currentColor; opacity: .72; font-size: 13px; line-height: 1.45; }

.unit-visual {
  width: 100%;
  max-height: 260px;
  object-fit: cover;
  margin-bottom: 14px;
  border: 1px solid var(--line);
}
.hook {
  margin: 0 0 14px;
  padding: 14px;
  background: rgba(166,21,23,.08);
  border-left: 4px solid var(--red);
  line-height: 1.75;
}
.terms { display: flex; flex-wrap: wrap; gap: 7px; margin: 12px 0; }
.terms span {
  padding: 6px 9px;
  color: var(--red);
  background: rgba(166,21,23,.08);
  border: 1px solid rgba(166,21,23,.16);
  font-size: 12px;
  font-weight: 800;
}

.sliders { display: grid; gap: 12px; margin-top: 14px; }
.slider label {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
  font-weight: 800;
}
input[type="range"] { width: 100%; accent-color: var(--red); }
.score-row {
  display: grid;
  grid-template-columns: 124px 1fr;
  gap: 18px;
  align-items: center;
  margin-top: 18px;
}
.score-ring {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  align-content: center;
  border: 8px solid rgba(166,21,23,.16);
  border-top-color: var(--red);
  border-radius: 50%;
  background: #fffaf2;
}
.score-ring strong { font-size: 36px; line-height: 1; }
.score-ring span { color: var(--muted); font-size: 12px; }
.result-text { margin: 0 0 8px; font-size: 18px; font-weight: 900; line-height: 1.5; }

.choice-list { display: grid; gap: 9px; margin-top: 12px; }
.choice {
  width: 100%;
  min-height: 48px;
  text-align: left;
  background: #fffaf2;
}
.choice.correct { color: white; background: var(--green); border-color: var(--green); }
.choice.wrong { color: white; background: var(--red); border-color: var(--red); }
.explanation { margin-top: 12px; padding: 13px; background: rgba(38,116,107,.08); line-height: 1.72; }

.mastery {
  height: 10px;
  background: rgba(23,19,16,.1);
  overflow: hidden;
  margin: 12px 0 14px;
}
.mastery i { display: block; width: 0; height: 100%; background: linear-gradient(90deg, var(--red), var(--gold)); }
.checks { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin-bottom: 12px; }
.checks label {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px;
  background: #fffaf2;
  border: 1px solid var(--line);
}
textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid rgba(23,19,16,.18);
  border-radius: 8px;
  padding: 12px;
  color: var(--ink);
  background: #fffdf8;
  font: inherit;
  line-height: 1.6;
}
#saveNoteBtn { width: 100%; margin-top: 10px; }

.appendix-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
}
.appendix-card {
  min-height: 168px;
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  background: #fffaf2;
}
.appendix-card img {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  border: 1px solid rgba(23,19,16,.1);
}
.appendix-card strong { font-size: 13px; line-height: 1.35; }

footer {
  margin-top: 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
}

@media (max-width: 980px) {
  body { display: block; }
  .rail {
    position: relative;
    height: auto;
    display: grid;
    grid-template-columns: 106px 1fr;
    gap: 14px;
    padding: 16px;
  }
  .brand { grid-column: 2; margin: 0; align-content: center; }
  .brand strong { font-size: 25px; }
  .cover { grid-row: 1 / span 2; }
  .stats { grid-column: 1 / -1; margin: 0; }
  nav { grid-column: 1 / -1; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  main { padding: 16px; }
  .topbar { display: grid; padding: 20px; }
  .top-actions { justify-content: start; }
  .dashboard, .path-panel, .toolbox-panel { display: grid; grid-template-columns: 1fr; }
  .path-panel, .toolbox-panel { grid-column: auto; }
}

@media (max-width: 560px) {
  .rail { grid-template-columns: 86px 1fr; }
  nav { grid-template-columns: 1fr; }
  h1 { font-size: 40px; }
  .unit-list, .appendix-grid, .checks { grid-template-columns: 1fr; }
  .score-row { grid-template-columns: 1fr; }
  .score-ring { width: 124px; }
  .panel { padding: 18px; }
}
