/* ==========================================================
   Sudip Tiwari, personal site
   Type:   Bricolage Grotesque (headings, UI), Source Serif 4 (body)
   Colour: paper / ink / indigo, with marigold reserved for the
           bounding box in the hero
   ========================================================== */

:root {
    color-scheme: light;
    --bg: #f6f7fb;
    --surface: #ffffff;
    --ink: #101b34;
    --muted: #56627c;
    --line: #dce1ec;
    --hover: #edf0f8;
    --accent: #2f42b0;
    --accent-ink: #ffffff;
    --mark: #e29a00;
    --mark-ink: #2a1a00;
    --sheet-line: rgba(47, 66, 176, 0.09);

    --display: "Bricolage Grotesque", "Segoe UI", system-ui, -apple-system, sans-serif;
    --text: "Source Serif 4", Georgia, "Times New Roman", serif;

    --max: 72rem;
    --gutter: clamp(1.25rem, 4vw, 2.5rem);
    --header-h: 4rem;
    --ease: cubic-bezier(0.3, 0.8, 0.2, 1);
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0d1322;
    --surface: #141b2f;
    --ink: #e9edf8;
    --muted: #9fa9c3;
    --line: #26304a;
    --hover: #182039;
    --accent: #9fb2ff;
    --accent-ink: #0d1322;
    --mark: #f5b72e;
    --sheet-line: rgba(159, 178, 255, 0.08);
}

/* If JavaScript is off, still follow the system theme */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
        color-scheme: dark;
        --bg: #0d1322;
        --surface: #141b2f;
        --ink: #e9edf8;
        --muted: #9fa9c3;
        --line: #26304a;
        --hover: #182039;
        --accent: #9fb2ff;
        --accent-ink: #0d1322;
        --mark: #f5b72e;
        --sheet-line: rgba(159, 178, 255, 0.08);
    }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html {
    scroll-behavior: smooth;
    scroll-padding-top: calc(var(--header-h) + 1rem);
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--text);
    font-size: 1.0625rem;
    line-height: 1.65;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.25s ease, color 0.25s ease;
}

h1, h2, h3, p, ul, ol, dl, dd, figure { margin: 0; padding: 0; }
ul, ol { list-style: none; }

a {
    color: var(--accent);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 0.2em;
    transition: color 0.15s ease, text-decoration-color 0.15s ease;
}
a:hover { text-decoration-thickness: 2px; }

::selection { background: var(--mark); color: var(--mark-ink); }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
    border-radius: 4px;
}

.wrap {
    width: 100%;
    max-width: var(--max);
    margin-inline: auto;
    padding-inline: var(--gutter);
}

.skip-link {
    position: fixed;
    top: 0.75rem;
    left: 0.75rem;
    z-index: 100;
    padding: 0.5rem 0.9rem;
    background: var(--ink);
    color: var(--bg);
    font-family: var(--display);
    font-weight: 600;
    border-radius: 6px;
    transform: translateY(-200%);
    transition: transform 0.2s ease;
}
.skip-link:focus { transform: translateY(0); }

/* ---------- Scroll progress ---------- */
.progress {
    position: fixed;
    inset: 0 0 auto 0;
    height: 2px;
    z-index: 60;
    background: var(--mark);
    transform: scaleX(0);
    transform-origin: left;
}

/* ---------- Header ---------- */
.site-header {
    position: fixed;
    inset: 0 0 auto 0;
    z-index: 50;
    height: var(--header-h);
    background: color-mix(in srgb, var(--bg) 84%, transparent);
    -webkit-backdrop-filter: saturate(1.4) blur(14px);
    backdrop-filter: saturate(1.4) blur(14px);
    border-bottom: 1px solid transparent;
    transition: border-color 0.2s ease;
}
.site-header.is-scrolled { border-bottom-color: var(--line); }

.bar {
    height: 100%;
    max-width: var(--max);
    margin-inline: auto;
    padding-inline: var(--gutter);
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.wordmark {
    font-family: var(--display);
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: -0.01em;
    color: var(--ink);
    text-decoration: none;
    margin-right: auto;
}
.wordmark:hover { color: var(--accent); }

.nav ul { display: flex; gap: 0.25rem; }
.nav a {
    display: block;
    padding: 0.4rem 0.75rem;
    font-family: var(--display);
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--muted);
    text-decoration: none;
    border-radius: 6px;
}
.nav a:hover { color: var(--ink); background: var(--hover); }
.nav a[aria-current="true"] {
    color: var(--ink);
    text-decoration: underline;
    text-decoration-color: var(--mark);
    text-decoration-thickness: 2px;
    text-underline-offset: 0.45em;
}

.bar-actions { display: flex; align-items: center; gap: 0.25rem; }

.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    color: var(--ink);
    background: transparent;
    border: 0;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.15s ease;
}
.icon-btn:hover { background: var(--hover); }

.icon-btn .i-sun { display: none; }
:root[data-theme="dark"] .icon-btn .i-sun { display: block; }
:root[data-theme="dark"] .icon-btn .i-moon { display: none; }

.menu-btn { display: none; }
.menu-btn path { transition: transform 0.25s var(--ease); transform-origin: center; transform-box: fill-box; }
.menu-btn[aria-expanded="true"] .l1 { transform: translateY(4px) rotate(45deg); }
.menu-btn[aria-expanded="true"] .l2 { transform: translateY(-4px) rotate(-45deg); }

/* ---------- Hero ---------- */
.hero {
    min-height: min(54rem, 100svh);
    display: flex;
    align-items: center;
    padding-top: calc(var(--header-h) + 2.5rem);
    padding-bottom: 4.5rem;
}

.hero-inner {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 21rem);
    gap: 3rem clamp(2rem, 6vw, 5rem);
    align-items: center;
}

.hero h1 {
    font-family: var(--display);
    font-weight: 700;
    font-size: clamp(2.9rem, 7vw, 5rem);
    line-height: 1;
    letter-spacing: -0.03em;
    margin-bottom: 1.5rem;
}

.lead {
    font-family: var(--display);
    font-weight: 500;
    font-size: clamp(1.25rem, 2.4vw, 1.55rem);
    line-height: 1.3;
    letter-spacing: -0.01em;
    max-width: 30ch;
}

.advisors {
    margin-top: 0.75rem;
    color: var(--muted);
}

.bio {
    margin-top: 1.75rem;
    max-width: 58ch;
}
.bio + .bio { margin-top: 0.9rem; color: var(--muted); }

.hero-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 2rem;
}

.btn {
    display: inline-block;
    padding: 0.65rem 1.2rem;
    font-family: var(--display);
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--ink);
    text-decoration: none;
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 999px;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.btn:hover { background: var(--hover); border-color: var(--muted); }
.btn-primary {
    background: var(--ink);
    color: var(--bg);
    border-color: var(--ink);
}
.btn-primary:hover { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* Photo carousel with a detector-style bracket: the memorable element */
.visual { width: 100%; max-width: 21rem; justify-self: end; outline: none; }

.portrait {
    position: relative;
    aspect-ratio: 4 / 5;
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
    touch-action: pan-y;
}

.slide {
    position: absolute;
    inset: 0;
    opacity: 0;
    visibility: hidden;
    transform: scale(1.04);
    transition: opacity 0.7s ease, transform 1.2s var(--ease), visibility 0s linear 0.7s;
}
.slide.is-active {
    opacity: 1;
    visibility: visible;
    transform: none;
    transition-delay: 0s;
}
.slide img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 25%;
}
.slide img.is-missing { display: none; }

/* Shown until a real photo loads */
.portrait-fallback {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font-family: var(--display);
    font-weight: 700;
    font-size: 5rem;
    letter-spacing: -0.04em;
    color: var(--muted);
    background:
        repeating-linear-gradient(to bottom, transparent 0, transparent calc(2.4rem - 1px), var(--sheet-line) calc(2.4rem - 1px), var(--sheet-line) 2.4rem),
        var(--hover);
}

/* The yellow brackets glide to each photo's own position and re-lock as it changes */
.focus {
    --b: 2px;
    --l: 1.4rem;
    position: absolute;
    top: 8%;
    right: 10%;
    bottom: 14%;
    left: 10%;
    pointer-events: none;
    transition: top 0.8s var(--ease), right 0.8s var(--ease), bottom 0.8s var(--ease), left 0.8s var(--ease);
}
.focus::before {
    content: "";
    position: absolute;
    inset: 0;
    background:
        linear-gradient(var(--mark) 0 0) 0 0 / var(--l) var(--b) no-repeat,
        linear-gradient(var(--mark) 0 0) 0 0 / var(--b) var(--l) no-repeat,
        linear-gradient(var(--mark) 0 0) 100% 0 / var(--l) var(--b) no-repeat,
        linear-gradient(var(--mark) 0 0) 100% 0 / var(--b) var(--l) no-repeat,
        linear-gradient(var(--mark) 0 0) 0 100% / var(--l) var(--b) no-repeat,
        linear-gradient(var(--mark) 0 0) 0 100% / var(--b) var(--l) no-repeat,
        linear-gradient(var(--mark) 0 0) 100% 100% / var(--l) var(--b) no-repeat,
        linear-gradient(var(--mark) 0 0) 100% 100% / var(--b) var(--l) no-repeat;
    filter: drop-shadow(0 0 1px rgba(0, 0, 0, 0.35));
}
.focus.is-refocus::before { animation: refocus 0.8s ease both; }
@keyframes refocus {
    0%   { opacity: 1; transform: scale(1); }
    35%  { opacity: 0; transform: scale(1.09); }
    65%  { opacity: 0; transform: scale(0.97); }
    100% { opacity: 1; transform: scale(1); }
}

.focus-tag {
    position: absolute;
    left: 0;
    bottom: calc(100% + 0.35rem);
    padding: 0.1rem 0.6rem 0.15rem;
    font-family: var(--display);
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1.5;
    white-space: nowrap;
    color: var(--mark-ink);
    background: var(--mark);
    border-radius: 4px;
    transition: opacity 0.18s ease, transform 0.18s ease;
}
.focus-tag.is-out { opacity: 0; transform: translateY(4px); }

/* Captions cross-fade in the same grid cell, so the layout never jumps */
.carousel-caption { margin-top: 0.9rem; }
.captions { display: grid; }
.caption-item {
    grid-area: 1 / 1;
    font-size: 0.95rem;
    font-style: italic;
    line-height: 1.5;
    color: var(--muted);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.5s ease, visibility 0s linear 0.5s;
}
.caption-item.is-active { opacity: 1; visibility: visible; transition-delay: 0s; }

.carousel-ctl { display: flex; align-items: center; justify-content: space-between; margin-top: 0.75rem; }
.arrows { display: flex; gap: 0.4rem; }
.dots { display: flex; }

.dot {
    position: relative;
    width: 1.5rem;
    height: 2.25rem;
    padding: 0;
    background: none;
    border: 0;
    cursor: pointer;
}
.dot::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 999px;
    background: var(--line);
    transform: translate(-50%, -50%);
    transition: width 0.3s var(--ease), background-color 0.3s ease;
}
.dot:hover::before { background: var(--muted); }
.dot[aria-current="true"]::before { width: 1.25rem; background: var(--ink); }

.round-btn {
    display: inline-grid;
    place-items: center;
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    color: var(--ink);
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 50%;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}
.round-btn:hover { background: var(--hover); border-color: var(--muted); }
.round-btn:active { background: var(--line); }

/* One load sequence, hero only */
@media (prefers-reduced-motion: no-preference) {
    .hero-copy > * { animation: rise 0.7s var(--ease) both; }
    .hero-copy > :nth-child(2) { animation-delay: 0.08s; }
    .hero-copy > :nth-child(3) { animation-delay: 0.14s; }
    .hero-copy > :nth-child(4) { animation-delay: 0.2s; }
    .hero-copy > :nth-child(5) { animation-delay: 0.26s; }
    .hero-copy > :nth-child(6) { animation-delay: 0.32s; }
    .portrait { animation: rise 0.8s var(--ease) 0.15s both; }
    .carousel-caption { animation: rise 0.8s var(--ease) 0.5s both; }
}
@keyframes rise {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: none; }
}

/* ---------- Sections ---------- */
.section {
    padding-block: 4.5rem;
    border-top: 1px solid var(--line);
}

.section-grid {
    display: grid;
    grid-template-columns: 12rem minmax(0, 1fr);
    gap: 1.5rem 3rem;
}

.section h2 {
    align-self: start;
    position: sticky;
    top: calc(var(--header-h) + 1.5rem);
    font-family: var(--display);
    font-weight: 700;
    font-size: 1.35rem;
    line-height: 1.2;
    letter-spacing: -0.015em;
}

.content { max-width: 46rem; }

/* News */
.news { display: grid; gap: 1.25rem; max-width: 46rem; }
.news li { display: grid; grid-template-columns: 7rem minmax(0, 1fr); gap: 1rem; }
.when {
    font-family: var(--display);
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--muted);
    padding-top: 0.1rem;
}

/* Publications */
.pub + .pub { margin-top: 2.75rem; }
.pub h3 {
    font-family: var(--display);
    font-weight: 600;
    font-size: 1.25rem;
    line-height: 1.3;
    letter-spacing: -0.01em;
    margin-bottom: 0.5rem;
}
.authors { color: var(--muted); }
.authors strong { color: var(--ink); font-weight: 600; }
.venue { margin-top: 0.15rem; margin-bottom: 0.75rem; font-style: italic; }
.status {
    display: inline-block;
    margin-right: 0.4rem;
    padding: 0 0.6rem;
    font-family: var(--display);
    font-style: normal;
    font-size: 0.8rem;
    font-weight: 600;
    line-height: 1.6;
    color: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 999px;
    vertical-align: 0.05em;
}
.links { display: flex; flex-wrap: wrap; gap: 0.25rem 1.5rem; margin-top: 0.75rem; font-family: var(--display); font-weight: 500; font-size: 0.95rem; }

/* Projects: whole row is one link */
.project-list { max-width: 46rem; }
.project-list li {
    position: relative;
    margin-inline: -1rem;
    padding: 1.25rem 3rem 1.25rem 1rem;
    border-radius: 10px;
    transition: background-color 0.18s ease;
}
.project-list li + li { border-top: 1px solid var(--line); border-top-left-radius: 0; border-top-right-radius: 0; }
.project-list li:hover { background: var(--hover); }

.project-list h3 {
    font-family: var(--display);
    font-weight: 600;
    font-size: 1.15rem;
    line-height: 1.3;
    letter-spacing: -0.01em;
    margin-bottom: 0.3rem;
}
.project-list h3 a { color: var(--ink); text-decoration: none; }
.project-list h3 a::after { content: ""; position: absolute; inset: 0; border-radius: 10px; }
.project-list li:hover h3 a { color: var(--accent); text-decoration: underline; text-underline-offset: 0.22em; }
.project-list h3 a:focus-visible { outline: none; }
.project-list h3 a:focus-visible::after { outline: 2px solid var(--accent); outline-offset: -2px; }

.project-list p { max-width: 60ch; }
.tags {
    margin-top: 0.35rem;
    font-family: var(--display);
    font-size: 0.875rem;
    color: var(--muted);
}
.ext {
    position: absolute;
    top: 1.4rem;
    right: 1rem;
    color: var(--muted);
    transition: color 0.18s ease, transform 0.25s var(--ease);
}
.project-list li:hover .ext { color: var(--accent); transform: translate(2px, -2px); }

.more { margin-top: 1.5rem; font-family: var(--display); font-weight: 500; }

/* Background */
.group {
    font-family: var(--display);
    font-weight: 600;
    font-size: 1.05rem;
    letter-spacing: -0.005em;
    padding-bottom: 0.6rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--line);
}
.group:not(:first-child) { margin-top: 3rem; }

.entry {
    display: grid;
    grid-template-columns: 8.5rem minmax(0, 1fr);
    gap: 0.25rem 1.5rem;
}
.entry + .entry { margin-top: 1.5rem; }
.entry .when { padding-top: 0.15rem; }
.role { font-family: var(--display); font-weight: 600; font-size: 1.05rem; line-height: 1.35; }
.org { color: var(--muted); margin-bottom: 0.25rem; }

/* Contact */
.contact-lead { max-width: 46ch; }
.email {
    margin-top: 1.25rem;
    font-family: var(--display);
    font-weight: 600;
    font-size: clamp(1.4rem, 5vw, 2rem);
    letter-spacing: -0.015em;
    color: var(--ink);
}
.email-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; margin-top: 1rem; }
button.btn { cursor: pointer; font-family: var(--display); }

.copy-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.65rem 1.1rem;
    font-family: var(--display);
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--ink);
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 999px;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}
.copy-btn:hover { background: var(--hover); border-color: var(--muted); }
.copy-btn.is-done { border-color: var(--accent); color: var(--accent); }

.social { display: flex; gap: 1.5rem; margin-top: 1.25rem; font-family: var(--display); font-weight: 500; }
.where { margin-top: 1.25rem; color: var(--muted); font-size: 0.95rem; }

/* Footer */
.site-footer { border-top: 1px solid var(--line); padding-block: 1.75rem; }
.foot {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    font-family: var(--display);
    font-size: 0.9rem;
    color: var(--muted);
}
.foot a { color: var(--muted); }
.foot a:hover { color: var(--accent); }

/* Toast */
.toast {
    position: fixed;
    left: 50%;
    bottom: 1.5rem;
    z-index: 70;
    padding: 0.6rem 1.1rem;
    font-family: var(--display);
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--bg);
    background: var(--ink);
    border-radius: 999px;
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 12px);
    transition: opacity 0.2s ease, transform 0.25s var(--ease);
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Responsive ---------- */
@media (max-width: 62rem) {
    .section-grid { grid-template-columns: 1fr; gap: 1.25rem; }
    .section h2 { position: static; }
    .content, .news, .project-list { max-width: none; }
}

@media (max-width: 52rem) {
    .hero { min-height: 0; padding-top: calc(var(--header-h) + 1.5rem); }
    .hero-inner { grid-template-columns: 1fr; }
    .visual { justify-self: start; }

    .menu-btn { display: inline-grid; }
    .nav {
        position: fixed;
        inset: var(--header-h) 0 auto 0;
        padding: 0.75rem var(--gutter) 1.25rem;
        background: var(--bg);
        border-bottom: 1px solid var(--line);
        opacity: 0;
        visibility: hidden;
        transform: translateY(-8px);
        transition: opacity 0.2s ease, transform 0.25s var(--ease), visibility 0s linear 0.25s;
    }
    .nav.is-open { opacity: 1; visibility: visible; transform: none; transition-delay: 0s; }
    .nav ul { flex-direction: column; gap: 0; }
    .nav a { padding: 0.85rem 0.25rem; font-size: 1.05rem; border-radius: 0; border-bottom: 1px solid var(--line); }
    .nav li:last-child a { border-bottom: 0; }
    .nav a:hover { background: transparent; }
}

@media (max-width: 40rem) {
    .section { padding-block: 3.25rem; }
    .news li, .entry { grid-template-columns: 1fr; gap: 0.1rem; }
    .project-list li { margin-inline: -0.75rem; padding: 1.1rem 2.5rem 1.1rem 0.75rem; }
    .ext { right: 0.75rem; }
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

@media print {
    .site-header, .progress, .carousel-ctl, .toast, .skip-link { display: none; }
    body { background: #fff; color: #000; }
    .section { padding-block: 1.5rem; break-inside: avoid; }
}
