:root {
  --bg: #F6F5FB;
  --surface: #FFFFFF;
  --text: #1E1B2E;
  --muted: #6B6880;
  --border: #E4E1EF;
  --brand: #4F46E5;
  --brand-strong: #4338CA;
  --brand-soft: #EEF0FF;
  --accent: #FDE68A;
  --danger: #DC2626;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(30, 27, 46, .06), 0 4px 16px rgba(30, 27, 46, .06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14121F;
    --surface: #1E1B2E;
    --text: #F1EFF8;
    --muted: #A29FB6;
    --border: #2F2B44;
    --brand: #8B85FF;
    --brand-strong: #A5A0FF;
    --brand-soft: #26224A;
    --danger: #F87171;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.2; margin: 0; }

button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
.muted { color: var(--muted); font-weight: 400; }
.hint { color: var(--muted); font-size: 14px; margin: 8px 0 0; }

.page {
  max-width: 720px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

.page--center {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 32px;
}
.brand img { width: 48px; height: 48px; border-radius: 12px; }
.brand span { font-size: 28px; font-weight: 800; letter-spacing: -.02em; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field { border: 0; padding: 0; min-width: 0; }
.field label, .field legend, .field .label { font-weight: 600; font-size: 14px; padding: 0; }
.field input, .field select, .field textarea, .notion input, .notion textarea, .page-text {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  font-size: 17px;
}
.field select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 15px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 36px; }
textarea { resize: vertical; line-height: 1.45; }
.field input:focus, .field select:focus, textarea:focus, .notion input:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: transparent; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  border: 0;
  border-radius: 12px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
}
.btn--primary { background: var(--brand); color: #fff; width: 100%; }
.btn--primary:hover { background: var(--brand-strong); }
.btn--ghost { background: transparent; color: var(--muted); padding: 8px 10px; }
.btn--ghost:hover { color: var(--text); }
.btn--soft { background: var(--brand-soft); color: var(--brand-strong); }
.btn--soft:hover { filter: brightness(.97); }
.btn--danger { color: var(--danger); }
.btn--danger:hover { color: var(--danger); text-decoration: underline; }
.btn:disabled { opacity: .55; cursor: default; }

.error { color: var(--danger); font-size: 14px; min-height: 21px; margin: 0 0 12px; }

/* Profile picker */
.profiles-title { font-size: 26px; margin-bottom: 24px; text-align: center; }
.profiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px; }
.profile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 28px 16px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .12s, border-color .12s;
}
.profile:hover, .profile:focus-visible { border-color: var(--child, var(--brand)); transform: translateY(-2px); outline: none; }
.profile-name { font-size: 20px; font-weight: 800; }
.profile-grade { color: var(--muted); font-weight: 600; }

.avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--child, var(--brand));
  color: #fff;
  font-size: 32px;
  font-weight: 800;
}
.avatar--small { width: 40px; height: 40px; font-size: 18px; }

/* Home */
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.topbar-who { flex: 1; min-width: 0; }
.topbar-who strong { display: block; font-size: 18px; }
.topbar-who span { color: var(--muted); font-size: 14px; }

.section { margin-bottom: 28px; }
.section h2 { font-size: 18px; margin-bottom: 12px; }

.empty { color: var(--muted); text-align: center; padding: 28px 20px; }

.subjects { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.subject {
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-weight: 600;
  min-width: 0;
}
.subject::before {
  content: "";
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--subject);
}
.subject span { line-height: 1.25; hyphens: auto; flex: 1; }
.subject:hover { border-color: var(--subject); }
.subject-count { color: var(--muted); font-weight: 700; }

.cta {
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 18px;
  margin-bottom: 28px;
  background: var(--brand);
  color: #fff;
  border: 0;
  border-radius: var(--radius);
  text-align: left;
}
.cta:disabled { opacity: .7; }
.cta-icon { font-size: 28px; }
.cta strong { display: block; font-size: 17px; }
.cta small { opacity: .85; }
.cta--session { margin-bottom: 12px; background: var(--surface); color: var(--text); border: 2px solid var(--subject, var(--brand)); }
.cta--session .cta-icon { display: grid; place-items: center; width: 44px; height: 44px; flex: none; border-radius: 50%; background: var(--subject, var(--brand)); color: #fff; font-size: 20px; }
.cta--session small { color: var(--muted); opacity: 1; }
#today-sessions:not(:empty) { margin-bottom: 16px; }

/* Inner pages */
.pagebar { display: flex; align-items: center; gap: 8px; margin-bottom: 24px; }
.pagebar h1 { font-size: 22px; min-width: 0; overflow-wrap: anywhere; }
.back {
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  margin-left: -8px;
  border-radius: 50%;
  text-decoration: none;
  font-size: 22px;
}
.back:hover { background: var(--brand-soft); }

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 420px) { .row { grid-template-columns: 1fr; gap: 0; } }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.chip {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }

.photo-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.photo-actions .btn { padding: 16px 10px; }

.thumbs { list-style: none; padding: 0; margin: 12px 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; }
.thumbs:empty { display: none; }
.thumb { position: relative; border-radius: 12px; overflow: hidden; background: var(--surface); border: 1px solid var(--border); }
.thumb img { display: block; width: 100%; aspect-ratio: 3 / 4; object-fit: cover; }
.thumb-no {
  position: absolute; top: 6px; left: 6px;
  min-width: 24px; height: 24px; padding: 0 6px; border-radius: 12px;
  background: rgba(0, 0, 0, .65); color: #fff; font-size: 13px; font-weight: 700;
  display: grid; place-items: center;
}
.thumb-tools { display: grid; grid-template-columns: repeat(3, 1fr); }
.thumb-tools button { border: 0; background: transparent; padding: 8px 0; font-size: 18px; cursor: pointer; }
.thumb-tools button:disabled { opacity: .25; cursor: default; }

.waiting { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; padding: 36px 20px; }
.waiting p { margin: 0; }
.spinner { width: 40px; height: 40px; border-radius: 50%; border: 4px solid var(--brand-soft); border-top-color: var(--brand); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

.notice { background: #FEF3C7; color: #78350F; border-radius: 12px; padding: 12px 16px; margin-bottom: 16px; font-size: 15px; }
.notice ul { margin: 4px 0 0; padding-left: 20px; }
@media (prefers-color-scheme: dark) { .notice { background: #422006; color: #FDE68A; } }

.notions { list-style: none; padding: 0; margin: 12px 0; display: flex; flex-direction: column; gap: 10px; counter-reset: notion; }
.notion {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 12px 4px 44px;
  counter-increment: notion;
}
.notion::before {
  content: counter(notion);
  position: absolute; left: 12px; top: 14px;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand-strong);
  font-size: 13px; font-weight: 800; display: grid; place-items: center;
}
.notion input, .notion textarea { border: 0; background: transparent; padding: 2px 0; border-radius: 6px; }
.notion input { font-weight: 700; font-size: 16px; }
.notion textarea { color: var(--muted); font-size: 15px; resize: none; overflow: hidden; }
.notion-remove { font-size: 13px; padding: 4px 0; }

.pages { display: flex; flex-direction: column; gap: 14px; }
.page-item { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.page-photo img { display: block; width: 100%; max-height: 360px; object-fit: contain; background: #111; }
.page-item details { padding: 12px; }
.page-item summary { cursor: pointer; font-weight: 600; }
.page-text { margin-top: 10px; padding: 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); font: 14px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }

.actions { display: flex; flex-direction: column; gap: 10px; }
.actions .btn { width: 100%; }
.danger-zone { text-align: center; margin-top: 28px; }

.doc-list { display: flex; flex-direction: column; gap: 10px; }
.doc-row {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px 14px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--subject);
  border-radius: 12px;
  text-decoration: none;
}
.doc-row:hover { border-color: var(--subject); }
.doc-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.doc-chapter { font-size: 14px; }
.doc-meta { color: var(--muted); font-size: 13px; }
.badge { flex: none; font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: var(--brand-soft); color: var(--brand-strong); }
.badge--failed { background: #FEE2E2; color: #991B1B; }
.badge--to_review { background: #FEF3C7; color: #92400E; }
@media (prefers-color-scheme: dark) {
  .badge--failed { background: #450A0A; color: #FCA5A5; }
  .badge--to_review { background: #422006; color: #FDE68A; }
}

/* Assessments (lot 2) */
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.section-head h2 { margin-bottom: 0; }
.btn--small { padding: 6px 12px; font-size: 14px; }
.btn--inline { width: auto; }
.empty--link { display: block; text-decoration: none; }
.empty--link:hover { border-color: var(--brand); color: var(--text); }
.button-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.button-pair .btn { width: 100%; padding: 14px 10px; }
@media (max-width: 420px) { .button-pair { grid-template-columns: 1fr; } }

.today-line { font-size: 14px; font-weight: 600; color: var(--brand-strong); margin-top: 2px; }
.today-line--done { color: #15803D; }
.doc-row--past { opacity: .65; }
@media (prefers-color-scheme: dark) { .today-line--done { color: #4ADE80; } }

.check-list { display: flex; flex-direction: column; gap: 8px; }
.check-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  font-weight: 400;
}
.check-item:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.check-item input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--brand); flex: none; }
.check-item span { display: flex; flex-direction: column; min-width: 0; }
.check-item small { font-size: 13px; }

.when { color: var(--muted); margin: -16px 0 20px; font-size: 15px; }
.subject-dot { font-weight: 700; color: var(--text); }
.subject-dot::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 6px; border-radius: 50%; background: var(--subject, var(--brand)); }

.overview { margin: 0 0 16px; padding: 14px 16px; background: var(--brand-soft); border-radius: 12px; }

.sessions { list-style: none; padding: 0; margin: 0 0 28px; display: flex; flex-direction: column; gap: 12px; }
.session {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.session--today { border: 2px solid var(--brand); }
.session--done { opacity: .7; }
.session--done h3::after { content: " ✓"; color: #15803D; }
.session--missed { border-style: dashed; }
.session--exam { background: transparent; border-style: dashed; }
.session--exam h3 { margin: 0; }
.session-day { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 14px; margin-bottom: 8px; }
.session-day strong { display: inline-block; }
.session-day strong::first-letter { text-transform: uppercase; }
.session h3 { font-size: 17px; margin-bottom: 4px; }
.session-goal { margin: 0 0 8px; color: var(--muted); font-size: 15px; }
.activities { list-style: none; padding: 0; margin: 10px 0 0; display: flex; flex-direction: column; gap: 8px; }
.activity { padding: 10px 12px; background: var(--bg); border-radius: 10px; }
.activity-head { display: flex; justify-content: space-between; gap: 8px; font-size: 15px; }
.activity p { margin: 4px 0 0; font-size: 14px; }
.tags { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 10px; font-size: 13px; }
.session-detail summary { cursor: pointer; font-size: 14px; font-weight: 600; color: var(--brand-strong); }
.session-detail[open] summary { margin-bottom: 2px; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); }
.session-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.session-actions .btn { padding: 10px 14px; }
.move { padding: 9px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); font-size: 15px; }
.badge--kind-mock_test { background: #FEE2E2; color: #991B1B; }
.badge--kind-light_review { background: #DCFCE7; color: #166534; }
@media (prefers-color-scheme: dark) {
  .session--done h3::after { color: #4ADE80; }
  .badge--kind-mock_test { background: #450A0A; color: #FCA5A5; }
  .badge--kind-light_review { background: #052E16; color: #86EFAC; }
}
.notice p { margin: 4px 0 10px; }
.danger-zone { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }

/* Read the course */
.read-link { width: 100%; margin-bottom: 16px; }
.keypoints { margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 10px; }
.keypoints p { margin: 2px 0 0; color: var(--muted); }
.course-text { display: flex; flex-direction: column; gap: 14px; }
.course-page { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 4px 18px 8px; overflow-x: auto; }
.course-page-no { margin: 12px 0 0; font-size: 13px; font-weight: 700; color: var(--muted); }
.course-page-body { line-height: 1.6; overflow-wrap: break-word; }
.course-page-body h1, .course-page-body h2, .course-page-body h3 { margin: 18px 0 8px; }
.course-page-body h1 { font-size: 21px; }
.course-page-body h2 { font-size: 18px; }
.course-page-body h3 { font-size: 16px; }
.course-page-body blockquote { margin: 12px 0; padding: 8px 14px; border-left: 4px solid var(--brand); background: var(--brand-soft); border-radius: 0 10px 10px 0; }
.course-page-body table { border-collapse: collapse; margin: 12px 0; font-size: 15px; }
.course-page-body th, .course-page-body td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: top; }
.course-page-body .katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }

.add-pages { margin-top: 18px; padding: 16px; border: 1px dashed var(--border); border-radius: var(--radius); }
.add-pages h3 { font-size: 16px; }
.add-pages .hint { margin-bottom: 12px; }
.add-pages .btn--primary { margin-top: 12px; }

/* Session player (lot 3) */
.progress { height: 6px; border-radius: 3px; background: var(--brand-soft); margin: -8px 0 16px; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--brand); border-radius: 3px; transition: width .3s; }
#player { display: flex; flex-direction: column; gap: 14px; }
.activity-banner { display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; background: var(--brand-soft); border-radius: 12px; }
.activity-banner .activity-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.activity-instructions summary { cursor: pointer; font-size: 14px; font-weight: 600; color: var(--brand-strong); }
.activity-instructions p { margin: 4px 0 0; font-size: 14px; }
.step-count { font-size: 14px; }
.timer { font-weight: 700; font-variant-numeric: tabular-nums; }
.timer--over { color: var(--danger); }
.exercise { display: flex; flex-direction: column; gap: 12px; }
.exercise .tags { margin-top: 0; }
.tag--review { background: #FEF3C7; border-color: #FDE68A; color: #92400E; }
.exercise-prompt { font-size: 18px; font-weight: 600; line-height: 1.45; overflow-wrap: break-word; }
.exercise-prompt p { margin: 0 0 8px; }
.exercise-prompt p:last-child { margin-bottom: 0; }
.choices { display: flex; flex-direction: column; gap: 8px; }
.choice {
  text-align: left; padding: 14px 16px; border: 2px solid var(--border); border-radius: 12px;
  background: var(--bg); cursor: pointer; font-size: 16px; line-height: 1.35;
}
.choice:hover:not(:disabled) { border-color: var(--brand); }
.choice:disabled { cursor: default; }
.choice--chosen { border-color: var(--brand); background: var(--brand-soft); }
.choice--right { border-color: #16A34A; background: #DCFCE7; }
.choice--wrong { border-color: var(--danger); background: #FEE2E2; }
.answer-input { width: 100%; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg); font-size: 17px; }
.answer-input:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: transparent; }
.answer-form { display: flex; flex-direction: column; gap: 10px; }
.answer-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.card-back { padding: 14px 16px; border: 2px dashed var(--brand); border-radius: 12px; font-size: 17px; }
.card-back p { margin: 0; }
.photo-preview { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.photo-preview img, .given-photo { max-width: 100%; max-height: 320px; border-radius: 10px; border: 1px solid var(--border); }
.correcting { display: flex; align-items: center; gap: 10px; margin: 0; }
.spinner--small { width: 20px; height: 20px; border-width: 3px; }
.given { margin: 0; overflow-wrap: anywhere; }
.correction { display: flex; flex-direction: column; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.correction .btn--ghost { align-self: flex-start; padding-left: 0; }
.result { margin: 0; font-weight: 800; font-size: 17px; }
.result--right { color: #15803D; }
.result--partial { color: #B45309; }
.result--wrong { color: var(--danger); }
.feedback { margin: 0; }
.expected { margin: 0; }
.expected p { margin: 4px 0 0; }
.explanation { color: var(--muted); font-size: 15px; }
.explanation p { margin: 0; }
.explanation summary { cursor: pointer; font-weight: 600; }
.recap-head strong, .score { font-size: 22px; }
.missed { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 10px; }
.missed p { margin: 0; }
@media (prefers-color-scheme: dark) {
  .tag--review { background: #422006; border-color: #713F12; color: #FDE68A; }
  .choice--right { border-color: #4ADE80; background: #052E16; }
  .choice--wrong { background: #450A0A; }
  .result--right { color: #4ADE80; }
  .result--partial { color: #FBBF24; }
}

/* Revision sheet + flashcards */
:root { --highlight: #FDE68A; --memo-bg: #FEF9C3; --memo-border: #FACC15; --trap-bg: #FFF7ED; --trap-border: #FB923C; }
@media (prefers-color-scheme: dark) {
  :root { --highlight: rgba(250, 204, 21, .32); --memo-bg: #2E2A12; --memo-border: #A16207; --trap-bg: #2A1708; --trap-border: #C2410C; }
}
.sheet-bar { margin: -8px 0 20px; }
.sheet-bar .button-pair { grid-template-columns: 1fr 1fr; }
.sheet-state { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin: 0; font-size: 15px; }
.sheet-page .pagebar h1 { font-size: 18px; color: var(--muted); }
.sheet { display: flex; flex-direction: column; gap: 16px; }
.sheet h2 { font-size: 18px; margin: 0; }

.sheet-hero {
  padding: 20px; border-radius: var(--radius); color: #fff;
  background: linear-gradient(135deg, var(--subject, var(--brand)), color-mix(in srgb, var(--subject, var(--brand)) 55%, #1E1B2E));
}
.sheet-kicker { margin: 0; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; opacity: .9; }
.sheet-child { display: none; }
.sheet-title { font-size: 26px !important; line-height: 1.15; margin: 6px 0 4px !important; }
.sheet-when { margin: 0; font-weight: 600; opacity: .95; }
.sheet-intro { margin: 12px 0 0; padding-top: 12px; border-top: 1px solid rgba(255, 255, 255, .35); line-height: 1.45; }

.sheet-toc { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.sheet-toc .chip { flex: none; text-decoration: none; font-size: 14px; padding: 6px 12px; white-space: nowrap; }
.sheet-toc .chip:hover { border-color: var(--subject, var(--brand)); }
.sheet [id] { scroll-margin-top: 12px; }

.sheet-memo { background: var(--memo-bg); border: 2px solid var(--memo-border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.sheet-memo ul { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.sheet-memo li { position: relative; padding-left: 28px; font-weight: 600; line-height: 1.4; }
.sheet-memo li::before { content: "✔"; position: absolute; left: 4px; top: 0; color: #A16207; font-weight: 800; }

.sheet-glossary .section-head { margin-bottom: 4px; flex-wrap: wrap; }
.sheet-quiz-hint { display: none; margin: 0 0 8px; }
.sheet-glossary--quiz .sheet-quiz-hint { display: block; }
.terms { margin: 8px 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.term { margin: 0; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--subject, var(--brand)); border-radius: 12px; }
.term dt { font-weight: 800; color: var(--subject, var(--brand-strong)); filter: brightness(.85); }
.term dd { margin: 4px 0 0; line-height: 1.4; border-radius: 6px; transition: background-color .2s, color .2s; }
.sheet-glossary--quiz .term { cursor: pointer; }
.sheet-glossary--quiz .term dd { color: transparent; background: var(--brand-soft); user-select: none; }
.sheet-glossary--quiz .term--shown dd { color: inherit; background: transparent; user-select: auto; }
@media (prefers-color-scheme: dark) { .term dt { filter: brightness(1.3); } }

.sheet-parts { display: flex; flex-direction: column; gap: 12px; }
.sheet-part { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px 8px; overflow-x: auto; }
.part-head { display: flex; align-items: center; gap: 10px; font-size: 17px !important; }
.part-no { flex: none; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--subject, var(--brand)); color: #fff; font-size: 14px; font-weight: 800; }
.part-icon { font-size: 22px; line-height: 1; }
.sheet-part .course-page-body p { margin: 8px 0; }
.sheet-part .course-page-body ul, .sheet-part .course-page-body ol { padding-left: 22px; }
.sheet-part .course-page-body li { margin: 3px 0; }
.sheet-part strong, .sheet-memo strong, .in-sheet .course-page-body strong { background: linear-gradient(transparent 58%, var(--highlight) 58%); padding: 0 1px; }
.sheet-part table { border-collapse: separate; border-spacing: 0; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.sheet-part th { background: var(--brand-soft); }
.sheet-part th, .sheet-part td { border: 0; border-bottom: 1px solid var(--border); }
.sheet-part tr:last-child td { border-bottom: 0; }

.sheet-traps { background: var(--trap-bg); border: 1px solid var(--trap-border); border-left-width: 6px; border-radius: var(--radius); padding: 16px 18px; }
.sheet-traps ul { margin: 10px 0 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; }

.card .sheet-part { border: 0; padding: 0; margin-bottom: 12px; background: transparent; }
.card .sheet-part h2 { font-size: 17px; margin: 0 0 4px; }
.card .terms { margin-bottom: 12px; }
.sheet-more { padding-left: 0; }
.in-sheet { background: var(--brand-soft); border-radius: 10px; padding: 8px 12px; font-size: 15px; }
.in-sheet summary { cursor: pointer; font-weight: 600; color: var(--brand-strong); }
.deck { display: flex; flex-direction: column; gap: 14px; }
.deck-count { display: flex; justify-content: space-between; align-items: center; margin: 0; color: var(--muted); font-weight: 600; }
.flip-card {
  min-height: 260px; display: flex; flex-direction: column; justify-content: space-between; gap: 12px;
  padding: 18px; border: 2px solid var(--border); border-radius: var(--radius); background: var(--surface);
  box-shadow: var(--shadow); cursor: pointer; text-align: center;
}
.flip-card--back { border-color: var(--subject, var(--brand)); background: var(--brand-soft); }
.flip-side { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.flip-face { font-size: 21px; font-weight: 700; line-height: 1.35; overflow-wrap: break-word; }
.flip-card--back .flip-face { font-weight: 600; font-size: 19px; }
.flip-tap { font-size: 13px; color: var(--muted); }
.deck-nav { display: grid; grid-template-columns: 80px 1fr; gap: 10px; }
.deck-nav .btn { padding: 14px; }

/* The sheet on paper: A4, colours kept, parts on two columns. */
@media print {
  :root { --bg: #fff; --surface: #fff; --text: #111; --muted: #555; --border: #ccc; --brand-soft: #EEF0FF; --brand-strong: #4338CA;
    --highlight: #FDE68A; --memo-bg: #FEF9C3; --memo-border: #EAB308; --trap-bg: #FFF7ED; --trap-border: #FB923C; color-scheme: light; }
  @page { size: A4; margin: 12mm; @bottom-center { content: "Déclic · page " counter(page) " / " counter(pages); font: 9pt sans-serif; color: #777; } }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  body { background: #fff; color: #111; font-size: 10.5pt; }
  .page { max-width: none; padding: 0; }
  .pagebar, .danger-zone, .sheet-bar, .sheet-toc, .sheet-glossary .btn, .sheet-quiz-hint { display: none !important; }
  .sheet { gap: 10px; }
  .sheet-hero { padding: 12px 16px; border-radius: 10px; }
  .sheet-child { display: inline; }
  .sheet-title { font-size: 20pt !important; }
  .sheet-intro { margin-top: 8px; padding-top: 8px; }
  .sheet-memo, .sheet-traps { box-shadow: none; padding: 10px 14px; break-inside: avoid; }
  .sheet-memo ul { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 18px; margin-top: 6px; }
  .sheet-glossary .section-head { break-after: avoid; }
  .terms { grid-template-columns: 1fr 1fr; gap: 6px; }
  .term { padding: 6px 10px; break-inside: avoid; }
  .sheet-glossary--quiz .term dd { color: inherit; background: transparent; }
  .sheet-parts { display: block; columns: 2; column-gap: 14px; }
  .sheet-part { break-inside: avoid; margin: 0 0 10px; padding: 10px 12px 4px; border-radius: 10px; overflow: visible; }
  .part-head { font-size: 12pt !important; }
  .part-no { width: 22px; height: 22px; font-size: 10pt; }
  .part-icon { font-size: 16px; }
  .course-page-body { line-height: 1.4; }
}
