/* Cipi — base design system: tokens, type, chrome (nav, footer), shared components.
   Pages: home, docs. Legacy pages (guides, alternatives) load this for nav + footer. */

:root {
    --paper: #F2F4F1;
    --paper-2: #E7EBE6;
    --card: #FBFCFA;
    --ink: #14201A;
    --ink-2: #34423A;
    --muted: #5B675F;
    --rule: #D3DAD2;
    --rule-2: #C2CBC1;
    --lime: #84CC16;
    --lime-ink: #3F6212;
    --lime-soft: #E3F1CB;
    --amber: #A85A06;
    --red: #B42318;
    --blue: #1F4FD1;

    --term: #0D1310;
    --term-2: #151D18;
    --term-rule: #253129;
    --term-text: #D5E1D7;
    --term-dim: #7A8B80;
    --term-lime: #A3E635;
    --term-cyan: #67D4E4;
    --term-amber: #F0B35A;
    --term-red: #F4776B;

    --f-sans: "Schibsted Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
    --f-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

    --wrap: 1180px;
    --r-sm: 4px;
    --r: 8px;
    --r-lg: 14px;
    --nav-h: 64px;
    --focus: 0 0 0 3px color-mix(in srgb, var(--lime) 55%, transparent);
    color-scheme: light;
}

[data-theme="dark"] {
    --paper: #0F1512;
    --paper-2: #141B17;
    --card: #18201B;
    --ink: #E6EDE7;
    --ink-2: #C4CFC7;
    --muted: #8E9C93;
    --rule: #26312A;
    --rule-2: #34413A;
    --lime-ink: #A3E635;
    --lime-soft: rgba(132, 204, 22, .14);
    --amber: #F0B35A;
    --red: #F4776B;
    --blue: #8BA7FF;
    --term: #090D0B;
    --term-2: #111814;
    color-scheme: dark;
}

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

html {
    -webkit-text-size-adjust: 100%;
    scroll-padding-top: calc(var(--nav-h) + 16px);
}

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font: 400 17px/1.6 var(--f-sans);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

img, svg { display: block; max-width: 100%; }
a { color: inherit; }
button { font: inherit; color: inherit; }
code, kbd, pre, samp { font-family: var(--f-mono); }

:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--r-sm); }

.page-w { width: min(var(--wrap), 100% - 40px); margin-inline: auto; }

.skip-link {
    position: absolute; left: 12px; top: -48px; z-index: 100;
    padding: 10px 14px; background: var(--ink); color: var(--paper);
    border-radius: var(--r); text-decoration: none; font-weight: 600;
}
.skip-link:focus { top: 12px; }

.visually-hidden {
    position: absolute !important; width: 1px; height: 1px; overflow: hidden;
    clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 8px;
    height: 44px; padding: 0 18px;
    border-radius: var(--r); border: 1px solid transparent;
    font: 600 15px/1 var(--f-sans); text-decoration: none; cursor: pointer;
    transition: background-color .15s, border-color .15s, color .15s;
}
.btn svg { width: 16px; height: 16px; flex: none; }
.btn-primary { background: var(--ink); color: var(--paper); }
.btn-primary:hover { background: var(--ink-2); }
.btn-lime { background: var(--lime); color: #12200A; }
.btn-lime:hover { background: #95DA2A; }
.btn-ghost { border-color: var(--rule-2); color: var(--ink); background: transparent; }
.btn-ghost:hover { border-color: var(--ink); }

/* ---------- Brand mark ---------- */
.mark { width: 26px; height: 26px; color: var(--ink); }
.mark .mark-signal { fill: var(--lime); }

/* ---------- Site nav ---------- */
.site-nav {
    position: sticky; top: 0; z-index: 50;
    height: var(--nav-h);
    background: color-mix(in srgb, var(--paper) 88%, transparent);
    backdrop-filter: saturate(1.4) blur(12px);
    -webkit-backdrop-filter: saturate(1.4) blur(12px);
    border-bottom: 1px solid var(--rule);
}
.site-nav .page-w, .site-nav .sn-wide {
    height: 100%; display: flex; align-items: center; gap: 28px;
}
.site-nav .sn-wide { padding-inline: 24px; }
.sn-brand {
    display: flex; align-items: center; gap: 10px;
    font: 800 21px/1 var(--f-sans); letter-spacing: -.03em; text-decoration: none;
}
.sn-links { display: flex; gap: 4px; margin-right: auto; }
.sn-links a {
    padding: 8px 12px; border-radius: var(--r);
    font-size: 15px; font-weight: 500; color: var(--ink-2); text-decoration: none;
}
.sn-links a:hover { color: var(--ink); background: var(--paper-2); }
.sn-links a[aria-current="page"] { color: var(--ink); background: var(--paper-2); }
.sn-actions { display: flex; align-items: center; gap: 8px; }
.sn-search {
    display: flex; align-items: center; gap: 10px;
    height: 38px; min-width: 210px; padding: 0 10px 0 12px;
    border: 1px solid var(--rule-2); border-radius: var(--r);
    background: var(--card); color: var(--muted); cursor: pointer;
    font-size: 14px; text-align: left;
}
.sn-search:hover { border-color: var(--ink-2); }
.sn-search svg { width: 15px; height: 15px; }
.sn-search span { flex: 1; }
.sn-search kbd, .kbd {
    font: 500 11px/1 var(--f-mono); padding: 4px 6px;
    border: 1px solid var(--rule-2); border-bottom-width: 2px; border-radius: 4px; color: var(--muted);
}
.icon-btn {
    width: 38px; height: 38px; display: inline-grid; place-items: center;
    border: 1px solid var(--rule-2); border-radius: var(--r); background: transparent; cursor: pointer;
    color: var(--ink-2);
}
.icon-btn:hover { border-color: var(--ink-2); color: var(--ink); }
.icon-btn svg { width: 17px; height: 17px; }
.sn-theme .i-sun { display: none; }
[data-theme="dark"] .sn-theme .i-sun { display: block; }
[data-theme="dark"] .sn-theme .i-moon { display: none; }

.gh-btn {
    display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px;
    border-radius: var(--r); background: var(--ink); color: var(--paper);
    font-size: 14px; font-weight: 600; text-decoration: none;
}
.gh-btn svg { width: 16px; height: 16px; }
.gh-btn .gh-stars { padding-left: 8px; border-left: 1px solid color-mix(in srgb, var(--paper) 30%, transparent); font-variant-numeric: tabular-nums; }

.sn-toggle { display: none; }
.sn-mobile { display: none; }

@media (max-width: 900px) {
    .sn-links, .sn-search, .gh-btn .gh-label, .gh-btn .gh-stars { display: none; }
    .sn-toggle { display: inline-grid; }
    .site-nav .page-w, .site-nav .sn-wide { gap: 12px; }
    .sn-actions { margin-left: auto; }
    .sn-mobile {
        position: fixed; inset: var(--nav-h) 0 0 0; z-index: 49;
        background: var(--paper); padding: 20px; overflow-y: auto;
        border-top: 1px solid var(--rule);
    }
    .sn-mobile.open { display: block; }
    .sn-mobile a {
        display: block; padding: 14px 4px; border-bottom: 1px solid var(--rule);
        font-size: 18px; font-weight: 600; text-decoration: none;
    }
    .sn-mobile .btn { margin-top: 20px; width: 100%; justify-content: center; }
}

/* ---------- Footer ---------- */
.site-footer {
    border-top: 1px solid var(--rule);
    padding: 56px 0 40px;
    font-size: 15px; color: var(--muted);
}
.sf-grid {
    display: grid; gap: 32px;
    grid-template-columns: 1.4fr repeat(4, 1fr);
}
.site-footer .sn-brand { color: var(--ink); }
.sf-brand p { max-width: 30ch; margin: 14px 0 0; }
.sf-col h2 {
    margin: 0 0 12px; font-size: 14px; font-weight: 700; color: var(--ink);
}
.sf-col ul { list-style: none; margin: 0; padding: 0; }
.sf-col li { margin: 7px 0; }
.sf-col a { text-decoration: none; }
.sf-col a:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
.sf-base {
    display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px;
    margin-top: 48px; padding-top: 20px; border-top: 1px solid var(--rule); font-size: 14px;
}
.sf-base a { text-decoration: none; }
.sf-base a:hover { color: var(--ink); }
.sf-tg {
    display: inline-flex; align-items: center; gap: 12px; margin-top: 20px;
    padding: 10px 14px 10px 12px; border: 1px solid var(--rule); border-radius: 10px;
    text-decoration: none; color: var(--ink); background: var(--paper-2, transparent);
    transition: border-color .15s;
}
.sf-tg:hover { border-color: #2AABEE; }
.sf-tg svg { width: 26px; height: 26px; color: #2AABEE; flex: none; }
.sf-tg span { display: flex; flex-direction: column; line-height: 1.25; }
.sf-tg strong { font-size: 14.5px; }
.sf-tg small { font-size: 13px; color: var(--muted); }
.sf-base a[href^="https://web.ap.it"] { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
/* Telegram card (docs, guides) */
.tg-card {
    display: flex; align-items: center; justify-content: space-between; gap: 20px; flex-wrap: wrap;
    margin: 18px 0 26px; padding: 18px 20px; border-radius: 12px;
    border: 1px solid color-mix(in srgb, #2AABEE 40%, var(--rule));
    background: color-mix(in srgb, #2AABEE 7%, transparent);
}
.tg-card strong { font-size: 16px; color: var(--ink); }
.tg-card p { margin: 4px 0 0 !important; max-width: 56ch; }
.tg-card .btn { background: #2AABEE; color: #fff; border-color: #2AABEE; }
.tg-card .btn:hover { background: #1d96d4; }
@media (max-width: 900px) {
    .sf-grid { grid-template-columns: 1fr 1fr; }
    .sf-brand { grid-column: 1 / -1; }
}

/* ---------- Terminal (animated) ---------- */
.term {
    --t-pad: 18px;
    background: var(--term);
    color: var(--term-text);
    border-radius: var(--r-lg);
    border: 1px solid #1F2A23;
    overflow: hidden;
    font: 400 13.5px/1.65 var(--f-mono);
    box-shadow: 0 1px 0 rgba(255,255,255,.04) inset, 0 24px 48px -24px rgba(10, 20, 14, .45);
    position: relative;
    text-align: left;
}
.term-bar {
    display: flex; align-items: center; gap: 12px;
    height: 40px; padding: 0 10px 0 var(--t-pad);
    background: var(--term-2); border-bottom: 1px solid var(--term-rule);
    color: var(--term-dim); font-size: 12px;
}
.term-dots { display: flex; gap: 6px; }
.term-dots i { width: 10px; height: 10px; border-radius: 50%; background: #2C3830; }
.term-title { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.term-btn {
    display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 9px;
    border: 1px solid var(--term-rule); border-radius: 5px; background: transparent;
    color: var(--term-dim); font: 500 11.5px/1 var(--f-mono); cursor: pointer;
}
.term-btn:hover { color: var(--term-text); border-color: #3A4A40; }
.term-btn svg { width: 12px; height: 12px; }
.term-body {
    margin: 0; padding: var(--t-pad);
    min-height: var(--term-min, 280px);
    max-height: var(--term-max, none);
    overflow: auto;
    white-space: pre-wrap; word-break: break-word;
    font: inherit;
    scrollbar-width: thin; scrollbar-color: #2C3830 transparent;
}
.term-line { display: block; min-height: 1.65em; }
.term-prompt { color: var(--term-lime); }
.term-path { color: var(--term-cyan); }
.term-cmd { color: #F3F8F4; }
.term-caret {
    display: inline-block; width: .6em; height: 1.15em; margin-left: 1px;
    vertical-align: -.2em; background: var(--term-lime);
    animation: caret 1s steps(1) infinite;
}
@keyframes caret { 50% { opacity: 0; } }
.t-ok { color: var(--term-lime); }
.t-dim { color: var(--term-dim); }
.t-info { color: var(--term-cyan); }
.t-warn { color: var(--term-amber); }
.t-err { color: var(--term-red); }
.t-hl { color: #F3F8F4; font-weight: 700; }
.t-key { color: var(--term-amber); }
.term-progress {
    display: inline-block; width: 22ch; height: .7em; margin-left: 1ch; vertical-align: 0;
    background: #1D2822; border-radius: 2px; overflow: hidden; position: relative;
}
.term-progress::after {
    content: ""; position: absolute; inset: 0; transform-origin: left;
    background: var(--term-lime); transform: scaleX(var(--p, 0));
}
.term-hint {
    position: absolute; right: 12px; bottom: 10px;
    font-size: 11px; color: var(--term-dim); pointer-events: none; opacity: 0; transition: opacity .3s;
}
.term[data-state="done"] .term-hint { opacity: 1; }

/* Static code (copyable) */
.cmd {
    display: flex; align-items: center; gap: 12px;
    padding: 0 6px 0 16px; height: 52px;
    background: var(--term); color: var(--term-text);
    border-radius: var(--r); font: 500 14.5px/1 var(--f-mono);
    border: 1px solid #1F2A23;
}
.cmd code { flex: 1; overflow-x: auto; white-space: nowrap; scrollbar-width: none; }
.cmd code::before { content: "$ "; color: var(--term-lime); }
.copy-btn {
    display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 12px;
    background: #1B241F; border: 1px solid var(--term-rule); border-radius: 6px;
    color: var(--term-text); font: 600 13px/1 var(--f-sans); cursor: pointer; flex: none;
}
.copy-btn:hover { background: #24302A; }
.copy-btn svg { width: 14px; height: 14px; }
.copy-btn[data-copied] { color: var(--term-lime); }

/* Telegram chip (shared) */
.tg-chip {
    position: fixed; right: 16px; bottom: 16px; z-index: 40;
    display: flex; align-items: stretch;
    background: var(--card); border: 1px solid var(--rule-2); border-radius: var(--r);
    box-shadow: 0 12px 32px -16px rgba(10, 20, 14, .35); font-size: 13px;
}
.tg-chip a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; text-decoration: none; }
.tg-chip svg.tg { width: 22px; height: 22px; fill: #2AABEE; }
.tg-chip strong { display: block; font-size: 13px; }
.tg-chip small { color: var(--muted); }
.tg-chip button { border: 0; border-left: 1px solid var(--rule); background: none; padding: 0 10px; cursor: pointer; color: var(--muted); }
@media (max-width: 640px) { .tg-chip { display: none; } }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
    .term-caret { animation: none; }
}
