/* =============================================================
   Simon Mishricky — personal academic site
   Design: working-paper editorial. Bone ground, ink text,
   deep-teal accent, brass numerals. Garamond prose, Inter UI,
   JetBrains Mono for data.
   ============================================================= */

:root {
    color-scheme: dark;

    /* Ground */
    --paper:      #14171b;
    --paper-alt:  #1a1e23;
    --paper-deep: #21262c;

    /* Ink */
    --ink:    #edeae3;
    --ink-2:  #cbc8c1;
    --ink-3:  #9b9a94;
    --ink-4:  #767570;
    --rule:   #2e333a;
    --rule-2: #23282e;

    /* Accents */
    --accent:       #74c2b1;
    --accent-hover: #9ad8c9;
    --accent-wash:  rgba(116, 194, 177, 0.12);
    --brass:        #c8a263;

    /* Type */
    --serif: 'EB Garamond', 'Iowan Old Style', Georgia, 'Times New Roman', serif;
    --ui:    'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
    --mono:  'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

    /* Metrics */
    --rail-w: 16.5rem;
    --gutter: clamp(1.25rem, 4vw, 3.5rem);
    --measure: 64ch;
}

/* ===== PER-PAGE ACCENTS =====
   One palette family, one accent per page. Brass numerals stay constant
   so the pages still read as one site. */

:root[data-page="about"] {
    --paper:      #14181a;
    --paper-alt:  #1a1f22;
    --paper-deep: #212a2c;
    --rule:       #2a332f;
    --rule-2:     #212925;
    --accent:       #74c2b1;
    --accent-hover: #9ad8c9;
    --accent-wash:  rgba(116, 194, 177, 0.12);
}

:root[data-page="research"] {
    --paper:      #14161b;
    --paper-alt:  #1a1d24;
    --paper-deep: #21262f;
    --rule:       #29303b;
    --rule-2:     #1f242c;
    --accent:       #8ab0dd;
    --accent-hover: #a9c6e8;
    --accent-wash:  rgba(138, 176, 221, 0.12);
}

:root[data-page="teaching"] {
    --paper:      #181614;
    --paper-alt:  #201c18;
    --paper-deep: #2a241d;
    --rule:       #352c24;
    --rule-2:     #28211b;
    --accent:       #e09a72;
    --accent-hover: #ecb492;
    --accent-wash:  rgba(224, 154, 114, 0.12);
}

:root[data-page="cv"] {
    --paper:      #17151a;
    --paper-alt:  #1f1c23;
    --paper-deep: #29242e;
    --rule:       #302a36;
    --rule-2:     #251f29;
    --accent:       #bf9ad0;
    --accent-hover: #d2b5df;
    --accent-wash:  rgba(191, 154, 208, 0.12);
}

/* Cross-document view transitions, desktop only.

   Two reasons they are scoped to the same breakpoint as the grid:

   1. Naming an element morphs it -- the browser animates its box from the
      old page's geometry to the new page's and stretches the snapshot to
      fit. That is free on the desktop grid, where the rail is a fixed-width
      100vh column and .main only changes height inside a fixed-width
      column. Below 62rem the grid collapses and both go full-width, so the
      morph visibly squashes the page.

   2. Even a plain root cross-fade jolts on a phone. Mobile browsers only
      collapse the address bar when a page has enough scrollable content,
      and re-expand it when it does not -- which resizes the viewport
      mid-navigation, so the snapshot and the new page are measured at
      different heights. Short pages trip this, and the two that jolted on
      a real phone are the two shortest. Measured in the stacked layout at
      960px wide (so taller again on an actual handset, but the ordering
      holds): cv 1026px, index 2014px, teaching 2480px, research 3243px.
      cv had 64px of overflow against the viewport; research had 2281px.

   If `@view-transition` inside `@media` is unsupported, the rule is dropped
   and no page transitions anywhere -- which is the safe direction. */
@media (min-width: 62rem) {
    @view-transition { navigation: auto; }

    .rail { view-transition-name: rail; }
    .main { view-transition-name: main; }
}

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

html {
    background: var(--paper);
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    /* Reserve the scrollbar on every page so short pages (cv) and long ones
       (research) centre their layout at exactly the same width. */
    scrollbar-gutter: stable;
}

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink-2);
    font-family: var(--serif);
    font-size: 1.0625rem;
    line-height: 1.7;
    font-feature-settings: "kern" 1, "liga" 1, "onum" 1;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* Paper grain */
body::after {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 999;
    opacity: 0.055;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 300'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.62' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
}

a {
    color: var(--accent);
    text-decoration: none;
    border-bottom: 1px solid var(--accent-wash);
    transition: color .18s ease, border-color .18s ease;
}
a:hover { color: var(--accent-hover); border-bottom-color: currentColor; }
a:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
    border-radius: 2px;
}

::selection { background: var(--accent-wash); color: var(--ink); }

.skip {
    position: absolute;
    left: -9999px;
}
.skip:focus {
    left: 1rem; top: 1rem;
    z-index: 1000;
    background: var(--paper);
    padding: .6rem 1rem;
    border: 1px solid var(--rule);
}

/* ============================== SHELL ============================== */

.shell {
    max-width: 74rem;
    margin: 0 auto;
    padding: 0 var(--gutter);
}

@media (min-width: 62rem) {
    .shell {
        display: grid;
        grid-template-columns: var(--rail-w) minmax(0, 1fr);
        gap: clamp(2.5rem, 5vw, 5rem);
        align-items: start;
    }
}

/* ============================== RAIL ============================== */

.rail {
    padding: 2.5rem 0 1.5rem;
    border-bottom: 1px solid var(--rule);
    margin-bottom: 2.5rem;
}

@media (min-width: 62rem) {
    .rail {
        position: sticky;
        top: 0;
        height: 100vh;
        display: flex;
        flex-direction: column;
        padding: 3.75rem 2rem 2.5rem 0;
        border-bottom: 0;
        border-right: 1px solid var(--rule);
        margin-bottom: 0;
    }
}

.rail-mark {
    display: inline-block;
    font-family: var(--serif);
    font-size: 1.5rem;
    font-weight: 500;
    letter-spacing: -0.015em;
    line-height: 1.15;
    color: var(--ink);
    border-bottom: 0;
}
.rail-mark:hover { color: var(--accent); }

.rail-role {
    margin: .45rem 0 0;
    font-family: var(--mono);
    font-size: .64rem;
    letter-spacing: .15em;
    text-transform: uppercase;
    color: var(--ink-4);
    line-height: 1.8;
}

.rail-nav {
    margin-top: 2rem;
    display: flex;
    flex-wrap: wrap;
    gap: .35rem 1.5rem;
}

@media (min-width: 62rem) {
    .rail-nav { flex-direction: column; gap: .1rem; margin-top: 2.75rem; align-items: stretch; }
    /* The whole row is clickable, not just the width of the words. */
    .rail-nav a { display: block; }
}

.rail-nav a {
    font-family: var(--ui);
    font-size: .74rem;
    font-weight: 500;
    letter-spacing: .13em;
    text-transform: uppercase;
    color: var(--ink-3);
    border-bottom: 0;
    padding: .4rem 0;
    position: relative;
}
.rail-nav a:hover { color: var(--ink); }

.rail-nav a[aria-current="page"] { color: var(--ink); }
.rail-nav a[aria-current="page"]::before {
    content: '';
    position: absolute;
    left: -1rem;
    top: 50%;
    width: .4rem;
    height: 1px;
    background: var(--accent);
}
@media (max-width: 61.99rem) {
    .rail-nav a[aria-current="page"] { color: var(--accent); }
    .rail-nav a[aria-current="page"]::before { display: none; }
}

.rail-foot {
    /* Sits directly under the nav as one block. It used to be pushed to the
       bottom of the viewport with margin-top:auto, which left the column
       split in two with a gap in the middle while the page scrolled. */
    margin-top: 2.75rem;
    padding-top: 1.75rem;
    border-top: 1px solid var(--rule);
    display: none;
}
@media (min-width: 62rem) { .rail-foot { display: block; } }

.rail-foot p {
    margin: 0 0 .3rem;
    font-family: var(--mono);
    font-size: .66rem;
    letter-spacing: .04em;
    color: var(--ink-4);
    line-height: 1.9;
}
.rail-foot a { color: var(--ink-3); border-bottom-color: transparent; }
.rail-foot a:hover { color: var(--accent); }

/* ============================== MAIN ============================== */

.main {
    padding: 0 0 5rem;
    min-width: 0;
}
@media (min-width: 62rem) { .main { padding: 3.75rem 0 6rem; } }

/* ---------- Page head ---------- */

.eyebrow {
    font-family: var(--mono);
    font-size: .66rem;
    letter-spacing: .24em;
    text-transform: uppercase;
    color: var(--brass);
    margin: 0 0 1.1rem;
}

.page-title {
    font-family: var(--serif);
    font-weight: 400;
    font-size: clamp(2.4rem, 6vw, 3.9rem);
    line-height: 1.04;
    letter-spacing: -0.022em;
    color: var(--ink);
    margin: 0 0 1.25rem;
}
.page-title em { font-style: italic; color: var(--accent); }

.lede {
    max-width: var(--measure);
    font-size: 1.19rem;
    line-height: 1.68;
    color: var(--ink-2);
    margin: 0 0 1.15rem;
}

.prose { max-width: var(--measure); }
.prose p { margin: 0 0 1.15rem; }
.prose p:last-child { margin-bottom: 0; }

/* ---------- Section heads ---------- */

.sec {
    display: flex;
    align-items: center;
    gap: .9rem;
    margin: 4rem 0 1.9rem;
    font-family: var(--ui);
    font-size: .7rem;
    font-weight: 600;
    letter-spacing: .2em;
    text-transform: uppercase;
    color: var(--ink-3);
}
.sec::before {
    content: attr(data-num);
    font-family: var(--mono);
    font-weight: 400;
    font-size: .68rem;
    letter-spacing: .06em;
    color: var(--brass);
}
.sec:not([data-num])::before { display: none; }

.sec::after {
    content: '';
    flex: 1 1 auto;
    height: 1px;
    background: var(--rule);
}

/* ---------- Meta grid (fields, contact, facts) ---------- */

.facts {
    margin: 2.25rem 0 0;
    border-top: 1px solid var(--rule);
}

.fact {
    display: grid;
    grid-template-columns: 1fr;
    gap: .1rem .5rem;
    padding: .85rem 0;
    border-bottom: 1px solid var(--rule-2);
}
@media (min-width: 34rem) {
    .fact { grid-template-columns: 9.5rem minmax(0, 1fr); gap: 1.5rem; align-items: baseline; }
}

.fact dt {
    font-family: var(--mono);
    font-size: .64rem;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--ink-4);
    padding-top: .32rem;
}
.fact dd { margin: 0; color: var(--ink-2); }

/* ---------- Entry rows (CV, teaching, awards) ---------- */

.entry {
    padding: 1.15rem 0;
    border-bottom: 1px solid var(--rule-2);
}
.entry:first-of-type { border-top: 1px solid var(--rule); }

.entry-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: .25rem 1.5rem;
}

.entry-title {
    flex: 1 1 22rem;
    min-width: 0;
    margin: 0;
    font-family: var(--serif);
    font-size: 1.16rem;
    font-weight: 600;
    line-height: 1.35;
    letter-spacing: -0.005em;
    color: var(--ink);
}
.entry-title .role {
    font-weight: 400;
    font-style: italic;
    color: var(--ink-3);
}

.years {
    flex: 0 0 auto;
    margin-left: auto;
    font-family: var(--mono);
    font-size: .72rem;
    letter-spacing: .05em;
    color: var(--ink-4);
    white-space: nowrap;
    font-variant-numeric: lining-nums tabular-nums;
}

.entry-head .years { padding-top: .15rem; }

.entry-sub {
    margin: .2rem 0 0;
    font-size: 1rem;
    color: var(--ink-3);
}

.entry ul {
    margin: .65rem 0 0;
    padding: 0;
    list-style: none;
    max-width: var(--measure);
}
.entry ul li {
    position: relative;
    padding-left: 1.15rem;
    margin-bottom: .4rem;
    color: var(--ink-2);
    line-height: 1.62;
}
.entry ul li::before {
    content: '';
    position: absolute;
    left: 0;
    top: .78em;
    width: .5rem;
    height: 1px;
    background: var(--ink-4);
}
.entry ul li:last-child { margin-bottom: 0; }

.entry ul ul { margin-top: .35rem; }
.entry ul ul li::before { width: .3rem; background: var(--rule); height: 2px; border-radius: 2px; top: .72em; }

/* ---------- Papers ---------- */

.paper {
    position: relative;
    padding: 1.75rem 0 1.9rem 0;
    border-bottom: 1px solid var(--rule-2);
}
.paper:first-of-type { border-top: 1px solid var(--rule); }

@media (min-width: 48rem) {
    .paper { padding-left: 1.6rem; }
    .paper::before {
        content: '';
        position: absolute;
        left: 0;
        top: 1.95rem;
        bottom: 2.1rem;
        width: 1px;
        background: var(--rule);
        transition: background .25s ease;
    }
    .paper:hover::before { background: var(--accent); }
}

.paper-flag {
    display: inline-block;
    margin-bottom: .7rem;
    padding: .22rem .55rem;
    font-family: var(--mono);
    font-size: .6rem;
    letter-spacing: .16em;
    text-transform: uppercase;
    color: var(--accent);
    background: var(--accent-wash);
}

.paper-title {
    margin: 0 0 .4rem;
    font-family: var(--serif);
    font-size: clamp(1.35rem, 2.6vw, 1.6rem);
    font-weight: 500;
    line-height: 1.28;
    letter-spacing: -0.012em;
    color: var(--ink);
    max-width: 34ch;
}
.paper-title a { color: inherit; border-bottom: 1px solid var(--rule); }
.paper-title a:hover { color: var(--accent); border-bottom-color: currentColor; }

.paper-meta {
    margin: 0 0 1rem;
    font-family: var(--mono);
    font-size: .68rem;
    letter-spacing: .09em;
    text-transform: uppercase;
    color: var(--ink-4);
}
.paper-meta a { color: var(--ink-3); border-bottom-color: transparent; }
.paper-meta a:hover { color: var(--accent); }

.abstract {
    max-width: var(--measure);
    margin: 0;
    color: var(--ink-2);
}
.abstract .abstract-label {
    display: block;
    font-family: var(--mono);
    font-size: .62rem;
    letter-spacing: .18em;
    text-transform: uppercase;
    color: var(--ink-4);
    margin-bottom: .45rem;
}
.abstract p { margin: 0 0 .9rem; }
.abstract p:last-child { margin-bottom: 0; }

.paper-links {
    margin-top: 1.1rem;
    display: flex;
    flex-wrap: wrap;
    gap: .5rem .65rem;
}

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    padding: .5rem .95rem;
    font-family: var(--ui);
    font-size: .72rem;
    font-weight: 500;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--ink-2);
    background: transparent;
    border: 1px solid var(--rule);
    border-radius: 1px;
    transition: color .18s ease, border-color .18s ease, background .18s ease;
}
.btn:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-wash);
}
.btn--solid {
    color: var(--paper);
    background: var(--accent);
    border-color: var(--accent);
}
.btn--solid:hover {
    color: var(--paper);
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}
.btn--solid, .btn--solid:hover { color: #14171b; }

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: .6rem;
    margin-top: 2rem;
}

/* ---------- Tags ---------- */

.tags {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem .45rem;
    margin: 0;
    padding: 0;
    list-style: none;
}
.tags li {
    font-family: var(--mono);
    font-size: .66rem;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--ink-3);
    padding: .3rem .6rem;
    border: 1px solid var(--rule);
    border-radius: 1px;
}

/* ---------- Pull panel ---------- */

.panel {
    margin: 2.5rem 0 0;
    padding: 1.75rem;
    background: var(--paper-alt);
    border-left: 2px solid var(--accent);
}
.panel h3 {
    margin: 0 0 .55rem;
    font-family: var(--serif);
    font-size: 1.28rem;
    font-weight: 500;
    line-height: 1.3;
    color: var(--ink);
}
.panel p { margin: 0 0 .9rem; max-width: var(--measure); }
.panel p:last-child { margin-bottom: 0; }

/* ---------- Simple list ---------- */

.plain {
    margin: 0;
    padding: 0;
    list-style: none;
    border-top: 1px solid var(--rule);
}
.plain li {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: .2rem 1.5rem;
    padding: .8rem 0;
    border-bottom: 1px solid var(--rule-2);
    color: var(--ink-2);
}
.plain li > span:first-child { flex: 1 1 22rem; min-width: 0; max-width: 56ch; }
.plain li > .years { margin-left: auto; }

/* ---------- Course block ---------- */

.courses { margin: 0; padding: 0; }
.courses dt {
    font-family: var(--mono);
    font-size: .64rem;
    letter-spacing: .15em;
    text-transform: uppercase;
    color: var(--brass);
    margin: 1.6rem 0 .55rem;
}
.courses dt:first-child { margin-top: 0; }
.courses dt span {
    color: var(--ink-4);
    letter-spacing: .1em;
}
.courses dt span::before {
    content: '\00B7';
    margin: 0 .45rem 0 .25rem;
    color: var(--rule);
}
.courses dd {
    margin: 0 0 .5rem;
    padding-left: 1.15rem;
    position: relative;
    max-width: var(--measure);
    color: var(--ink-2);
}
.courses dd::before {
    content: '';
    position: absolute;
    left: 0;
    top: .78em;
    width: .5rem;
    height: 1px;
    background: var(--ink-4);
}
.courses dd b {
    font-weight: 600;
    color: var(--ink);
}

/* ---------- Stat row ---------- */

.stats {
    display: flex;
    flex-wrap: wrap;
    gap: 2rem 3.25rem;
    margin: 2.5rem 0 0;
    padding: 0;
    list-style: none;
}
.stats li { position: relative; }
.stats li + li::before {
    content: '';
    position: absolute;
    left: -1.6rem;
    top: .3rem;
    bottom: .3rem;
    width: 1px;
    background: var(--rule);
}
.stat-value {
    display: block;
    font-family: var(--serif);
    font-size: 2.1rem;
    font-weight: 500;
    line-height: 1;
    letter-spacing: -0.02em;
    color: var(--ink);
    font-variant-numeric: lining-nums;
}
.stat-label {
    display: block;
    margin-top: .45rem;
    font-family: var(--mono);
    font-size: .62rem;
    letter-spacing: .15em;
    text-transform: uppercase;
    color: var(--ink-4);
}

/* ---------- Footer ---------- */

.foot {
    margin-top: 4.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--rule);
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: .5rem 2rem;
    font-family: var(--mono);
    font-size: .65rem;
    letter-spacing: .08em;
    color: var(--ink-4);
}
.foot a { color: var(--ink-3); border-bottom-color: transparent; }
.foot a:hover { color: var(--accent); }

/* ---------- Print ---------- */

@media print {
    /* Same specificity as the per-page blocks, and later in the source, so a
       dark page ground never reaches paper. */
    :root, :root[data-page] {
        --paper: #fff; --paper-alt: #fff;
        --ink: #000; --ink-2: #000; --ink-3: #333; --ink-4: #555;
        --rule: #999; --rule-2: #ccc; --brass: #555;
        --accent: #000; --accent-hover: #000; --accent-wash: transparent;
    }
    body { font-size: 10pt; line-height: 1.4; }
    body::after, .rail-nav, .actions, .foot, .skip { display: none !important; }
    .shell { display: block; max-width: none; padding: 0; }
    .rail { border: 0; padding: 0 0 .5rem; margin-bottom: 1rem; border-bottom: 1px solid #999; }
    .rail-foot { display: block; margin-top: .5rem; }
    .main { padding: 0; }
    .sec { margin: 1.25rem 0 .6rem; }
    .entry, .paper { break-inside: avoid; padding: .5rem 0; }
    a { color: #000; border: 0; }
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    * { transition: none !important; animation: none !important; }
    /* `*` does not reach the view-transition pseudo-elements. */
    ::view-transition-group(*),
    ::view-transition-old(*),
    ::view-transition-new(*) { animation: none !important; }
}
