/* ---------- themes ---------- */
:root { --fs: 17px; --radius: 20px; }

[data-theme="playful"] {
  --font: ui-rounded, "Segoe UI Variable", "Segoe UI", system-ui, sans-serif;
  --bg: #fff7ed; --bg2: #ffe4f1; --card: #ffffff; --ink: #2b2340; --muted: #6f6788;
  --line: #f0e3d4; --brand: #7c3aed; --brand-ink: #ffffff; --code-inline: #fde68a;
  --c1: #7c3aed; --c2: #ec4899; --c3: #f59e0b; --c4: #10b981; --c5: #0ea5e9; --c6: #ef4444;
  --hero-bg: linear-gradient(135deg, #7c3aed, #ec4899 60%, #f59e0b); --hero-ink: #fff;
  --shadow: 0 8px 24px rgba(124, 58, 237, .12);
}
[data-theme="midnight"] {
  --font: ui-rounded, "Segoe UI Variable", "Segoe UI", system-ui, sans-serif;
  --bg: #0f1226; --bg2: #1a1640; --card: #1a1d3a; --ink: #e8e9ff; --muted: #9a9cc7;
  --line: #2b2f5a; --brand: #a78bfa; --brand-ink: #12102a; --code-inline: #3b3566;
  --c1: #a78bfa; --c2: #f472b6; --c3: #fbbf24; --c4: #34d399; --c5: #38bdf8; --c6: #fb7185;
  --hero-bg: linear-gradient(135deg, #4c1d95, #be185d 70%, #b45309); --hero-ink: #fff;
  --shadow: 0 8px 28px rgba(0, 0, 0, .45);
}
[data-theme="paper"] {
  --font: Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  --bg: #f4ecd8; --bg2: #efe3c4; --card: #fbf6e9; --ink: #3b2f1e; --muted: #7d6b50;
  --line: #dfd0aa; --brand: #9a3412; --brand-ink: #fff7e6; --code-inline: #ead9a8;
  --c1: #9a3412; --c2: #b45309; --c3: #4d7c0f; --c4: #0f766e; --c5: #1d4ed8; --c6: #9f1239;
  --hero-bg: linear-gradient(135deg, #9a3412, #b45309); --hero-ink: #fff7e6;
  --shadow: 0 6px 18px rgba(90, 60, 20, .15);
}
[data-theme="terminal"] {
  --font: ui-monospace, "Cascadia Code", Consolas, monospace;
  --bg: #050805; --bg2: #0a140a; --card: #0b110b; --ink: #b6ffb6; --muted: #5fb85f;
  --line: #1f4a1f; --brand: #39ff14; --brand-ink: #021002; --code-inline: #143314;
  --c1: #39ff14; --c2: #00e5ff; --c3: #ffd400; --c4: #7CFC00; --c5: #00bfa5; --c6: #ff6e40;
  --hero-bg: linear-gradient(135deg, #0b2b0b, #123d12); --hero-ink: #39ff14;
  --shadow: 0 0 0 1px #1f4a1f, 0 0 18px rgba(57, 255, 20, .12);
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  margin: 0; font: var(--fs) / 1.7 var(--font); color: var(--ink);
  background: linear-gradient(160deg, var(--bg), var(--bg2)) fixed; min-height: 100vh;
}
button { font: inherit; color: inherit; }
.spacer { flex: 1; }

#bar { position: fixed; top: 0; left: 0; height: 5px; width: 0; z-index: 50;
  background: linear-gradient(90deg, var(--c1), var(--c2), var(--c3)); transition: width .25s; }

#top {
  position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; background: color-mix(in srgb, var(--card) 82%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.logo { font-size: 1.4rem; }
.docname { color: var(--muted); font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.btn {
  border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 6px 12px;
  cursor: pointer; font-weight: 600; font-size: .9rem; transition: transform .12s, box-shadow .12s;
}
.btn:hover:not(:disabled) { transform: translateY(-2px); box-shadow: var(--shadow); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: transparent; }
.chip {
  display: inline-flex; align-items: center; gap: .3em; padding: .15em .75em; border-radius: 999px;
  background: color-mix(in srgb, var(--ink) 8%, transparent); font-size: .8rem; font-weight: 600;
  color: var(--muted); white-space: nowrap;
}
.only-small { display: none; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 32px;
  max-width: 1180px; margin: 0 auto; padding: 28px 20px 90px; }
#toc { position: sticky; top: 76px; align-self: start; max-height: calc(100vh - 96px); overflow: auto; }
#toc h4 { margin: 0 0 8px 10px; font-size: .75rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
#tocList button {
  display: flex; width: 100%; align-items: center; gap: 10px; text-align: left; cursor: pointer;
  background: none; border: 0; border-radius: 12px; padding: 8px 10px; font-size: .92rem; color: var(--muted);
}
#tocList button:hover { background: color-mix(in srgb, var(--ink) 7%, transparent); }
#tocList button.active { background: var(--card); color: var(--ink); font-weight: 700; box-shadow: var(--shadow); }
#tocList .ttl { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#tocList .tick { opacity: 0; color: var(--c4); font-weight: 800; }
#tocList button.seen .tick { opacity: 1; }

/* ---------- hero ---------- */
.hero {
  position: relative; overflow: hidden; border-radius: 28px; padding: 38px 34px; margin-bottom: 24px;
  background: var(--hero-bg); color: var(--hero-ink); box-shadow: var(--shadow); animation: pop .5s both;
}
.hero::after { content: ""; position: absolute; right: -60px; top: -60px; width: 220px; height: 220px;
  border-radius: 50%; background: rgba(255, 255, 255, .12); }
.hero .emoji { font-size: 3rem; display: inline-block; animation: wiggle 3s ease-in-out infinite; }
.hero h1 { margin: .15em 0 .25em; font-size: 2.3rem; line-height: 1.15; }
.hero .sub { margin: 0 0 16px; font-size: 1.1rem; opacity: .95; max-width: 60ch; }
.hero .chips { display: flex; flex-wrap: wrap; gap: 8px; }
.hero .chip { background: rgba(255, 255, 255, .2); color: var(--hero-ink); }
[data-theme="terminal"] .hero { border: 1px solid var(--brand); }

/* ---------- cards ---------- */
.step { scroll-margin-top: 80px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-top: 6px solid var(--accent, var(--brand));
  border-radius: var(--radius); box-shadow: var(--shadow); margin: 0 0 22px; overflow: hidden;
  animation: pop .5s both; animation-delay: calc(var(--i, 0) * 60ms);
}
.card-head { display: flex; align-items: center; gap: 12px; padding: 16px 22px; cursor: pointer; user-select: none; }
.card-head:hover .chev { transform: translateY(2px); }
.card-head .ico {
  font-size: 1.6rem; width: 48px; height: 48px; display: grid; place-items: center; border-radius: 14px; flex: none;
  background: color-mix(in srgb, var(--accent, var(--brand)) 18%, transparent);
}
.card-head h2 { margin: 0; flex: 1; font-size: 1.3rem; line-height: 1.3; }
.chev { transition: transform .2s; color: var(--muted); }
.card.collapsed .chev { transform: rotate(-90deg); }
.card.collapsed .card-body { display: none; }
.card-body { padding: 2px 26px 24px; }
.card.plain { padding: 8px 26px 20px; border-top-color: var(--line); }

.story .step { display: none; }
.story .step.current { display: block; animation: pop .35s both; }

/* ---------- markdown content ---------- */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: .9em 0; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { line-height: 1.3; scroll-margin-top: 80px; }
.md h3 { font-size: 1.15rem; margin: 1.7em 0 .5em; padding-left: 12px;
  border-left: 5px solid var(--accent, var(--brand)); border-radius: 3px; }
.md h4 { font-size: 1.02rem; margin: 1.4em 0 .4em; color: var(--accent, var(--brand)); }
.md a { color: var(--brand); text-decoration-thickness: 2px; text-underline-offset: 3px; }
.md ul, .md ol { padding-left: 1.5em; }
.md li { margin: .3em 0; }
.md li::marker { color: var(--accent, var(--brand)); font-weight: 700; }
.md li.task { list-style: none; margin-left: -1.3em; }
.md input[type="checkbox"] { width: 1.1em; height: 1.1em; margin-right: .5em; vertical-align: -.15em;
  accent-color: var(--accent, var(--brand)); cursor: pointer; }
.md img { max-width: 100%; border-radius: 14px; }
.md hr { border: 0; height: 3px; border-radius: 3px; margin: 2em 0;
  background: linear-gradient(90deg, var(--c1), var(--c2), var(--c3)); opacity: .5; }
.md code { font: .86em ui-monospace, "Cascadia Code", Consolas, monospace; background: var(--code-inline);
  padding: .12em .4em; border-radius: 6px; }
.md kbd { font: .85em ui-monospace, Consolas, monospace; padding: .1em .5em; border-radius: 6px;
  border: 1px solid var(--line); border-bottom-width: 3px; background: var(--card); }
.md blockquote { margin: 1em 0; padding: .1em 1em; border-left: 4px solid var(--line); color: var(--muted); }
.md details { border: 2px dashed var(--line); border-radius: 14px; padding: .5em 1em; margin: 1em 0; }
.md summary { cursor: pointer; font-weight: 700; }
.md details[open] summary { margin-bottom: .4em; color: var(--accent, var(--brand)); }

.codebox { margin: 1.1em 0; border-radius: 14px; overflow: hidden; background: #0d1117; color: #e6edf3; }
.codebar { display: flex; justify-content: space-between; align-items: center; padding: 6px 12px;
  background: #161b22; font: .75rem ui-monospace, Consolas, monospace; color: #8b949e; }
.copy { background: #30363d; color: #e6edf3; border: 0; border-radius: 8px; padding: 3px 10px; cursor: pointer; font: inherit; }
.copy:hover { background: #484f58; }
.codebox pre { margin: 0; padding: 14px 16px; overflow: auto; }
.codebox pre code, .codebox pre code.hljs { background: transparent; padding: 0; font-size: .86rem; line-height: 1.55; color: inherit; }

.table-wrap { overflow-x: auto; margin: 1.1em 0; border: 1px solid var(--line); border-radius: 14px; }
.md table { border-collapse: collapse; width: 100%; font-size: .95rem; }
.md th { text-align: left; background: color-mix(in srgb, var(--accent, var(--brand)) 16%, transparent); }
.md th, .md td { padding: 9px 14px; border-bottom: 1px solid var(--line); }
.md tr:nth-child(even) td { background: color-mix(in srgb, var(--ink) 4%, transparent); }
.md tr:last-child td { border-bottom: 0; }

.md blockquote.callout { color: var(--ink); border-left: 5px solid var(--cc); border-radius: 12px;
  background: color-mix(in srgb, var(--cc) 12%, transparent); padding: .7em 1.1em; }
.callout-title { font-weight: 800; color: var(--cc); margin-bottom: .2em; }
.md blockquote.callout p { margin: .3em 0; }

.mermaid { margin: 1.2em 0; text-align: center; overflow-x: auto; white-space: pre; font-size: .8rem; color: var(--muted); }
.mermaid[data-processed] { white-space: normal; }

/* ---------- step bar, overlays ---------- */
#stepbar { display: none; position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 30;
  align-items: center; gap: 14px; padding: 8px 12px; border-radius: 18px; background: var(--card);
  border: 1px solid var(--line); box-shadow: var(--shadow); }
.story #stepbar { display: flex; }
#stepLabel { font-weight: 700; min-width: 56px; text-align: center; color: var(--muted); }

#dropveil { position: fixed; inset: 0; z-index: 90; display: none; place-items: center; font-size: 2rem; font-weight: 800;
  color: var(--brand); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(6px); }
#dropveil div { padding: 40px 60px; border: 4px dashed var(--brand); border-radius: 28px; }
#dropveil.on { display: grid; }

#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 100; }
#toast { position: fixed; top: 70px; left: 50%; transform: translate(-50%, -20px); opacity: 0; z-index: 110; pointer-events: none;
  background: var(--brand); color: var(--brand-ink); padding: 10px 20px; border-radius: 999px; font-weight: 700;
  box-shadow: var(--shadow); transition: .3s; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }

dialog { border: 0; border-radius: 24px; padding: 0; width: min(560px, 92vw); background: var(--card); color: var(--ink);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
dialog::backdrop { background: rgba(10, 10, 30, .55); backdrop-filter: blur(3px); }
.dlg { padding: 22px 24px 24px; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.dlg h3 { margin: 0; }
.dlg h4 { margin: 20px 0 8px; font-size: .75rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
#dropzone { display: grid; gap: 4px; place-items: center; text-align: center; padding: 26px 12px; cursor: pointer; font-weight: 700;
  border: 3px dashed var(--brand); border-radius: 18px; color: var(--brand); }
#dropzone:hover { background: color-mix(in srgb, var(--brand) 8%, transparent); }
#dropzone small { color: var(--muted); font-weight: 500; }
.dlg label { display: block; margin-top: 14px; font-weight: 600; font-size: .9rem; }
.dlg textarea { width: 100%; margin: 6px 0 10px; padding: 10px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); font: .85rem ui-monospace, Consolas, monospace; resize: vertical; }
.rec { display: flex; align-items: center; gap: 8px; }
.rec-open { flex: 1; display: flex; justify-content: space-between; gap: 10px; text-align: left; cursor: pointer;
  background: none; border: 0; border-radius: 10px; padding: 7px 10px; }
.rec-open:hover, .rec-x:hover { background: color-mix(in srgb, var(--ink) 8%, transparent); }
.rec-open span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rec-open small { color: var(--muted); white-space: nowrap; }
.rec-x { background: none; border: 0; border-radius: 8px; cursor: pointer; color: var(--muted); padding: 4px 8px; }
.empty { color: var(--muted); font-size: .9rem; }

/* ---------- motion ---------- */
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.985); } to { opacity: 1; transform: none; } }
@keyframes wiggle { 0%, 100% { transform: rotate(0); } 8% { transform: rotate(-12deg); } 16% { transform: rotate(10deg); } 24% { transform: rotate(0); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* ---------- small screens ---------- */
@media (max-width: 999px) {
  .only-small { display: inline-block; }
  .layout { grid-template-columns: 1fr; padding-top: 20px; }
  #toc { position: fixed; top: 56px; bottom: 0; left: 0; width: 290px; max-height: none; z-index: 35; padding: 16px 10px;
    background: var(--card); border-right: 1px solid var(--line); transform: translateX(-105%); transition: transform .25s; }
  body.toc-open #toc { transform: none; box-shadow: var(--shadow); }
}
@media (max-width: 720px) {
  .lbl, .docname { display: none; }
  .hero { padding: 28px 22px; }
  .hero h1 { font-size: 1.8rem; }
  .card-body { padding: 2px 18px 20px; }
  .card-head { padding: 14px 16px; }
}
