/*
 * Thought Cloud — unified index of writing, visuals, papers, and software.
 * Side-by-side layout (list left, map right). No page scroll: list scrolls
 * within its panel; wheel over the map zooms instead of scrolling.
 */

:root {
    /* Atlas palette — cartographic / topographic. Background is parchment;
       ink is warm dark brown; the single accent is sienna, used only for
       featured-item stars and the active filter. Grey is gone. */
    --bg-warm: #f4efe5;
    --text-primary: #2b1f15;
    --text-muted: #6b5840;
    --text-faint: #a8967a;
    --text-active: #b8431f;
    --rule: rgba(43, 31, 21, 0.10);
    --rule-strong: rgba(43, 31, 21, 0.20);
    --accent: #b8431f;
    --ink-deep: #2b1f15;
    --header-height: 64px;
    --transition-fast: 0.15s ease;
    --transition-medium: 0.3s ease;
    --content-max-width: 1400px;
    --list-width: 380px;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-serif: 'EB Garamond', Georgia, serif;
    --font-mono: 'IBM Plex Mono', ui-monospace, Menlo, monospace;
    /* Custom 4-triangle plus cursor — sharp sienna arrowheads radiating from
       a center. Two variants, only the center mark differs:
       - default (non-clickable): tiny ink dot in the center square
       - clickable: filled ink square fills the center
       Hot-spot at 12,12 for both. */
    --cursor-plus: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'><g fill='%23b8431f'><polygon points='12,2 10,9.8 14,9.8'/><polygon points='22,12 14.2,10 14.2,14'/><polygon points='12,22 10,14.2 14,14.2'/><polygon points='2,12 9.8,10 9.8,14'/></g><circle cx='12' cy='12' r='1' fill='%232b1f15'/></svg>") 12 12, crosshair;
    --cursor-plus-click: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'><g fill='%23b8431f'><polygon points='12,2 10,9.8 14,9.8'/><polygon points='22,12 14.2,10 14.2,14'/><polygon points='12,22 10,14.2 14,14.2'/><polygon points='2,12 9.8,10 9.8,14'/></g><rect x='10' y='10' width='4' height='4' fill='%232b1f15'/></svg>") 12 12, pointer;
}

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

html, body {
    height: 100%;
    overflow: hidden;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-serif);
    background-color: var(--bg-warm);
    color: var(--text-primary);
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    /* Atlas: precision over signature. The cloud cursor used elsewhere on
       the site is replaced with a custom 4-triangle plus — same visual
       identity across the whole page, but with two states:
         - body / non-interactive areas: plus with a small dot in the center
         - clickable surfaces: plus with a filled center square
       The page never falls back to the browser arrow.  */
    cursor: var(--cursor-plus);
}

a, button, [role="button"],
input[type="range"], input[type="checkbox"], input[type="number"], input[type="radio"],
label, select, summary,
.filter, .sort-btn, .nav-link, .item {
    cursor: var(--cursor-plus-click);
}

/* ===== Header (matches rest of site) ===== */
.site-header {
    flex-shrink: 0;
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    background: linear-gradient(to bottom, var(--bg-warm) 0%, var(--bg-warm) 80%, transparent 100%);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    z-index: 100;
}
/* Lift the header above the .mobile-menu overlay (z 999) when open, so the
   hamburger (now an ✕) stays visible and tappable to close. */
.site-header.menu-open {
    position: relative;   /* needed for z-index to apply (header is otherwise static) */
    z-index: 1000;
    transform: none;
}

.site-nav {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.nav-item { display: flex; align-items: center; }

.nav-link {
    color: var(--text-muted);
    text-decoration: none;
    letter-spacing: 0.02em;
    transition: color var(--transition-fast);
    padding: 0.5rem 0;
    display: block;
}

.nav-link:hover { color: var(--text-primary); }
.nav-link em { font-style: italic; }
.nav-link.active { color: var(--text-active); }

.hamburger {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 24px;
    height: 24px;
    background: none;
    border: none;
    padding: 0;
    margin-left: auto;
}

.hamburger span {
    display: block;
    width: 100%;
    height: 2px;
    background: var(--text-primary);
    transition: transform var(--transition-fast), opacity var(--transition-fast);
}

/* ===== Main ===== */
.content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0.5rem 2rem 1rem;
    margin: 0 auto;
    width: 100%;
    max-width: var(--content-max-width);
    min-height: 0;
}

/* ===== Split layout ===== */
.split-layout {
    flex: 1;
    display: flex;
    gap: 2rem;
    min-height: 0;
}

/* ===== List panel (controls + scrollable list) ===== */
.list-panel {
    flex: 0 0 var(--list-width);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.list-controls {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    padding: 0 0.5rem 0.75rem 0;
    border-bottom: 1px solid var(--rule);
    margin-bottom: 0.25rem;
}

.filter-row, .sort-row {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.25rem 0.85rem;
    font-family: var(--font-sans);
    font-size: 0.85rem;
}

.control-label {
    color: var(--text-faint);
    font-family: var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 0.16em;
    font-size: 0.65rem;
    margin-right: 0.15rem;
}

.filter, .sort-btn {
    background: none;
    border: none;
    padding: 0.2rem 0;
    color: var(--text-muted);
    letter-spacing: 0.04em;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    transition: color var(--transition-fast);
}

.filter:hover, .sort-btn:hover { color: var(--text-primary); }
.filter.active, .sort-btn.active {
    color: var(--accent);
    font-weight: 500;
}

.list-scroll {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    padding-right: 0.5rem;
    scrollbar-width: thin;
    scrollbar-color: var(--rule-strong) transparent;
}

.list-scroll::-webkit-scrollbar {
    width: 6px;
}
.list-scroll::-webkit-scrollbar-thumb {
    background: var(--rule-strong);
    border-radius: 3px;
}

.cloud-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.item {
    display: block;
    color: inherit;
    text-decoration: none;
    border-bottom: 1px solid var(--rule);
    transition: padding-left var(--transition-fast);
    padding: 0.65rem 0;
}

.item:first-child {
    border-top: 1px solid var(--rule);
}

.item:hover,
.item.cloud-hover-target {
    padding-left: 0.4rem;
}

/* Title — uniform across featured and non-featured. Featured items are
   distinguished by a small star prefix instead of bolder weight. */
.item-title {
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.35;
}

.item-star {
    color: var(--accent);
    margin-right: 0.25rem;
    display: inline-flex;
    align-items: center;
    vertical-align: -0.08em;
}

.item-star svg {
    width: 0.85em;
    height: 0.85em;
    fill: currentColor;
}

/* Summary collapsed by default; expands on hover or when cloud hovers it */
.item-summary {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    color: var(--text-muted);
    font-size: 0.92rem;
    line-height: 1.5;
    transition: max-height 0.28s ease, opacity 0.22s ease, margin-top 0.22s ease;
}

.item:hover .item-summary,
.item.cloud-hover-target .item-summary {
    max-height: 8em;
    opacity: 1;
    margin-top: 0.35rem;
}

.item-meta {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-faint);
    margin-top: 0.25rem;
    display: flex;
    gap: 0.5rem;
    align-items: baseline;
}

.item-meta .dot { color: var(--text-faint); }
.item-type { font-weight: 500; }

/* Technical-level indicator: three dots (●○○ / ●●○ / ●●●), inherits the
   meta-line's faint mono treatment but is not uppercased (dots have no case)
   and slightly tighter letter-spacing so the glyphs sit closer together. */
.item-technical {
    letter-spacing: 0.04em;
    font-size: 0.95em;
    line-height: 1;
}

.item-technical-dots {
    letter-spacing: 0.04em;
}

/* Two manual offsets — one to align text with the em-centered circle glyphs,
   one to nudge the whole pair down to the row's optical center.
   - Text needs ~0.15em more downward shift than the circles to meet them
     (em-center sits above text baseline by roughly this amount).
   - Then both get an additional ~0.05em so the whole pair settles at the
     row's optical center rather than floating slightly high.
   No CSS spec keyword does this automatically — it's a font-metrics
   correction. Tweak both values in tandem if the font ever changes. */
.item-meta .item-technical-dots {
    position: relative;
    top: 0.1em;
}
.item-meta .item-type,
.item-meta .item-technical-word,
.item-meta .item-wordcount,
.item-meta .item-date,
.item-meta .dot {
    position: relative;
    top: 0.2em;
}

/* Word-count chip: compact number always visible ("4.7k", "340"), the
   literal word "words" slides in on hover/cloud-hover-target — same pattern
   as the technical-level chip. Hidden on de-highlighted items to keep them
   quiet. inline-flex (not inline-block) on the word span avoids the
   overflow:hidden + inline-block baseline quirk that pushes inner text
   out of line with the surrounding meta-line baseline. */
.item-wordcount {
    display: inline-flex;
    align-items: baseline;
}
.item-wordcount-word {
    display: inline-flex;
    max-width: 0;
    opacity: 0;
    overflow: hidden;
    white-space: nowrap;
    transition: max-width 0.28s ease, opacity 0.22s ease, margin-left 0.22s ease;
}
.item:hover .item-wordcount-word,
.item.cloud-hover-target .item-wordcount-word {
    max-width: 5em;
    opacity: 1;
    margin-left: 0.3em;
}
.item.dehighlighted:hover .item-wordcount-word,
.item.dehighlighted.cloud-hover-target .item-wordcount-word {
    max-width: 0;
    opacity: 0;
    margin-left: 0;
}

/* Word label ("More technical" etc.) hidden at rest, slides in on item hover
   or cloud-hover-target — same engagement signal that expands the summary.
   Matches the summary's transition timing so both reveals feel like one motion.
   `inline-flex` (not inline-block!) because per CSS spec, an inline-block with
   `overflow: hidden` has its baseline set to the bottom margin edge instead of
   the inner text baseline — that bug pushed the revealed word up out of line
   with ESSAY / OCT 2025. Flex containers derive baseline from the first flex
   item (the text), so alignment stays natural even with overflow clipping. */
.item-technical-word {
    display: inline-flex;
    max-width: 0;
    opacity: 0;
    overflow: hidden;
    white-space: nowrap;
    letter-spacing: 0.08em;       /* match the rest of the meta line */
    transition: max-width 0.28s ease, opacity 0.22s ease, margin-left 0.22s ease;
}

.item:hover .item-technical-word,
.item.cloud-hover-target .item-technical-word {
    max-width: 12em;
    opacity: 1;
    margin-left: 0.45em;
}

/* De-highlighted items keep the word hidden — their whole point is to be
   quiet, and the summary doesn't expand on hover either. */
.item.dehighlighted:hover .item-technical-word,
.item.dehighlighted.cloud-hover-target .item-technical-word {
    max-width: 0;
    opacity: 0;
    margin-left: 0;
}

.item-external {
    color: var(--text-faint);
    margin-left: 0.15rem;
    font-family: var(--font-sans);
    font-size: 0.7em;
    position: relative;
    top: -0.2em;
}

.empty {
    color: var(--text-faint);
    font-style: italic;
    padding: 2rem 0;
    text-align: center;
}

/* De-highlighted items — present but quiet. Smaller text, lower opacity,
   no hover-expand of summary, no star treatment even if technically featured.
   Render at the bottom of every list (sort step handles ordering). */
.item.dehighlighted {
    opacity: 0.55;
    padding: 0.4rem 0;
}
.item.dehighlighted .item-title {
    font-size: 0.88rem;
}
.item.dehighlighted .item-meta {
    font-size: 0.58rem;
}
.item.dehighlighted:hover,
.item.dehighlighted.cloud-hover-target {
    opacity: 0.85;
}
.item.dehighlighted:hover .item-summary,
.item.dehighlighted.cloud-hover-target .item-summary {
    /* Override the hover-expand. De-highlighted means "you probably don't
       need to read this," so the summary stays hidden. */
    max-height: 0;
    opacity: 0;
    margin-top: 0;
}

/* Faint separator before the de-highlighted block. JS sets data-first-dehl
   on the first de-highlighted list entry. */
.item[data-first-dehl="true"] {
    border-top: 1px dashed var(--rule-strong);
    margin-top: 0.6rem;
    padding-top: 0.6rem;
}

/* ===== Cloud view ===== */
.cloud-view {
    flex: 1;
    position: relative;
    min-width: 0;
    min-height: 0;
}

#cloud-canvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: var(--cursor-plus);
}

.cloud-tooltip {
    position: absolute;
    pointer-events: none;
    background: var(--bg-warm);
    border: 1px solid var(--rule-strong);
    border-radius: 2px;
    padding: 0.35rem 0.6rem;
    z-index: 10;
    box-shadow: 0 2px 10px rgba(43, 31, 21, 0.06);
    transition: opacity 0.12s ease;
    font-family: var(--font-serif);
    font-size: 0.95rem;
    color: var(--text-primary);
    white-space: nowrap;
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cloud-tooltip[hidden] { display: none; }

/* "How this map works" affordance — small caption-style link in the bottom
   corner of the canvas. Same monospace small-caps treatment as the filter /
   sort labels so it reads as a control, not a content element. */
.cloud-info-btn {
    position: absolute;
    bottom: 0.6rem;
    right: 0.9rem;
    z-index: 5;
    background: transparent;
    border: none;
    padding: 0.25rem 0.4rem;
    font-family: var(--font-mono);
    font-size: 0.62rem;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: var(--text-faint);
    transition: color var(--transition-fast);
}
.cloud-info-btn:hover { color: var(--text-primary); }

/* Modal overlay — dims the page and presents a parchment card centered. */
.cloud-info-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}
.cloud-info-overlay[hidden] { display: none; }

.cloud-info-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(43, 31, 21, 0.28);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    cursor: var(--cursor-plus-click);
}

.cloud-info-panel {
    position: relative;
    background: var(--bg-warm);
    border: 1px solid var(--rule-strong);
    border-radius: 2px;
    padding: 1.8rem 2.1rem 1.6rem;
    max-width: 560px;
    width: 100%;
    max-height: calc(100vh - 4rem);
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(43, 31, 21, 0.18);
    font-family: var(--font-serif);
    color: var(--text-primary);
}

.cloud-info-panel h2 {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 0.85rem;
    letter-spacing: 0.01em;
}

.cloud-info-panel p {
    font-size: 0.98rem;
    line-height: 1.55;
    margin-bottom: 0.85rem;
}
.cloud-info-panel p:last-child { margin-bottom: 0; }
.cloud-info-panel em { font-style: italic; }

.cloud-info-close {
    position: absolute;
    top: 0.25rem;
    right: 0.55rem;
    background: transparent;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    color: var(--text-faint);
    padding: 0.25rem 0.5rem;
    transition: color var(--transition-fast);
    font-family: var(--font-serif);
}
.cloud-info-close:hover { color: var(--text-primary); }

/* Mobile menu (matches rest of site) */
.mobile-menu {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--bg-warm);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-medium), visibility 0s var(--transition-medium);
}

.mobile-menu.open {
    opacity: 1;
    visibility: visible;
    transition: opacity var(--transition-medium), visibility 0s 0s;
}

.mobile-menu-content {
    padding: calc(var(--header-height) + 2rem) 1.5rem 2rem;
}

.mobile-menu .mobile-nav-item { margin-bottom: 1.5rem; }

.mobile-menu .mobile-nav-link {
    display: block;
    font-size: 1.25rem;
    color: var(--text-primary);
    text-decoration: none;
}

.mobile-menu .mobile-nav-link em { font-style: italic; }
.mobile-menu .mobile-nav-link.active { color: var(--text-active); }

/* ===== Responsive ===== */
@media (max-width: 900px) {
    /* Stack vertically: list above cloud */
    html, body { overflow: auto; height: auto; }
    body { min-height: 100vh; }

    .split-layout {
        flex-direction: column-reverse;
        gap: 1rem;
    }

    .list-panel {
        flex: none;
    }

    .list-scroll {
        max-height: none;
        overflow-y: visible;
    }

    .cloud-view {
        height: 40vh;
        min-height: 240px;
    }

    .content {
        padding: 0.5rem 1.25rem 1rem;
    }
}

@media (max-width: 768px) {
    :root { --header-height: 56px; }

    .site-header {
        padding: 0 1rem;
    }

    .site-nav { display: none; }
    .hamburger { display: flex; }

    .site-header.menu-open .hamburger span:nth-child(1) {
        transform: rotate(45deg) translate(5px, 5px);
    }
    .site-header.menu-open .hamburger span:nth-child(2) { opacity: 0; }
    .site-header.menu-open .hamburger span:nth-child(3) {
        transform: rotate(-45deg) translate(5px, -5px);
    }
}
