@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500&family=Syne:wght@700;800&display=swap');

/* ── TOKENS ── */
:root {
  --bg:         #09070f;
  --bg-2:       #0f0c1a;
  --surface:    #140f22;
  --surface-2:  #1c1630;
  --border:     #2a2040;
  --border-2:   #3d3060;
  --text:       #e8e0ff;
  --text-muted: #8070a8;
  --text-dim:   #4a3d6e;
  --purple-1:   #c4b0ff;
  --purple-2:   #9d80f0;
  --purple-3:   #7c5ce8;
  --purple-4:   #5a3db8;
  --glow:       rgba(124, 92, 232, 0.15);
  --glow-2:     rgba(124, 92, 232, 0.30);
  --font-sans:  'Inter', system-ui, sans-serif;
  --font-mono:  'JetBrains Mono', 'Fira Code', monospace;
  --font-display: 'Syne', sans-serif;
  --radius:     8px;
  --radius-lg:  12px;
}

/* ── RESET ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* ── BACKGROUND ── */
.bg-gradient {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(ellipse 80% 50% at 20% 0%, rgba(90, 61, 184, 0.18) 0%, transparent 60%),
    radial-gradient(ellipse 60% 40% at 80% 100%, rgba(124, 92, 232, 0.12) 0%, transparent 60%),
    radial-gradient(ellipse 40% 60% at 60% 40%, rgba(60, 30, 120, 0.08) 0%, transparent 50%),
    #09070f;
  pointer-events: none;
}

.bg-noise {
  position: fixed;
  inset: 0;
  z-index: 0;
  opacity: 0.03;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  pointer-events: none;
}

.site-wrap {
  position: relative;
  z-index: 1;
}

a { color: var(--purple-2); text-decoration: none; transition: color 0.15s; }
a:hover { color: var(--purple-1); }

img { max-width: 100%; height: auto; }

/* ── SCROLLBAR ── */
/* height sizes HORIZONTAL scrollbars; without it they fell back to the browser
   default (~15px), which is what made command-block scrollbars look chunky. */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--purple-3); }

/* ── UTILITIES ── */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }

/* ── NOTE CONTENT TYPOGRAPHY ── */
.note-shell .note-main h1 {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 800;
  color: var(--purple-1);
  letter-spacing: -0.02em;
  margin-bottom: 0.5rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-2);
}

.note-shell .note-main h2 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--purple-2);
  margin: 2rem 0 0.75rem;
  padding-left: 0.75rem;
  border-left: 3px solid var(--purple-3);
}

.note-shell .note-main h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin: 1.5rem 0 0.5rem;
}

.note-shell .note-main h4 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  margin: 1rem 0 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.note-shell .note-main p {
  margin-bottom: 1rem;
  color: var(--text);
}

.note-shell .note-main ul,
.note-shell .note-main ol {
  padding-left: 1.5rem;
  margin-bottom: 1rem;
}

.note-shell .note-main li {
  margin-bottom: 0.3rem;
  color: var(--text);
}

.note-shell .note-main a {
  color: var(--purple-2);
  border-bottom: 1px solid var(--border-2);
}

.note-shell .note-main a:hover {
  color: var(--purple-1);
  border-bottom-color: var(--purple-3);
}

/* ── EXTERNAL LINK INDICATOR (Phase 7) ──
   Small trailing arrow marks outbound links (added by the rehypeExternalLinks
   build plugin). Internal note links get no icon. */
.note-shell .note-main a.external-link { border-bottom-style: dotted; }
.external-link-icon {
  display: inline-block;
  margin-left: 0.15em;
  font-size: 0.72em;
  line-height: 1;
  vertical-align: baseline;
  color: var(--text-muted);
  border-bottom: none;
}
.note-shell .note-main a.external-link:hover .external-link-icon { color: var(--purple-1); }

/* ── CODE BLOCKS ──
   Presentation taxonomy (see docs/FORMATTING.md):
   • PLAIN CODE BLOCK (taxonomy B) — the default for every ``` fence
     (bare, ```bash, ```powershell, …): a clean, minimal box meant for
     copy-paste commands. No terminal chrome, no heavy border.
   • FAKE TERMINAL (taxonomy A) — opt-in via ```console ONLY, reserved for
     example OUTPUT, script listings, or full session transcripts. Shiki
     tags it data-language="console", which is the single hook below. */

/* Plain code block — DEFAULT */
.note-shell .note-main pre {
  position: relative;
  background: #0a0812 !important;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.1rem !important;
  margin: 1.25rem 0;
  overflow-x: auto;
  box-shadow: none;
}

.note-shell .note-main pre code {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.65;
  background: transparent !important;
  padding: 0 !important;
}

/* Fake terminal — ONLY ```console blocks */
.note-shell .note-main pre[data-language="console"] {
  border-radius: 10px;
  padding: 2.5rem 1.25rem 1.25rem !important;
  box-shadow: 0 4px 24px rgba(0,0,0,0.4);
}

.note-shell .note-main pre[data-language="console"]::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2rem;
  background: #130f20;
  border-radius: 10px 10px 0 0;
  /* No border-bottom: the header bar sits flush over the code body so there
     is no stray line/gap between the traffic lights and the text (issue 9). */
}

.note-shell .note-main pre[data-language="console"]::after {
  content: '';
  position: absolute;
  top: 0.7rem;
  left: 0.85rem;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: #ff5f56;
  box-shadow: 1rem 0 0 #ffbd2e, 2rem 0 0 #27c93f;
}

/* ── INLINE CODE ──
   Scannable emphasis (Carbon): a subtle purple-tinted field distinct from both
   the page and callout backgrounds, with bright high-contrast text, so inline
   `code` in prose reads as emphasized without shouting (Phase 3). */
.note-shell .note-main :not(pre) > code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: rgba(124, 92, 232, 0.16);
  color: #d9ccff;
  padding: 0.1em 0.36em;
  border-radius: 4px;
  border: 1px solid rgba(124, 92, 232, 0.24);
  /* Long inline commands (e.g. full curl lines) must stay readable in prose:
     let them wrap at any point instead of overflowing the column (issue 1). */
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* ── TABLES ── */
.note-shell .note-main table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 1.25rem 0;
  font-size: 0.85rem;
  border: 1px solid var(--border-2);
  border-radius: 8px;
  overflow: hidden;
  background: rgba(20, 15, 34, 0.6);
  backdrop-filter: blur(8px);
}

.note-shell .note-main th {
  background: rgba(90, 61, 184, 0.25);
  color: var(--purple-1);
  font-weight: 700;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.7rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border-2);
}

.note-shell .note-main td {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: top;
}

.note-shell .note-main tr:last-child td { border-bottom: none; }
.note-shell .note-main tr:hover td {
  background: rgba(124, 92, 232, 0.06);
}

/* ── CALLOUTS ──
   A callout is a collapsible container (taxonomy D). It may CONTAIN a plain
   code block, but never wraps command lines in terminal chrome or chip borders.
   Phase 4: the type accent runs down the WHOLE card's left edge (not just the
   title) so header + body + any nested code block read as one coherent unit. */
.callout {
  margin: 1.25rem 0;
  border-radius: 8px;
  border: 1px solid var(--border-2);
  border-left: 3px solid var(--callout-accent, var(--purple-3));
  overflow: hidden;
  background: rgba(20, 15, 34, 0.6);
  backdrop-filter: blur(8px);
}

details.callout[open] .callout-body,
div.callout .callout-body {
  display: block;
}

.callout-title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  /* Title bar carries a faint wash of the type accent so warning/danger headers
     read as distinct at a glance, not just at the left edge. */
  background: color-mix(in srgb, var(--callout-accent, var(--purple-3)) 14%, transparent);
  list-style: none;
  transition: background 0.15s;
}

/* Hover affordance on collapsible headers so the click target is obvious. */
details.callout > summary.callout-title:hover { background: color-mix(in srgb, var(--callout-accent, var(--purple-3)) 22%, transparent); }
div.callout .callout-title { cursor: default; }

details.callout > summary { list-style: none; }
details.callout > summary::-webkit-details-marker { display: none; }

.callout-title::after {
  content: '▾';
  margin-left: auto;
  font-size: 0.78rem;
  color: var(--text-muted);
  transition: transform 0.2s, color 0.15s;
}

details.callout > summary.callout-title:hover::after { color: var(--purple-1); }
details.callout[open] .callout-title::after { transform: rotate(180deg); }
div.callout .callout-title::after { display: none; }

.callout-icon {
  flex-shrink: 0;
  width: 1.1rem;
  text-align: center;
  font-size: 0.95rem;
  line-height: 1;
  /* Icon is tinted with the same accent as the left edge (Phase 4a). */
  color: var(--callout-accent, var(--purple-3));
  /* Nudge the glyph onto the text baseline of the title. */
  transform: translateY(0.02em);
}

/* Thin seam separates the title bar from the body for a clear two-part card. */
.callout-body {
  padding: 0.85rem 1rem 0.9rem;
  border-top: 1px solid var(--border);
  font-size: 0.88rem;
  line-height: 1.65;
  color: var(--text);
}

/* Genuine inline code inside callout prose — matches the site-wide inline code
   treatment (Phase 3): purple-tinted, distinct from the callout background. */
.callout-body code {
  font-family: var(--font-mono);
  font-size: 0.82em;
  background: rgba(124, 92, 232, 0.16);
  color: #d9ccff;
  padding: 0.1em 0.36em;
  border-radius: 4px;
  border: 1px solid rgba(124, 92, 232, 0.24);
  overflow-wrap: anywhere;
}

/* First/last child flush with the padding box for consistent spacing */
.callout-body > :first-child { margin-top: 0; }
.callout-body > :last-child { margin-bottom: 0; }
.callout-body p { margin-bottom: 0.5rem; }

/* ── COMMAND BLOCKS INSIDE CALLOUTS (Phase 2) ──
   Carbon single/multi-line model. These override the heavy default .note-main
   pre chrome so commands read as clean content, not a wall of boxes:
   • .callout-commands            → one light container; consecutive commands
     stack inside it (never a per-line chip stack). Lines never wrap — long
     lines scroll horizontally so they stay copyable.
   • .callout-commands--single    → a lone command; a compact single-line
     snippet, same light treatment, horizontal scroll if long. */
.note-shell .note-main pre.callout-commands {
  /* !important on background beats the base .note-main pre dark fill, which is
     itself !important. */
  background: rgba(124, 92, 232, 0.07) !important;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.55rem 0.75rem !important;
  margin: 0.5rem 0;
  box-shadow: none;
  overflow-x: auto;
}

.note-shell .note-main pre.callout-commands--single {
  padding: 0.4rem 0.7rem !important;
}

.note-shell .note-main pre.callout-commands code {
  background: transparent;
  border: none;
  padding: 0 !important;
  color: var(--purple-1);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  line-height: 1.6;
  white-space: pre;
}

/* ── TYPE ACCENTS (Phase 4a) ──
   Each type defines --callout-accent; the left edge, the title-bar wash, and the
   icon all read from it, so edge + icon stay in lockstep. info/note/tip live in
   the purple family (on-theme); warning is high-visibility amber and
   danger/caution/error high-visibility red so they stand out against the
   purple UI as the important-content markers. */
.callout-info, .callout-note        { --callout-accent: #9d80f0; }
.callout-tip, .callout-hint         { --callout-accent: #b79cff; }
.callout-warning, .callout-warn     { --callout-accent: #ffb02e; }
.callout-danger, .callout-error, .callout-caution { --callout-accent: #ff5b5b; }
.callout-success, .callout-check    { --callout-accent: #5ec27a; }
.callout-example                    { --callout-accent: var(--purple-3); }
.callout-abstract, .callout-summary { --callout-accent: var(--purple-2); }
.callout-todo, .callout-bug, .callout-quote { --callout-accent: var(--purple-2); }

/* ── PAIR DIVIDERS (Phase 4b) ──
   A faint hairline sits between DISTINCT description+command pairs — i.e. above
   any description that follows a command block — never between a description and
   its own command below it. A quiet segment marker, not a hard rule. The
   .cmd-wrap selector covers the state after the copy-button JS wraps each block;
   the bare pre selector covers the pre-JS render. */
.callout-body pre.callout-commands + p,
.callout-body .cmd-wrap + p {
  margin-top: 0.7rem;
  padding-top: 0.7rem;
  border-top: 1px solid rgba(196, 176, 255, 0.08);
}

/* ── COMMAND BLOCK: THIN SCROLLBAR (Phase 4d) ──
   The horizontal overflow bar under a long command is made thin and muted —
   well under the command line-height — on both engines. */
.note-shell .note-main pre.callout-commands {
  scrollbar-width: thin;
  scrollbar-color: var(--border-2) transparent;
}
.note-shell .note-main pre.callout-commands::-webkit-scrollbar { height: 6px; width: 6px; }
.note-shell .note-main pre.callout-commands::-webkit-scrollbar-track { background: transparent; }
.note-shell .note-main pre.callout-commands::-webkit-scrollbar-thumb {
  background: var(--border-2);
  border-radius: 3px;
}
.note-shell .note-main pre.callout-commands::-webkit-scrollbar-thumb:hover { background: var(--purple-3); }

/* ── COMMAND COPY BUTTON (Phase 4c) ──
   Note JS wraps each command block in a non-scrolling .cmd-wrap and drops a copy
   button into it. The wrapper (not the scrolling pre) is the positioning context
   so the button stays pinned top-right even when a long command scrolls
   horizontally. It is revealed only on hover of its own block (LazyHackers
   style) and copies the raw command text, including every line of a multi-line
   block. */
.cmd-wrap { position: relative; margin: 0.5rem 0; }
.cmd-wrap > pre.callout-commands { margin: 0; }
.cmd-copy {
  position: absolute;
  top: 0.3rem;
  right: 0.3rem;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.45rem;
  font-family: var(--font-sans);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--purple-1);
  background: rgba(12, 9, 20, 0.9);
  border: 1px solid var(--border-2);
  border-radius: 5px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s ease, background 0.12s, color 0.12s, border-color 0.12s;
  z-index: 2;
}
.cmd-wrap:hover .cmd-copy,
.cmd-copy:focus-visible { opacity: 1; }
.cmd-copy:hover { background: var(--surface-2); color: #fff; border-color: var(--purple-3); }
.cmd-copy.copied { color: #5ec27a; border-color: #5ec27a; }
.cmd-copy-icon { font-size: 0.8rem; line-height: 1; }

/* ── TOC INNER (slot content — must be global) ── */
.toc-inner {
  position: sticky;
  top: 76px;
  max-height: calc(100vh - 96px);
  overflow-y: auto;
  background: rgba(20, 15, 34, 0.6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 0;
}

.toc-label {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 0 0.75rem 0.5rem 0.75rem;
  margin: 0 0 0.5rem 0;
  border-bottom: 1px solid var(--border);
  display: block;
}

.toc-link {
  display: block;
  font-size: 0.74rem;
  font-weight: 400;
  color: var(--text-muted);
  padding: 0.25rem 0.75rem;
  border-left: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  text-decoration: none;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toc-link:hover { color: var(--text); }

.toc-link.active {
  color: var(--purple-1);
  border-left-color: var(--purple-3);
  background: rgba(124, 92, 232, 0.1);
  font-weight: 500;
}

.toc-h2 { padding-left: 0.75rem; }
.toc-h3 { padding-left: 1.5rem; font-size: 0.69rem; }
.toc-h4 { padding-left: 2.25rem; font-size: 0.65rem; color: var(--text-dim); }

/* ── BACKGROUND GRID OVERLAY ── */
.bg-grid {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(124, 92, 232, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(124, 92, 232, 0.03) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse 80% 80% at 50% 50%, black 30%, transparent 100%);
  -webkit-mask-image: radial-gradient(ellipse 80% 80% at 50% 50%, black 30%, transparent 100%);
}
