:root {
  --cream: #fff6ee;
  --paper: #fffbf7;
  --ink: #323232;
  --muted: #6f6a66;
  --navy: #304254;
  --blue: #7794b6;
  --sky: #dffaff;
  --line: #eadfd4;
  --soft: #f6ebe0;
  --radius: 14px;
  --serif: 'Cormorant Garamond', Georgia, serif;
  --sans: 'Inter', system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--cream); color: var(--ink); font: 16px/1.7 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: var(--navy); }
button { font: inherit; cursor: pointer; }
h1, h2, h3, h4 { font-family: var(--serif); color: var(--navy); line-height: 1.15; font-weight: 600; }

/* ---------- login / auth ---------- */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.card { width: 100%; max-width: 420px; background: var(--paper); border: 1px solid var(--line); border-radius: 22px; padding: 36px 28px; text-align: center; box-shadow: 0 20px 60px -30px rgba(48, 66, 84, .35); }
.brand { font-family: var(--serif); letter-spacing: .32em; font-size: 15px; color: var(--navy); margin: 0 0 22px; }
.card h1 { font-size: 34px; margin: 0 0 8px; }
.card p { color: var(--muted); margin: 0 0 22px; }
.field { width: 100%; padding: 13px 16px; border-radius: 999px; border: 1px solid var(--line); background: #fff; font: inherit; color: var(--ink); }
.field:focus { outline: 2px solid var(--blue); outline-offset: 1px; }
.btn { display: inline-block; border: 0; background: var(--navy); color: var(--cream); padding: 12px 24px; border-radius: 999px; text-decoration: none; font-weight: 500; }
.btn:hover { background: #22303e; }
.btn.block { width: 100%; margin-top: 12px; }
.btn.ghost { background: transparent; color: var(--navy); border: 1px solid var(--line); }
.btn.ghost:hover { background: var(--soft); }
.btn[disabled] { opacity: .6; cursor: default; }
.fine { font-size: 13px; color: var(--muted); margin-top: 18px !important; margin-bottom: 0 !important; }
.msg { font-size: 14px; margin-top: 14px; min-height: 1em; }
.msg.err { color: #a2413a; }

/* ---------- app shell ---------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 14px; padding: 12px 20px; background: rgba(255, 246, 238, .92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.topbar .brand { margin: 0; font-size: 13px; white-space: nowrap; }
.topbar .spacer { flex: 1; }
.menu-btn { display: none; background: none; border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; color: var(--navy); }
.progress-pill { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 10px; }
.bar { width: 120px; height: 6px; background: var(--soft); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--blue); width: 0; transition: width .4s; }
.link-btn { background: none; border: 0; color: var(--muted); font-size: 13px; text-decoration: underline; padding: 0; }

.shell { display: grid; grid-template-columns: 300px minmax(0, 1fr); min-height: calc(100vh - 57px); }
.sidebar { border-right: 1px solid var(--line); padding: 18px 14px 60px; position: sticky; top: 57px; height: calc(100vh - 57px); overflow-y: auto; background: var(--cream); }
.nav-section { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); margin: 22px 10px 6px; }
.nav-section:first-child { margin-top: 4px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; color: var(--ink); text-decoration: none; font-size: 14.5px; line-height: 1.35; }
.nav-item:hover { background: var(--soft); }
.nav-item.active { background: var(--navy); color: var(--cream); }
.nav-item .dot { flex: 0 0 18px; height: 18px; border-radius: 50%; border: 1.5px solid var(--line); display: grid; place-items: center; font-size: 11px; }
.nav-item.done .dot { background: var(--blue); border-color: var(--blue); color: #fff; }
.nav-item.active .dot { border-color: rgba(255, 255, 255, .5); }
.nav-item .label { flex: 1; }
.badge { font-size: 10px; letter-spacing: .08em; text-transform: uppercase; padding: 2px 7px; border-radius: 99px; background: var(--soft); color: var(--muted); white-space: nowrap; }
.badge.vip { background: var(--sky); color: var(--navy); }
.nav-item.active .badge { background: rgba(255, 255, 255, .15); color: var(--cream); }

.main { position: relative; padding: 40px 24px 120px; }
.lesson-wrap { max-width: 720px; margin: 0 auto; position: relative; }
.eyebrow { font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--blue); margin-bottom: 6px; }
.lesson-wrap > h1, .lesson-preview > h1 { font-size: clamp(34px, 5vw, 48px); margin: 0 0 18px; }
.toc { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px; margin: 0 0 30px; font-size: 14px; }
.toc summary { cursor: pointer; color: var(--navy); font-weight: 500; }
.toc ol { margin: 10px 0 0; padding-left: 20px; }
.toc a { color: var(--ink); text-decoration: none; }
.toc a:hover { text-decoration: underline; }

/* ---------- lesson content ---------- */
.lesson { font-size: 17px; }
.lesson h2 { font-size: 30px; margin: 46px 0 12px; scroll-margin-top: 80px; }
.lesson h3 { font-size: 23px; margin: 30px 0 8px; scroll-margin-top: 80px; }
.lesson h4 { font-size: 19px; margin: 24px 0 6px; }
.lesson p { margin: 0 0 16px; }
.lesson ul, .lesson ol { padding-left: 22px; margin: 0 0 18px; }
.lesson li { margin-bottom: 6px; }
.lesson img { max-width: 100%; border-radius: var(--radius); }
.lesson img.float-right { float: right; width: 42%; max-width: 300px; margin: 6px 0 16px 26px; box-shadow: 0 16px 36px -24px rgba(48, 66, 84, .6); }
@media (max-width: 600px) { .lesson img.float-right { float: none; width: 100%; max-width: none; margin: 0 0 18px; } }
.lesson h2 { clear: both; }
.figs { display: flex; flex-wrap: wrap; gap: 14px; margin: 4px 0 22px; }
.figs img { flex: 1 1 220px; min-width: 0; max-width: 100%; height: auto; object-fit: contain; background: #fff; border: 1px solid var(--line); padding: 10px; box-shadow: 0 12px 30px -22px rgba(48, 66, 84, .5); }
.figs:has(img:only-child) img { flex: 0 1 460px; }
.lesson code { background: var(--soft); padding: 1px 6px; border-radius: 6px; font-size: .9em; }
.lesson .lede { font-size: 18px; color: var(--muted); }
.callout { background: var(--sky); border-radius: var(--radius); padding: 14px 18px; margin: 0 0 20px; color: var(--navy); }
.callout p:last-child { margin-bottom: 0; }

.prompt { position: relative; background: var(--paper); border: 1px solid var(--line); border-left: 4px solid var(--blue); border-radius: var(--radius); padding: 16px 18px; margin: 0 0 22px; scroll-margin-top: 80px; }
.prompt-title { font-family: var(--serif); font-size: 19px; color: var(--navy); font-weight: 600; margin: 0 70px 8px 0; }
.prompt-title a { color: inherit; text-decoration: none; }
.prompt-title a:hover { text-decoration: underline; }
.prompt pre { margin: 0; white-space: pre-wrap; word-wrap: break-word; font: 14.5px/1.65 var(--sans); color: var(--ink); }
.prompt .copy { position: absolute; top: 12px; right: 12px; background: var(--navy); color: var(--cream); border: 0; border-radius: 99px; font-size: 12px; padding: 5px 13px; }
.prompt:not(:has(.prompt-title)) pre { padding-right: 62px; }
.prompt.flash { animation: flash 1.6s ease; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 4px var(--sky); } 100% { box-shadow: none; } }

.checklist { list-style: none; padding: 0 !important; }
.checklist li { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
.checklist label { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; }
.checklist input { margin-top: 6px; width: 17px; height: 17px; accent-color: var(--navy); flex: 0 0 auto; }
.checklist input:checked + span { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--blue); }

.lesson-foot { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: center; border-top: 1px solid var(--line); margin-top: 50px; padding-top: 24px; }
.lesson-foot .btn { min-width: 150px; text-align: center; }

.soon, .locked { text-align: center; background: var(--paper); border: 1px dashed var(--line); border-radius: 22px; padding: 34px 24px; margin-bottom: 30px; }
.soon h2, .locked h2 { margin-top: 0; font-size: 28px; }
.soon p, .locked p { color: var(--muted); }

/* screenshot deterrent: the student's email, faint, across the lesson */
.watermark { position: absolute; inset: 0; pointer-events: none; z-index: 5; background-repeat: repeat; opacity: .07; }

.loading { color: var(--muted); text-align: center; padding: 80px 0; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .menu-btn { display: inline-block; }
  .sidebar { position: fixed; top: 57px; left: 0; width: min(320px, 88vw); z-index: 30; transform: translateX(-102%); transition: transform .25s; box-shadow: 10px 0 40px -20px rgba(0, 0, 0, .3); }
  .sidebar.open { transform: none; }
  .bar { width: 60px; }
  .topbar { padding: 10px 16px; gap: 10px; }
  .topbar .brand { font-size: 11px; letter-spacing: .2em; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .main { padding: 28px 16px 100px; }
  .lesson { font-size: 16.5px; }
}
@media (max-width: 440px) { .topbar .brand { display: none; } }
@media print { .lesson, .main { display: none !important; } }

/* local preview only */
.preview-banner { background: var(--navy); color: var(--cream); text-align: center; font-size: 13px; padding: 8px 16px; }
.lesson-preview { max-width: 720px; margin: 0 auto 90px; }

/* admin */
.admin { max-width: 980px; margin: 0 auto; padding: 30px 16px 80px; }
.admin table { width: 100%; border-collapse: collapse; font-size: 14px; background: var(--paper); border-radius: var(--radius); overflow: hidden; }
.admin th, .admin td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); }
.admin th { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.admin .row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 0 0 18px; }
.admin .row .field { width: auto; flex: 1; min-width: 200px; border-radius: 12px; }
.admin select.field { flex: 0 0 auto; min-width: 0; }
.admin .panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 22px; }
.table-scroll { overflow-x: auto; }

/* ---------- worksheets ---------- */
.worksheet { background: var(--paper); border: 1px solid var(--line); border-radius: 20px; margin: 10px 0 30px; overflow: hidden; box-shadow: 0 18px 40px -32px rgba(48, 66, 84, .55); scroll-margin-top: 80px; }
.ws-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; background: var(--sky); flex-wrap: wrap; }
.ws-head h3 { margin: 0; font-size: 24px; flex: 1; min-width: 180px; }
.ws-tag { font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; background: var(--navy); color: var(--cream); padding: 3px 9px; border-radius: 99px; }
.ws-count { font-size: 13px; color: var(--navy); white-space: nowrap; }
.worksheet.complete .ws-count::after { content: ' ✓'; }
.ws-body { padding: 20px 20px 4px; }
.ws-body > p { font-size: 16px; }
.ws-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); }
.ws-foot .btn { padding: 8px 16px; font-size: 14px; }
.ws-saved { font-size: 12.5px; color: var(--muted); margin-left: auto; }
.q { display: block; margin: 0 0 20px; }
.f-label { display: block; font-weight: 600; font-size: 15.5px; margin-bottom: 7px; color: var(--ink); line-height: 1.45; }
.q input[type=text], .q input[type=date], .q textarea { width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 11px 13px; font: 15.5px/1.55 var(--sans); background: #fff; color: var(--ink); }
.q textarea { resize: vertical; min-height: 96px; }
.q input:focus, .q textarea:focus { outline: 2px solid var(--blue); outline-offset: 0; border-color: transparent; }
.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 99px; padding: 7px 15px; font-size: 14.5px; }
.pill:hover { border-color: var(--blue); }
.pill.on { background: var(--navy); border-color: var(--navy); color: var(--cream); }
.worksheet .checklist li { background: #fff; }

/* ---------- my workbook ---------- */
.nav-workbook { margin-bottom: 6px; font-weight: 500; }
.nav-workbook .dot { border: 0; font-size: 14px; }
.wb-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; margin: 0 0 30px; color: var(--muted); font-size: 14px; }
.wb-sheet { border-top: 1px solid var(--line); padding: 24px 0 10px; }
.wb-sheet h2 { font-size: 26px; margin: 2px 0 14px; }
.wb-list { list-style: none; padding: 0; margin: 0 0 12px; }
.wb-list li { margin-bottom: 14px; }
.wb-q { display: block; font-weight: 600; font-size: 15px; }
.wb-a { display: block; white-space: normal; color: var(--ink); }
.wb-a.empty { color: var(--muted); font-style: italic; }
.wb-check { color: var(--muted); }
.wb-check.on { color: var(--ink); }
