/* =====================================================================
   Design tokens
   Single source of truth for color, type, spacing, elevation and motion.
   Everything downstream references these — no ad-hoc values.
   ===================================================================== */

:root {
    /* Layout */
    --nav-width: clamp(200px, 19vw, 260px);

    /* --- Warm terracotta palette --- */
    --color-background: #2f241f;   /* deep brown behind the desktop */
    --color-ink: #1d1816;          /* primary text */
    --color-ink-soft: #4a403b;     /* secondary text */
    --color-muted: #6b605a;        /* tertiary / captions */
    --color-accent: #dc3c0c;       /* terracotta-orange */
    --color-accent-deep: #691f0c;  /* burnt accent for hovers / links */
    --color-on-accent: #f6efe7;    /* warm off-white on accent fills */

    --color-surface: #d4c0b2;      /* panel base */
    --color-surface-soft: #ece1d8; /* lighter inset surface */
    --color-surface-raised: color-mix(in srgb, var(--color-surface) 88%, white 12%);

    /* Borders — warm taupe, used at a few opacities */
    --color-line: 111, 93, 82;     /* rgb triple for rgba() */
    --border-hairline: 1px solid rgba(var(--color-line), 0.40);
    --border-soft:     1px solid rgba(var(--color-line), 0.55);
    --border-strong:   1px solid rgba(var(--color-line), 0.75);

    /* Backwards-compatible aliases (older rules / inline refs) */
    --color-text: var(--color-ink);
    --color-border: rgba(var(--color-line), 0.55);

    /* --- Typography --- */
    --font-sans: 'Inter', system-ui, -apple-system, Arial, sans-serif;
    --font-mono: 'JetBrains Mono', 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;

    --text-xs: 0.74rem;
    --text-sm: 0.9rem;
    --text-md: 1rem;
    --text-lg: clamp(1.2rem, 1.8vw, 1.5rem);
    --text-xl: clamp(1.45rem, 2.2vw, 1.9rem);
    --text-2xl: clamp(2rem, 3.6vw, 2.8rem);

    --tracking-label: 0.12em;   /* eyebrows / mono labels */
    --tracking-title: 0.07em;   /* window titles */

    /* --- Spacing scale --- */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
    --space-7: 48px;

    /* --- Elevation — hard offset shadows, classic-OS style --- */
    --shadow-sm: 2px 2px 0 rgba(17, 13, 11, 0.25);
    --shadow-md: 4px 4px 0 rgba(17, 13, 11, 0.30);
    --shadow-lg: 6px 6px 0 rgba(17, 13, 11, 0.40);

    /* --- Motion --- */
    --transition: 0.18s ease;

    /* Set per-day by the inline script in base.html */
    --daily-background-image: url('/static/website/images/bay_room.png');
}

/* =====================================================================
   Base / reset
   ===================================================================== */

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

html, body {
    margin: 0;
    padding: 0;
    color: var(--color-ink);
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.6;
}

body {
    min-height: 100vh;
    background-color: var(--color-background);
    /* Painting + a faint 2px checker dither so the room reads like
       period desktop wallpaper rather than a photo. */
    background-image:
        linear-gradient(rgba(31, 23, 20, 0.35), rgba(31, 23, 20, 0.35)),
        repeating-conic-gradient(rgba(24, 17, 14, 0.09) 0% 25%, transparent 0% 50%),
        var(--daily-background-image);
    background-position: right top;
    background-repeat: no-repeat, repeat, no-repeat;
    background-size: auto, 4px 4px, calc(100vw - var(--nav-width)) auto;
    background-attachment: fixed;
}

a { color: var(--color-accent-deep); }

/* Shared mono label treatment (eyebrows, kickers). */
.eyebrow {
    font-family: var(--font-mono);
    text-transform: uppercase;
    letter-spacing: var(--tracking-label);
    font-size: var(--text-xs);
    font-weight: 700;
    color: var(--color-muted);
}

.muted { color: var(--color-muted); }

/* =====================================================================
   Side navigation
   ===================================================================== */

.side-nav {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--nav-width);
    padding: var(--space-4);
    background: var(--color-surface-raised);
    border-right: var(--border-soft);
    overflow-y: auto;
    overflow-x: hidden;
}

.nav-avatar {
    width: 60%;
    aspect-ratio: 1 / 1;
    margin: 0 0 var(--space-4);
    border: var(--border-strong);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    background: var(--color-surface-soft);
    padding: 3px; /* thin mat between frame and photo */
}

.nav-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.site-title {
    margin: 0 0 var(--space-3);
    font-family: var(--font-mono);
    font-size: var(--text-lg);
    font-weight: 700;
    letter-spacing: 0.02em;
}
.site-title a { color: var(--color-ink); text-decoration: none; }
.site-title a:hover { color: var(--color-accent-deep); }

.nav-links { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-1); }

/* Nav reads as OS chrome: mono labels, selection is an accent bar —
   the same idiom as the active tab and the CV index cards. */
.nav-links a {
    display: block;
    padding: var(--space-2) var(--space-3);
    text-decoration: none;
    color: var(--color-ink);
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-left: 3px solid transparent;
    transition: color var(--transition), border-color var(--transition), background-color var(--transition);
}

.nav-links a:hover {
    color: var(--color-accent-deep);
    background: var(--color-surface-soft);
}

.nav-links a.active {
    border-left-color: var(--color-accent);
    color: var(--color-accent-deep);
    background: var(--color-surface-soft);
}

.sub-nav-links {
    list-style: none;
    margin: var(--space-1) 0 var(--space-1) var(--space-3);
    padding: 0;
    display: grid;
    gap: 2px;
    border-left: var(--border-hairline);
}
.sub-nav-links a {
    font-size: var(--text-sm);
    font-weight: 500;
    text-transform: none;
    letter-spacing: 0.02em;
    padding: var(--space-1) var(--space-2);
}

/* =====================================================================
   Desktop — the area behind the windows
   ===================================================================== */

.desktop {
    margin-left: var(--nav-width);
    min-height: 100vh;
    padding: clamp(18px, 4vh, 44px) clamp(16px, 3vw, 40px);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* =====================================================================
   Window chrome — refined-minimal
   ===================================================================== */

.window {
    position: relative;
    display: flex;
    flex-direction: column;
    width: min(1040px, 100%);
    max-height: calc(100vh - clamp(36px, 8vh, 88px));
    background: var(--color-surface-raised);
    border: 1px solid rgba(var(--color-line), 0.9);
    box-shadow: var(--shadow-lg);
    /* Quick fade only — period windows snap open; no scale/slide. */
    animation: window-open 0.12s ease-out;
}

.window.window-closing { animation: window-close 0.10s ease-in forwards; }
.window.window-hidden { display: none; }

@keyframes window-open {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes window-close {
    from { opacity: 1; }
    to   { opacity: 0; }
}

/* System 7-style titlebar: horizontal pinstripes inset from the edges,
   with the title sitting on a solid chip that interrupts them. */
.window-titlebar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    background:
        repeating-linear-gradient(
            to bottom,
            transparent 0 2px,
            rgba(var(--color-line), 0.55) 2px 3px
        ) content-box,
        var(--color-surface);
    border-bottom: 1px solid rgba(var(--color-line), 0.9);
    cursor: grab;
    user-select: none;
    touch-action: none;
}

.window-titlebar:active { cursor: grabbing; }

.window-title {
    flex: 0 1 auto;
    min-width: 0;
    padding: 0 var(--space-2);
    background: var(--color-surface); /* solid chip over the stripes */
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: var(--text-sm);
    letter-spacing: var(--tracking-title);
    text-transform: uppercase;
    color: var(--color-ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.window-close,
.window-close:link,
.window-close:visited {
    flex: 0 0 auto;
    margin-left: auto;
    position: relative;
    width: 20px;
    height: 20px;
    background: var(--color-surface);
    border: 1px solid var(--color-ink-soft);
    color: var(--color-ink);
    font-size: 0; /* hide the &times; glyph; the × is drawn below */
    text-decoration: none;
    cursor: pointer;
    /* Solid halo interrupts the pinstripes so they stop short of the box. */
    box-shadow: 0 0 0 6px var(--color-surface);
    transition: background-color var(--transition), color var(--transition), border-color var(--transition);
}

/* Draw the × as two crossed lines, absolutely centered in the box —
   the text glyph never centers exactly, and the hidden text node would
   skew any flow-based centering. */
.window-close::before,
.window-close::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 10px;
    height: 2px;
    background: currentColor;
}
.window-close::before { transform: translate(-50%, -50%) rotate(45deg); }
.window-close::after  { transform: translate(-50%, -50%) rotate(-45deg); }

.window-close:hover {
    background: var(--color-accent);
    border-color: var(--color-accent-deep);
    color: var(--color-on-accent);
}
.window-close:active {
    background: var(--color-ink);
    border-color: var(--color-ink);
    color: var(--color-on-accent);
}

.window-body {
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: clamp(20px, 2.4vw, 32px);
}

/* Square, surface-toned scrollbars — default browser scrollbars are the
   loudest modern element inside an otherwise period window. */
.window-body::-webkit-scrollbar,
.side-nav::-webkit-scrollbar { width: 12px; height: 12px; }
.window-body::-webkit-scrollbar-track,
.side-nav::-webkit-scrollbar-track {
    background: var(--color-surface-soft);
    border-left: var(--border-hairline);
}
.window-body::-webkit-scrollbar-thumb,
.side-nav::-webkit-scrollbar-thumb {
    background: var(--color-surface);
    border: 1px solid rgba(var(--color-line), 0.75);
}
.window-body::-webkit-scrollbar-thumb:hover,
.side-nav::-webkit-scrollbar-thumb:hover {
    background: color-mix(in srgb, var(--color-surface) 85%, var(--color-ink) 15%);
}

/* ----- Section tabs (CV / Writings sub-sections) -----
   Folder-style tabs. Rendered as the first child of .window-body; the strip
   bleeds to the body edges so it spans full width directly under the title bar.
   Inactive tabs read as recessed bordered tabs sitting on a baseline; the active
   tab is raised, lit, accent-topped, and merges into the content panel below by
   covering the baseline. */

.window-tabs {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--space-1);
    margin: calc(-1 * clamp(20px, 2.4vw, 32px));
    margin-bottom: clamp(18px, 2vw, 26px);
    padding: var(--space-4) clamp(20px, 2.4vw, 32px) 0;
    background: var(--color-surface); /* one surface with the titlebar base */
    border-bottom: 1px solid rgba(var(--color-line), 0.9); /* the baseline the tabs sit on */
}

.window-tabs .window-tab,
.window-tabs .window-tab:link,
.window-tabs .window-tab:visited {
    padding: var(--space-2) var(--space-4);
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    font-weight: 600;
    letter-spacing: 0.03em;
    text-decoration: none;
    color: var(--color-muted);
    background: var(--color-surface);
    border: var(--border-soft);
    border-bottom: none;        /* open at the bottom, sitting on the baseline */
    margin-bottom: -1px;        /* overlap the baseline by 1px */
    transition: color var(--transition), background-color var(--transition), border-color var(--transition);
}

.window-tabs .window-tab:hover {
    color: var(--color-accent-deep);
    background: var(--color-surface-soft);
    text-decoration: none;
}

.window-tabs .window-tab--active,
.window-tabs .window-tab--active:link,
.window-tabs .window-tab--active:visited {
    color: var(--color-accent-deep);
    /* Match the window body so the tab opens into the content below. */
    background: var(--color-surface-raised);
    border-color: rgba(var(--color-line), 0.75);
    border-top: 2px solid var(--color-accent);   /* selected indicator */
    margin-top: -6px;                             /* lift it above its neighbours */
    padding-bottom: calc(var(--space-2) + 1px);   /* cover the baseline cleanly */
}

/* Framed variant: standalone pages (the terminal) embedded via iframe */
.window--frame {
    width: min(1280px, 100%);
    height: calc(100vh - clamp(36px, 8vh, 88px));
}

.window--frame .window-body {
    padding: 0;
    overflow: hidden;
    background: #1a120c; /* warm CRT void — matches terminal.css */
}

.window-iframe {
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
}

/* ----- Field mode: multiple absolutely-positioned windows (enabled by JS) ----- */

.desktop--field {
    display: block;
    position: relative;
    height: 100vh;
    padding: 0;
    overflow: hidden;
}

.desktop--field .window {
    position: absolute;
    width: min(1040px, calc(100% - 48px));
    max-height: calc(100% - 48px);
    box-shadow: var(--shadow-md);
}

.desktop--field .window--frame {
    width: min(1280px, calc(100% - 48px));
    height: calc(100% - 48px);
}

.desktop--field .window--focused { box-shadow: var(--shadow-lg); }

/* Unfocused windows lose their pinstripes — the classic focus cue. */
.desktop--field .window:not(.window--focused) .window-titlebar {
    background: var(--color-surface);
}
.desktop--field .window:not(.window--focused) .window-title {
    color: var(--color-muted);
}
.desktop--field .window:not(.window--focused) .window-close {
    color: var(--color-muted);
    border-color: rgba(var(--color-line), 0.55);
}

/* =====================================================================
   Surfaces — one panel recipe, sizing handled separately
   ===================================================================== */

.surface-panel {
    background: color-mix(in srgb, var(--color-surface-soft) 82%, white 18%);
    border: var(--border-hairline);
    box-shadow: var(--shadow-sm);
}

.page-container {
    max-width: 1140px;
    margin: 0 auto;
    padding: var(--space-6) clamp(20px, 3vw, 36px);
    background: var(--color-surface-raised);
    border: var(--border-hairline);
    box-shadow: var(--shadow-sm);
}

.section-card { padding: clamp(20px, 2.2vw, 30px); }

.section-title { margin: 0 0 var(--space-3); }
.content-actions { margin-top: var(--space-5); display: flex; gap: var(--space-3); flex-wrap: wrap; }

.surface-panel :is(h1, h2, h3, h4, h5, h6) { text-align: left; }

/* =====================================================================
   Typography inside content (windows / panels)
   ===================================================================== */

.window-body :is(h1, h2, h3) { line-height: 1.2; }
.window-body h1 { font-size: var(--text-2xl); }
.window-body h2 { font-size: var(--text-xl); }
.window-body h3 { font-size: var(--text-lg); }

/* Default content links read as accent, underline on hover.
   Kept at low specificity (:where) so component link styles override it. */
:where(.window-body) a:where(:not(.btn):not(.tag):not(.window-close)) {
    color: var(--color-accent-deep);
    text-decoration: none;
    font-weight: 600;
    transition: color var(--transition);
}
:where(.window-body) a:where(:not(.btn):not(.tag):not(.window-close)):hover {
    color: var(--color-accent);
    text-decoration: underline;
}

/* =====================================================================
   Buttons
   ===================================================================== */

.btn,
.btn:link,
.btn:visited,
.btn:active {
    display: inline-block;
    padding: var(--space-3) var(--space-5);
    background-color: var(--color-accent);
    color: var(--color-on-accent);
    text-decoration: none;
    border: 1px solid var(--color-accent-deep);
    border-radius: 0;
    cursor: pointer;
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    box-shadow: var(--shadow-sm);
    transition: background-color var(--transition);
}

.btn:hover {
    background-color: var(--color-accent-deep);
}

/* Press into the hard shadow — tactile, no modern hover-lift. */
.btn:active {
    transform: translate(2px, 2px);
    box-shadow: none;
}

.btn:focus-visible {
    outline: 2px solid var(--color-accent-deep);
    outline-offset: 2px;
}

/* =====================================================================
   Normalize legacy page containers when nested inside a window
   ===================================================================== */

.window-body .page-container,
.window-body .drawer-content.surface-panel {
    max-width: none;
    margin: 0;
    padding: 0;
    background: transparent;
    border: none;
    box-shadow: none;
}

.window-body .drawer-layout { max-width: none; margin: 0; }
.window-body .drawer-content { padding: 0; min-height: 0; }
.window-body .about-wrapper { min-height: 0; }
.window-body .home-hero { width: auto; margin: 0; padding: 0; }

/* =====================================================================
   Responsive
   ===================================================================== */

@media (max-width: 920px) {
    :root { --nav-width: 170px; }

    .desktop { padding: 14px 10px; }
    .window { max-height: calc(100vh - 28px); }
    .window--frame { height: calc(100vh - 28px); }
    .window-body { padding: var(--space-4); }

    /* Keep the tab strip aligned with the smaller mobile body padding. */
    .window-tabs {
        margin: calc(-1 * var(--space-4));
        margin-bottom: var(--space-4);
        padding-left: var(--space-4);
        padding-right: var(--space-4);
    }
}
