/* =============================================================
   CodeLore — Design System
   Calm, professional, developer-focused. Indigo accent on slate
   neutrals. Light + dark. No heavy framework.
   ============================================================= */

:root {
  /* palette — light */
  --bg: #ffffff;
  --bg-subtle: #f7f8fa;
  --bg-elevated: #ffffff;
  --bg-code: #0f172a;
  --surface: #ffffff;
  --border: #e6e8ec;
  --border-strong: #d3d7de;
  --text: #1f2733;
  --text-soft: #54607a;
  --text-faint: #8a93a6;
  --accent: #4f46e5;
  --accent-soft: #eef0fe;
  --accent-text: #4338ca;
  --success: #0f9d6b;
  --warning: #b7791f;
  --danger: #d14343;
  --ring: rgba(79, 70, 229, 0.35);

  /* type */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, "Noto Sans", sans-serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", ui-monospace, "Menlo",
    "Consolas", "Liberation Mono", monospace;

  /* scale (fluid) */
  --step--1: clamp(0.83rem, 0.79rem + 0.18vw, 0.92rem);
  --step-0: clamp(1rem, 0.95rem + 0.22vw, 1.08rem);
  --step-1: clamp(1.2rem, 1.1rem + 0.5vw, 1.45rem);
  --step-2: clamp(1.5rem, 1.32rem + 0.9vw, 2rem);
  --step-3: clamp(1.9rem, 1.6rem + 1.5vw, 2.7rem);
  --step-4: clamp(2.4rem, 1.9rem + 2.5vw, 3.6rem);

  /* spacing / shape */
  --sp-1: 0.4rem;
  --sp-2: 0.8rem;
  --sp-3: 1.2rem;
  --sp-4: 2rem;
  --sp-5: 3rem;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 4px 14px rgba(16, 24, 40, 0.08);
  --maxw: 1200px;
  --header-h: 60px;
  --reading: 72ch;
}

[data-theme="dark"] {
  --bg: #0d1117;
  --bg-subtle: #121821;
  --bg-elevated: #161c26;
  --bg-code: #0a0e15;
  --surface: #161c26;
  --border: #232b38;
  --border-strong: #313b4c;
  --text: #e6e9ef;
  --text-soft: #aab3c2;
  --text-faint: #79839a;
  --accent: #818cf8;
  --accent-soft: #1e2233;
  --accent-text: #a5b0ff;
  --success: #2dd4a0;
  --warning: #e0b15e;
  --danger: #f0726f;
  --ring: rgba(129, 140, 248, 0.45);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + 16px); }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--step-0);
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

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

:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; border-radius: 4px; }

.skip-link {
  position: absolute; left: -999px; top: 8px; z-index: 100;
  background: var(--accent); color: #fff; padding: 8px 14px; border-radius: 8px;
}
.skip-link:focus { left: 12px; }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  height: var(--header-h);
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 0 clamp(0.8rem, 3vw, 1.6rem);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 0.55rem; font-weight: 700; color: var(--text); font-size: 1.12rem; letter-spacing: -0.01em; }
.brand:hover { text-decoration: none; }
.brand .logo {
  width: 30px; height: 30px; border-radius: 9px; flex: 0 0 auto;
  background: linear-gradient(135deg, var(--accent), #7c6cf0);
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 0.95rem;
  box-shadow: var(--shadow-sm);
}
.brand .logo span { transform: translateY(-1px); }

.primary-nav { display: flex; gap: 0.25rem; margin-left: 0.5rem; }
.primary-nav a {
  color: var(--text-soft); font-weight: 550; font-size: var(--step--1);
  padding: 0.45rem 0.7rem; border-radius: 8px;
}
.primary-nav a:hover { background: var(--bg-subtle); color: var(--text); text-decoration: none; }
.primary-nav a.active { color: var(--accent-text); background: var(--accent-soft); }

.header-tools { margin-left: auto; display: flex; align-items: center; gap: 0.5rem; }

.search-box {
  position: relative; display: flex; align-items: center;
}
.search-box input {
  font: inherit; font-size: var(--step--1);
  width: 200px; max-width: 42vw;
  padding: 0.45rem 0.7rem 0.45rem 2rem;
  border: 1px solid var(--border-strong); border-radius: 9px;
  background: var(--bg-subtle); color: var(--text);
}
.search-box input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
.search-box .s-icon { position: absolute; left: 0.6rem; color: var(--text-faint); pointer-events: none; }

.icon-btn {
  width: 40px; height: 40px; flex: 0 0 auto;
  display: grid; place-items: center;
  border: 1px solid var(--border-strong); border-radius: 9px;
  background: var(--bg-subtle); color: var(--text-soft); cursor: pointer;
}
.icon-btn:hover { color: var(--text); border-color: var(--text-faint); }
.menu-btn { display: none; }

/* search results dropdown */
.search-results {
  position: absolute; right: 0; top: calc(100% + 8px); width: min(420px, 90vw);
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow-md); padding: 0.4rem; max-height: 60vh; overflow: auto; z-index: 60;
  display: none;
}
.search-results.open { display: block; }
.search-results a { display: block; padding: 0.55rem 0.7rem; border-radius: 8px; color: var(--text); }
.search-results a:hover { background: var(--bg-subtle); text-decoration: none; }
.search-results .r-kind { font-size: 0.72rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.04em; }
.search-results .r-title { font-weight: 600; }
.search-results .empty { padding: 0.8rem; color: var(--text-faint); font-size: var(--step--1); }

/* ---------- Hero (home) ---------- */
.hero { padding: clamp(2.5rem, 6vw, 5rem) clamp(0.8rem, 3vw, 1.6rem); max-width: var(--maxw); margin: 0 auto; }
.hero h1 { font-size: var(--step-4); line-height: 1.08; margin: 0 0 0.6rem; letter-spacing: -0.02em; }
.hero .lede { font-size: var(--step-1); color: var(--text-soft); max-width: 56ch; margin: 0 0 1.6rem; }
.hero .cta { display: flex; gap: 0.7rem; flex-wrap: wrap; }

/* ---------- Layout ---------- */
.layout {
  max-width: var(--maxw); margin: 0 auto; padding: 0 clamp(0.8rem, 3vw, 1.6rem);
  display: grid; grid-template-columns: 248px minmax(0, 1fr); gap: var(--sp-4);
  align-items: start;
}
.sidebar {
  position: sticky; top: calc(var(--header-h) + 16px);
  align-self: start; max-height: calc(100vh - var(--header-h) - 32px);
  overflow: auto; padding: 0.4rem 0; font-size: var(--step--1);
}
.sidebar .side-group { margin-bottom: 1.1rem; }
.sidebar .side-title {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-faint); font-weight: 700; margin: 0 0 0.35rem; padding-left: 0.6rem;
}
.sidebar a {
  display: block; padding: 0.34rem 0.6rem; border-radius: 7px;
  color: var(--text-soft); border-left: 2px solid transparent;
}
.sidebar a:hover { background: var(--bg-subtle); color: var(--text); text-decoration: none; }
.sidebar a.active { color: var(--accent-text); background: var(--accent-soft); border-left-color: var(--accent); font-weight: 600; }

.main-col { min-width: 0; padding-bottom: var(--sp-5); }
.toc {
  position: sticky; top: calc(var(--header-h) + 16px);
  align-self: start; width: 220px; font-size: var(--step--1);
  max-height: calc(100vh - var(--header-h) - 32px); overflow: auto;
}
.toc .toc-title { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-faint); font-weight: 700; margin-bottom: 0.4rem; }
.toc a { display: block; padding: 0.26rem 0; color: var(--text-soft); border-left: 2px solid var(--border); padding-left: 0.7rem; }
.toc a:hover { color: var(--text); text-decoration: none; border-left-color: var(--text-faint); }
.toc a.lvl-3 { padding-left: 1.5rem; font-size: 0.86em; }
.toc a.active { color: var(--accent-text); border-left-color: var(--accent); font-weight: 600; }

.has-toc { grid-template-columns: 248px minmax(0,1fr) 220px; }
@media (max-width: 1100px) { .has-toc { grid-template-columns: 220px minmax(0,1fr); } .toc { display: none; } }
@media (max-width: 860px) {
  .layout, .has-toc { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; left: 0; top: var(--header-h); bottom: 0; width: 280px; z-index: 45;
    background: var(--bg-elevated); border-right: 1px solid var(--border); padding: 1rem;
    transform: translateX(-102%); transition: transform 0.22s ease;
  }
  .sidebar.open { transform: none; box-shadow: var(--shadow-md); }
  .scrim { position: fixed; inset: var(--header-h) 0 0 0; background: rgba(0,0,0,0.4); z-index: 44; display: none; }
  .scrim.open { display: block; }
  .menu-btn { display: grid; }
  .primary-nav { display: none; }
}

/* ---------- Breadcrumbs ---------- */
.breadcrumbs { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; color: var(--text-faint); font-size: var(--step--1); margin-bottom: 1rem; }
.breadcrumbs a { color: var(--text-soft); }
.breadcrumbs .sep { opacity: 0.6; }
.breadcrumbs .cur { color: var(--text); }

/* ---------- Content prose ---------- */
.content { max-width: var(--reading); }
.content > * + * { margin-top: 1.1rem; }
.content h1 { font-size: var(--step-3); line-height: 1.12; letter-spacing: -0.02em; margin: 0 0 0.4rem; }
.content .subtitle { font-size: var(--step-1); color: var(--text-soft); margin: 0 0 1.4rem; }
.content h2 { font-size: var(--step-2); margin-top: 2.4rem; letter-spacing: -0.01em; scroll-margin-top: calc(var(--header-h) + 16px); }
.content h3 { font-size: var(--step-1); margin-top: 1.7rem; scroll-margin-top: calc(var(--header-h) + 16px); }
.content h2, .content h3 { position: relative; }
.content h2::before, .content h3::before { content: "#"; position: absolute; left: -1.1em; color: var(--text-faint); opacity: 0; font-weight: 400; transition: opacity 0.15s; }
.content h2:hover::before, .content h3:hover::before { opacity: 0.7; }
.content p { margin: 0; }
.content ul, .content ol { margin: 0; padding-left: 1.4rem; }
.content li { margin: 0.3rem 0; }
.content li::marker { color: var(--text-faint); }
.content strong { font-weight: 650; color: var(--text); }

.content :not(pre) > code {
  font-family: var(--font-mono); font-size: 0.88em;
  background: var(--bg-subtle); border: 1px solid var(--border);
  padding: 0.1em 0.36em; border-radius: 6px; color: var(--accent-text);
}
.content pre {
  background: var(--bg-code); color: #e6edf3; border-radius: var(--radius);
  padding: 0; overflow: auto; font-size: 0.86rem; line-height: 1.6; box-shadow: var(--shadow-sm);
  border: 1px solid #1e293b;
}
.content pre .code-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.5rem 0.9rem; border-bottom: 1px solid #1e293b; color: #93a1b5; font-size: 0.74rem;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.content pre .copy-btn {
  background: #1e293b; color: #cbd5e1; border: 1px solid #334155; border-radius: 6px;
  padding: 0.2rem 0.6rem; font-size: 0.72rem; cursor: pointer;
}
.content pre .copy-btn:hover { background: #273449; color: #fff; }
.content pre code { display: block; padding: 0.9rem 1.1rem; font-family: var(--font-mono); }

.content blockquote {
  margin: 0; padding: 0.2rem 0 0.2rem 1.1rem; border-left: 3px solid var(--border-strong); color: var(--text-soft);
}
.content table { width: 100%; border-collapse: collapse; font-size: var(--step--1); margin: 0; }
.content th, .content td { text-align: left; padding: 0.55rem 0.7rem; border-bottom: 1px solid var(--border); }
.content th { background: var(--bg-subtle); font-weight: 650; color: var(--text); }
.content tr:hover td { background: var(--bg-subtle); }

.callout {
  display: flex; gap: 0.8rem; padding: 0.9rem 1.1rem; border-radius: var(--radius);
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 22%, var(--border));
  color: var(--text);
}
.callout .c-ico { font-size: 1.2rem; line-height: 1.3; }
.callout.note { background: var(--bg-subtle); border-color: var(--border-strong); }
.callout.warn { background: color-mix(in srgb, var(--warning) 12%, var(--bg)); border-color: color-mix(in srgb, var(--warning) 40%, var(--border)); }

/* ---------- Cards / grids ---------- */
.grid { display: grid; gap: var(--sp-3); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
@media (max-width: 720px) { .grid.cols-2, .grid.cols-3 { grid-template-columns: minmax(0,1fr); } }

.card {
  display: block; padding: 1.2rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow-sm); color: var(--text); transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--border-strong); text-decoration: none; }
.card .c-ico {
  width: 42px; height: 42px; border-radius: 11px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent-text); font-size: 1.3rem; margin-bottom: 0.7rem;
}
.card h3 { font-size: var(--step-1); margin: 0 0 0.35rem; }
.card p { color: var(--text-soft); font-size: var(--step--1); margin: 0; }

.section { max-width: var(--maxw); margin: 0 auto; padding: clamp(1.5rem, 4vw, 3rem) clamp(0.8rem, 3vw, 1.6rem); }
.section > .sec-head { margin-bottom: 1.4rem; }
.sec-head h2 { font-size: var(--step-2); margin: 0 0 0.3rem; letter-spacing: -0.01em; }
.sec-head p { color: var(--text-soft); margin: 0; max-width: 60ch; }

/* ---------- Buttons / badges / chips ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 0.45rem; cursor: pointer;
  font: inherit; font-weight: 600; font-size: var(--step--1);
  padding: 0.6rem 1.1rem; border-radius: 10px; border: 1px solid transparent;
  min-height: 44px; transition: background 0.15s ease, border-color 0.15s ease;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-text); text-decoration: none; }
.btn.ghost { background: var(--bg-subtle); color: var(--text); border-color: var(--border-strong); }
.btn.ghost:hover { text-decoration: none; border-color: var(--text-faint); }

.badge { display: inline-block; font-size: 0.72rem; font-weight: 650; padding: 0.15rem 0.55rem; border-radius: 999px; background: var(--accent-soft); color: var(--accent-text); }
.badge.mute { background: var(--bg-subtle); color: var(--text-faint); }
.chip { display: inline-block; font-size: 0.78rem; padding: 0.2rem 0.6rem; border-radius: 999px; background: var(--bg-subtle); border: 1px solid var(--border); color: var(--text-soft); }
.chip:hover { text-decoration: none; border-color: var(--accent); color: var(--accent-text); }

/* ---------- FAQ ---------- */
.faq { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.faq details { border-bottom: 1px solid var(--border); }
.faq details:last-child { border-bottom: none; }
.faq summary { cursor: pointer; padding: 0.9rem 1.1rem; font-weight: 600; background: var(--surface); list-style: none; }
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; float: right; color: var(--text-faint); font-weight: 400; }
.faq details[open] summary::after { content: "–"; }
.faq .a { padding: 0 1.1rem 1rem; color: var(--text-soft); }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--border); background: var(--bg-subtle); margin-top: var(--sp-5); }
.footer-inner { max-width: var(--maxw); margin: 0 auto; padding: var(--sp-4) clamp(0.8rem, 3vw, 1.6rem); display: grid; grid-template-columns: 1.4fr repeat(3, 1fr); gap: var(--sp-3); }
@media (max-width: 760px) { .footer-inner { grid-template-columns: 1fr 1fr; } }
.footer-inner h4 { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-faint); margin: 0 0 0.6rem; }
.footer-inner a { display: block; color: var(--text-soft); padding: 0.2rem 0; font-size: var(--step--1); }
.footer-inner a:hover { color: var(--text); }
.footer-brand p { color: var(--text-soft); font-size: var(--step--1); max-width: 34ch; }
.footer-note { border-top: 1px solid var(--border); padding: 1rem clamp(0.8rem,3vw,1.6rem); max-width: var(--maxw); margin: 0 auto; color: var(--text-faint); font-size: 0.8rem; display: flex; justify-content: space-between; flex-wrap: wrap; gap: 0.5rem; }

/* ---------- Tool pages (ported from localtoolkit, CodeLore skin) ---------- */
.tool-wrap { max-width: 860px; margin: 0 auto; }
.tool-card { border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-sm); padding: 1.4rem; }
.tool-card label { display: block; font-weight: 600; margin: 1rem 0 0.4rem; font-size: var(--step--1); }
.tool-card textarea, .tool-card input[type=text], .tool-card select {
  width: 100%; font: inherit; font-family: var(--font-mono); font-size: 0.9rem;
  padding: 0.7rem; border: 1px solid var(--border-strong); border-radius: 10px;
  background: var(--bg-subtle); color: var(--text); resize: vertical;
}
.tool-card textarea:focus, .tool-card input:focus, .tool-card select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
.tool-output { margin-top: 1rem; }
.tool-output pre { max-height: 420px; }
.tool-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-top: 1rem; }

/* ---------- Syntax highlight tokens (minimal highlighter) ---------- */
.tok-kw { color: #c792ea; }
.tok-str { color: #9ece6a; }
.tok-num { color: #ff9e64; }
.tok-com { color: #5c6b82; font-style: italic; }
.tok-fn { color: #7aa2f7; }
.tok-punc { color: #89a; }
[data-theme="light"] .content pre, pre { color: #e6edf3; }
[data-theme="light"] .tok-kw { color: #d8a0ff; }
[data-theme="light"] .tok-str { color: #a6e88c; }
[data-theme="light"] .tok-num { color: #ffb37a; }

/* ---------- Utilities ---------- */
.muted { color: var(--text-soft); }
.faint { color: var(--text-faint); }
.center { text-align: center; }
.mt-0 { margin-top: 0 !important; }
.updated-stamp { font-size: var(--step--1); color: var(--text-faint); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
