/* ============ Tokens ============ */
:root {
  --bg: #F6F3FA;
  --bg-2: #EEE8F6;
  --surface: #FFFFFF;
  --surface-2: #FAF8FD;
  --ink: #2A2140;
  --ink-2: #5B5273;
  --ink-3: #8A82A0;
  --line: #E5DEF0;
  --line-2: #D8CFE8;

  --lav: #8B76E0;
  --rose: #DD7BA3;
  --peri: #5C80E4;
  --gold: #D9A752;
  --mint: #4FAF95;
  --lav-soft: #EEE9FC;
  --rose-soft: #FBEAF1;
  --peri-soft: #E8EEFC;
  --gold-soft: #FAF0DC;
  --mint-soft: #E3F4EF;

  --grad: linear-gradient(120deg, #8B76E0 0%, #B57ACB 50%, #DD7BA3 100%);
  --grad-py: linear-gradient(135deg, #5C80E4, #8B76E0 55%, #DD7BA3);

  /* the editor stays dark in both themes */
  --code-bg: #211A31;
  --code-bg-2: #2A2140;
  --code-line: #3A2F52;
  --code-ink: #E9E3F5;
  --code-dim: #8F84AB;
  --tk-key: #F29CC4;
  --tk-str: #F1D08F;
  --tk-fn: #A9BAFF;
  --tk-num: #F6AE8E;
  --tk-com: #8C80A9;
  --tk-bi: #95DCCB;

  --shadow-sm: 0 1px 2px rgba(58, 32, 92, .06), 0 2px 6px rgba(58, 32, 92, .04);
  --shadow-md: 0 1px 2px rgba(58, 32, 92, .05), 0 14px 34px -14px rgba(76, 42, 120, .22);
  --shadow-lg: 0 2px 4px rgba(58, 32, 92, .05), 0 30px 60px -24px rgba(76, 42, 120, .32);

  --r-xl: 28px; --r-lg: 20px; --r-md: 14px; --r-sm: 10px;
  --ease: cubic-bezier(.22, .8, .24, 1);
  --ease-spring: cubic-bezier(.34, 1.4, .5, 1);

  --font: 'Sora', ui-sans-serif, system-ui, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'Cascadia Code', Consolas, monospace;

  --gutter: clamp(16px, 4vw, 40px);
  --maxw: 1240px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15111D; --bg-2: #1B1626; --surface: #1F1A2B; --surface-2: #251F33;
    --ink: #F1ECF8; --ink-2: #BBB1CD; --ink-3: #8C82A1; --line: #2F2740; --line-2: #3B3250;
    --lav: #A897F2; --rose: #EE96B8; --peri: #8AA4F5; --gold: #E8C27C; --mint: #74CDB4;
    --lav-soft: #2A2342; --rose-soft: #352232; --peri-soft: #212A45; --gold-soft: #33291C; --mint-soft: #1C3330;
    --code-bg: #1A1527; --code-bg-2: #211A31;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
    --shadow-md: 0 1px 2px rgba(0,0,0,.3), 0 16px 36px -16px rgba(0,0,0,.6);
    --shadow-lg: 0 2px 4px rgba(0,0,0,.3), 0 30px 60px -24px rgba(0,0,0,.7);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15111D; --bg-2: #1B1626; --surface: #1F1A2B; --surface-2: #251F33;
  --ink: #F1ECF8; --ink-2: #BBB1CD; --ink-3: #8C82A1; --line: #2F2740; --line-2: #3B3250;
  --lav: #A897F2; --rose: #EE96B8; --peri: #8AA4F5; --gold: #E8C27C; --mint: #74CDB4;
  --lav-soft: #2A2342; --rose-soft: #352232; --peri-soft: #212A45; --gold-soft: #33291C; --mint-soft: #1C3330;
  --code-bg: #1A1527; --code-bg-2: #211A31;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  --shadow-md: 0 1px 2px rgba(0,0,0,.3), 0 16px 36px -16px rgba(0,0,0,.6);
  --shadow-lg: 0 2px 4px rgba(0,0,0,.3), 0 30px 60px -24px rgba(0,0,0,.7);
  color-scheme: dark;
}

/* ============ Base ============ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink);
  font: 400 16px/1.6 var(--font); letter-spacing: -0.005em;
  -webkit-font-smoothing: antialiased; overflow-x: hidden;
  transition: background-color .4s var(--ease), color .4s var(--ease);
}
img, svg { display: block; max-width: 100%; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.025em; line-height: 1.15; }
p { margin: 0; }
kbd { font: 500 11px/1 var(--mono); padding: 4px 6px; border-radius: 6px; border: 1px solid var(--line-2); color: var(--ink-3); background: var(--surface-2); }
:focus-visible { outline: 2px solid var(--lav); outline-offset: 3px; border-radius: 8px; }
::selection { background: color-mix(in srgb, var(--lav) 30%, transparent); }
code, pre, kbd { font-family: var(--mono); font-variant-ligatures: none; }

svg path, svg circle, svg line, svg rect, svg polyline { vector-effect: non-scaling-stroke; }
.topbar svg, .icon-btn svg, .btn svg, .search-btn svg, .palette svg, .chip svg, .tab svg {
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}

/* ============ Ambient background ============ */
.bg { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.orb { position: absolute; border-radius: 50%; filter: blur(70px); opacity: .55; will-change: transform; }
.orb-a { width: 46vmax; height: 46vmax; left: -12vmax; top: -16vmax; background: radial-gradient(circle, #CFC3F7, transparent 65%); animation: drift-a 38s ease-in-out infinite alternate; }
.orb-b { width: 40vmax; height: 40vmax; right: -14vmax; top: 10vh; background: radial-gradient(circle, #F6C9DC, transparent 65%); animation: drift-b 44s ease-in-out infinite alternate; }
.orb-c { width: 34vmax; height: 34vmax; left: 30vw; bottom: -18vmax; background: radial-gradient(circle, #C8D5FA, transparent 65%); animation: drift-a 50s ease-in-out infinite alternate-reverse; }
:root[data-theme="dark"] .orb { opacity: .16; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .orb { opacity: .16; } }
.grid {
  position: absolute; inset: 0;
  background-image: radial-gradient(color-mix(in srgb, var(--ink) 13%, transparent) 1px, transparent 1.2px);
  background-size: 26px 26px;
  mask-image: radial-gradient(ellipse at 50% 0%, #000 0%, transparent 70%);
  -webkit-mask-image: radial-gradient(ellipse at 50% 0%, #000 0%, transparent 70%);
  opacity: .5;
}
@keyframes drift-a { to { transform: translate(8vw, 6vh) scale(1.08); } }
@keyframes drift-b { to { transform: translate(-6vw, 10vh) scale(.94); } }

/* ============ Intro ============ */
.intro {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
  background: radial-gradient(ellipse at 50% 40%, #2E2347 0%, #1A1427 55%, #120E1C 100%);
  color: #F3EEFB; transition: opacity .9s var(--ease), visibility .9s, filter .9s var(--ease);
}
.no-intro .intro { display: none; }
.intro.is-leaving { opacity: 0; visibility: hidden; filter: blur(6px); }
.intro-inner { text-align: center; padding: 0 var(--gutter); }
.intro-prompt {
  font: 400 clamp(13px, 1.6vw, 16px)/1 var(--mono); color: #B9ADD6; margin-bottom: 28px;
  min-height: 1em; opacity: 0; animation: fade-in .5s .15s var(--ease) forwards;
}
.intro-chevrons { color: #F29CC4; }
.intro-prompt .tk-str { color: var(--tk-str); }
.intro-prompt .tk-fn { color: var(--tk-fn); }
.caret { display: inline-block; width: .55em; height: 1.05em; margin-left: 2px; vertical-align: -0.15em; background: #F29CC4; animation: blink 1s steps(1) infinite; }
.intro-title {
  font-size: clamp(48px, 11vw, 132px); font-weight: 600; letter-spacing: -0.045em; line-height: 1; color: #F3EEFB;
}
.intro-title .ch { display: inline-block; opacity: 0; transform: translateY(.35em); filter: blur(10px); color: var(--c); text-shadow: 0 0 40px color-mix(in srgb, var(--c) 45%, transparent); }
.intro.play .intro-title .ch { animation: letter-in 1s var(--ease) forwards; animation-delay: calc(1.05s + var(--i) * 45ms); }
.intro-line { width: min(380px, 60vw); height: 10px; margin: 22px auto 16px; overflow: visible; }
.intro-line path { fill: none; stroke: #DD7BA3; stroke-width: 2; stroke-linecap: round; stroke-dasharray: 420; stroke-dashoffset: 420; }
.intro.play .intro-line path { animation: draw 1.1s 1.7s var(--ease) forwards; }
.intro-sub { font-size: 14px; color: #A99DC6; letter-spacing: .02em; opacity: 0; }
.intro.play .intro-sub { animation: fade-up .8s 2.05s var(--ease) forwards; }
.intro-skip {
  position: absolute; bottom: max(24px, env(safe-area-inset-bottom)); right: 24px;
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.12); color: #CFC6E4;
  padding: 8px 14px; border-radius: 999px; font-size: 13px; opacity: 0; animation: fade-in .6s 1.2s forwards;
  transition: background .2s;
}
.intro-skip:hover { background: rgba(255,255,255,.12); }
@keyframes letter-in { to { opacity: 1; transform: none; filter: blur(0); } }
@keyframes sheen { from { background-position: 100% 0; } to { background-position: 0% 0; } }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes fade-in { to { opacity: 1; } }
@keyframes fade-up { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ============ Top bar ============ */
.topbar {
  position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 20px;
  padding: 14px var(--gutter); max-width: calc(var(--maxw) + 2 * var(--gutter)); margin: 0 auto;
  transition: transform .5s var(--ease), opacity .5s;
}
.topbar::before {
  content: ''; position: absolute; inset: 0; z-index: -1;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: blur(16px) saturate(1.3); -webkit-backdrop-filter: blur(16px) saturate(1.3);
  border-bottom: 1px solid transparent; transition: border-color .3s;
  left: calc(50% - 50vw); right: calc(50% - 50vw);
}
.scrolled .topbar::before { border-bottom-color: var(--line); }
.brand { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 11px; background: var(--grad); display: grid; place-items: center;
  box-shadow: 0 6px 16px -6px color-mix(in srgb, var(--lav) 70%, transparent);
  transition: transform .5s var(--ease-spring);
}
.brand:hover .brand-mark { transform: rotate(-8deg) scale(1.05); }
.brand-mark svg { width: 20px; height: 20px; stroke: #fff; stroke-width: 2.4; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text b { font-weight: 600; font-size: 15px; letter-spacing: -0.02em; }
.brand-text small { font: 500 11px/1.3 var(--mono); color: var(--ink-3); }

.mainnav { display: flex; gap: 2px; margin: 0 auto; position: relative; }
.mainnav a {
  position: relative; padding: 8px 14px; border-radius: 999px; font-size: 14px; color: var(--ink-2);
  transition: color .25s; white-space: nowrap; z-index: 1;
}
.mainnav a:hover { color: var(--ink); }
.mainnav a.active { color: var(--ink); }
.nav-pill {
  position: absolute; top: 0; height: 100%; border-radius: 999px; background: var(--surface);
  box-shadow: var(--shadow-sm); border: 1px solid var(--line); z-index: 0;
  transition: left .45s var(--ease), width .45s var(--ease), opacity .3s;
}
.top-actions { display: flex; gap: 8px; align-items: center; margin-left: auto; }
.mainnav + .top-actions { margin-left: 0; }
.search-btn {
  display: flex; align-items: center; gap: 10px; height: 40px; padding: 0 8px 0 12px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink-3); font-size: 14px;
  transition: border-color .2s, box-shadow .2s;
}
.search-btn:hover { border-color: var(--line-2); box-shadow: var(--shadow-sm); }
.search-btn svg { width: 17px; height: 17px; }
.search-btn span { min-width: 60px; text-align: left; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--line); transition: border-color .2s, transform .3s var(--ease-spring);
}
.icon-btn:hover { border-color: var(--line-2); }
.icon-btn:active { transform: scale(.92); }
.icon-btn svg { width: 18px; height: 18px; grid-area: 1 / 1; transition: transform .5s var(--ease-spring), opacity .3s; }
.i-moon { opacity: 0; transform: rotate(-60deg) scale(.5); }
:root[data-theme="dark"] .i-sun { opacity: 0; transform: rotate(60deg) scale(.5); }
:root[data-theme="dark"] .i-moon { opacity: 1; transform: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .i-sun { opacity: 0; transform: rotate(60deg) scale(.5); }
  :root:not([data-theme]) .i-moon { opacity: 1; transform: none; }
}

/* mobile tab bar */
.tabbar { display: none; }

/* ============ Layout ============ */
main { max-width: calc(var(--maxw) + 2 * var(--gutter)); margin: 0 auto; padding: 8px var(--gutter) 96px; outline: none; }
.view { animation: view-in .55s var(--ease) both; }
@keyframes view-in { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.view-leave { animation: view-out .22s ease both; }
@keyframes view-out { to { opacity: 0; transform: translateY(-6px); } }

.btn {
  display: inline-flex; align-items: center; gap: 8px; height: 42px; padding: 0 18px; border-radius: 12px;
  font-size: 14px; font-weight: 500; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  transition: transform .25s var(--ease-spring), box-shadow .25s, border-color .2s, background .2s; white-space: nowrap;
}
.btn:hover { border-color: var(--line-2); box-shadow: var(--shadow-sm); }
.btn:active { transform: scale(.96); }
.btn svg { width: 17px; height: 17px; }
.btn-primary { background: var(--grad); color: #fff; border-color: transparent; box-shadow: 0 8px 20px -10px color-mix(in srgb, var(--rose) 80%, transparent); }
.btn-primary:hover { box-shadow: 0 12px 26px -10px color-mix(in srgb, var(--rose) 90%, transparent); border-color: transparent; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface); }
.btn-sm { height: 34px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn.is-on { background: var(--mint-soft); border-color: color-mix(in srgb, var(--mint) 40%, transparent); color: var(--mint); }

/* ============ Home: hero ============ */
.hero { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.08fr); gap: clamp(28px, 4vw, 56px); align-items: center; padding: clamp(20px, 5vw, 56px) 0 clamp(40px, 6vw, 72px); }
.hero-copy h1 { font-size: clamp(36px, 5.4vw, 62px); font-weight: 600; letter-spacing: -0.045em; line-height: 1.04; }
.hero-copy h1 .grad { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero-copy > p { margin-top: 18px; font-size: 17px; color: var(--ink-2); max-width: 46ch; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 28px; }

.continue {
  display: flex; align-items: center; gap: 14px; margin-top: 28px; padding: 10px 14px 10px 10px; max-width: 420px;
  border-radius: 16px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-sm);
  transition: transform .3s var(--ease), box-shadow .3s;
}
.continue:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.continue img { width: 64px; height: 44px; object-fit: cover; object-position: top; border-radius: 9px; border: 1px solid var(--line); background: var(--bg-2); }
.continue small { display: block; font-size: 12px; color: var(--ink-3); }
.continue strong { display: block; font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.continue > div { min-width: 0; }

/* Editor window + flowchart visualizer */
.editor {
  border-radius: var(--r-xl); background: var(--code-bg); color: var(--code-ink); overflow: hidden;
  box-shadow: var(--shadow-lg), inset 0 0 0 1px rgba(255,255,255,.05); position: relative;
}
.editor-bar { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--code-line); background: var(--code-bg-2); }
.dots { display: flex; gap: 6px; }
.dots i { width: 11px; height: 11px; border-radius: 50%; background: #F29CC4; }
.dots i:nth-child(2) { background: #F1D08F; }
.dots i:nth-child(3) { background: #95DCCB; }
.editor-tab { margin-left: 10px; font: 400 12px/1 var(--mono); color: var(--code-dim); padding: 6px 10px; border-radius: 7px; background: rgba(255,255,255,.04); }
.editor-ctrl { margin-left: auto; display: flex; gap: 6px; }
.ectl {
  height: 30px; padding: 0 11px; border-radius: 8px; border: 1px solid var(--code-line); background: rgba(255,255,255,.03);
  color: var(--code-ink); font: 500 12px/1 var(--font); display: inline-flex; align-items: center; gap: 6px; transition: background .2s, border-color .2s;
}
.ectl:hover { background: rgba(255,255,255,.08); }
.ectl svg { width: 13px; height: 13px; fill: currentColor; stroke: none; }
.ectl svg.i-line { fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.ectl.run { background: linear-gradient(120deg, #8B76E0, #DD7BA3); border-color: transparent; color: #fff; }
.editor-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.ed-left { border-right: 1px solid var(--code-line); display: flex; flex-direction: column; min-width: 0; }
.ed-code { padding: 16px 0; font: 400 13px/1.75 var(--mono); overflow-x: auto; scrollbar-width: none; }
.ed-code .ln span { white-space: pre; }
.ed-code .ln { display: flex; padding: 0 16px; transition: background .3s; position: relative; }
.ed-code .ln i { font-style: normal; width: 22px; flex-shrink: 0; color: #5D5278; user-select: none; }
.ed-code .ln.hot { background: rgba(242,156,196,.1); }
.ed-code .ln.hot::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 2px; background: #F29CC4; }
.ed-vars { margin: 0 16px; padding: 10px 12px; border-radius: 10px; background: rgba(255,255,255,.035); border: 1px solid var(--code-line); font: 400 12px/1.6 var(--mono); display: flex; gap: 18px; }
.ed-vars span { color: var(--code-dim); }
.ed-vars b { font-weight: 500; color: var(--tk-num); display: inline-block; min-width: 2ch; transition: transform .3s var(--ease-spring); }
.ed-vars b.bump { animation: bump .45s var(--ease-spring); }
@keyframes bump { 40% { transform: scale(1.35); color: #fff; } }
.ed-term { margin: 12px 16px 16px; flex: 1; min-height: 120px; max-height: 150px; overflow: hidden; border-radius: 10px; background: #150F21; padding: 10px 12px; font: 400 12px/1.65 var(--mono); color: #CFC6E4; display: flex; flex-direction: column; justify-content: flex-end; }
.ed-term .tline { animation: fade-up .35s var(--ease) both; white-space: pre; }
.ed-term .tdim { color: #6E6390; }
.ed-flow { padding: 10px; display: grid; place-items: center; min-width: 0; }
.flow { width: 100%; max-width: 320px; height: auto; overflow: visible; }
.flow .node rect, .flow .node polygon, .flow .node ellipse { fill: rgba(255,255,255,.04); stroke: #4A3E66; stroke-width: 1.2; transition: fill .35s, stroke .35s, filter .35s; }
.flow .node text { fill: #CFC6E4; font: 400 11px var(--mono); text-anchor: middle; dominant-baseline: central; transition: fill .3s; }
.flow .node.on rect, .flow .node.on polygon, .flow .node.on ellipse { fill: rgba(242,156,196,.16); stroke: #F29CC4; filter: drop-shadow(0 0 10px rgba(242,156,196,.45)); }
.flow .node.on text { fill: #fff; }
.flow .edge { fill: none; stroke: #4A3E66; stroke-width: 1.2; marker-end: url(#arrow); transition: stroke .3s; }
.flow .edge.on { stroke: #F29CC4; }
.flow .elabel { fill: #8F84AB; font: 400 10px var(--mono); }
.flow .token { fill: #F1D08F; filter: drop-shadow(0 0 6px rgba(241,208,143,.8)); opacity: 0; transition: opacity .3s; }
.flow .token.show { opacity: 1; }
.editor-foot { padding: 10px 16px; border-top: 1px solid var(--code-line); font: 400 11.5px/1.4 var(--mono); color: var(--code-dim); display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* Syntax colours */
.tk-key { color: var(--tk-key); }
.tk-str { color: var(--tk-str); }
.tk-fn { color: var(--tk-fn); }
.tk-num { color: var(--tk-num); }
.tk-com { color: var(--tk-com); font-style: italic; }
.tk-bi { color: var(--tk-bi); }
.tk-op { color: #CBB8F0; }

/* ============ Section headings ============ */
.sec-head { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin: 0 0 22px; flex-wrap: wrap; }
.sec-head h2 { font-size: clamp(24px, 3vw, 32px); }
.sec-head p { color: var(--ink-2); margin-top: 6px; font-size: 15px; max-width: 60ch; }
.block { margin-top: clamp(48px, 7vw, 88px); }

/* ============ Library bento ============ */
.bento { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 16px; }
.lib {
  --a: var(--lav); --a-soft: var(--lav-soft);
  position: relative; display: flex; flex-direction: column; border-radius: var(--r-lg); padding: 24px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-sm); overflow: hidden;
  transition: transform .5s var(--ease), box-shadow .5s var(--ease), border-color .3s; isolation: isolate; min-height: 230px;
}
.lib::after {
  content: ''; position: absolute; inset: 0; z-index: -1; opacity: 0; transition: opacity .5s;
  background: radial-gradient(420px circle at var(--mx, 50%) var(--my, 0%), color-mix(in srgb, var(--a) 14%, transparent), transparent 60%);
}
.lib:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); border-color: color-mix(in srgb, var(--a) 35%, var(--line)); }
.lib:hover::after { opacity: 1; }
.lib[data-accent="peri"] { --a: var(--peri); --a-soft: var(--peri-soft); }
.lib[data-accent="rose"] { --a: var(--rose); --a-soft: var(--rose-soft); }
.lib[data-accent="gold"] { --a: var(--gold); --a-soft: var(--gold-soft); }
.lib[data-accent="mint"] { --a: var(--mint); --a-soft: var(--mint-soft); }
.lib-slides { grid-column: span 4; grid-row: span 2; min-height: 420px; }
.lib-sheets { grid-column: span 2; grid-row: span 2; }
.lib-practice, .lib-exams, .lib-extra { grid-column: span 2; }
.lib-icon { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; background: var(--a-soft); color: var(--a); transition: transform .6s var(--ease-spring); }
.lib:hover .lib-icon { transform: rotate(-6deg) scale(1.06); }
.lib-icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.lib h3 { font-size: 21px; margin-top: 18px; }
.lib p { color: var(--ink-2); font-size: 14px; margin-top: 8px; max-width: 42ch; }
.lib-meta { margin-top: auto; padding-top: 18px; display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 13px; color: var(--ink-3); }
.lib-count { font-weight: 500; color: var(--ink-2); }
.lib-go { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--a-soft); color: var(--a); transition: transform .4s var(--ease-spring), background .3s, color .3s; }
.lib-go svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.lib:hover .lib-go { transform: translateX(4px); background: var(--a); color: #fff; }
.progress { display: flex; align-items: center; gap: 8px; }
.progress-bar { width: 64px; height: 5px; border-radius: 3px; background: var(--bg-2); overflow: hidden; }
.progress-bar i { display: block; height: 100%; border-radius: 3px; background: var(--a); transition: width .8s var(--ease); }

/* slide fan inside the big slides card */
.fan { position: relative; flex: 1; min-height: 190px; margin: 22px -8px 0; }
.fan img {
  position: absolute; height: 78%; width: auto; max-width: 46%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 12px; border: 1px solid var(--line);
  box-shadow: var(--shadow-md); background: var(--bg-2); left: 50%; top: 50%;
  transform: translate(-50%, -50%) translateX(calc(var(--k) * 40%)) rotate(calc(var(--k) * 5deg)) translateY(calc(var(--ak) * 6%));
  transition: transform .7s var(--ease); z-index: calc(10 - var(--ak));
}
.lib-slides:hover .fan img { transform: translate(-50%, -50%) translateX(calc(var(--k) * 62%)) rotate(calc(var(--k) * 7deg)) translateY(calc(var(--ak) * 9%)); }
/* paper stack inside sheets card */
.stack { position: relative; flex: 1; min-height: 200px; margin-top: 22px; }
.stack img {
  position: absolute; height: 88%; width: auto; max-width: 56%; aspect-ratio: 1 / 1.41; object-fit: cover; object-position: top; border-radius: 8px;
  border: 1px solid var(--line); background: #fff; box-shadow: var(--shadow-md); left: 50%; top: 50%;
  transform: translate(-50%, -50%) rotate(calc(var(--k) * 6deg)) translateX(calc(var(--k) * 16%)); transition: transform .7s var(--ease);
}
.lib-sheets:hover .stack img { transform: translate(-50%, -54%) rotate(calc(var(--k) * 10deg)) translateX(calc(var(--k) * 30%)); }


/* ============ Resource rows (used in meeting panel + search) ============ */
.row {
  display: flex; align-items: center; gap: 14px; padding: 10px 14px 10px 10px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--surface-2); transition: transform .3s var(--ease), border-color .2s, background .2s;
}
.row:hover { transform: translateX(4px); border-color: var(--line-2); background: var(--surface); }
.row-thumb { width: 58px; height: 40px; border-radius: 8px; overflow: hidden; flex-shrink: 0; background: var(--bg-2); border: 1px solid var(--line); display: grid; place-items: center; }
.row-thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.row-thumb.code { background: var(--code-bg); color: var(--tk-key); font: 500 11px var(--mono); }
.row-k { font-size: 12px; color: var(--ink-3); }
.row-t { font-size: 14px; font-weight: 500; }
.row > div { min-width: 0; flex: 1; }
.row .tag { margin-left: auto; }
.tag { font: 500 11px/1 var(--mono); padding: 5px 8px; border-radius: 7px; background: var(--bg-2); color: var(--ink-2); white-space: nowrap; }
.tag.pdf { background: var(--rose-soft); color: var(--rose); }
.tag.pptx { background: var(--lav-soft); color: var(--lav); }
.tag.docx { background: var(--peri-soft); color: var(--peri); }
.tag.py { background: var(--gold-soft); color: var(--gold); }

/* ============ Section page ============ */
.crumbs { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-3); margin: 12px 0 20px; }
.crumbs a:hover { color: var(--ink); }
.crumbs svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; }
.page-head { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 20px; align-items: center; margin-bottom: 30px; }
.page-head .lib-icon { width: 60px; height: 60px; border-radius: 18px; }
.page-head .lib-icon svg { width: 28px; height: 28px; }
.page-head h1 { font-size: clamp(30px, 4.4vw, 46px); letter-spacing: -0.04em; }
.page-head p { color: var(--ink-2); margin-top: 6px; max-width: 62ch; }
.page-head .count { font: 500 13px/1 var(--mono); color: var(--ink-3); text-align: right; }
.page-head .count b { display: block; font: 600 34px/1 var(--font); color: var(--ink); letter-spacing: -0.03em; margin-bottom: 6px; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: -6px 0 26px; }
.chip { padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: 13px; color: var(--ink-2); transition: all .25s var(--ease); }
.chip:hover { border-color: var(--line-2); color: var(--ink); }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.group-t { font-size: 15px; font-weight: 600; margin: 34px 0 14px; display: flex; align-items: center; gap: 10px; color: var(--ink-2); }
.group-t::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.group-t:first-child { margin-top: 0; }

.tiles { display: grid; gap: 18px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr)); }
.tiles.wide { grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); }
.tile {
  --a: var(--lav); position: relative; display: flex; flex-direction: column; border-radius: var(--r-lg); overflow: hidden;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-sm);
  transition: transform .5s var(--ease), box-shadow .5s var(--ease), border-color .3s;
  animation: tile-in .6s var(--ease) both; animation-delay: calc(var(--i, 0) * 45ms);
}
@keyframes tile-in { from { opacity: 0; transform: translateY(18px) scale(.98); } }
.tile:hover { transform: translateY(-5px); box-shadow: var(--shadow-md); border-color: color-mix(in srgb, var(--a) 35%, var(--line)); }
.tile-cover { position: relative; aspect-ratio: 16 / 10; overflow: hidden; background: var(--bg-2); border-bottom: 1px solid var(--line); }
.tile-cover img { width: 100%; height: 100%; object-fit: cover; object-position: top; transition: transform .8s var(--ease); }
.tile.shape-tall .tile-cover img { object-position: 50% 4%; }
.tile:hover .tile-cover img { transform: scale(1.05); }
.tile-cover .n {
  position: absolute; left: 12px; top: 12px; padding: 5px 9px; border-radius: 8px; font: 500 12px/1 var(--mono);
  background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(6px); color: var(--ink); border: 1px solid var(--line);
}
.tile-cover .studied {
  position: absolute; right: 12px; top: 12px; width: 26px; height: 26px; border-radius: 50%; background: var(--mint); display: grid; place-items: center;
  box-shadow: 0 4px 10px -4px var(--mint); animation: pop .5s var(--ease-spring);
}
.tile-cover .studied svg { width: 13px; height: 13px; stroke: #fff; stroke-width: 3; fill: none; }
@keyframes pop { from { transform: scale(0); } }
.tile-body { padding: 16px 18px 18px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.tile-k { font-size: 12px; color: var(--ink-3); }
.tile-t { font-size: 16px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.3; }
.tile-meta { display: flex; gap: 8px; align-items: center; margin-top: auto; padding-top: 12px; font-size: 12px; color: var(--ink-3); }
.tile a.cover-link::after { content: ''; position: absolute; inset: 0; z-index: 1; }
.tile .tile-dl { position: relative; z-index: 2; margin-left: auto; color: var(--ink-3); padding: 4px; border-radius: 6px; transition: color .2s, background .2s; }
.tile .tile-dl:hover { color: var(--ink); background: var(--bg-2); }
.tile .tile-dl svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.tile-code .tile-cover { background: var(--code-bg); }
.tile-code pre { margin: 0; padding: 16px 18px; font-size: 11.5px; line-height: 1.6; color: var(--code-ink); white-space: pre; overflow: hidden; height: 100%;
  mask-image: linear-gradient(#000 60%, transparent); -webkit-mask-image: linear-gradient(#000 60%, transparent); }


/* ============ Viewer ============ */
.viewer { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 18px; height: calc(100vh - 92px); height: calc(100dvh - 92px); padding-bottom: 16px; }
.viewer.no-side { grid-template-columns: minmax(0, 1fr); }
.v-side { display: flex; flex-direction: column; min-height: 0; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); overflow: hidden; animation: side-in .6s var(--ease) both; }
@keyframes side-in { from { opacity: 0; transform: translateX(-16px); } }
.v-side-head { padding: 18px 18px 12px; border-bottom: 1px solid var(--line); }
.v-side-head small { font-size: 12px; color: var(--ink-3); }
.v-side-head h2 { font-size: 17px; margin-top: 4px; line-height: 1.3; }
.v-outline { list-style: none; margin: 0; padding: 8px; overflow-y: auto; flex: 1; scrollbar-width: thin; }
.v-outline button { width: 100%; text-align: left; display: flex; gap: 10px; padding: 7px 10px; border: 0; background: none; border-radius: 9px; font-size: 13px; color: var(--ink-2); line-height: 1.35; transition: background .2s, color .2s; }
.v-outline button:hover { background: var(--bg-2); color: var(--ink); }
.v-outline button.on { background: var(--lav-soft); color: var(--ink); }
.v-outline span { font: 400 11px/1.6 var(--mono); color: var(--ink-3); min-width: 22px; }
.v-main { display: flex; flex-direction: column; min-height: 0; min-width: 0; border-radius: var(--r-lg); overflow: hidden; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-md); }
.v-bar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.v-title { flex: 1; min-width: 160px; padding: 0 6px; }
.v-title small { display: block; font-size: 12px; color: var(--ink-3); }
.v-title strong { display: block; font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -0.015em; }
.v-frame { position: relative; flex: 1; min-height: 0; background: var(--bg-2); }
.v-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; opacity: 0; transition: opacity .5s var(--ease); }
.v-frame iframe.ready { opacity: 1; }
.v-loading { position: absolute; inset: 0; display: grid; place-items: center; font: 400 13px var(--mono); color: var(--ink-3); }
.v-loading::before { content: ''; width: 34px; height: 34px; border-radius: 50%; border: 2.5px solid var(--line-2); border-top-color: var(--lav); animation: spin .9s linear infinite; position: absolute; top: calc(50% - 44px); }
@keyframes spin { to { transform: rotate(360deg); } }
.v-mobile { position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 24px; text-align: center; }
.v-mobile img { width: min(320px, 80%); border-radius: 12px; border: 1px solid var(--line); box-shadow: var(--shadow-md); }
.v-mobile p { color: var(--ink-2); font-size: 14px; max-width: 34ch; }
.v-nav { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; border-top: 1px solid var(--line); }
.v-nav a { display: flex; flex-direction: column; font-size: 13px; padding: 6px 10px; border-radius: 10px; max-width: 48%; transition: background .2s; }
.v-nav a:hover { background: var(--bg-2); }
.v-nav a small { color: var(--ink-3); font-size: 11px; }
.v-nav a span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.v-nav a.next { text-align: right; margin-left: auto; }

/* Full screen: #app is the full-screen element (or is fixed over the page where the API is missing) */
#app:fullscreen, #app.is-max { max-width: none; margin: 0; padding: 12px; background: var(--bg); overflow: hidden; }
#app:-webkit-full-screen { max-width: none; margin: 0; padding: 12px; background: var(--bg); overflow: hidden; }
#app.is-max { position: fixed; inset: 0; z-index: 60; padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom)); animation: max-in .4s var(--ease) both; }
#app:fullscreen .viewer, #app.is-max .viewer { height: 100%; padding-bottom: 0; gap: 12px; }
#app:-webkit-full-screen .viewer { height: 100%; padding-bottom: 0; gap: 12px; }
#app:fullscreen .foot, #app.is-max .foot { display: none; }
#app::backdrop { background: var(--bg); }
@keyframes max-in { from { opacity: 0; transform: scale(.98); } }

/* ============ Exercises (practice code) ============ */
.ex { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 28px; align-items: start; }
.ex-nav { position: sticky; top: 84px; display: flex; flex-direction: column; gap: 4px; }
.ex-nav a { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-radius: 12px; font-size: 14px; color: var(--ink-2); transition: background .2s, color .2s; }
.ex-nav a:hover { background: var(--surface); color: var(--ink); }
.ex-nav a.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); border: 1px solid var(--line); }
.ex-nav a span { font: 400 12px var(--mono); color: var(--ink-3); }
.ex-note { margin-top: 14px; padding: 14px; border-radius: 12px; background: var(--peri-soft); font-size: 13px; color: var(--ink-2); line-height: 1.5; }
.ex-list { display: grid; gap: 14px; }
.ex-meeting { font-size: 22px; margin: 26px 0 4px; scroll-margin-top: 90px; }
.ex-meeting:first-child { margin-top: 0; }
.q { border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-sm); overflow: hidden; scroll-margin-top: 90px; animation: tile-in .5s var(--ease) both; }
.q-head { display: flex; gap: 14px; padding: 18px 20px; align-items: start; }
.q-n { flex-shrink: 0; min-width: 40px; height: 32px; padding: 0 8px; border-radius: 10px; display: grid; place-items: center; font: 500 12px var(--mono); background: var(--rose-soft); color: var(--rose); }
.q-text { flex: 1; font-size: 15px; color: var(--ink); white-space: pre-line; }
.q-text.empty { color: var(--ink-3); }
.q-actions { display: flex; gap: 8px; padding: 0 20px 18px 74px; flex-wrap: wrap; }
.q-sol { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .5s var(--ease); }
.q.open .q-sol { grid-template-rows: 1fr; }
.q-sol > div { overflow: hidden; }
.code { margin: 0; background: var(--code-bg); color: var(--code-ink); font-size: 13px; line-height: 1.7; padding: 18px 20px; overflow-x: auto; tab-size: 4; }
.code .ln-n { color: #5D5278; user-select: none; display: inline-block; width: 28px; }
.console { background: #150F21; color: #CFC6E4; font: 400 12.5px/1.6 var(--mono); padding: 12px 20px 16px; border-top: 1px solid var(--code-line); white-space: pre-wrap; max-height: 260px; overflow: auto; }
.console .err { color: #F6A3A3; }
.console .sys { color: #8C80A9; }

/* ============ Search palette ============ */
.palette { position: fixed; inset: 0; z-index: 80; display: grid; justify-items: center; align-items: start; padding: 12vh 16px 16px; }
.palette[hidden] { display: none; }
.palette-scrim { position: absolute; inset: 0; background: color-mix(in srgb, #1A1427 40%, transparent); backdrop-filter: blur(4px); animation: fade-in .25s both; opacity: 0; }
.palette-box { position: relative; width: min(620px, 100%); max-height: 70vh; display: flex; flex-direction: column; border-radius: 20px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-lg); overflow: hidden; animation: pal-in .35s var(--ease-spring) both; }
@keyframes pal-in { from { opacity: 0; transform: translateY(-10px) scale(.97); } }
.palette-input { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.palette-input svg { width: 20px; height: 20px; color: var(--ink-3); flex-shrink: 0; }
.palette-input input { flex: 1; border: 0; outline: 0; background: none; font: 400 16px var(--font); color: var(--ink); min-width: 0; }
.palette-input input::-webkit-search-cancel-button { display: none; }
.palette-list { list-style: none; margin: 0; padding: 8px; overflow-y: auto; }
.palette-list li a { display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 12px; }
.palette-list li a > div { min-width: 0; flex: 1; }
.palette-list li a .row-t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.palette-list li.sel a { background: var(--lav-soft); }
.palette-list .empty { padding: 28px; text-align: center; color: var(--ink-3); font-size: 14px; }
.palette-list .grp { font-size: 12px; color: var(--ink-3); padding: 10px 10px 4px; }

/* ============ Toast ============ */
.toast { position: fixed; left: 50%; bottom: 28px; z-index: 90; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; box-shadow: var(--shadow-lg); transition: all .4s var(--ease-spring); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ============ Footer ============ */
.foot { margin-top: 80px; padding-top: 24px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--ink-3); }
.foot button { background: none; border: 0; color: var(--ink-2); padding: 0; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line-2); }

/* ============ Page entrance (after intro) ============ */
.enter > * { animation: enter .9s var(--ease) both; }
.enter > *:nth-child(2) { animation-delay: .08s; }
.enter > *:nth-child(3) { animation-delay: .16s; }
.enter > *:nth-child(4) { animation-delay: .24s; }
.enter > *:nth-child(5) { animation-delay: .32s; }
@keyframes enter { from { opacity: 0; transform: translateY(24px); filter: blur(4px); } }
.bento .lib { animation: tile-in .7s var(--ease) both; animation-delay: calc(.15s + var(--i, 0) * 70ms); }

/* reveal on scroll (only for blocks below the fold) */
.reveal { opacity: 0; transform: translateY(26px); transition: opacity .8s var(--ease), transform .8s var(--ease); }
.reveal.in { opacity: 1; transform: none; }

/* View Transitions API */
::view-transition-old(root) { animation: vt-out .25s ease both; }
::view-transition-new(root) { animation: vt-in .5s var(--ease) both; }
@keyframes vt-out { to { opacity: 0; transform: translateY(-8px); filter: blur(3px); } }
@keyframes vt-in { from { opacity: 0; transform: translateY(12px); filter: blur(3px); } }
::view-transition-group(doc) { animation-duration: .55s; animation-timing-function: cubic-bezier(.22,.8,.24,1); }
.topbar { view-transition-name: topbar; }
::view-transition-old(topbar), ::view-transition-new(topbar) { animation: none; }

/* ============ Responsive ============ */
@media (max-width: 1080px) {
  .mainnav { display: none; }
  .search-btn { margin-left: auto; }
  .hero { grid-template-columns: minmax(0, 1fr); }
  .bento { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lib-slides { grid-column: span 2; grid-row: auto; min-height: 380px; }
  .lib-sheets { grid-column: span 1; grid-row: auto; min-height: 340px; }
  .lib-practice { grid-column: span 1; }
  .lib-exams, .lib-extra { grid-column: span 1; }
  .viewer { grid-template-columns: minmax(0, 1fr); }
  .v-side { display: none; }
  .ex { grid-template-columns: minmax(0, 1fr); }
  .ex-nav { position: static; flex-direction: row; overflow-x: auto; gap: 6px; padding-bottom: 4px; scrollbar-width: none; }
  .ex-nav a { white-space: nowrap; }
  .ex-note { display: none; }
}
@media (max-width: 720px) {
  body { font-size: 15px; }
  .topbar { padding-top: 10px; padding-bottom: 10px; gap: 10px; }
  .brand-text small { display: none; }
  .search-btn span, .search-btn kbd { display: none; }
  .search-btn { width: 40px; padding: 0; justify-content: center; }
  .tabbar {
    display: flex; position: fixed; left: 12px; right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); z-index: 45;
    justify-content: space-around; padding: 6px; border-radius: 20px;
    background: color-mix(in srgb, var(--surface) 86%, transparent); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
    border: 1px solid var(--line); box-shadow: var(--shadow-lg);
  }
  .tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 7px 2px; border-radius: 14px; font-size: 10.5px; color: var(--ink-3); transition: color .2s, background .3s; }
  .tab svg { width: 21px; height: 21px; transition: transform .4s var(--ease-spring); }
  .tab.active { color: var(--ink); background: var(--lav-soft); }
  .tab.active svg { transform: translateY(-1px) scale(1.06); color: var(--lav); }
  main { padding-bottom: 120px; }
  .editor-body { grid-template-columns: minmax(0, 1fr); }
  .ectl span { display: none; }
  .ectl { padding: 0 9px; }
  .editor-tab { display: none; }
  .ed-code { font-size: 12px; }
  .editor-foot span:last-child { display: none; }
  .ed-left { border-right: 0; border-bottom: 1px solid var(--code-line); }
  .ed-flow { padding: 14px; }
  .flow { max-width: 260px; }
  .bento { grid-template-columns: minmax(0, 1fr); }
  .lib-slides, .lib-sheets, .lib-practice, .lib-exams, .lib-extra { grid-column: auto; min-height: 0; }
  .fan { min-height: 150px; }
  .stack { min-height: 150px; }
  .page-head { grid-template-columns: auto minmax(0, 1fr); }
  .page-head .count { display: none; }
  .page-head .lib-icon { width: 48px; height: 48px; border-radius: 14px; }
  .viewer { height: calc(100dvh - 160px); }
  .v-frame iframe, .v-loading { display: none; }
  .v-mobile { display: flex; }
  .v-bar .hide-sm { display: none; }
  .q-actions { padding-left: 20px; }
}
@media (pointer: coarse) and (min-width: 721px) {
  .v-frame iframe, .v-loading { display: none; }
  .v-mobile { display: flex; }
}

/* ============ Arabic (right to left) ============ */
.lang-btn span { font: 600 15px/1 'Readex Pro', var(--font); }
:root[lang="ar"] { --font: 'Readex Pro', 'Sora', ui-sans-serif, system-ui, 'Segoe UI', Tahoma, sans-serif; --flip: -1; }
:root[lang="ar"] body { line-height: 1.75; }
/* tight letter-spacing breaks joined Arabic letters */
:root[lang="ar"] body *:not(pre):not(code):not(kbd):not(.ce-hl):not(.ce-ta):not(.intro-title):not(.ch) { letter-spacing: 0 !important; }
/* code, terminals and program output always read left to right */
pre, code, kbd, .code, .ce, .mt-out, .mt-term, .console, .editor, .mt-input.mono, .fc-canvas, .row-thumb.code, .v-outline,
.fc-svg, .flow, .mt-flow-answer, .mt-fig { direction: ltr; unicode-bidi: isolate; }
.flow text, .fc-svg text { font-variant-ligatures: none !important; }
pre, .mt-out, .mt-input.mono, .ce-hl, .ce-ta, .mt-term, .console { text-align: left; }
[dir="rtl"] .v-outline { text-align: left; }
[dir="rtl"] .search-btn span { text-align: right; }
/* arrows and chevrons point the other way */
[dir="rtl"] .crumbs svg, [dir="rtl"] .lib-go svg, [dir="rtl"] .mtq-step svg, [dir="rtl"] .v-bar .btn-ghost svg { transform: scaleX(-1); }
[dir="rtl"] .lib:hover .lib-go { transform: translateX(-4px); }
[dir="rtl"] .row:hover { transform: translateX(-4px); }
/* things pushed to the far side */
[dir="rtl"] .top-actions { margin-left: 0; margin-right: auto; }
[dir="rtl"] .mainnav + .top-actions { margin-right: 0; }
[dir="rtl"] .tile .tile-dl { margin-left: 0; margin-right: auto; }
[dir="rtl"] .v-nav a.next { text-align: left; margin-left: 0; margin-right: auto; }
[dir="rtl"] .page-head .count { text-align: left; }
[dir="rtl"] .q-actions { padding: 0 74px 18px 20px; }
[dir="rtl"] .tile-cover .n { left: auto; right: 12px; }
[dir="rtl"] .tile-cover .studied { right: auto; left: 12px; }
[dir="rtl"] .format li::marker, [dir="rtl"] ol { unicode-bidi: isolate; }
@media (max-width: 1080px) { [dir="rtl"] .search-btn { margin-left: 0; margin-right: auto; } }
@media (max-width: 720px) { [dir="rtl"] .q-actions { padding-right: 20px; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  .reveal { opacity: 1; transform: none; }
  .intro-title .ch { opacity: 1; transform: none; filter: none; }
}
