:root {
  --paper: #f5f0e2;
  --paper-deep: #e5d8bd;
  --ink: #17140f;
  --ink-soft: #352f25;
  --muted: #7c725f;
  --line: rgba(42, 34, 24, .16);
  --gold: #d8a32c;
  --gold-deep: #a66d12;
  --teal: #2d837b;
  --red: #90443a;
  --panel: rgba(255, 252, 242, .86);
  --panel-solid: #fffaf0;
  --shadow: 0 24px 70px rgba(37, 28, 13, .16);
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 332px minmax(0, 1fr);
  background:
    linear-gradient(115deg, rgba(255, 255, 255, .45), transparent 34%),
    radial-gradient(circle at 26% 12%, rgba(216, 163, 44, .22), transparent 30%),
    linear-gradient(135deg, #fbf6e8 0%, var(--paper) 48%, #e8d7ad 100%);
  color: var(--ink);
  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: .22;
  background-image:
    linear-gradient(rgba(23, 20, 15, .08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 20, 15, .05) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(90deg, #000, transparent 72%);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  border-right: 1px solid rgba(23, 20, 15, .18);
  padding: 26px 22px;
  background:
    linear-gradient(180deg, rgba(25, 22, 17, .95), rgba(38, 30, 20, .92)),
    #191611;
  color: #fffaf0;
}

.brand {
  display: grid;
  gap: 8px;
  margin-bottom: 20px;
}

.brand span {
  width: fit-content;
  padding: 6px 10px;
  background: var(--gold);
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
}

.brand strong {
  display: block;
  font-size: 30px;
  line-height: 1.06;
  letter-spacing: 0;
}

.cover-frame {
  margin: 0;
  padding: 10px;
  border: 1px solid rgba(255, 250, 240, .18);
  background: rgba(255, 250, 240, .06);
  box-shadow: 0 18px 48px rgba(0, 0, 0, .34);
}

.cover-frame img {
  display: block;
  width: 100%;
  aspect-ratio: 1055 / 1491;
  object-fit: cover;
}

.side-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 18px 0 20px;
}

.side-stats div {
  min-height: 62px;
  display: grid;
  align-content: center;
  gap: 2px;
  border: 1px solid rgba(255, 250, 240, .16);
  background: rgba(255, 250, 240, .07);
  padding: 9px;
}

.side-stats strong {
  font-size: 24px;
  line-height: 1;
  color: var(--gold);
}

.side-stats span {
  color: rgba(255, 250, 240, .68);
  font-size: 12px;
}

nav {
  display: grid;
  gap: 8px;
  padding-bottom: 12px;
}

nav button,
.chapter-list button,
.hero-actions button,
.hero-actions a,
.choice {
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(216, 163, 44, .28);
}

nav button {
  background: rgba(255, 250, 240, .08);
  color: rgba(255, 250, 240, .78);
  min-height: 42px;
  padding: 10px 12px;
  text-align: left;
}

nav button.active {
  background: var(--gold);
  color: var(--ink);
  border-color: var(--gold);
  font-weight: 800;
}

nav button:active,
.chapter-list button:active,
.hero-actions button:active,
.choice:active {
  transform: translateY(1px);
}

main {
  min-width: 0;
  padding: 28px clamp(20px, 3.5vw, 48px) 24px;
}

.hero {
  position: relative;
  min-height: 318px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(190px, 280px);
  gap: clamp(24px, 4vw, 52px);
  align-items: center;
  margin-bottom: 18px;
  padding: clamp(24px, 4vw, 44px);
  overflow: hidden;
  border: 1px solid rgba(23, 20, 15, .12);
  background:
    linear-gradient(110deg, rgba(255, 250, 240, .94), rgba(255, 250, 240, .68)),
    linear-gradient(90deg, rgba(216, 163, 44, .22), transparent 54%);
  box-shadow: var(--shadow);
}

.hero::before {
  content: "";
  position: absolute;
  left: clamp(24px, 4vw, 44px);
  top: 32px;
  width: 122px;
  height: 12px;
  background: var(--gold);
}

.hero-copy,
.hero-book {
  position: relative;
  z-index: 1;
}

.eyebrow,
.section-kicker {
  margin: 0;
  color: var(--teal);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0;
}

h1 {
  margin: 26px 0 16px;
  max-width: 760px;
  line-height: .98;
  letter-spacing: 0;
}

h1 span {
  display: block;
  width: fit-content;
  margin-bottom: 12px;
  padding: 8px 12px 10px;
  background: var(--gold);
  color: var(--ink);
  font-size: clamp(28px, 4.6vw, 62px);
  font-weight: 950;
}

h1 strong {
  display: block;
  color: var(--ink);
  font-size: clamp(38px, 6.8vw, 96px);
  font-weight: 950;
}

.lede {
  max-width: 720px;
  margin: 0;
  color: var(--ink-soft);
  font-size: 18px;
  line-height: 1.72;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 24px;
}

.hero-actions button,
.hero-actions a {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 11px 16px;
  text-decoration: none;
}

.hero-actions button {
  background: var(--ink);
  color: #fffaf0;
  border-color: var(--ink);
}

.hero-actions a {
  background: transparent;
  color: var(--ink);
  border-color: rgba(23, 20, 15, .22);
}

.hero-book {
  justify-self: center;
  width: min(100%, 236px);
}

.hero-book img {
  position: relative;
  z-index: 2;
  display: block;
  width: 100%;
  aspect-ratio: 1055 / 1491;
  object-fit: cover;
  box-shadow: 0 28px 64px rgba(37, 28, 13, .28);
}

.book-shadow {
  position: absolute;
  z-index: 1;
  inset: 9% -12% 7% 12%;
  background: rgba(23, 20, 15, .16);
  transform: skewY(-5deg);
}

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1.22fr) minmax(310px, .78fr);
  gap: 16px;
}

.panel {
  position: relative;
  min-width: 0;
  padding: 20px;
  border: 1px solid rgba(23, 20, 15, .12);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 38px rgba(37, 28, 13, .08);
  backdrop-filter: blur(14px);
  scroll-margin-top: 18px;
}

.wide { grid-row: span 3; }

h2 {
  margin: 4px 0 12px;
  color: var(--ink);
  font-size: 23px;
  line-height: 1.22;
  letter-spacing: 0;
}

#pathMeta,
.muted,
footer,
#scoreText {
  color: var(--muted);
  line-height: 1.65;
}

.chapter-list {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.chapter-list button {
  width: 100%;
  min-height: 74px;
  padding: 13px 14px;
  background: rgba(255, 255, 255, .62);
  color: var(--ink);
  text-align: left;
  transition: transform .16s ease, border-color .16s ease, background .16s ease;
}

.chapter-list button:hover {
  transform: translateY(-1px);
  border-color: rgba(216, 163, 44, .65);
  background: #fffdf7;
}

.chapter-list button.selected {
  border-color: var(--gold-deep);
  background: #fff3cf;
  box-shadow: inset 4px 0 0 var(--gold);
}

.chapter-list strong {
  display: block;
  margin-bottom: 5px;
  font-size: 15px;
  line-height: 1.34;
}

.hook {
  margin: 0 0 14px;
  padding: 14px 15px;
  border-left: 5px solid var(--gold);
  background: #f7edd3;
  color: var(--ink-soft);
  line-height: 1.7;
}

.terms {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0;
}

.terms span {
  border: 1px solid rgba(45, 131, 123, .22);
  border-radius: 999px;
  padding: 4px 8px;
  background: rgba(45, 131, 123, .08);
  color: var(--teal);
  font-size: 12px;
  font-weight: 700;
}

label {
  display: grid;
  gap: 6px;
  margin: 14px 0;
  color: var(--muted);
  font-size: 14px;
}

label span {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--ink);
  font-weight: 800;
}

label span strong {
  min-width: 34px;
  color: var(--gold-deep);
  text-align: right;
}

label small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--gold-deep);
}

.score {
  margin: 18px 0 8px;
  padding: 17px;
  border: 1px solid rgba(216, 163, 44, .42);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(216, 163, 44, .24), rgba(255, 250, 240, .76));
}

.score span {
  display: block;
  color: var(--red);
  font-size: 46px;
  font-weight: 950;
  line-height: 1;
}

.score small {
  color: var(--muted);
  font-weight: 700;
}

.sim-intro {
  margin: 0 0 12px;
  color: var(--ink-soft);
  line-height: 1.68;
}

.sim-steps {
  display: grid;
  gap: 7px;
  margin: 0 0 16px;
  padding: 13px 15px 13px 34px;
  border: 1px solid rgba(216, 163, 44, .28);
  border-radius: 8px;
  background: rgba(247, 237, 211, .72);
  color: var(--ink-soft);
  line-height: 1.55;
}

.sim-output {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid rgba(45, 131, 123, .22);
  border-radius: 8px;
  background: rgba(45, 131, 123, .08);
}

.sim-output strong {
  color: var(--teal);
}

.sim-output p {
  margin: 6px 0 0;
  color: var(--ink-soft);
  line-height: 1.58;
}

.mastery-card {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid rgba(216, 163, 44, .36);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(216, 163, 44, .18), rgba(255, 250, 240, .8));
}

.mastery-card div:first-child {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

.mastery-card span {
  color: var(--muted);
  font-weight: 800;
}

.mastery-card strong {
  color: var(--red);
  font-size: 30px;
  line-height: 1;
}

.mastery-bar {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(23, 20, 15, .12);
}

.mastery-bar i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--gold), var(--teal));
  transition: width .24s ease;
}

.challenge-step {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  padding: 13px;
  border: 1px solid rgba(23, 20, 15, .1);
  border-radius: 8px;
  background: rgba(255, 255, 255, .52);
}

.challenge-step strong {
  color: var(--ink);
}

.challenge-step p {
  margin: 0;
  color: var(--muted);
  line-height: 1.58;
}

.prediction-options {
  display: grid;
  gap: 8px;
}

.prediction-choice,
.mini-action {
  min-height: 42px;
  border: 1px solid rgba(23, 20, 15, .14);
  border-radius: 8px;
  background: #fffaf0;
  color: var(--ink);
  padding: 10px 12px;
  text-align: left;
  cursor: pointer;
  font: inherit;
  touch-action: manipulation;
}

.prediction-choice.picked,
.mini-action:active {
  border-color: var(--gold-deep);
  background: #fff0c6;
}

.mini-action {
  width: fit-content;
  min-width: 118px;
  font-weight: 800;
}

textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid rgba(23, 20, 15, .16);
  border-radius: 8px;
  background: #fffdf7;
  color: var(--ink);
  padding: 11px;
  font: inherit;
  line-height: 1.55;
}

textarea:focus {
  outline: 2px solid rgba(216, 163, 44, .36);
  border-color: var(--gold-deep);
}

.step-ledger {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 12px;
}

.step-ledger span {
  padding: 5px 8px;
  border: 1px solid rgba(23, 20, 15, .12);
  border-radius: 999px;
  background: rgba(255, 255, 255, .52);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.step-ledger span.done {
  border-color: rgba(45, 131, 123, .28);
  background: rgba(45, 131, 123, .1);
  color: var(--teal);
}

.choice {
  display: block;
  width: 100%;
  margin: 8px 0;
  padding: 11px;
  background: rgba(255, 255, 255, .7);
  color: var(--ink);
  text-align: left;
}

.choice.correct {
  border-color: var(--teal);
  background: #e8f4f1;
}

.choice.wrong {
  border-color: var(--red);
  background: #f7e9e5;
}

.choice.correct,
.choice.wrong {
  font-weight: 800;
}

footer {
  margin-top: 18px;
  font-size: 13px;
}

@media (max-width: 1080px) {
  body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    height: auto;
    display: grid;
    grid-template-columns: minmax(180px, 240px) 1fr;
    gap: 18px;
    border-right: 0;
    border-bottom: 1px solid rgba(23, 20, 15, .18);
  }

  .brand,
  .side-stats,
  nav {
    grid-column: 2;
  }

  .cover-frame {
    grid-row: 1 / span 3;
  }

  nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  main {
    padding: 18px;
  }

  .sidebar,
  .hero,
  .grid {
    grid-template-columns: 1fr;
  }

  .cover-frame,
  .brand,
  .side-stats,
  nav {
    grid-column: auto;
  }

  .cover-frame {
    max-width: 240px;
  }

  nav {
    grid-template-columns: 1fr;
  }

  .hero-book {
    display: none;
  }

  h1 {
    margin-top: 24px;
  }

  h1 strong {
    font-size: 46px;
  }

  .wide {
    grid-row: auto;
  }
}
