:root {
  --bg: #efe6d6;
  --ink: #1c2420;
  --muted: #5c675f;
  --card: #fffdf8;
  --card-2: #f6f1e6;
  --line: #e4d8c4;
  --green: #146b43;
  --green-deep: #0c3b26;
  --green-soft: #e4f5ea;
  --amber: #8a5600;
  --amber-soft: #fff1cc;
  --idle-soft: #eef1ef;
  --honors: #5a39b8;
  --honors-soft: #efeaff;
  --danger: #8d2f2f;
  --shadow: 0 16px 40px rgba(55, 42, 18, 0.08);
  --radius: 22px;
  --top: 72px;
  --font: "Nunito", "Segoe UI", sans-serif;
  --display: "Fraunces", Georgia, serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 1.0625rem;
  line-height: 1.55;
  color: var(--ink);
  background:
    radial-gradient(1000px 420px at -10% -10%, #d9efe0 0%, transparent 60%),
    radial-gradient(800px 360px at 110% -8%, #f6e2b8 0%, transparent 46%),
    var(--bg);
}
body.lesson-open { padding-bottom: 168px; }
img, svg { max-width: 100%; }
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--green-deep); }
h1, h2, h3, h4 { font-family: var(--display); font-weight: 560; line-height: 1.15; letter-spacing: -0.02em; margin: 0; overflow-wrap: anywhere; }
p { margin: 0; }

.skip {
  position: absolute;
  left: 12px;
  top: -40px;
  background: white;
  padding: 8px 12px;
  z-index: 80;
}
.skip:focus { top: 12px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--top);
  padding: 10px 16px;
  background: rgba(255, 253, 248, 0.92);
  border-bottom: 1px solid rgba(228, 216, 196, 0.9);
  backdrop-filter: blur(10px);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
  min-height: 48px;
}
.brand-mark {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
}
.brand-name { display: block; font-family: var(--display); font-size: 1.35rem; line-height: 1; }
.brand-sub { display: block; color: var(--muted); font-size: 0.82rem; font-weight: 700; }
.top-link {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--green-soft);
  text-decoration: none;
  font-weight: 800;
}

.page { width: min(1120px, calc(100% - 28px)); margin: 0 auto; padding: 22px 0 48px; }
.stack { display: grid; gap: 16px; }
.welcome h1 { font-size: clamp(2.1rem, 5vw, 3.4rem); max-width: 14ch; }
.lede { max-width: 62ch; color: var(--muted); font-size: 1.08rem; margin-top: 8px; }
.kicker {
  font-family: var(--font);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--green);
}

.continue {
  background: linear-gradient(165deg, #18764b 0%, #0c3b26 78%);
  color: #f4fff7;
  border-radius: 28px;
  padding: 22px;
  box-shadow: var(--shadow);
}
.continue .kicker { color: #b7ebc8; }
.continue h2 { font-size: clamp(1.7rem, 3vw, 2.3rem); margin: 6px 0; }
.continue p { color: #e5f6ea; max-width: 58ch; }
.continue-meta { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 16px; }
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  font-weight: 800;
  font-size: 0.92rem;
}
.continue .btn-light { background: #fffdf8; color: var(--green-deep); }

.stat-grid, .quick-grid { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.stat, .class-card, .panel, .overview-card, .lesson-card, .chapter-block, .problem, .example, .try-card, .watch {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.stat { padding: 14px; }
.stat strong { display: block; font-size: 1.45rem; font-family: var(--display); font-weight: 560; }
.stat span, .muted { color: var(--muted); }
.bar {
  position: relative;
  height: 10px;
  margin-top: 10px;
  border-radius: 999px;
  background: #ece7dc;
  overflow: hidden;
}
.bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #1d8a56, #146b43);
  border-radius: inherit;
}
.bar.amber > span { background: linear-gradient(90deg, #e0a23a, #b87400); }

.class-card { padding: 18px; display: grid; gap: 10px; }
.class-card h2 { font-size: 1.8rem; }
.citation { color: var(--ink); }
.originality {
  background: var(--card-2);
  border-radius: 14px;
  padding: 10px 12px;
  color: var(--muted);
}

.section-head { display: flex; justify-content: space-between; gap: 12px; align-items: end; }
.section-head h2 { font-size: 1.55rem; }

.strip {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(210px, 78%);
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 6px;
  scroll-snap-type: x mandatory;
}
.strip-card {
  scroll-snap-align: start;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 148px;
  padding: 14px;
  text-decoration: none;
  color: inherit;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
}
.strip-card:hover, .status-link:hover, .tab:hover, .lesson-title:hover { transform: translateY(-1px); }
.strip-num {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--green);
  color: white;
  font-weight: 800;
}
.strip-card small, .note { color: var(--muted); font-weight: 700; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; }
.chapter-block { padding: 0; overflow: hidden; }
.chapter-block > summary {
  list-style: none;
  cursor: pointer;
  display: grid;
  gap: 4px;
  padding: 14px 16px;
  min-height: 72px;
}
.chapter-block > summary::-webkit-details-marker { display: none; }
.chapter-block[open] > summary { border-bottom: 1px solid var(--line); }
.summary-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.chapter-lessons { display: grid; gap: 10px; padding: 12px; }
.lesson-card { padding: 12px; box-shadow: none; }
.lesson-title {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  text-decoration: none;
  color: inherit;
  font-weight: 800;
  min-height: 44px;
}
.lesson-id {
  font-variant-numeric: tabular-nums;
  color: var(--green);
}
.chip-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.status-link, .tab, .quick-grid a {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  min-height: 56px;
  padding: 8px 12px;
  border-radius: 16px;
  text-decoration: none;
  border: 1px solid var(--line);
  background: var(--idle-soft);
  color: var(--ink);
  font-weight: 800;
}
.status-link small, .tab small, .quick-grid a small {
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.status-link.is-completed, .tab.is-completed, .quick-grid a.is-completed { background: var(--green-soft); border-color: #b7dfc6; }
.status-link.is-in_progress, .tab.is-in_progress, .quick-grid a.is-in_progress { background: var(--amber-soft); border-color: #efd59a; }
.tab.is-active { background: var(--green-deep); color: white; border-color: var(--green-deep); }
.tab.is-active small { color: #c9ecd6; }
.honors {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  background: var(--honors-soft);
  color: var(--honors);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.volume-note {
  font-weight: 800;
  color: var(--amber);
  font-size: 0.85rem;
}

.crumb { display: flex; flex-wrap: wrap; gap: 6px; color: var(--muted); font-weight: 800; font-size: 0.92rem; }
.crumb a { text-decoration: none; }
.lesson-head h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); margin: 4px 0; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.panel, .overview-card, .example, .try-card, .watch, .problem { padding: 16px; }
.overview-card { display: grid; gap: 8px; background: #f3faf5; }
.idea, .steps { display: grid; gap: 8px; }
.steps ol, .watch ul, .arc { margin: 0; padding-left: 1.2rem; display: grid; gap: 8px; }
.example { display: grid; gap: 8px; border-left: 6px solid var(--green); }
.example h3, .problem h3, .try-card h3 { font-size: 1.25rem; }
.work-line { margin: 0; padding-left: 1.1rem; }
.prompt, .keybox p, .history li { white-space: pre-wrap; }
.checkline { color: var(--green-deep); font-weight: 800; }
.watch { background: #fff8ee; }
.keybox {
  margin-top: 10px;
  background: var(--green-soft);
  border-radius: 14px;
  padding: 10px 12px;
  display: grid;
  gap: 4px;
}
label.field { display: grid; gap: 6px; font-weight: 800; }
textarea, input[type="text"] {
  width: 100%;
  border: 2px solid #ddcfb8;
  background: white;
  border-radius: 14px;
  padding: 12px;
  font-size: 1.05rem;
  line-height: 1.45;
}
textarea { min-height: 88px; resize: vertical; }
textarea.notebook { min-height: 280px; }
textarea:focus, input:focus { outline: 3px solid #e0a23a; border-color: #e0a23a; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 10px 16px;
  border-radius: 14px;
  border: 2px solid transparent;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
  background: var(--card-2);
}
.btn-primary { background: var(--green); color: white; }
.btn-secondary { background: white; color: var(--green-deep); border-color: var(--green); }
.btn-light { background: white; color: var(--green-deep); }
.btn-danger { background: white; color: var(--danger); border-color: #e4b4b4; }
.btn:disabled { opacity: 0.6; cursor: default; }

.lesson-actions {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: rgba(255, 253, 248, 0.96);
  border-top: 1px solid var(--line);
  box-shadow: 0 -10px 30px rgba(55, 42, 18, 0.08);
}
.lesson-actions-inner { width: min(1120px, 100%); margin: 0 auto; display: grid; gap: 8px; }
.action-status { font-weight: 800; }
.action-buttons, .confirm-row { display: flex; gap: 8px; }
.action-buttons .btn, .confirm-row .btn { flex: 1; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  z-index: 50;
  width: min(520px, calc(100% - 24px));
  background: var(--ink);
  color: white;
  border-radius: 16px;
  padding: 12px 14px;
  font-weight: 800;
  box-shadow: var(--shadow);
}
.modal-back {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(20, 28, 24, 0.46);
  display: grid;
  place-items: end center;
  padding: 16px;
}
.modal {
  width: min(520px, 100%);
  background: var(--card);
  border-radius: 24px;
  padding: 18px;
  display: grid;
  gap: 10px;
  margin-bottom: 8px;
}
.modal h2 { font-size: 1.7rem; }
.footer { color: var(--muted); display: grid; gap: 8px; padding-top: 8px; }
.history { color: var(--muted); }
.completion-banner {
  background: var(--green-soft);
  border-radius: 14px;
  padding: 10px 12px;
  font-weight: 800;
}
.revision-banner {
  background: var(--amber-soft);
  border-radius: 14px;
  padding: 10px 12px;
  font-weight: 800;
}

body.lesson-open .toast { bottom: 124px; }
@media (max-width: 560px) {
  body.lesson-open { padding-bottom: 230px; }
  .action-buttons, .confirm-row { flex-direction: column; }
  body.lesson-open .toast { bottom: 214px; }
}
@media (min-width: 720px) {
  .page { width: min(1120px, calc(100% - 48px)); }
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .quick-grid, .tabs, .chip-row { grid-template-columns: repeat(4, 1fr); }
  .strip { grid-auto-columns: 230px; }
  .modal-back { place-items: center; }
  body.lesson-open { padding-bottom: 132px; }
}
@media (min-width: 960px) {
  .home-split { display: grid; grid-template-columns: 1.3fr 0.7fr; gap: 16px; align-items: start; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .strip-card, .status-link, .tab, .lesson-title { transition: none; }
}
:focus-visible { outline: 3px solid #e0a23a; outline-offset: 2px; }
