/* ==========================================================================
   Temporeum User Guide (/guide)
   Standalone documentation page. Loaded directly (not via the app bundle) so
   guide content can be iterated without rebuilding static/dist. Themed with the
   shared theme_tokens.css custom properties.
   ========================================================================== */

:root {
    --guide-max: 1180px;
    --guide-sidebar: 260px;
    --guide-gap: 40px;
    --guide-accent: var(--primary-color, #0a7d32);
    --guide-ink: var(--app-text-color, #1b1b1f);
    --guide-muted: var(--text-muted, #5b6067);
    --guide-card: #ffffff;
    --guide-line: rgba(0, 0, 0, 0.09);
    --guide-soft: rgba(10, 125, 50, 0.06);
}

/* The app locks the whole document (`html, body { overflow:hidden !important }`
   in style_base.css) because the timeline is a fixed fullscreen canvas. The
   guide is a normal scrolling document, so undo that lock here. This file loads
   after the app CSS (and after the production bundle), so these win. */
/* Only the viewport (html) scrolls. Keeping BOTH html and body as scroll
   containers (overflow:auto on each) breaks mouse-wheel scrolling in Firefox:
   the body shrinks to content so it has nothing to scroll, the wheel targets
   it and does nothing, while programmatic scrollTo still moves the viewport.
   So: html = the scroll container (overflow-y:auto, no visible/auto mix), body
   = plain visible flow. */
html {
    overflow-x: hidden !important;
    overflow-y: auto !important;
    height: auto !important;
    scrollbar-width: auto;
    scrollbar-color: #60636a #e4e4df;
    scrollbar-gutter: stable;
}
body.guide-page {
    overflow: visible !important;
    height: auto !important;
}

html::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}
html::-webkit-scrollbar-track {
    background: #e4e4df;
}
html::-webkit-scrollbar-thumb {
    min-height: 48px;
    background: #60636a;
    border: 2px solid #e4e4df;
    border-radius: 999px;
}
html::-webkit-scrollbar-thumb:hover {
    background: #3f4248;
}

body.guide-page {
    margin: 0;
    min-height: 100vh;
    color: var(--guide-ink);
    font-family: 'Montserrat', system-ui, sans-serif;
    /* Deliberately NOT the app's --app-background (#fcfcf7): that token has a
       green-yellow cast. The guide uses a neutral off-white instead. */
    background: #fafafa;
    -webkit-font-smoothing: antialiased;
}

/* --- Top bar ------------------------------------------------------------- */
.guide-topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 24px;
    background: #17181c;
    color: #f6f4ec;
    box-shadow: 0 2px 14px rgba(0, 0, 0, 0.18);
}

.guide-topbar a { color: inherit; text-decoration: none; }

.guide-brand {
    font-family: 'Playfair Display', serif;
    font-style: italic;
    font-size: 1.4rem;
    letter-spacing: 0.01em;
}

.guide-brand .beta {
    font-family: 'Montserrat', sans-serif;
    font-style: normal;
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    vertical-align: super;
    opacity: 0.7;
    margin-left: 4px;
}

.guide-back {
    font-size: 0.85rem;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.10);
    transition: background 0.15s ease;
}
.guide-back:hover { background: rgba(255, 255, 255, 0.20); }

/* --- Layout shell -------------------------------------------------------- */
.guide-shell {
    max-width: var(--guide-max);
    margin: 0 auto;
    padding: 40px 24px 96px;
    display: grid;
    grid-template-columns: var(--guide-sidebar) minmax(0, 1fr);
    gap: var(--guide-gap);
    align-items: start;
}

/* --- Sidebar / table of contents ---------------------------------------- */
.guide-toc {
    position: sticky;
    top: 84px;
    max-height: calc(100vh - 108px);
    overflow-y: auto;
    padding-right: 8px;
}

.guide-toc-title {
    margin: 0 0 12px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--guide-muted);
}

.guide-toc ol {
    list-style: none;
    margin: 0;
    padding: 0;
}

.guide-toc-part {
    margin: 18px 0 6px;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--guide-accent);
}
.guide-toc-part:first-child { margin-top: 0; }

.guide-toc a {
    display: block;
    padding: 6px 12px;
    border-left: 2px solid transparent;
    color: var(--guide-muted);
    text-decoration: none;
    font-size: 0.9rem;
    line-height: 1.35;
    border-radius: 0 6px 6px 0;
    transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.guide-toc a:hover,
.guide-toc a.is-active {
    color: var(--guide-ink);
    background: var(--guide-soft);
    border-left-color: var(--guide-accent);
}

.guide-toc a .muted { color: var(--guide-muted); opacity: 0.6; }

/* --- Main content -------------------------------------------------------- */
.guide-main { min-width: 0; }

.guide-hero {
    margin-bottom: 40px;
}
.guide-hero .eyebrow {
    margin: 0 0 10px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--guide-accent);
}
.guide-hero h1 {
    margin: 0;
    font-family: 'Playfair Display', serif;
    font-size: clamp(2.1rem, 4vw, 3rem);
    line-height: 1.08;
}
.guide-hero p {
    margin: 14px 0 0;
    max-width: 64ch;
    font-size: 1.05rem;
    line-height: 1.65;
    color: var(--guide-muted);
}

.guide-section {
    scroll-margin-top: 84px;
    padding: 32px 0 8px;
    border-top: 1px solid var(--guide-line);
    margin-top: 28px;
}
.guide-section:first-of-type { border-top: 0; margin-top: 0; }

.guide-section > h2 {
    margin: 0 0 6px;
    font-family: 'Playfair Display', serif;
    font-size: clamp(1.5rem, 2.6vw, 2rem);
    line-height: 1.15;
    scroll-margin-top: 84px;
}
.guide-section .section-kicker {
    margin: 0 0 14px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--guide-accent);
}
.guide-section > p {
    max-width: 68ch;
    font-size: 1rem;
    line-height: 1.7;
    color: var(--guide-ink);
}
.guide-section strong { font-weight: 700; }

/* --- Annotated figure ---------------------------------------------------- */
.guide-figure {
    position: relative;
    margin: 30px 0 10px;
    padding: clamp(9px, 1.2vw, 13px);
    background: linear-gradient(145deg, #303238, #202227);
    border: 1px solid rgba(10, 125, 50, 0.34);
    border-radius: 20px;
    box-shadow:
        0 22px 52px rgba(0, 0, 0, 0.20),
        0 0 0 1px rgba(255, 255, 255, 0.5),
        0 0 40px rgba(18, 160, 71, 0.07);
}

.guide-figure::before {
    content: "Real product interface";
    display: block;
    padding: 0 4px 11px 23px;
    color: rgba(255, 255, 255, 0.92);
    background:
        radial-gradient(circle at 8px 7px,
            #35d36f 0 4px,
            rgba(53, 211, 111, 0.18) 4.5px 7px,
            transparent 7.5px)
        no-repeat;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 14px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.guide-figure-stage {
    position: relative;
    line-height: 0;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.34);
    border-radius: 13px;
    background: #fff;
    box-shadow: 0 18px 44px rgba(0, 0, 0, 0.36);
}
.guide-figure-stage img {
    display: block;
    width: 100%;
    height: auto;
}

/* Numbered callout markers. The span sits at the exact target point (its
   left/top). To avoid covering the UI, only a small dot marks that point; a
   thin leader line reaches up (or down, via [data-dir="down"]) to the numbered
   circle floating clear of the target. Positioned by percent so everything
   tracks the image at any width. Coordinates come from the live DOM. */
.guide-callout {
    --lead: 30px;          /* fallback line length (JS overrides per marker) */
    --dot: 11px;           /* anchor dot diameter */
    --circle: 28px;        /* numbered circle diameter */
    /* Circle-center offset from the anchor point, in px. JS solves these to
       keep circles from overlapping; CSS defaults = straight up. */
    --cx: 0px;
    --cy: calc(-1 * var(--lead));
    --len: var(--lead);    /* leader-line length  = hypot(cx, cy) */
    --ang: -90deg;         /* leader-line angle    = atan2(cy, cx) */
    position: absolute;
    transform: translate(-50%, -50%);
    width: var(--dot);
    height: var(--dot);
    z-index: 2;
    border-radius: 999px;
    /* Faint dot + line so they don't obscure the UI they point at. The
       numbered circle (::after) keeps full opacity. */
    background: color-mix(in srgb, var(--guide-accent) 32%, transparent);
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.5), 0 2px 5px rgba(0, 0, 0, 0.18);
    font-size: 0;          /* hide the literal digit; ::after renders it */
    cursor: pointer;
}
/* Leader line from the point out to the circle. Drawn from the anchor centre
   and rotated toward the (possibly displaced) circle. */
.guide-callout::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: var(--len);
    height: 2px;
    transform-origin: 0 50%;
    transform: rotate(var(--ang));
    background: var(--guide-accent);
    opacity: 0.5;
}
/* The numbered circle, floating clear of the target point. */
.guide-callout::after {
    content: attr(data-n);
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(calc(-50% + var(--cx)), calc(-50% + var(--cy)));
    width: var(--circle);
    height: var(--circle);
    border-radius: 999px;
    background: var(--guide-accent);
    color: #fff;
    font-family: 'Montserrat', sans-serif;
    font-size: 0.85rem;
    font-weight: 700;
    line-height: var(--circle);
    text-align: center;
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.9), 0 4px 10px rgba(0, 0, 0, 0.35);
    transition: transform 0.12s ease;
}
/* Fallback for markers near the top edge (no-JS): point down instead. */
.guide-callout[data-dir="down"] {
    --cy: var(--lead);
    --ang: 90deg;
}
.guide-callout:hover,
.guide-callout.is-active {
    z-index: 5;
}
.guide-callout:hover::after,
.guide-callout.is-active::after {
    transform: translate(calc(-50% + var(--cx)), calc(-50% + var(--cy))) scale(1.18);
}

.guide-figure-caption {
    padding: 12px 4px 1px;
    font-size: 0.8rem;
    line-height: 1.5;
    color: rgba(246, 244, 236, 0.72);
}

/* --- Legend (numbered explanations under a figure) ---------------------- */
.guide-legend {
    list-style: none;
    counter-reset: legend;
    margin: 22px 0 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px 28px;
}
.guide-legend li {
    position: relative;
    padding-left: 40px;
    font-size: 0.95rem;
    line-height: 1.55;
}
.guide-legend li::before {
    counter-increment: legend;
    content: counter(legend);
    position: absolute;
    left: 0;
    top: 0;
    width: 26px;
    height: 26px;
    border-radius: 999px;
    background: var(--guide-accent);
    color: #fff;
    font-weight: 700;
    font-size: 0.82rem;
    line-height: 26px;
    text-align: center;
}
.guide-legend li b { display: block; font-weight: 700; }
.guide-legend li span { color: var(--guide-muted); }

/* --- Tip callout box ----------------------------------------------------- */
.guide-tip {
    margin: 22px 0 0;
    padding: 14px 18px 14px 44px;
    position: relative;
    background: var(--guide-soft);
    border: 1px solid rgba(10, 125, 50, 0.18);
    border-radius: 12px;
    font-size: 0.95rem;
    line-height: 1.6;
}
.guide-tip::before {
    content: "\1F4A1";
    position: absolute;
    left: 16px;
    top: 13px;
    font-size: 1rem;
}
.guide-tip b { font-weight: 700; }

/* --- Part dividers -------------------------------------------------------- */
/* Chapter markers between the guide's seven parts (A–G). Each is a lettered
   badge plus a short "what this part answers" line, so the page reads as a
   book with chapters rather than 23 flat sections. */
.guide-part {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-top: 72px;
    padding-top: 40px;
    border-top: 1px solid var(--guide-line);
}
.guide-hero + .guide-part {
    margin-top: 8px;
    padding-top: 0;
    border-top: 0;
}
.guide-part-letter {
    flex: none;
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    background: var(--guide-accent);
    color: #fff;
    font-family: 'Playfair Display', serif;
    font-size: 1.4rem;
    font-weight: 700;
    box-shadow: 0 6px 16px rgba(10, 125, 50, 0.25);
}
.guide-part-text h2 {
    margin: 0;
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--guide-accent);
}
.guide-part-text p {
    margin: 3px 0 0;
    font-size: 0.95rem;
    font-style: italic;
    color: var(--guide-muted);
}
/* The part divider already draws the rule — don't double it on the section
   that follows. */
.guide-part + .guide-section {
    border-top: 0;
    margin-top: 0;
    padding-top: 24px;
}

/* --- "Which block when" choice table (Section 7, LifeOS) ------------------ */
.guide-choice {
    width: 100%;
    margin: 20px 0 8px;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--guide-card);
    border: 1px solid var(--guide-line);
    border-radius: 12px;
    overflow: hidden;
    font-size: 0.92rem;
    line-height: 1.5;
}
.guide-choice th,
.guide-choice td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--guide-line);
    vertical-align: top;
}
.guide-choice thead th {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--guide-accent);
    background: var(--guide-soft);
    border-bottom: 1px solid rgba(10, 125, 50, 0.18);
}
.guide-choice tbody tr:last-child td { border-bottom: 0; }
.guide-choice td:nth-child(2) { white-space: nowrap; }
.guide-choice td:last-child { color: var(--guide-muted); }
@media (max-width: 560px) {
    .guide-choice { font-size: 0.84rem; }
    .guide-choice th, .guide-choice td { padding: 8px 10px; }
    .guide-choice td:nth-child(2) { white-space: normal; }
}

/* Sub-heading inside a section (e.g. the Panels menu inside "The top bar"). */
.guide-section > h3 {
    margin: 34px 0 6px;
    font-family: 'Playfair Display', serif;
    font-size: 1.2rem;
    line-height: 1.2;
    scroll-margin-top: 84px;
}

/* --- Guide search --------------------------------------------------------- */
.guide-search { margin: 0 0 14px; }

.guide-search input {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 12px;
    font: inherit;
    font-size: 0.88rem;
    color: var(--guide-ink);
    background: var(--guide-card);
    border: 1px solid var(--guide-line);
    border-radius: 8px;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.guide-search input:focus {
    border-color: var(--guide-accent);
    box-shadow: 0 0 0 3px var(--guide-soft);
}

.guide-search-count {
    margin: 0 0 10px;
    padding: 0 2px;
    font-size: 0.74rem;
    color: var(--guide-muted);
}

.guide-search-sec {
    display: block;
    margin: 14px 0 4px;
    padding: 0 2px;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--guide-accent);
    text-decoration: none;
}
.guide-search-sec:first-of-type { margin-top: 0; }
.guide-search-sec:hover { text-decoration: underline; }

.guide-search-item {
    display: block;
    width: 100%;
    /* The app-wide button rules pin a fixed height; snippets need to wrap. */
    height: auto;
    min-height: 0;
    white-space: normal;
    margin: 0 0 4px;
    padding: 6px 10px;
    font: inherit;
    font-size: 0.8rem;
    line-height: 1.45;
    text-align: left;
    color: var(--guide-muted);
    background: transparent;
    border: none;
    border-left: 2px solid transparent;
    border-radius: 0 6px 6px 0;
    cursor: pointer;
    transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.guide-search-item:hover {
    color: var(--guide-ink);
    background: var(--guide-soft);
    border-left-color: var(--guide-accent);
}
.guide-search-item mark,
.guide-search-flash mark {
    padding: 0 1px;
    border-radius: 2px;
    color: inherit;
    background: rgba(10, 125, 50, 0.22);
}

/* Flash the block a clicked search result points at. */
.guide-search-flash {
    animation: guideSearchFlash 2.2s ease;
    border-radius: 6px;
}
@keyframes guideSearchFlash {
    0%, 55% { background: var(--guide-soft); box-shadow: 0 0 0 6px var(--guide-soft); }
    100% { background: transparent; box-shadow: 0 0 0 6px transparent; }
}

/* --- Responsive ---------------------------------------------------------- */
@media (max-width: 900px) {
    .guide-shell {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    .guide-toc {
        position: static;
        max-height: none;
        padding: 14px 16px;
        background: var(--guide-card);
        border: 1px solid var(--guide-line);
        border-radius: 12px;
    }
    .guide-legend { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
    .guide-figure {
        margin-top: 24px;
        border-radius: 17px;
    }
    .guide-figure-stage { border-radius: 9px; }
    .guide-figure-caption {
        padding-top: 11px;
        font-size: 0.76rem;
    }
    .guide-callout {
        --lead: 22px;
        --dot: 9px;
        --circle: 23px;
    }
    .guide-callout::after {
        font-size: 0.74rem;
    }
}
