/* ============================================================
   CCA-F Trainer — Design System
   Anthropic-inspired: warm cream canvas, ink text, coral accent.
   Mobile-first, responsive, offline-friendly (system-font fallbacks).
   ============================================================ */

:root {
  /* Canvas & ink */
  --bg: #F5F4EE;
  --surface: #FFFFFF;
  --surface-2: #FBFAF6;
  --ink: #1A1A1A;
  --ink-soft: #3D3D3A;
  --muted: #6B6A63;
  --line: #E6E2D6;
  --line-strong: #D8D3C4;

  /* Brand */
  --accent: #D97757;       /* Anthropic coral */
  --accent-deep: #C2613F;
  --clay: #CC785C;

  /* Domain palette (5) */
  --d1: #D97757;  --d1-bg: #FBEFE9;
  --d2: #5F8D6E;  --d2-bg: #EAF1EC;
  --d3: #4A6FA5;  --d3-bg: #E9EEF6;
  --d4: #A56BA0;  --d4-bg: #F2EAF1;
  --d5: #C0922F;  --d5-bg: #F6EFDC;

  /* Status */
  --ok: #2E7D52; --ok-bg: #E7F2EC;
  --bad: #C0392B; --bad-bg: #FBEBE9;
  --warn: #B7791F; --warn-bg: #FAF0DC;

  /* Type */
  --serif: "Lora", "PT Serif", Georgia, "Times New Roman", serif;
  --sans: "Inter", "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", "SFMono-Regular", "Cascadia Code", Consolas, "Liberation Mono", monospace;

  /* Geometry */
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(26,26,26,.05), 0 8px 24px rgba(26,26,26,.06);
  --shadow-sm: 0 1px 2px rgba(26,26,26,.06);
  --sidebar-w: 312px;
  --header-h: 60px;
  --reading: 768px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  font-size: 16px;
  line-height: 1.62;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { font-family: var(--serif); font-weight: 600; line-height: 1.22; color: var(--ink); }
a { color: var(--accent-deep); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, kbd { font-family: var(--mono); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---------- Header ---------- */
.appbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--header-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  background: rgba(245,244,238,.86);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.appbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.01em; }
.appbar .brand .logo {
  width: 30px; height: 30px; border-radius: 8px; flex: none;
  background: var(--ink); color: #fff;
  display: grid; place-items: center; font-family: var(--serif); font-size: 17px;
}
.appbar .brand b { font-family: var(--sans); font-size: 15px; }
.appbar .brand small { color: var(--muted); font-weight: 600; font-size: 11px; display: block; margin-top: -3px; }
.appbar .spacer { flex: 1; }

.iconbtn {
  appearance: none; border: 1px solid var(--line-strong); background: var(--surface);
  width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center;
  cursor: pointer; color: var(--ink-soft);
}
.iconbtn:hover { background: var(--surface-2); }
.menu-toggle { display: none; }

/* language pill */
.langtoggle { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 999px; overflow: hidden; background: var(--surface); }
.langtoggle button { appearance: none; border: 0; background: transparent; padding: 7px 12px; font-weight: 700; font-size: 13px; cursor: pointer; color: var(--muted); }
.langtoggle button.active { background: var(--ink); color: #fff; }

/* top progress strip */
.topprogress { position: fixed; top: var(--header-h); left: 0; right: 0; height: 3px; background: transparent; z-index: 39; }
.topprogress > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--clay)); transition: width .4s ease; }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: var(--sidebar-w) 1fr; align-items: start; }

.sidebar {
  position: sticky; top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto; overscroll-behavior: contain;
  border-right: 1px solid var(--line);
  padding: 16px 12px 48px;
  background: var(--surface-2);
}
.sidebar .nav-group { margin-bottom: 6px; }
.sidebar .nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 10px; color: var(--ink-soft); font-weight: 600; font-size: 14px;
  cursor: pointer;
}
.sidebar .nav-link:hover { background: #efece2; text-decoration: none; }
.sidebar .nav-link.active { background: var(--ink); color: #fff; }
.sidebar .nav-link .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--accent); }
.sidebar .nav-sep { font-size: 11px; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); padding: 14px 12px 6px; font-weight: 700; }

.sidebar .module-row { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 10px; cursor: pointer; }
.sidebar .module-row:hover { background: #efece2; }
.sidebar .module-row.active { background: #efece2; }
.sidebar .module-row .check { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line-strong); flex: none; display: grid; place-items: center; font-size: 11px; color: #fff; }
.sidebar .module-row.done .check { background: var(--ok); border-color: var(--ok); }
.sidebar .module-row .mtitle { font-size: 13.5px; font-weight: 600; color: var(--ink-soft); line-height: 1.3; }
.sidebar .module-row .mw { margin-left: auto; font-size: 11px; color: var(--muted); font-weight: 700; }

.content { min-width: 0; padding: 28px clamp(16px, 4vw, 56px) 96px; }
.container { max-width: var(--reading); margin: 0 auto; }

/* ---------- Backdrop for mobile drawer ---------- */
.backdrop { display: none; position: fixed; inset: var(--header-h) 0 0 0; background: rgba(26,26,26,.38); z-index: 35; }

/* ---------- Generic content ---------- */
.eyebrow { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 12.5px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.page-title { font-size: clamp(26px, 4.6vw, 40px); margin: 10px 0 6px; letter-spacing: -.015em; }
.lead { font-size: 18px; color: var(--ink-soft); margin: 0 0 8px; }
.prose { font-size: 16.5px; }
.prose p { margin: 0 0 16px; }
.prose h2 { font-size: 25px; margin: 38px 0 12px; padding-top: 8px; }
.prose h3 { font-size: 19.5px; margin: 28px 0 8px; font-family: var(--sans); font-weight: 700; }
.prose ul, .prose ol { margin: 0 0 16px; padding-left: 22px; }
.prose li { margin: 6px 0; }
.prose strong { color: var(--ink); }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 30px 0; }
.prose table { width: 100%; border-collapse: collapse; margin: 16px 0; font-size: 14.5px; }
.prose th, .prose td { border: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
.prose th { background: var(--surface-2); font-weight: 700; }
.prose :not(pre) > code { background: #efece2; padding: .12em .4em; border-radius: 5px; font-size: .9em; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card.pad { padding: 22px; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }

/* ---------- Callouts ---------- */
.callout { border-radius: var(--radius); padding: 16px 18px; margin: 20px 0; border: 1px solid var(--line); background: var(--surface); position: relative; }
.callout .c-h { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }
.callout p:last-child { margin-bottom: 0; }
.callout.exam { background: var(--d1-bg); border-color: #f0d3c6; }
.callout.exam .c-h { color: var(--accent-deep); }
.callout.case { background: var(--d3-bg); border-color: #cdddef; }
.callout.case .c-h { color: var(--d3); }
.callout.pitfall { background: var(--bad-bg); border-color: #f0cdc8; }
.callout.pitfall .c-h { color: var(--bad); }
.callout.tip { background: var(--d2-bg); border-color: #cfe1d4; }
.callout.tip .c-h { color: var(--d2); }

/* ---------- Code blocks ---------- */
.codewrap { position: relative; margin: 18px 0; }
.codewrap .code-head { display: flex; align-items: center; gap: 8px; background: #20201e; color: #d6d3c8; padding: 7px 12px; border-radius: 12px 12px 0 0; font-size: 12px; font-family: var(--mono); }
.codewrap .code-head .lang { text-transform: uppercase; letter-spacing: .06em; color: #b7b3a6; font-weight: 700; }
.codewrap .copybtn { margin-left: auto; appearance: none; border: 1px solid #3a3a36; background: #2b2b28; color: #d6d3c8; border-radius: 7px; padding: 3px 9px; font-size: 11.5px; cursor: pointer; font-family: var(--sans); font-weight: 600; }
.codewrap .copybtn:hover { background: #34342f; }
.codewrap pre { margin: 0; background: #1b1b19; color: #e9e6dc; padding: 16px; border-radius: 0 0 12px 12px; overflow-x: auto; font-size: 13.5px; line-height: 1.6; }
.codewrap.plain pre { border-radius: 12px; }
pre code { background: transparent !important; padding: 0; font-size: inherit; color: inherit; }

/* ---------- Buttons ---------- */
.btn { appearance: none; cursor: pointer; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font-weight: 700; font-size: 14.5px; padding: 11px 18px; border-radius: 11px; display: inline-flex; align-items: center; gap: 8px; font-family: var(--sans); }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.primary:hover { background: #000; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.accent:hover { background: var(--accent-deep); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }

/* ---------- Badges / chips ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 800; padding: 4px 10px; border-radius: 999px; }
.badge.d1 { background: var(--d1-bg); color: var(--d1); }
.badge.d2 { background: var(--d2-bg); color: var(--d2); }
.badge.d3 { background: var(--d3-bg); color: var(--d3); }
.badge.d4 { background: var(--d4-bg); color: var(--d4); }
.badge.d5 { background: var(--d5-bg); color: var(--d5); }
.badge.soft { background: #efece2; color: var(--muted); }

/* ---------- Progress ring ---------- */
.ring { --p: 0; --size: 84px; width: var(--size); height: var(--size); border-radius: 50%;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), #e7e3d7 0);
  display: grid; place-items: center; flex: none; }
.ring > span { width: calc(var(--size) - 18px); height: calc(var(--size) - 18px); background: var(--surface); border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-family: var(--serif); }

.meter { height: 12px; border-radius: 999px; background: #e7e3d7; overflow: hidden; }
.meter > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--clay)); transition: width .5s ease; }

/* ---------- Module/lesson ---------- */
.lesson { margin-bottom: 14px; }
.lesson + .lesson { border-top: 1px solid var(--line); padding-top: 10px; }
.ts-tag { font-family: var(--mono); font-size: 12px; color: var(--muted); font-weight: 700; }

.lesson-nav { display: flex; justify-content: space-between; gap: 12px; margin-top: 40px; border-top: 1px solid var(--line); padding-top: 20px; }

/* ---------- Quiz ---------- */
.quiz-q { margin: 0 0 10px; font-weight: 600; font-size: 17px; }
.opt { display: flex; gap: 12px; align-items: flex-start; border: 1.5px solid var(--line-strong); border-radius: 12px; padding: 13px 15px; margin: 9px 0; cursor: pointer; background: var(--surface); transition: border-color .15s, background .15s; }
.opt:hover { border-color: var(--clay); }
.opt .key { font-weight: 800; flex: none; width: 24px; height: 24px; border-radius: 7px; background: #efece2; display: grid; place-items: center; font-size: 13px; }
.opt.selected { border-color: var(--ink); background: var(--surface-2); }
.opt.correct { border-color: var(--ok); background: var(--ok-bg); }
.opt.wrong { border-color: var(--bad); background: var(--bad-bg); }
.opt.correct .key { background: var(--ok); color: #fff; }
.opt.wrong .key { background: var(--bad); color: #fff; }
.opt.disabled { cursor: default; }
.explain { margin-top: 10px; padding: 14px 16px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); font-size: 15px; }
.explain.show { display: block; }

/* ---------- Exam ---------- */
.exam-hud { position: sticky; top: calc(var(--header-h) + 4px); z-index: 20; display: flex; align-items: center; gap: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 16px; box-shadow: var(--shadow-sm); margin-bottom: 18px; }
.exam-hud .timer { font-family: var(--mono); font-weight: 700; font-size: 18px; }
.exam-hud .qcount { color: var(--muted); font-weight: 700; font-size: 14px; }

.score-hero { text-align: center; padding: 30px; }
.score-num { font-family: var(--serif); font-size: 72px; font-weight: 700; line-height: 1; }
.score-num.pass { color: var(--ok); }
.score-num.fail { color: var(--bad); }

/* ---------- Flashcards ---------- */
.flash { perspective: 1400px; }
.flash .inner { position: relative; min-height: 230px; transition: transform .5s; transform-style: preserve-3d; }
.flash.flipped .inner { transform: rotateY(180deg); }
.flash .face { position: absolute; inset: 0; backface-visibility: hidden; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); padding: 28px; display: grid; place-items: center; text-align: center; box-shadow: var(--shadow-sm); }
.flash .face.back { transform: rotateY(180deg); background: var(--surface-2); }
.flash .face .term { font-family: var(--serif); font-size: 26px; }
.flash .face .def { font-size: 16px; color: var(--ink-soft); }

/* ---------- Search ---------- */
.search-input { width: 100%; border: 1px solid var(--line-strong); border-radius: 12px; padding: 13px 16px; font-size: 16px; font-family: var(--sans); background: var(--surface); }
.search-result { display: block; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; margin: 10px 0; background: var(--surface); cursor: pointer; }
.search-result:hover { background: var(--surface-2); text-decoration: none; }
.search-result mark { background: #fde8b0; border-radius: 3px; padding: 0 2px; }

/* ---------- Misc ---------- */
.kpi { font-family: var(--serif); font-size: 32px; font-weight: 700; }
.muted { color: var(--muted); }
.center { text-align: center; }
.hide { display: none !important; }
.stack > * + * { margin-top: 14px; }
.row { display: flex; align-items: center; gap: 12px; }
.wrap { flex-wrap: wrap; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .menu-toggle { display: grid; }
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: var(--header-h); left: 0; bottom: 0; width: min(86vw, var(--sidebar-w));
    height: calc(100vh - var(--header-h)); z-index: 36; transform: translateX(-104%);
    transition: transform .26s ease; box-shadow: var(--shadow);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .backdrop { display: block; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
  .content { padding: 22px 16px 88px; }
}
@media (min-width: 901px) {
  .grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 560px) {
  .appbar .brand small { display: none; }
  .score-num { font-size: 56px; }
  .exam-hud { flex-wrap: wrap; gap: 8px; }
}

/* print-friendly cheat sheets */
@media print {
  .appbar, .sidebar, .backdrop, .topprogress, .lesson-nav, .btn-row { display: none !important; }
  .layout { grid-template-columns: 1fr; }
  .content { padding: 0; }
  body { background: #fff; }
}
