/* ==========================================================================
   LaTeX Studio — design system
   A clean documentation-style language: system UI type ramp, #0067B8
   communication blue, 2px geometry, layered depth shadows, light + dark.
   ========================================================================== */

/* ---------------------------------------------------------------- tokens */
:root {
  color-scheme: light;

  /* brand */
  --brand:            #0067b8;
  --brand-hover:      #005da6;
  --brand-pressed:    #004e8c;
  --brand-tint:       #eff6fc;
  --brand-tint-2:     #deecf9;
  --brand-border:     #c7e0f4;

  /* neutrals — Fluent neutral ramp */
  --n-white:  #ffffff;
  --n-2:      #faf9f8;
  --n-4:      #f3f2f1;
  --n-6:      #edebe9;
  --n-8:      #e1dfdd;
  --n-20:     #d2d0ce;
  --n-30:     #a19f9d;
  --n-40:     #8a8886;
  --n-60:     #605e5c;
  --n-80:     #323130;
  --n-100:    #201f1e;

  --bg:            var(--n-white);
  --bg-alt:        var(--n-2);
  --bg-sunken:     var(--n-4);
  --bg-raised:     var(--n-white);
  --bg-overlay:    rgba(0, 0, 0, .4);
  --fg:            var(--n-100);
  --fg-secondary:  var(--n-60);
  /* n-40 (#8a8886) is only 3.5:1 on white — below AA, and this token is used
     for real instructions (empty states, the palette footer, file:line
     labels), not just decoration. n-60 is 6.4:1. */
  --fg-muted:      var(--n-60);
  --fg-on-brand:   #ffffff;
  --border:        var(--n-8);
  --border-strong: var(--n-20);

  /* status */
  --success:       #107c10;
  --success-bg:    #dff6dd;
  --warning:       #797673;
  --warning-accent:#ffb900;
  --warning-bg:    #fff4ce;
  --danger:        #a4262c;
  --danger-bg:     #fde7e9;
  --info:          #0067b8;
  --info-bg:       #eff6fc;
  --tip:           #107c10;
  --tip-bg:        #f1faf1;
  --important:     #8661c5;
  --important-bg:  #f2eefb;

  /* type */
  --font: "Segoe UI Variable Text", "Segoe UI", -apple-system, BlinkMacSystemFont,
          "Microsoft JhengHei UI", "Microsoft JhengHei", "PingFang TC",
          "Noto Sans TC", "Helvetica Neue", Arial, sans-serif;
  --font-display: "Segoe UI Variable Display", "Segoe UI Semibold", "Segoe UI",
          -apple-system, "Microsoft JhengHei UI", "Noto Sans TC", sans-serif;
  --font-mono: "Cascadia Mono", "Cascadia Code", ui-monospace, SFMono-Regular,
          Consolas, "Liberation Mono", Menlo, monospace;

  /* depth */
  --shadow-2:  0 1.6px 3.6px rgba(0,0,0,.13), 0 .3px .9px rgba(0,0,0,.11);
  --shadow-4:  0 3.2px 7.2px rgba(0,0,0,.13), 0 .6px 1.8px rgba(0,0,0,.11);
  --shadow-8:  0 6.4px 14.4px rgba(0,0,0,.13), 0 1.2px 3.6px rgba(0,0,0,.11);
  --shadow-16: 0 12.8px 28.8px rgba(0,0,0,.22), 0 2.4px 7.2px rgba(0,0,0,.18);

  --radius: 4px;
  --radius-sm: 2px;
  --header-h: 56px;
  --content-max: 1600px;
  --ease: cubic-bezier(.1, .9, .2, 1);
}

[data-theme="dark"] {
  color-scheme: dark;
  --brand:          #4db2ff;
  --brand-hover:    #6cc0ff;
  --brand-pressed:  #8fcfff;
  --brand-tint:     #12232f;
  --brand-tint-2:   #16303f;
  --brand-border:   #24506b;

  --bg:            #1b1a19;
  --bg-alt:        #201f1e;
  --bg-sunken:     #141313;
  --bg-raised:     #252423;
  --bg-overlay:    rgba(0, 0, 0, .6);
  --fg:            #f3f2f1;
  --fg-secondary:  #c8c6c4;
  --fg-muted:      #979593;
  --border:        #3b3a39;
  --border-strong: #4f4e4c;

  --success:       #6bb700;
  --success-bg:    #17240f;
  --warning-bg:    #2b2410;
  --danger:        #f1707b;
  --danger-bg:     #2b1416;
  --info-bg:       #12232f;
  --tip-bg:        #12240f;
  --important:     #b28bf0;
  --important-bg:  #1f1830;

  --shadow-2:  0 1.6px 3.6px rgba(0,0,0,.4), 0 .3px .9px rgba(0,0,0,.3);
  --shadow-4:  0 3.2px 7.2px rgba(0,0,0,.45), 0 .6px 1.8px rgba(0,0,0,.3);
  --shadow-8:  0 6.4px 14.4px rgba(0,0,0,.5), 0 1.2px 3.6px rgba(0,0,0,.35);
  --shadow-16: 0 12.8px 28.8px rgba(0,0,0,.6), 0 2.4px 7.2px rgba(0,0,0,.4);
}

/* ------------------------------------------------------------- baseline */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.25;
  margin: 0 0 .5em;
  letter-spacing: -.01em;
}
h1 { font-size: 2.6rem; }
h2 { font-size: 1.75rem; margin-top: 2em; }
h3 { font-size: 1.25rem; margin-top: 1.6em; }
h4 { font-size: 1.05rem; margin-top: 1.4em; }
p  { margin: 0 0 1em; }

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
[data-theme="dark"] :focus-visible { outline-color: var(--brand); }

code, kbd, samp, pre { font-family: var(--font-mono); font-size: .9em; }

code:not(pre code) {
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .1em .34em;
  font-size: .875em;
  word-break: break-word;
}

hr { border: 0; border-top: 1px solid var(--border); margin: 2em 0; }

img { max-width: 100%; }

::selection { background: var(--brand-tint-2); color: var(--fg); }

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 200;
  background: var(--brand); color: #fff; padding: 10px 18px; font-weight: 600;
}
.skip-link:focus { left: 8px; top: 8px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* --------------------------------------------------------------- header */
.site-header {
  position: sticky; top: 0; z-index: 100;
  height: var(--header-h);
  display: flex; align-items: center; gap: 4px;
  padding: 0 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.site-header .brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 600; font-size: 15px; color: var(--fg);
  padding: 6px 8px 6px 0; white-space: nowrap;
}
.site-header .brand:hover { text-decoration: none; }
.brand-mark { width: 24px; height: 24px; flex: none; display: block; border-radius: 6px; }
.brand-product { color: var(--fg); font-weight: 600; }

.site-nav { display: flex; align-items: center; gap: 2px; flex: 1; min-width: 0; }
.site-nav a {
  color: var(--fg); padding: 8px 12px; font-size: 14px; border-radius: var(--radius-sm);
  white-space: nowrap; position: relative;
}
.site-nav a:hover { background: var(--bg-sunken); text-decoration: none; }
.site-nav a[aria-current="page"] { font-weight: 600; }
.site-nav a[aria-current="page"]::after {
  content: ""; position: absolute; left: 12px; right: 12px; bottom: -1px;
  height: 2px; background: var(--brand);
}

.header-actions { display: flex; align-items: center; gap: 4px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border: 1px solid transparent; border-radius: var(--radius-sm);
  background: transparent; color: var(--fg); cursor: pointer;
}
.icon-btn:hover { background: var(--bg-sunken); }
.icon-btn svg { width: 17px; height: 17px; }

.nav-toggle { display: none; }

@media (max-width: 900px) {
  .site-header { padding: 0 12px; }
  .nav-toggle { display: inline-flex; }
  .site-nav {
    position: absolute; top: var(--header-h); left: 0; right: 0;
    flex-direction: column; align-items: stretch; gap: 0;
    background: var(--bg); border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-8); padding: 6px; display: none;
  }
  .site-nav.open { display: flex; }
  .site-nav a { padding: 12px; }
  .site-nav a[aria-current="page"]::after { display: none; }
}

/* -------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: inherit; font-size: 14px; font-weight: 600; line-height: 1.2;
  padding: 9px 20px; min-height: 36px;
  border: 1px solid var(--fg); border-radius: var(--radius-sm);
  background: transparent; color: var(--fg);
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .12s var(--ease), border-color .12s var(--ease);
}
.btn:hover { background: var(--bg-sunken); text-decoration: none; }
.btn:active { background: var(--n-6); }
.btn:disabled, .btn[aria-disabled="true"] {
  opacity: .45; cursor: not-allowed; pointer-events: none;
}
.btn svg { width: 15px; height: 15px; flex: none; }

.btn-primary {
  background: var(--brand); border-color: var(--brand); color: var(--fg-on-brand);
}
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn-primary:active { background: var(--brand-pressed); }
[data-theme="dark"] .btn-primary { color: #06131c; }

.btn-subtle { border-color: transparent; color: var(--fg); padding: 8px 12px; }
.btn-subtle:hover { background: var(--bg-sunken); }

.btn-danger { border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); }

.btn-sm { font-size: 13px; padding: 5px 12px; min-height: 30px; }
.btn-lg { font-size: 15px; padding: 12px 28px; min-height: 44px; }
.btn-block { width: 100%; }

/* --------------------------------------------------------------- layout */
.page { min-height: calc(100vh - var(--header-h) - 260px); }
.wrap { max-width: 1360px; margin: 0 auto; padding: 0 24px; }
.wrap-narrow { max-width: 900px; margin: 0 auto; padding: 0 24px; }
@media (max-width: 640px) { .wrap, .wrap-narrow { padding: 0 16px; } }

.stack > * + * { margin-top: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row-end { margin-left: auto; }
.muted { color: var(--fg-secondary); }
.small { font-size: 13px; }
.center { text-align: center; }

/* ----------------------------------------------------------------- hero */
.hero {
  background: linear-gradient(115deg, #f2f8fd 0%, #e6f1fb 45%, #f7f6f4 100%);
  border-bottom: 1px solid var(--border);
  padding: 72px 0 68px;
  position: relative; overflow: hidden;
}
[data-theme="dark"] .hero {
  background: linear-gradient(115deg, #16242f 0%, #1b2b38 45%, #1b1a19 100%);
}
.hero::after {
  content: ""; position: absolute; right: -80px; top: -60px;
  width: 460px; height: 460px; border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, rgba(0,103,184,.14), transparent 62%);
  pointer-events: none;
}
.hero .eyebrow {
  font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: var(--brand); margin-bottom: 14px;
}
.hero h1 { font-size: clamp(2.1rem, 4.4vw, 3.2rem); max-width: 880px; margin-bottom: .35em; }
.hero p.lede {
  font-size: 1.15rem; color: var(--fg-secondary); max-width: 62ch; margin-bottom: 28px;
}
.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.hero-stats {
  display: flex; gap: 40px; margin-top: 46px; flex-wrap: wrap;
  padding-top: 26px; border-top: 1px solid var(--border);
}
.hero-stats .stat b {
  display: block; font-family: var(--font-display); font-size: 2rem; font-weight: 600;
  line-height: 1.1;
}
.hero-stats .stat span { font-size: 13px; color: var(--fg-secondary); }

/* ---------------------------------------------------------------- cards */
.card-grid {
  display: grid; gap: 20px;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
}
.card {
  display: flex; flex-direction: column;
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px;
  transition: box-shadow .15s var(--ease), transform .15s var(--ease),
              border-color .15s var(--ease);
  color: inherit; text-decoration: none; position: relative;
}
a.card:hover, .card.interactive:hover {
  box-shadow: var(--shadow-8); border-color: var(--border-strong);
  transform: translateY(-2px); text-decoration: none;
}
.card h3 { margin: 0 0 8px; font-size: 1.08rem; }
.card p { color: var(--fg-secondary); font-size: 14px; margin: 0 0 14px; }
.card .card-foot {
  margin-top: auto; padding-top: 12px; display: flex; align-items: center;
  gap: 10px; font-size: 13px; color: var(--fg-secondary);
}
.card-icon {
  width: 40px; height: 40px; border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  background: var(--brand-tint); color: var(--brand); margin-bottom: 16px;
}
.card-icon svg { width: 21px; height: 21px; }

/* --------------------------------------------------------------- badges */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 600; line-height: 1;
  padding: 4px 9px; border-radius: 999px;
  background: var(--bg-sunken); color: var(--fg-secondary);
  border: 1px solid var(--border);
}
.badge-beginner     { background: var(--tip-bg);      color: var(--success); border-color: transparent; }
.badge-intermediate { background: var(--info-bg);     color: var(--brand);   border-color: transparent; }
.badge-advanced     { background: var(--important-bg);color: var(--important);border-color: transparent; }
.badge-done         { background: var(--success);     color: #fff; border-color: transparent; }

/* ----------------------------------------------------------- breadcrumb */
.breadcrumb {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  font-size: 13px; color: var(--fg-secondary); padding: 14px 0;
}
.breadcrumb a { color: var(--fg-secondary); }
.breadcrumb a:hover { color: var(--brand); }
.breadcrumb .sep { opacity: .55; }

/* ------------------------------------------------------------- messages */
.alert {
  border: 1px solid var(--border); border-left: 4px solid var(--brand);
  background: var(--info-bg); border-radius: var(--radius);
  padding: 14px 18px; margin: 20px 0; font-size: 14px;
}
.alert > .alert-title {
  display: flex; align-items: center; gap: 8px;
  font-weight: 600; margin-bottom: 6px; color: var(--brand);
}
.alert > .alert-title svg { width: 16px; height: 16px; }
.alert p:last-child { margin-bottom: 0; }
.alert-tip       { border-left-color: var(--tip); background: var(--tip-bg); }
.alert-tip .alert-title { color: var(--tip); }
.alert-warning   { border-left-color: var(--warning-accent); background: var(--warning-bg); }
.alert-warning .alert-title { color: #8a6d00; }
[data-theme="dark"] .alert-warning .alert-title { color: var(--warning-accent); }
.alert-important { border-left-color: var(--important); background: var(--important-bg); }
.alert-important .alert-title { color: var(--important); }
.alert-danger    { border-left-color: var(--danger); background: var(--danger-bg); }
.alert-danger .alert-title { color: var(--danger); }

/* ---------------------------------------------------------------- table */
.md-table-wrap { overflow-x: auto; margin: 20px 0; }
table.md-table {
  border-collapse: collapse; width: 100%; font-size: 14px;
  border: 1px solid var(--border);
}
table.md-table th, table.md-table td {
  border: 1px solid var(--border); padding: 9px 13px; text-align: left;
  vertical-align: top;
}
table.md-table th { background: var(--bg-sunken); font-weight: 600; }
table.md-table tbody tr:nth-child(even) { background: var(--bg-alt); }

/* ----------------------------------------------------------- code block */
.code-block {
  border: 1px solid var(--border); border-radius: var(--radius);
  margin: 20px 0; overflow: hidden; background: var(--bg-sunken);
}
.code-block .cb-head {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 7px 10px 7px 14px; background: var(--bg-alt);
  border-bottom: 1px solid var(--border); font-size: 12.5px;
  color: var(--fg-secondary);
}
.code-block .cb-head .cb-title { font-weight: 600; color: var(--fg); }
.code-block .cb-head .cb-actions { margin-left: auto; display: flex; gap: 4px; }
.code-block pre {
  margin: 0; padding: 14px 16px; overflow-x: auto; font-size: 13px;
  line-height: 1.55; background: var(--bg-sunken); tab-size: 2;
}
.code-block .cb-explain {
  padding: 10px 16px; border-top: 1px solid var(--border);
  font-size: 13.5px; color: var(--fg-secondary); background: var(--bg-raised);
}
.cb-result {
  border-top: 1px solid var(--border); background: var(--bg-raised);
  padding: 12px 16px;
}
.cb-result img, .cb-result canvas {
  max-width: 100%; border: 1px solid var(--border); background: #fff;
  box-shadow: var(--shadow-2);
}

/* minimal TeX syntax colouring for static code blocks */
.tex-cmd  { color: #0000c0; }
.tex-arg  { color: #a31515; }
.tex-cmt  { color: #6a8759; font-style: italic; }
.tex-math { color: #7a3e9d; }
[data-theme="dark"] .tex-cmd  { color: #7cb7ff; }
[data-theme="dark"] .tex-arg  { color: #ff9e80; }
[data-theme="dark"] .tex-cmt  { color: #7f9f6a; }
[data-theme="dark"] .tex-math { color: #d1a0ff; }

/* --------------------------------------------------- learn page layout */
.learn-layout {
  display: grid; grid-template-columns: 300px minmax(0, 1fr) 220px;
  gap: 40px; align-items: start;
  max-width: var(--content-max); margin: 0 auto; padding: 0 24px 80px;
}
@media (max-width: 1280px) { .learn-layout { grid-template-columns: 280px minmax(0,1fr); } .on-this-page { display: none; } }
@media (max-width: 960px)  { .learn-layout { grid-template-columns: minmax(0,1fr); gap: 0; padding: 0 16px 60px; } .toc-rail { display: none; } }

.toc-rail {
  position: sticky; top: calc(var(--header-h) + 16px);
  max-height: calc(100vh - var(--header-h) - 32px); overflow-y: auto;
  padding: 20px 0 20px; font-size: 14px;
  border-right: 1px solid var(--border);
}
.toc-rail h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--fg-secondary); margin: 0 0 12px; }
.toc-module { margin-bottom: 6px; }
.toc-module > button {
  display: flex; align-items: center; gap: 8px; width: 100%;
  background: none; border: 0; font: inherit; font-weight: 600; color: var(--fg);
  text-align: left; padding: 7px 10px; cursor: pointer; border-radius: var(--radius-sm);
}
.toc-module > button:hover { background: var(--bg-sunken); }
.toc-module > button .chev { margin-left: auto; transition: transform .15s var(--ease); }
.toc-module[open] > button .chev, .toc-module.open > button .chev { transform: rotate(90deg); }
.toc-lessons { list-style: none; margin: 0 0 4px; padding: 0 0 0 10px; display: none; }
.toc-module.open .toc-lessons { display: block; }
.toc-lessons a {
  display: flex; gap: 8px; align-items: center;
  padding: 6px 10px 6px 14px; color: var(--fg-secondary);
  border-left: 2px solid var(--border); font-size: 13.5px;
}
.toc-lessons a:hover { color: var(--brand); background: var(--bg-sunken); text-decoration: none; }
.toc-lessons a.active {
  color: var(--brand); font-weight: 600; border-left-color: var(--brand);
  background: var(--brand-tint);
}
.toc-check { width: 14px; height: 14px; flex: none; color: var(--success); }

.lesson-body { padding: 8px 0 60px; min-width: 0; max-width: 820px; }
.lesson-body h1 { font-size: 2.1rem; margin-bottom: .3em; }
.lesson-meta {
  display: flex; gap: 14px; flex-wrap: wrap; align-items: center;
  color: var(--fg-secondary); font-size: 13.5px; margin-bottom: 26px;
  padding-bottom: 18px; border-bottom: 1px solid var(--border);
}
.objectives {
  background: var(--bg-alt); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 22px; margin: 24px 0 30px;
}
.objectives h2 { font-size: 1rem; margin: 0 0 10px; }
.objectives ul { margin: 0; padding-left: 20px; }
.objectives li { margin: 4px 0; color: var(--fg-secondary); }

.on-this-page {
  position: sticky; top: calc(var(--header-h) + 16px); padding: 24px 0;
  font-size: 13px;
}
.on-this-page h2 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--fg-secondary); margin: 0 0 10px;
}
.on-this-page a { display: block; padding: 5px 0 5px 12px; color: var(--fg-secondary);
  border-left: 2px solid var(--border); }
.on-this-page a:hover { color: var(--brand); }

.lesson-nav {
  display: flex; gap: 16px; justify-content: space-between; margin-top: 48px;
  padding-top: 24px; border-top: 1px solid var(--border); flex-wrap: wrap;
}
.lesson-nav a {
  flex: 1 1 260px; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 18px; color: inherit;
}
.lesson-nav a:hover { border-color: var(--brand); text-decoration: none; }
.lesson-nav .dir { font-size: 12px; color: var(--fg-secondary); display: block; }
.lesson-nav .t { font-weight: 600; }
.lesson-nav .next { text-align: right; }

/* ----------------------------------------------------------------- quiz */
.quiz {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px 22px; margin: 26px 0; background: var(--bg-raised);
}
.quiz .q { font-weight: 600; margin-bottom: 14px; }
.quiz .opt {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  margin-bottom: 8px; cursor: pointer; background: var(--bg);
  transition: border-color .12s var(--ease), background .12s var(--ease);
}
.quiz .opt:hover { border-color: var(--brand); background: var(--brand-tint); }
.quiz .opt input { margin-top: 4px; accent-color: var(--brand); }
.quiz .opt.correct { border-color: var(--success); background: var(--success-bg); }
.quiz .opt.wrong   { border-color: var(--danger);  background: var(--danger-bg); }
.quiz .explain {
  margin-top: 12px; padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--bg-alt); font-size: 14px; border-left: 3px solid var(--brand);
}

/* ------------------------------------------------------------- exercise */
.exercise {
  border: 1px solid var(--brand-border); border-radius: var(--radius);
  margin: 36px 0 0; overflow: hidden;
}
.exercise > header {
  background: var(--brand-tint); padding: 14px 20px;
  border-bottom: 1px solid var(--brand-border);
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.exercise > header h2 { margin: 0; font-size: 1.1rem; color: var(--brand); }
.exercise .ex-body { padding: 20px; }
.ex-editor {
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  margin: 16px 0;
}
.ex-editor .CodeMirror { height: 320px; }
.ex-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.check-list { list-style: none; margin: 18px 0 0; padding: 0; }
.check-list li {
  display: flex; gap: 10px; align-items: flex-start; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  margin-bottom: 6px; font-size: 14px; background: var(--bg-raised);
}
.check-list li.pass { border-color: var(--success); background: var(--success-bg); }
.check-list li.fail { border-color: var(--danger); background: var(--danger-bg); }
.check-list .ic { flex: none; width: 17px; height: 17px; margin-top: 2px; }
.check-list .pt { margin-left: auto; font-size: 12px; color: var(--fg-secondary); font-weight: 600; }
.check-list .note { display: block; font-size: 12.5px; color: var(--fg-secondary); margin-top: 2px; }

.score-banner {
  display: flex; align-items: center; gap: 16px; padding: 16px 20px;
  border-radius: var(--radius); margin: 18px 0; font-weight: 600;
}
.score-banner.ok   { background: var(--success-bg); color: var(--success); }
.score-banner.part { background: var(--warning-bg); color: #8a6d00; }
.score-banner.bad  { background: var(--danger-bg);  color: var(--danger); }
[data-theme="dark"] .score-banner.part { color: var(--warning-accent); }
.score-banner .n { font-family: var(--font-display); font-size: 2rem; line-height: 1; }

/* -------------------------------------------------------- progress bars */
.progress {
  height: 4px; background: var(--bg-sunken); border-radius: 999px; overflow: hidden;
}
.progress > i { display: block; height: 100%; background: var(--brand); transition: width .4s var(--ease); }
.progress.lg { height: 8px; }

/* --------------------------------------------------------------- editor */
.editor-page {
  display: flex; flex-direction: column;
  /* 100vh on iOS Safari excludes the dynamic URL bar, so the status bar and
     part of the console ended up below the fold with overflow:hidden making
     them unreachable. dvh tracks the visible area; vh stays as the fallback. */
  height: calc(100vh - var(--header-h));
  height: calc(100dvh - var(--header-h));
  overflow: hidden;
}
.ed-toolbar {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 7px 12px; border-bottom: 1px solid var(--border);
  background: var(--bg-alt); flex: none;
}
.ed-toolbar .sep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }
.ed-toolbar .grow { flex: 1; }
.ed-title {
  font-weight: 600; font-size: 14px; border: 1px solid transparent;
  background: transparent; color: var(--fg); padding: 5px 8px;
  border-radius: var(--radius-sm); min-width: 110px; max-width: 240px;
  font-family: inherit;
}
.ed-title:hover { border-color: var(--border); }
.ed-title:focus { border-color: var(--brand); background: var(--bg); outline: none; }

select.ed-select, input.ed-input {
  font-family: inherit; font-size: 13px; padding: 6px 9px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--fg); min-height: 32px;
}
select.ed-select:focus, input.ed-input:focus { border-color: var(--brand); outline: none; }

.ed-panes { display: flex; flex: 1; min-height: 0; }
.ed-side {
  width: 260px; flex: none; border-right: 1px solid var(--border);
  background: var(--bg-alt); display: flex; flex-direction: column; min-height: 0;
}
.ed-side.collapsed { display: none; }
.ed-side-tabs { display: flex; border-bottom: 1px solid var(--border); flex: none; }
.ed-side-tabs button {
  flex: 1; background: none; border: 0; border-bottom: 2px solid transparent;
  font: inherit; font-size: 12.5px; padding: 9px 4px; cursor: pointer; color: var(--fg-secondary);
}
.ed-side-tabs button[aria-selected="true"] {
  color: var(--brand); border-bottom-color: var(--brand); font-weight: 600;
}
.ed-side-panel { flex: 1; overflow-y: auto; padding: 10px; min-height: 0; }

.file-list { list-style: none; margin: 0 0 10px; padding: 0; }
.file-list li {
  display: flex; align-items: center; gap: 7px; padding: 6px 8px; font-size: 13px;
  border-radius: var(--radius-sm); cursor: pointer; color: var(--fg-secondary);
}
.file-list li:hover { background: var(--bg-sunken); }
.file-list li.active { background: var(--brand-tint); color: var(--brand); font-weight: 600; }
.file-list li .fx { margin-left: auto; display: flex; gap: 2px; opacity: 0; pointer-events: none; }
.file-list li:hover .fx,
.file-list li:focus-within .fx { opacity: 1; pointer-events: auto; }
.file-list li .fx button {
  border: 0; background: none; cursor: pointer; color: var(--fg-muted);
  padding: 2px; line-height: 0; border-radius: 2px;
}
.file-list li .fx button:hover { color: var(--danger); background: var(--bg); }
.file-main-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--brand); flex: none; }

.sym-groups { display: flex; flex-direction: column; gap: 14px; }
.sym-group h4 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase;
  letter-spacing: .04em; color: var(--fg-secondary); }
.sym-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 4px; }
.sym-grid button {
  min-height: 36px; border: 1px solid var(--border); background: var(--bg);
  border-radius: var(--radius-sm); cursor: pointer; color: var(--fg);
  display: flex; align-items: center; justify-content: center; font-size: 14px;
  padding: 2px; overflow: hidden;
}
.sym-grid button:hover { border-color: var(--brand); background: var(--brand-tint); }
.snippet-list { display: flex; flex-direction: column; gap: 4px; }
.snippet-list button {
  text-align: left; border: 1px solid var(--border); background: var(--bg);
  border-radius: var(--radius-sm); padding: 8px 10px; cursor: pointer;
  font: inherit; font-size: 13px; color: var(--fg);
}
.snippet-list button:hover { border-color: var(--brand); background: var(--brand-tint); }
.snippet-list button span { display: block; font-size: 11.5px; color: var(--fg-secondary); }

.ed-main { flex: 1; display: flex; flex-direction: column; min-width: 320px; min-height: 0; }
.ed-editor-wrap { flex: 1; min-height: 0; position: relative; }
.ed-editor-wrap .CodeMirror { height: 100%; font-size: 14px; }

.splitter {
  flex: none; width: 5px; cursor: col-resize; background: var(--border);
  transition: background .12s var(--ease);
}
.splitter:hover, .splitter.dragging { background: var(--brand); }
.splitter.horizontal { width: auto; height: 5px; cursor: row-resize; }

.ed-preview {
  width: 46%; flex: none; display: flex; flex-direction: column;
  background: var(--bg-sunken); min-width: 240px; min-height: 0;
}
.ed-preview-bar {
  display: flex; align-items: center; gap: 6px; padding: 6px 10px;
  border-bottom: 1px solid var(--border); background: var(--bg-alt); flex: none;
  font-size: 12.5px; color: var(--fg-secondary);
}
.pdf-scroll { flex: 1; overflow: auto; padding: 16px; text-align: center; min-height: 0; }
.pdf-scroll canvas {
  display: block; margin: 0 auto 14px; box-shadow: var(--shadow-8); background: #fff;
  max-width: 100%;
}
.pdf-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; color: var(--fg-muted); gap: 12px; padding: 30px; text-align: center;
}
.pdf-empty svg { width: 44px; height: 44px; opacity: .5; }

.ed-console { flex: none; height: 190px; display: flex; flex-direction: column;
  border-top: 1px solid var(--border); background: var(--bg-alt); min-height: 0; }
.ed-console.collapsed { height: 36px; }
.ed-console-tabs { display: flex; align-items: center; gap: 2px; padding: 0 8px; flex: none;
  border-bottom: 1px solid var(--border); }
.ed-console-tabs button {
  background: none; border: 0; border-bottom: 2px solid transparent; font: inherit;
  font-size: 12.5px; padding: 9px 12px; cursor: pointer; color: var(--fg-secondary);
}
.ed-console-tabs button[aria-selected="true"] { color: var(--brand);
  border-bottom-color: var(--brand); font-weight: 600; }
.ed-console-body { flex: 1; overflow: auto; min-height: 0; }
.ed-console.collapsed .ed-console-body { display: none; }
.ed-console pre { margin: 0; padding: 12px 14px; font-size: 12px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word; }

.diag-list { list-style: none; margin: 0; padding: 4px 0; }
.diag-list li {
  display: flex; gap: 9px; padding: 7px 14px; font-size: 13px; cursor: pointer;
  border-left: 3px solid transparent; align-items: flex-start;
}
.diag-list li:hover { background: var(--bg-sunken); }
.diag-list li.error   { border-left-color: var(--danger); }
.diag-list li.warning { border-left-color: var(--warning-accent); }
.diag-list .loc { color: var(--fg-muted); font-family: var(--font-mono); font-size: 11.5px;
  flex: none; min-width: 46px; }
.diag-list .dtl { display: block; font-family: var(--font-mono); font-size: 11.5px;
  color: var(--fg-secondary); white-space: pre-wrap; margin-top: 3px; }

.cm-error-line { background: rgba(164, 38, 44, .12) !important; }
.cm-warn-line  { background: rgba(255, 185, 0, .12) !important; }

.ed-status {
  flex: none; display: flex; align-items: center; gap: 14px;
  padding: 4px 12px; font-size: 12px; color: var(--fg-secondary);
  border-top: 1px solid var(--border); background: var(--bg-alt); min-height: 26px;
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--fg-muted); flex: none; }
.dot.ok { background: var(--success); }
.dot.err { background: var(--danger); }
.dot.busy { background: var(--warning-accent); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .3 } }

@media (max-width: 900px) {
  .ed-panes { flex-direction: column; position: relative; }
  .ed-preview { width: auto; height: 45%; border-top: 1px solid var(--border); }
  .splitter { display: none; }
  /* The file sidebar is an overlay here, so it starts hidden and the toolbar
     button opens it. It used to render on top of the code area on every
     phone visit with no hint of how to dismiss it. */
  .ed-side {
    position: absolute; inset: 0 auto 0 0; z-index: 20; height: 100%;
    box-shadow: var(--shadow-16); display: none;
  }
  .ed-side.open { display: flex; }
  .ed-toolbar { gap: 4px; padding: 6px 8px; }
}

/* On a phone the 13-button toolbar wrapped to six rows and ate most of the
   screen. Drop the labels from the secondary actions — the icons and the
   title attributes carry them — and keep Compile spelled out. */
@media (max-width: 640px) {
  .ed-toolbar .btn-sm:not(.btn-primary) span { display: none; }
  .ed-toolbar .btn-sm:not(.btn-primary) { padding: 5px 9px; }
  .ed-toolbar .sep { display: none; }
  .ed-toolbar input[type="text"] { min-width: 0; flex: 1 1 90px; }
  .ed-toolbar label.row span { display: none; }
}

/* Pointer-coarse devices have no hover, so anything revealed by :hover is
   either invisible-but-tappable (the file delete button was exactly that) or
   unreachable. Show the row actions and give everything a real touch target. */
@media (hover: none) {
  .file-list li .fx { opacity: 1; }
  .icon-btn { min-width: 40px; min-height: 40px; }
  .btn-sm { min-height: 40px; }
  .ed-side-tabs button { min-height: 44px; }
}

/* --------------------------------------------------------------- modals */
.modal-backdrop {
  position: fixed; inset: 0; background: var(--bg-overlay); z-index: 300;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  animation: fade .12s var(--ease);
}
@keyframes fade { from { opacity: 0 } }
.modal {
  background: var(--bg-raised); border-radius: var(--radius);
  box-shadow: var(--shadow-16); width: 100%; max-width: 460px;
  max-height: 90vh; overflow: auto; border: 1px solid var(--border);
}
.modal.wide { max-width: 720px; }
.modal header {
  display: flex; align-items: center; padding: 18px 22px 0;
}
.modal header h2 { margin: 0; font-size: 1.25rem; }
.modal header .icon-btn { margin-left: auto; }
.modal .modal-body { padding: 14px 22px 22px; }
.modal footer { display: flex; gap: 10px; justify-content: flex-end; padding: 0 22px 22px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; font: inherit; font-size: 14px; padding: 8px 10px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--fg);
}
.field input:focus, .field select:focus { border-color: var(--brand); outline: none;
  box-shadow: 0 0 0 1px var(--brand); }
.field .hint { font-size: 12px; color: var(--fg-secondary); margin-top: 4px; }
.form-error {
  background: var(--danger-bg); color: var(--danger); border-radius: var(--radius-sm);
  padding: 9px 12px; font-size: 13px; margin-bottom: 14px;
}

/* --------------------------------------------------------------- toasts */
#toasts {
  position: fixed; right: 20px; bottom: 20px; z-index: 400;
  display: flex; flex-direction: column; gap: 10px; max-width: 380px;
}
.toast {
  background: var(--bg-raised); border: 1px solid var(--border);
  border-left: 4px solid var(--brand); border-radius: var(--radius);
  box-shadow: var(--shadow-16); padding: 12px 16px; font-size: 14px;
  animation: slide .18s var(--ease);
}
@keyframes slide { from { transform: translateY(8px); opacity: 0 } }
.toast.success { border-left-color: var(--success); }
.toast.error   { border-left-color: var(--danger); }
.toast .t { font-weight: 600; }
.toast-action {
  margin-top: 8px; border: 1px solid var(--border-strong); background: var(--bg);
  color: var(--brand); font: inherit; font-weight: 600; cursor: pointer;
  border-radius: var(--radius-sm); padding: 5px 12px; min-height: 32px;
}
.toast-action:hover { background: var(--bg-sunken); }
@media (hover: none) { .toast-action { min-height: 40px; } }

/* the save indicator turns into a warning when local storage is full */
.ed-status .danger, .danger { color: var(--danger); }

/* --------------------------------------------------------------- tables */
.tpl-grid { display: grid; gap: 20px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.tpl-card .tpl-preview {
  height: 120px; border-radius: var(--radius-sm); margin-bottom: 14px;
  background: linear-gradient(135deg, var(--brand-tint), var(--bg-sunken));
  display: flex; align-items: center; justify-content: center;
  color: var(--brand); font-family: var(--font-mono); font-size: 12px;
  border: 1px solid var(--border); overflow: hidden; position: relative;
}
.tpl-card .tpl-preview .sheet {
  width: 62px; height: 84px; background: #fff; box-shadow: var(--shadow-4);
  padding: 8px 7px; display: flex; flex-direction: column; gap: 3px;
}
.tpl-card .tpl-preview .sheet i { display: block; height: 3px; background: #c8c6c4; border-radius: 1px; }
.tpl-card .tpl-preview .sheet i.h { height: 5px; background: var(--brand); width: 70%; }
.tpl-card .tpl-preview .sheet i.s { width: 45%; }

/* ------------------------------------------------------------ reference */
.ref-search { display: flex; gap: 10px; margin-bottom: 24px; flex-wrap: wrap; }
.ref-search input { flex: 1 1 260px; font: inherit; padding: 10px 14px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--fg); }
.ref-search input:focus { border-color: var(--brand); outline: none; }

.sym-table { display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: 8px; }
.sym-cell {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; background: var(--bg-raised); text-align: left; font: inherit;
  color: var(--fg);
}
.sym-cell:hover { border-color: var(--brand); background: var(--brand-tint); }
.sym-cell .glyph { min-width: 32px; text-align: center; font-size: 15px; }
.sym-cell code { font-size: 11.5px; background: none; border: 0; padding: 0;
  color: var(--fg-secondary); word-break: break-all; }

/* ------------------------------------------------------------- progress */
.dash-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 18px; }
.stat-tile {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; background: var(--bg-raised);
}
.stat-tile b { display: block; font-family: var(--font-display); font-size: 2.2rem;
  line-height: 1.1; font-weight: 600; }
.stat-tile span { font-size: 13px; color: var(--fg-secondary); }

/* --------------------------------------------------------------- footer */
.site-footer {
  background: var(--bg-sunken); border-top: 1px solid var(--border);
  padding: 40px 0 26px; font-size: 13px; color: var(--fg-secondary);
  margin-top: 0;
}
.site-footer .cols {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 26px; margin-bottom: 28px;
}
.site-footer h3 { font-size: 13px; color: var(--fg); margin: 0 0 10px; }
.site-footer ul { list-style: none; margin: 0; padding: 0; }
.site-footer li { margin-bottom: 7px; }
.site-footer a { color: var(--fg-secondary); }
.site-footer a:hover { color: var(--fg); }
.site-footer .legal {
  display: flex; gap: 18px; flex-wrap: wrap; align-items: center;
  padding-top: 18px; border-top: 1px solid var(--border); font-size: 12px;
}

/* --------------------------------------------------------------- misc */
.spinner {
  width: 15px; height: 15px; border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin .7s linear infinite; flex: none;
}
@keyframes spin { to { transform: rotate(360deg) } }

.loading-page {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 100px 20px; color: var(--fg-secondary);
}

.empty-state {
  text-align: center; padding: 70px 20px; color: var(--fg-secondary);
}
.empty-state svg { width: 46px; height: 46px; opacity: .4; margin-bottom: 14px; }

.katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }

@media print {
  .site-header, .site-footer, .toc-rail, .on-this-page, .lesson-nav { display: none; }
}

/* ==========================================================================
   Additions — search trigger, command palette, editor panels, share, a11y
   ========================================================================== */

/* --------------------------------------------------------- search button */
.search-trigger {
  display: inline-flex; align-items: center; gap: 8px;
  height: 32px; padding: 0 10px 0 11px; margin-right: 4px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--bg-alt); color: var(--fg-secondary);
  font: inherit; font-size: 13px; cursor: pointer; min-width: 180px;
  transition: border-color .12s var(--ease), background .12s var(--ease);
}
.search-trigger:hover { border-color: var(--brand); background: var(--bg); }
.search-trigger svg { width: 15px; height: 15px; flex: none; }
.search-trigger span { flex: 1; text-align: left; }

kbd, .kbd-hint {
  display: inline-block; font-family: var(--font-mono); font-size: 11px;
  line-height: 1.5; padding: 1px 6px; color: var(--fg-secondary);
  background: var(--bg-sunken); border: 1px solid var(--border);
  border-bottom-width: 2px; border-radius: 3px; white-space: nowrap;
}
@media (max-width: 1100px) { .search-trigger { min-width: 0; } .search-trigger span,
  .search-trigger .kbd-hint { display: none; } }

/* ------------------------------------------------------- command palette */
.cp-backdrop {
  position: fixed; inset: 0; z-index: 350; background: var(--bg-overlay);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 12vh 16px 16px; animation: fade .12s var(--ease);
  backdrop-filter: blur(2px);
}
.cp-box {
  width: 100%; max-width: 660px; background: var(--bg-raised);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-16); overflow: hidden;
  display: flex; flex-direction: column; max-height: 70vh;
  animation: cp-in .14s var(--ease);
}
@keyframes cp-in { from { transform: translateY(-8px); opacity: .4 } }
.cp-head {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  border-bottom: 1px solid var(--border); flex: none; color: var(--fg-muted);
}
.cp-input {
  flex: 1; border: 0; background: none; font: inherit; font-size: 16px;
  color: var(--fg); outline: none; min-width: 0;
}
.cp-results { overflow-y: auto; flex: 1; padding: 6px 0; min-height: 90px; }
.cp-group {
  font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase;
  color: var(--fg-muted); padding: 10px 16px 5px;
}
.cp-item {
  display: flex; align-items: center; gap: 12px; padding: 8px 16px;
  cursor: pointer; border-left: 2px solid transparent;
}
.cp-item.active { background: var(--brand-tint); border-left-color: var(--brand); }
.cp-glyph {
  width: 26px; height: 26px; flex: none; display: flex; align-items: center;
  justify-content: center; color: var(--brand); background: var(--bg-sunken);
  border-radius: var(--radius-sm); font-size: 13px; overflow: hidden;
}
.cp-item.active .cp-glyph { background: var(--bg); }
.cp-text { min-width: 0; flex: 1; }
.cp-title {
  font-size: 14px; font-weight: 600; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.cp-sub {
  font-size: 12px; color: var(--fg-secondary); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.cp-empty {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 40px 20px; color: var(--fg-muted);
}
.cp-foot {
  display: flex; align-items: center; padding: 8px 14px; flex: none;
  border-top: 1px solid var(--border); background: var(--bg-alt);
  font-size: 12px; color: var(--fg-muted);
}

/* --------------------------------------------------------- resume card */
.resume-card {
  display: flex; align-items: center; gap: 18px;
  border: 1px solid var(--brand-border); background: var(--brand-tint);
  border-radius: var(--radius); padding: 18px 22px; color: inherit;
  transition: box-shadow .15s var(--ease), transform .15s var(--ease);
}
.resume-card:hover {
  text-decoration: none; box-shadow: var(--shadow-8); transform: translateY(-1px);
}
.resume-card .card-icon { margin: 0; background: var(--bg); }
.resume-card .grow { flex: 1; min-width: 0; }
.resume-title { font-family: var(--font-display); font-size: 1.2rem; font-weight: 600; }
.resume-meter { width: 160px; flex: none; }
.resume-meter .progress { margin-bottom: 6px; }
@media (max-width: 720px) { .resume-meter { display: none; } }

/* ------------------------------------------------------ lesson controls */
.lesson-done-row {
  display: flex; align-items: center; gap: 12px; margin-top: 34px;
  padding-top: 20px; border-top: 1px solid var(--border);
}

/* ------------------------------------------------------ editor: outline */
.outline-list { display: flex; flex-direction: column; gap: 1px; }
.outline-item {
  text-align: left; border: 0; background: none; font: inherit; font-size: 13px;
  color: var(--fg-secondary); padding: 5px 8px; cursor: pointer;
  border-radius: var(--radius-sm); border-left: 2px solid transparent;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.outline-item:hover { background: var(--bg-sunken); color: var(--brand); border-left-color: var(--brand); }
.outline-item.lvl0 { font-weight: 600; color: var(--fg); }
.outline-item.lvl1 { font-weight: 600; color: var(--fg); }
.outline-item.lvl2 { padding-left: 20px; }
.outline-item.lvl3 { padding-left: 32px; font-size: 12.5px; }
.outline-item.lvl4 { padding-left: 44px; font-size: 12.5px; font-style: italic; }

/* ------------------------------------------------- editor: engine notice */
.engine-warn {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 14px; font-size: 13px; flex: none;
  background: var(--warning-bg); color: #6b5200;
  border-bottom: 1px solid var(--border);
}
[data-theme="dark"] .engine-warn { color: var(--warning-accent); }
.engine-warn svg { flex: none; }
.engine-warn .btn { margin-left: auto; }
.engine-warn .btn + .btn { margin-left: 0; }

/* ------------------------------------------------- editor: project rows */
.project-row {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 9px 12px; margin-bottom: 8px; background: var(--bg-raised);
}
.project-row .grow { flex: 1; min-width: 0; }
.project-row .grow > div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.panel-h {
  font-size: 12px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--fg-secondary); margin: 22px 0 10px;
}

/* ----------------------------------------------------- editor: page box */
.page-input {
  width: 46px; text-align: center; font: inherit; font-size: 12.5px;
  padding: 3px 4px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--bg); color: var(--fg);
}
.page-input:focus { border-color: var(--brand); outline: none; }
.ed-preview:fullscreen { background: var(--bg-sunken); }
.ed-preview:fullscreen .pdf-scroll { padding: 24px; }

/* --------------------------------------------------------- reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ----------------------------------------------------- high-contrast mode */
@media (forced-colors: active) {
  .card, .btn, .cp-box, .modal { border: 1px solid CanvasText; }
  .progress > i { background: Highlight; }
}

/* ==========================================================================
   v1.2 — SyncTeX highlights, AI assistant panel, editor drop target
   ========================================================================== */

/* ------------------------------------------------------ SyncTeX highlight */
.pdf-page { position: relative; margin: 0 auto 14px; }
.pdf-page canvas { display: block; margin: 0; }
.pdf-hl {
  position: absolute; pointer-events: none; border-radius: 2px;
  background: rgba(255, 185, 0, .34);
  box-shadow: 0 0 0 1.5px rgba(255, 185, 0, .85);
  transition: opacity .8s ease;
}
.pdf-hl.fade { opacity: 0; }
.pdf-scroll .pdf-page canvas { box-shadow: var(--shadow-8); background: #fff; }

.cm-sync-line { background: rgba(0, 103, 184, .16) !important; }

.ed-editor-wrap.drag-over::after {
  content: ""; position: absolute; inset: 6px; pointer-events: none;
  border: 2px dashed var(--brand); border-radius: var(--radius);
  background: var(--brand-tint); opacity: .55;
}

/* ------------------------------------------------------------ AI drawer */
.ed-ai {
  width: 360px; min-width: 300px; flex: none; border-left: 1px solid var(--border);
  background: var(--bg-alt); display: flex; flex-direction: column; min-height: 0;
}
@media (max-width: 1100px) {
  .ed-ai { position: absolute; right: 0; top: 0; height: 100%; z-index: 30;
           box-shadow: var(--shadow-16); }
}
@media (max-width: 620px) { .ed-ai { width: 100%; } }

.ai-panel { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.ai-slot .ai-panel { height: 420px; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--bg-alt); margin-top: 14px; }

.ai-head {
  display: flex; align-items: center; gap: 8px; flex: none;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.ai-head svg { color: var(--brand); }

.ai-chips {
  display: flex; gap: 6px; flex-wrap: wrap; padding: 10px 12px 4px; flex: none;
}
.ai-chip {
  font: inherit; font-size: 12.5px; padding: 4px 11px; cursor: pointer;
  border: 1px solid var(--border-strong); border-radius: 999px;
  background: var(--bg); color: var(--fg-secondary);
}
.ai-chip:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-tint); }

.ai-log { flex: 1; overflow-y: auto; padding: 10px 12px; min-height: 0; }
.ai-empty {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 34px 18px; color: var(--fg-muted); text-align: center; font-size: 13px;
}
.ai-msg { margin-bottom: 14px; }
.ai-role {
  display: flex; align-items: center; gap: 5px; font-size: 11.5px;
  color: var(--fg-muted); margin-bottom: 4px; font-weight: 600;
}
.ai-msg.user .ai-body {
  background: var(--brand-tint); border: 1px solid var(--brand-border);
  border-radius: var(--radius); padding: 8px 12px; font-size: 13.5px;
  white-space: pre-wrap; word-break: break-word;
}
.ai-msg.assistant .ai-body { font-size: 13.5px; }
.ai-msg.assistant .ai-body p { margin: 0 0 .7em; }
.ai-msg.assistant .ai-body .code-block { margin: 10px 0; }
.ai-msg.assistant .ai-body pre { font-size: 12px; padding: 10px 12px; }
.ai-msg.assistant .ai-body h2,
.ai-msg.assistant .ai-body h3 { font-size: 1rem; margin: 1em 0 .4em; }
.ai-error {
  display: flex; gap: 8px; align-items: flex-start; font-size: 13px;
  color: var(--danger); background: var(--danger-bg);
  border-radius: var(--radius-sm); padding: 9px 12px;
}

.ai-foot { flex: none; padding: 10px 12px; border-top: 1px solid var(--border); }
.ai-input {
  width: 100%; font: inherit; font-size: 13.5px; resize: vertical;
  padding: 8px 10px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--bg); color: var(--fg);
  min-height: 46px;
}
.ai-input:focus { border-color: var(--brand); outline: none; }

.diag-ai { margin-left: 8px; flex: none; }
.diag-list li:hover .diag-ai { border-color: var(--brand); color: var(--brand); }

/* ==========================================================================
   v1.3 — quick fixes, version history, table builder, review list
   ========================================================================== */

/* --------------------------------------------------------- quick fix bar */
.fix-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; flex: none;
  padding: 8px 14px; font-size: 13px;
  background: var(--tip-bg); border-bottom: 1px solid var(--border);
}
.fix-bar svg { color: var(--success); flex: none; }
.fix-bar .btn { background: var(--bg); }

/* ------------------------------------------------------- version history */
.history-split { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 18px; }
@media (max-width: 720px) { .history-split { grid-template-columns: 1fr; } }
.history-list { max-height: 62vh; overflow-y: auto; }
.history-item {
  display: flex; flex-direction: column; gap: 2px; padding: 9px 12px;
  border: 1px solid var(--border); border-left: 3px solid transparent;
  border-radius: var(--radius-sm); margin-bottom: 6px; cursor: pointer;
  background: var(--bg-raised);
}
.history-item:hover { border-color: var(--border-strong); }
.history-item.active { border-left-color: var(--brand); background: var(--brand-tint); }
.history-item.current strong { color: var(--brand); }
.history-detail { max-height: 62vh; overflow-y: auto; min-width: 0; }
.diff-file { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 14px; }
.diff-head {
  display: flex; align-items: center; gap: 10px; padding: 7px 12px;
  background: var(--bg-alt); border-bottom: 1px solid var(--border); font-size: 13px;
}
.diff { font-family: var(--font-mono); font-size: 12px; line-height: 1.5; overflow-x: auto; }
.diff-row { padding: 0 12px; white-space: pre; }
.diff-row.add { background: var(--success-bg); color: var(--success); }
.diff-row.del { background: var(--danger-bg); color: var(--danger); }
.diff-row.gap { color: var(--fg-muted); background: var(--bg-alt); font-style: italic; }

/* -------------------------------------------------------- table builder */
.tbl-builder { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 20px; }
@media (max-width: 720px) { .tbl-builder { grid-template-columns: 1fr; } }
.tbl-form .field { margin-bottom: 10px; }
.tbl-form label.row { margin-bottom: 8px; font-size: 13.5px; }
.tbl-preview {
  margin: 0; padding: 14px; background: var(--bg-sunken); border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 12px; line-height: 1.5;
  overflow: auto; max-height: 52vh; white-space: pre;
}

/* ---------------------------------------------------------- review list */
.review-grid {
  display: grid; gap: 10px; margin-top: 14px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.review-card {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-raised); color: inherit;
}
.review-card:hover { border-color: var(--brand); text-decoration: none; box-shadow: var(--shadow-4); }
.review-card .grow { flex: 1; min-width: 0; }
.review-card .grow > div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.review-score {
  font-weight: 600; font-size: 13px; padding: 3px 10px; border-radius: 999px; flex: none;
}
.review-score.warn { background: var(--warning-bg); color: #8a6d00; }
.review-score.bad { background: var(--danger-bg); color: var(--danger); }
[data-theme="dark"] .review-score.warn { color: var(--warning-accent); }
