/* Main CSS file for the personal website.
   Colors live in CSS variables so that the dark theme only has to
   redefine the palette. The theme is set as data-theme="light|dark"
   on <html> by assets/js/theme.js (and by the inline script in <head>,
   which runs before paint to avoid a flash of the wrong theme). */

/* ---------- Palette ---------- */
/* Light theme: a dimmed, slightly warm "paper" palette. Background and
   surface sit around 90-94% luminance with a small yellow-orange cast;
   text is warm near-black rather than pure black so contrast stays
   comfortable without glare. */
:root {
    --bg: #e6e2db;
    --surface: #f0ece5;
    --text: #2f2b27;
    --heading: #2b3b4c;
    --subheading: #3d4a58;
    --muted: #5a5550;
    --muted-2: #6c665f;
    --muted-3: #857e76;
    --border: #ddd7ce;
    --border-dotted: #cbc4b9;
    --accent: #2f7fb8;
    --accent-hover: #256a9b;
    --on-accent: #ffffff;
    --panel: #e8e3db;
    --panel-hover: #dfd9cf;
    --code-bg: #e2dcd2;
    --code-text: #b3304e;
    --tag-bg: #e2dcd2;
    --topic-bg: #dbe6ee;
    --difficulty-bg: #eee2c2;
    --difficulty-text: #755512;
    --shadow: rgba(60, 45, 30, 0.12);
    --shadow-strong: rgba(60, 45, 30, 0.22);
    color-scheme: light;
}

:root[data-theme="dark"] {
    --bg: #121417;
    --surface: #1b1f25;
    --text: #d5d9df;
    --heading: #eaeef3;
    --subheading: #cfd6de;
    --muted: #b1b7bf;
    --muted-2: #a1a8b1;
    --muted-3: #8b929b;
    --border: #2b3037;
    --border-dotted: #3a4048;
    --accent: #5dade2;
    --accent-hover: #85c1e9;
    --on-accent: #0f1419;
    --panel: #22262d;
    --panel-hover: #2b3038;
    --code-bg: #2b3038;
    --code-text: #f28ba1;
    --tag-bg: #2b3038;
    --topic-bg: #1e3a4f;
    --difficulty-bg: #4a3b12;
    --difficulty-text: #f3d27a;
    --shadow: rgba(0, 0, 0, 0.45);
    --shadow-strong: rgba(0, 0, 0, 0.6);
    color-scheme: dark;
}

/* If the visitor has never chosen a theme and JavaScript is off,
   follow the operating system preference. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
        --bg: #121417;
        --surface: #1b1f25;
        --text: #d5d9df;
        --heading: #eaeef3;
        --subheading: #cfd6de;
        --muted: #b1b7bf;
        --muted-2: #a1a8b1;
        --muted-3: #8b929b;
        --border: #2b3037;
        --border-dotted: #3a4048;
        --accent: #5dade2;
        --accent-hover: #85c1e9;
        --on-accent: #0f1419;
        --panel: #22262d;
        --panel-hover: #2b3038;
        --code-bg: #2b3038;
        --code-text: #f28ba1;
        --tag-bg: #2b3038;
        --topic-bg: #1e3a4f;
        --difficulty-bg: #4a3b12;
        --difficulty-text: #f3d27a;
        --shadow: rgba(0, 0, 0, 0.45);
        --shadow-strong: rgba(0, 0, 0, 0.6);
        color-scheme: dark;
    }
}

/* ---------- Base styles ---------- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: var(--text);
    background-color: var(--bg);
    transition: background-color 0.25s ease, color 0.25s ease;
}

html {
    scroll-padding-top: 80px; /* keep anchors clear of the sticky banner */
}

/* ---------- Sticky banner (same on every page) ---------- */
.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 8px var(--shadow);
    transition: background-color 0.25s ease;
}

.site-header-inner {
    max-width: 1280px;
    margin: 0 auto;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px 24px;
    flex-wrap: wrap;
}

.site-name {
    font-size: 1.35rem;
    font-weight: 600;
    color: var(--heading);
    text-decoration: none;
}

.site-name:hover {
    color: var(--accent);
}

.site-nav ul {
    list-style: none;
    display: flex;
    align-items: center;
    gap: 6px 22px;
    flex-wrap: wrap;
}

.site-nav a {
    color: var(--text);
    text-decoration: none;
    font-weight: 500;
    padding: 4px 0;
    border-bottom: 2px solid transparent;
    transition: color 0.2s ease, border-color 0.2s ease;
}

.site-nav a:hover {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.site-nav a[aria-current="page"] {
    border-bottom-color: var(--accent);
}

/* ---------- Page layout: content card + sidebar ---------- */
.layout {
    max-width: 1280px;
    margin: 0 auto;
    padding: 24px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 220px;
    gap: 24px;
    align-items: start;
}

.container {
    background: var(--surface);
    border-radius: 8px;
    box-shadow: 0 2px 15px var(--shadow);
    padding: 40px;
}

/* Photo + profile links, always visible beside the content */
.sidebar {
    position: sticky;
    top: 84px;
    text-align: center;
}

.sidebar-photo {
    display: block;
    width: 200px;
    max-width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border-radius: 50%;
    margin: 0 auto;
    box-shadow: 0 4px 6px var(--shadow);
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation; /* no double-tap zoom on phones */
}

/* Profile icons: two rows of three, each a comfortable tap target */
.sidebar .social-links {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    max-width: 200px;
    margin: 16px auto 0;
}

.sidebar .social-links a {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 46px;
    margin: 0;
    font-size: 1.6rem;
    border-radius: 8px;
    transition: color 0.2s ease, background-color 0.2s ease;
}

.sidebar .social-links a:hover {
    background-color: var(--panel);
}

/* Visible outline for keyboard users (appears when navigating with Tab, not on mouse clicks) */
a:focus-visible,
button:focus-visible,
summary:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 3px;
}

/* Name subtitle under the home-page heading */
.page-subtitle {
    margin-top: 8px;
    font-size: 1.05rem;
    color: var(--muted);
}

/* Job market references (home page) */
.references {
    margin-top: 36px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.references h2 {
    font-size: 1.3rem;
    color: var(--heading);
    margin-bottom: 14px;
}

.reference-list {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

.reference-list a {
    display: block;
    font-weight: 600;
}

.reference-list span {
    display: block;
    font-size: 0.92rem;
    color: var(--muted);
    line-height: 1.45;
}

/* Rotating student comment under the profile icons (see assets/js/quotes.js) */
.sidebar-quote {
    margin: 24px 0 0;
    padding: 12px 14px;
    min-height: 9em;
    text-align: left;
    background: var(--panel);
    border-left: 3px solid var(--accent);
    border-radius: 4px;
    transition: opacity 0.4s ease;
}

.sidebar-quote.fading {
    opacity: 0;
}

.sidebar-quote blockquote {
    font-size: 0.88rem;
    font-style: italic;
    line-height: 1.5;
    color: var(--muted);
}

.sidebar-quote {
    cursor: pointer;
}

.sidebar-quote:hover {
    background: var(--panel-hover);
}

.sidebar-quote figcaption {
    margin-top: 8px;
    font-size: 0.75rem;
    color: var(--muted-3);
}

.sidebar-quote figcaption a {
    color: inherit;
    text-decoration: none;
    border-bottom: 1px dotted currentColor;
}

.sidebar-quote:hover figcaption a {
    color: var(--accent);
}

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

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

h1 {
    font-size: 2.5rem;
    margin-bottom: 15px;
    color: var(--heading);
}

.intro {
    font-size: 1.1rem;
    color: var(--muted);
    margin-bottom: 20px;
}

.intro a {
    color: var(--accent);
    text-decoration: none;
    border-bottom: 1px dotted var(--accent);
    transition: color 0.2s ease, border-bottom 0.2s ease;
}

.intro a:hover {
    color: var(--accent-hover);
    border-bottom: 1px solid var(--accent-hover);
}

.intro-links {
    font-size: 1rem;
    color: var(--muted);
}

/* ---------- Page title ---------- */
.page-header {
    margin-bottom: 32px;
    border-bottom: 2px solid var(--border);
    padding-bottom: 16px;
}

.page-header h1 {
    margin-bottom: 0;
}

/* ---------- Theme toggle ---------- */
.theme-toggle {
    background: transparent;
    border: 1px solid var(--border-dotted);
    color: var(--muted);
    border-radius: 999px;
    width: 38px;
    height: 38px;
    cursor: pointer;
    font-size: 1rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s ease, border-color 0.2s ease, background-color 0.2s ease;
}

.theme-toggle:hover {
    color: var(--accent);
    border-color: var(--accent);
    background-color: var(--panel);
}

/* ---------- Generic sections (inner pages) ---------- */
section {
    margin-bottom: 50px;
}

section h2 {
    color: var(--heading);
    font-size: 1.8rem;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
}

section h3 {
    color: var(--subheading);
}

/* ---------- Footer ---------- */
footer {
    margin-top: 60px;
    text-align: center;
    border-top: 1px solid var(--border);
    padding-top: 20px;
}

.social-links {
    margin-bottom: 15px;
}

.social-links a {
    display: inline-block;
    margin: 0 10px;
    font-size: 1.5rem;
    color: var(--muted);
    transition: color 0.3s ease;
}

.social-links a:hover {
    color: var(--accent);
}

.copyright {
    font-size: 0.9rem;
    color: var(--muted-3);
}

/* ---------- Collapsible sections ---------- */
details.collapsible {
    margin-bottom: 30px;
}

details.collapsible > summary {
    list-style: none;
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 18px;
}

details.collapsible > summary::-webkit-details-marker {
    display: none;
}

details.collapsible > summary h2 {
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 0;
    color: var(--heading);
    font-size: 1.5rem;
}

/* Nested collapsibles (e.g. one per document inside "Lecture Notes") */
details.collapsible.sub {
    margin-bottom: 14px;
}

details.collapsible.sub > summary {
    border-bottom: 1px dotted var(--border-dotted);
    margin-bottom: 12px;
}

details.collapsible > summary h3 {
    margin: 0;
    font-size: 1.15rem;
    color: var(--subheading);
}

details.collapsible > summary:hover h3 {
    color: var(--accent);
}

/* PDF shortcuts and chevron grouped at the right of a summary line */
details.collapsible > summary .summary-pdfs {
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
    flex: 0 0 auto;
}

details.collapsible[open] > summary .summary-pdfs .chevron {
    transform: rotate(180deg);
}

details.collapsible > summary .summary-hint {
    font-size: 0.85rem;
    color: var(--muted-3);
    font-weight: 400;
    margin-left: 10px;
}

details.collapsible > summary .chevron {
    color: var(--accent);
    font-size: 0.95rem;
    transition: transform 0.25s ease;
    flex: 0 0 auto;
}

details.collapsible[open] > summary .chevron {
    transform: rotate(180deg);
}

details.collapsible > summary:hover h2 {
    color: var(--accent);
}

/* ---------- PDF overlay viewer ---------- */
body.pdf-open {
    overflow: hidden;
}

.pdf-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background-color: rgba(0, 0, 0, 0.55);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
}

.pdf-overlay.open {
    display: flex;
}

.pdf-panel {
    width: min(960px, 100%);
    height: 100%;
    max-height: calc(100vh - 48px);
    display: flex;
    flex-direction: column;
    background-color: var(--surface);
    border-radius: 8px;
    box-shadow: 0 10px 40px var(--shadow-strong);
    overflow: hidden;
}

.pdf-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 12px 8px 16px;
    border-bottom: 1px solid var(--border);
    background-color: var(--panel);
}

.pdf-title {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--heading);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pdf-actions {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.pdf-actions a,
.pdf-actions button {
    background: transparent;
    border: none;
    color: var(--muted);
    width: 36px;
    height: 36px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1rem;
    text-decoration: none;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.pdf-actions a:hover,
.pdf-actions button:hover {
    background-color: var(--panel-hover);
    color: var(--accent);
}

.pdf-actions .pdf-close {
    font-size: 1.25rem;
}

.pdf-frame {
    flex: 1;
    width: 100%;
    border: none;
    background-color: #525659; /* matches the native viewer's grey */
}

@media (max-width: 768px) {
    .pdf-overlay {
        padding: 8px;
    }

    .pdf-panel {
        max-height: calc(100vh - 16px);
        border-radius: 6px;
    }
}

/* ---------- Responsive adjustments ---------- */
@media (max-width: 900px) {
    /* Sidebar moves above the content as a compact strip: small photo
       on the left, profile icons beside it. */
    .layout {
        grid-template-columns: minmax(0, 1fr);
        padding: 16px;
        gap: 16px;
    }

    .sidebar {
        order: -1;
        position: static;
        display: flex;
        align-items: center;
        gap: 18px;
        text-align: left;
    }

    .sidebar-photo {
        width: clamp(72px, 20vw, 96px);
        flex: 0 0 auto;
        margin: 0;
    }

    .sidebar .social-links {
        grid-template-columns: repeat(3, 48px);
        margin: 0;
        gap: 4px;
    }

    .sidebar .social-links a {
        height: 44px;
        font-size: 1.4rem;
    }

    .container {
        padding: 24px;
    }

    /* The quote would crowd the compact strip; it appears on wider screens only */
    .sidebar-quote {
        display: none;
    }
}

@media (max-width: 600px) {
    /* Compact two-line banner: name, then the links */
    .site-header-inner {
        padding: 6px 14px;
        flex-direction: column;
        align-items: flex-start;
        gap: 0;
    }

    .site-name {
        font-size: 1.05rem;
        line-height: 1.3;
    }

    .site-nav ul {
        gap: 2px 14px;
        font-size: 0.9rem;
    }

    .site-nav a {
        padding: 2px 0;
    }

    .site-nav .theme-toggle {
        width: 28px;
        height: 28px;
        font-size: 0.8rem;
    }

    .reference-list {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .layout {
        padding: 12px;
    }

    .container {
        padding: 18px;
    }

    h1 {
        font-size: 2rem;
    }
}
