/* ============================================================
   Rajat Komawar — portfolio

   1.  Tokens & reset
   2.  Base
   3.  Primitives (container, labels, links)
   4.  Header & navigation
   5.  Intro
   6.  Section scaffolding
   7.  Experience
   8.  Projects
   9.  Education
   10. Contact & footer
   11. Motion
   12. Responsive
   ============================================================ */

/* 1. Tokens & reset
   ------------------------------------------------------------ */
:root {
    --paper: #f7f5f2;
    --ink: #1a1916;
    --ink-2: #4f4b44;
    --ink-3: #6e6960;
    --line: #e4dfd7;
    --line-strong: #c9c2b6;
    --accent: #c08552;
    --img-bg: #ece7e0;

    --dark: #141311;
    --dark-line: #2b2823;
    --dark-line-strong: #4a453d;
    --dark-ink-2: #b3ada3;
    --dark-ink-3: #8e887e;

    --sans: 'General Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

    --container: 1080px;
    --meta-col: 220px;
    --col-gap: clamp(2rem, 5vw, 4.5rem);
}

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

/* 2. Base
   ------------------------------------------------------------ */
html {
    scroll-behavior: smooth;
    scroll-padding-top: 5.5rem;
}

body {
    font-family: var(--sans);
    background: var(--paper);
    color: var(--ink);
    line-height: 1.6;
    font-feature-settings: 'ss01', 'ss02';
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

img {
    display: block;
    max-width: 100%;
    height: auto;
}

ul {
    list-style: none;
}

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

.contact ::selection,
.site-footer ::selection {
    background: var(--paper);
    color: var(--ink);
}

:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 3px;
}

/* 3. Primitives
   ------------------------------------------------------------ */
.container {
    width: min(var(--container), 100% - 3rem);
    margin-inline: auto;
}

/* Small label. Only used where the content beneath it would be
   ambiguous on its own (e.g. "GPA" above "3.57"). Same family as
   everything else; hierarchy comes from size and color, not case. */
.label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--ink-3);
}

.skip-link {
    position: absolute;
    left: 1rem;
    top: -3.5rem;
    z-index: 100;
    background: var(--ink);
    color: var(--paper);
    padding: 0.5rem 0.875rem;
    border-radius: 2px;
    font-size: 0.8125rem;
    text-decoration: none;
    transition: top 0.2s ease;
}

.skip-link:focus {
    top: 0.75rem;
}

/* 4. Header & navigation
   ------------------------------------------------------------ */
.site-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background: rgba(247, 245, 242, 0.92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid transparent;
    transition: border-color 0.25s ease;
}

.site-header.scrolled {
    border-bottom-color: var(--line);
}

.header-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-block: 1.0625rem;
}

.brand {
    font-size: 0.9375rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--ink);
    text-decoration: none;
}

nav[aria-label="Primary"] {
    display: flex;
    align-items: center;
    gap: 1.875rem;
}

.nav-list {
    display: flex;
    gap: 1.875rem;
}

/* Always-visible contact button; the only outlined element in the header. */
.nav-cta {
    font-size: 0.875rem;
    font-weight: 500;
    letter-spacing: -0.005em;
    line-height: 1;
    color: var(--ink);
    text-decoration: none;
    padding: 0.5rem 0.9375rem;
    border: 1px solid var(--line-strong);
    border-radius: 999px;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.nav-cta:hover {
    background: var(--ink);
    border-color: var(--ink);
    color: var(--paper);
}

.nav-list a {
    font-size: 0.875rem;
    font-weight: 500;
    letter-spacing: -0.005em;
    color: var(--ink-2);
    text-decoration: none;
    transition: color 0.15s ease;
}

.nav-list a:hover {
    color: var(--ink);
}

.menu-toggle {
    display: none;
    color: var(--ink);
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.375rem 0;
}

.menu-icon {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 22px;
    height: 18px;
}

.menu-icon span {
    display: block;
    width: 100%;
    height: 1.5px;
    background: currentColor;
    border-radius: 999px;
    transform-origin: center;
    transition: opacity 0.18s ease, transform 0.18s ease;
}

.menu-toggle[aria-expanded="true"] .menu-icon span:first-child {
    transform: translateY(6.5px) rotate(45deg);
}

.menu-toggle[aria-expanded="true"] .menu-icon span:nth-child(2) {
    opacity: 0;
}

.menu-toggle[aria-expanded="true"] .menu-icon span:last-child {
    transform: translateY(-6.5px) rotate(-45deg);
}

/* 5. Intro
   ------------------------------------------------------------ */
.intro {
    padding-block: clamp(4.5rem, 13vh, 8.5rem) clamp(3.5rem, 8vw, 5.5rem);
}

.intro-grid {
    display: grid;
    grid-template-columns: minmax(0, 7fr) minmax(0, 4fr);
    gap: clamp(3rem, 7vw, 6rem);
    align-items: center;
}

.intro h1 {
    font-size: clamp(2.75rem, 6vw, 4.25rem);
    font-weight: 500;
    letter-spacing: -0.035em;
    line-height: 1.02;
    margin-bottom: 1.75rem;
}

.lede {
    font-size: clamp(1.0625rem, 1.6vw, 1.1875rem);
    color: var(--ink-2);
    line-height: 1.7;
    max-width: 34rem;
}

.intro-portrait {
    position: relative;
    justify-self: end;
    width: min(100%, 340px);
}

/* Lightweight offset frame peeking out behind the portrait. */
.intro-portrait::before {
    content: "";
    position: absolute;
    inset: 0;
    border: 1px solid var(--line-strong);
    border-radius: 12px;
    transform: translate(0.8rem, 0.8rem);
    z-index: -1;
}

.intro-portrait img {
    width: 100%;
    aspect-ratio: 4 / 5;
    object-fit: cover;
    object-position: center top;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: var(--img-bg);
}

/* 6. Section scaffolding
   ------------------------------------------------------------ */
.section {
    padding-block: clamp(3rem, 7vw, 4.75rem);
}

/* Sections are separated by whitespace and tonal bands,
   not by full-width rules. */
.section-head {
    margin-bottom: clamp(2.25rem, 5vw, 3.25rem);
}

.section-title {
    font-size: clamp(1.75rem, 3.5vw, 2.25rem);
    font-weight: 500;
    letter-spacing: -0.02em;
    line-height: 1;
}

/* 7. Experience
   ------------------------------------------------------------ */
.xp-list {
    border-top: 1px solid var(--line);
}

.xp {
    border-bottom: 1px solid var(--line);
    interpolate-size: allow-keywords;
}

.xp-row {
    display: grid;
    grid-template-columns: 10.5rem minmax(0, 1fr) auto 1rem;
    align-items: center;
    gap: 1.5rem;
    padding-block: 1.375rem;
    cursor: pointer;
    list-style: none;
}

.xp-row::-webkit-details-marker {
    display: none;
}

.xp-row:focus-visible {
    outline: 2px solid var(--ink);
    outline-offset: 4px;
    border-radius: 2px;
}

.xp-when {
    font-size: 0.9375rem;
    color: var(--ink-3);
    font-variant-numeric: tabular-nums;
}

.xp-title {
    font-size: 1.1875rem;
    font-weight: 500;
    letter-spacing: -0.015em;
    color: var(--ink);
}

.xp-org {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    min-width: 7rem;
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--ink-2);
}

/* amazon.png has heavy padding inside a square canvas; crop to the wordmark */
.org-logo--amazon {
    width: 58px;
    height: 21px;
    object-fit: cover;
}

.org-logo--cisco {
    height: 22px;
    width: auto;
}

.xp-chev {
    width: 1rem;
    height: 1rem;
    color: var(--ink-3);
    transition: transform 0.25s ease, color 0.15s ease;
}

.xp-row:hover .xp-chev {
    color: var(--ink);
}

.xp[open] .xp-chev {
    transform: rotate(180deg);
}

.xp::details-content {
    height: 0;
    overflow: clip;
    transition: height 0.35s ease, content-visibility 0.35s allow-discrete;
}

.xp[open]::details-content {
    height: auto;
}

.xp-body {
    margin-left: calc(10.5rem + 1.5rem);
    max-width: 62ch;
    padding-bottom: 2.25rem;
}

.xp-body p {
    font-size: 1.0625rem;
    color: var(--ink-2);
    line-height: 1.75;
}

.xp-body p + p {
    margin-top: 0.875rem;
}

.xp-body .xp-built {
    margin-top: 1.25rem;
    font-size: 0.9375rem;
    color: var(--ink-3);
}

/* Hand-drawn underline that sketches itself in when a role opens. */
.ink {
    color: var(--ink);
    padding-bottom: 0.14em;
    -webkit-box-decoration-break: clone;
    box-decoration-break: clone;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 10' preserveAspectRatio='none'%3E%3Cpath d='M1 6.5 C 18 3.5, 34 8, 52 5.2 S 84 3.8, 99 6' fill='none' stroke='%23c08552' stroke-width='3.2' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: left bottom;
    background-size: 0% 0.5em;
}

.xp[open] .ink {
    animation: ink-draw 0.6s cubic-bezier(0.5, 0, 0.2, 1) forwards;
    animation-delay: calc(0.25s + var(--i, 0) * 0.18s);
}

@keyframes ink-draw {
    to { background-size: 100% 0.5em; }
}

@media (prefers-reduced-motion: reduce) {
    .xp[open] .ink {
        animation: none;
        background-size: 100% 0.5em;
    }

    .xp::details-content {
        transition: none;
    }
}

.feature-stack {
    font-size: 0.875rem;
    color: var(--ink-3);
    line-height: 1.7;
    margin-top: 1.5rem;
}

/* 8. Projects
   ------------------------------------------------------------ */
.feature {
    display: grid;
    grid-template-columns: minmax(0, 6fr) minmax(0, 5fr);
    gap: clamp(2.5rem, 6vw, 5rem);
    align-items: center;
}

.feature-media {
    overflow: hidden;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: #fff;
}

.logo-field {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    min-height: clamp(220px, 42vw, 360px);
    overflow: hidden;
    background: #fff;
}

.logo-field__item {
    position: absolute;
    left: 0;
    top: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.35rem;
    border: 1px solid rgba(26, 25, 22, 0.08);
    border-radius: 12px;
    background: #fff;
    user-select: none;
    will-change: transform;
}

.logo-field__item[hidden] {
    display: none;
}

.logo-field__item img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
}

.feature-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.375rem;
}

.status {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--ink-3);
    white-space: nowrap;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #22c55e;
    flex-shrink: 0;
    animation: pulse 1.6s ease-in-out infinite;
}

.feature-body h3 {
    font-size: clamp(1.625rem, 3vw, 2rem);
    font-weight: 500;
    letter-spacing: -0.02em;
    margin-bottom: 1rem;
}

.feature-body > p:not(.feature-stack) {
    font-size: 1.0625rem;
    color: var(--ink-2);
    line-height: 1.75;
}

/* 9. Education
   ------------------------------------------------------------ */
.edu {
    display: grid;
    grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
    gap: clamp(2.5rem, 6vw, 5rem);
    align-items: center;
}

.edu-body {
    order: -1;
}

.edu-media {
    overflow: hidden;
    border-radius: 2px;
    background: var(--paper);
}

.edu-media img {
    width: 100%;
    aspect-ratio: 16 / 10;
    object-fit: cover;
}

.edu-body h3 {
    font-size: clamp(1.625rem, 3vw, 2rem);
    font-weight: 500;
    letter-spacing: -0.02em;
    margin-bottom: 0.375rem;
}

.edu-degree {
    font-size: 1.0625rem;
    color: var(--ink-2);
    margin-bottom: 2rem;
}

.edu-meta {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.5rem;
    max-width: 20rem;
    border-top: 1px solid var(--line);
    padding-top: 1.375rem;
    margin-bottom: 2rem;
}

.edu-meta dt {
    margin-bottom: 0.375rem;
}

.edu-meta dd {
    font-size: 1.0625rem;
    font-variant-numeric: tabular-nums;
}

.edu-orgs .label {
    display: block;
    margin-bottom: 0.375rem;
}

.edu-orgs p {
    font-size: 0.9375rem;
    color: var(--ink-2);
    line-height: 1.65;
    max-width: 40ch;
}

/* Education image — Geisel Library draws itself line-by-line as an ink sketch
   (self-drawing SVG strokes), then the real building colours in over it. The
   photo is a sky-free cutout (UCSD-cutout.webp) so it sits on the page with no
   frame. Plays once when the section scrolls into view (see script.js).
   Reduced-motion / no-JS users get the cutout immediately. */
.education-image-animated {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 10;
    background: var(--paper);
}

.education-image-animated .color-layer {
    position: absolute;
    inset: 0;
    z-index: 1;
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.education-image-animated .sketch-svg {
    position: absolute;
    inset: 0;
    z-index: 2;
    width: 100%;
    height: 100%;
    display: none;
    pointer-events: none;
}

.education-image-animated .ink path {
    fill: none;
    stroke: #1f1d19;
    stroke-width: 1.3;
    stroke-linecap: round;
    stroke-linejoin: round;
    vector-effect: non-scaling-stroke;
    shape-rendering: geometricPrecision;
}

@media (prefers-reduced-motion: no-preference) {
    /* Armed once JS is active: photo hidden below a soft reveal band, ink
       strokes not yet drawn. */
    .js .education-image-animated .color-layer {
        opacity: 0;
        -webkit-mask-image: linear-gradient(to top, #000 0%, #000 42%, transparent 58%, transparent 100%);
        mask-image: linear-gradient(to top, #000 0%, #000 42%, transparent 58%, transparent 100%);
        -webkit-mask-size: 100% 300%;
        mask-size: 100% 300%;
        -webkit-mask-repeat: no-repeat;
        mask-repeat: no-repeat;
        -webkit-mask-position: 0 0%;
        mask-position: 0 0%;
    }

    .js .education-image-animated .sketch-svg {
        display: block;
        mix-blend-mode: multiply;
    }

    .js .education-image-animated .sketch-svg path {
        stroke-dasharray: 1;
        stroke-dashoffset: 1;
    }

    /* Play: each stroke draws itself, staggered by its inline --d delay,
       building the structure from the ground up, then the window tiles. */
    .js .education-image-animated.is-playing .sketch-svg path {
        animation: edu-draw 0.5s ease-in-out var(--d, 0s) forwards;
    }

    /* Once the building is drawn (~2.4s), hold briefly, then wipe the photo in
       from the base as a faded monochrome wash that warms into full colour.
       The ink lingers over the photo a beat before fading. */
    .js .education-image-animated.is-playing .color-layer {
        animation:
            edu-photo-wipe 0.85s cubic-bezier(0.45, 0, 0.25, 1) 2.9s both,
            edu-photo-wash 0.9s ease-out 3.1s both;
    }

    .js .education-image-animated.is-playing .sketch-svg {
        animation: edu-sketch-out 0.55s ease 3.35s forwards;
    }
}

@keyframes edu-draw {
    to { stroke-dashoffset: 0; }
}

@keyframes edu-photo-wipe {
    from { opacity: 1; -webkit-mask-position: 0 0%; mask-position: 0 0%; }
    to { opacity: 1; -webkit-mask-position: 0 100%; mask-position: 0 100%; }
}

@keyframes edu-photo-wash {
    from { filter: grayscale(1) sepia(0.12) contrast(0.9) brightness(1.08); }
    to { filter: none; }
}

@keyframes edu-sketch-out {
    to { opacity: 0; }
}

/* 10. Contact & footer
   ------------------------------------------------------------ */
.contact {
    position: relative;
    background: var(--dark);
    color: #fff;
    margin-top: clamp(3rem, 7vw, 4.75rem);
    padding-block: clamp(5rem, 12vw, 8rem);
}

/* Quiet label naming the section; the email below is the real headline. */
.contact-label {
    font-size: 1.125rem;
    font-weight: 300;
    color: var(--dark-ink-3);
    margin-bottom: 1rem;
}

.contact-mail {
    display: inline-block;
    font-size: clamp(1.875rem, 5.5vw, 3.25rem);
    font-weight: 500;
    letter-spacing: -0.03em;
    line-height: 1.1;
    color: #fff;
    text-decoration: none;
    border-bottom: 1px solid var(--dark-line-strong);
    padding-bottom: 0.375rem;
    transition: border-color 0.2s ease;
}

.contact-mail:hover {
    border-color: #fff;
}

.contact-alt {
    margin-top: 1.25rem;
}

/* Secondary link: plain white text; the underline appears on hover only. */
.contact-social {
    font-size: 1.375rem;
    font-weight: 400;
    letter-spacing: -0.01em;
    color: #fff;
    text-decoration: underline;
    text-decoration-color: transparent;
    text-decoration-thickness: 1px;
    text-underline-offset: 0.3em;
    transition: text-decoration-color 0.2s ease;
}

.contact-social:hover {
    text-decoration-color: currentColor;
}

.site-footer {
    background: var(--dark);
    padding-block: 0 1.75rem;
}

/* Contact robot — overlay where the Three.js animation lives. On desktop it
   sits on the right, vertically in line with the email; on narrow screens it drops to a clear band below the text so it never
   overlaps the copy. The robot enters/exits off the right edge and the canvas
   fills this box (positioned by robot.js). Remove this rule together with
   #robot-stage, the robot block in index.html, and robot.js. */
.robot-stage {
    position: absolute;
    top: 50%;
    right: 0;
    transform: translateY(-50%); /* in line with the heading & email */
    width: min(440px, 46vw);
    height: 240px;
    pointer-events: none;
    overflow: hidden;
}

@media (max-width: 640px) {
    /* Narrow screens: give the contact section extra bottom room and drop the
       robot into that band, full-width and below the text — never on top of it. */
    .contact {
        padding-bottom: 8rem;
    }

    .robot-stage {
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        transform: none;
        width: auto;
        height: 130px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .robot-stage {
        display: none;
    }
}

.footer-inner {
    font-size: 0.8125rem;
    color: var(--dark-ink-3);
}

/* 11. Motion
   ------------------------------------------------------------ */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

@keyframes rise {
    from {
        opacity: 0;
        transform: translateY(14px);
    }
}

@media (prefers-reduced-motion: no-preference) {
    .js .reveal {
        opacity: 0;
        transform: translateY(14px);
        transition: opacity 0.55s ease, transform 0.55s ease;
    }

    .js .reveal.is-visible {
        opacity: 1;
        transform: none;
    }

    /* Hold the underline sketch until the role has scrolled into view. */
    .js .xp.reveal:not(.is-visible) .ink {
        animation: none;
    }

    .js .intro-text > *,
    .js .intro-portrait {
        animation: rise 0.6s ease both;
    }

    .js .intro-text > h1 { animation-delay: 0s; }
    .js .intro-text > .lede { animation-delay: 0.08s; }
    .js .intro-portrait { animation-delay: 0.12s; }
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    .status-dot {
        animation: none;
    }

    .feature-media img {
        transition: none;
    }
}

/* 12. Responsive
   ------------------------------------------------------------ */
@media (max-width: 900px) {
    .intro-grid {
        grid-template-columns: 1fr;
        gap: 3rem;
    }

    .intro-portrait {
        justify-self: start;
        width: min(300px, 75%);
    }

    .feature,
    .edu {
        grid-template-columns: 1fr;
        gap: 2rem;
    }

    .edu-body {
        order: 0;
    }
}

@media (max-width: 760px) {
    html {
        scroll-padding-top: 4.5rem;
    }

    nav[aria-label="Primary"] {
        gap: 1.125rem;
    }

    .menu-toggle {
        display: inline-flex;
    }

    .nav-list {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        flex-direction: column;
        gap: 1.125rem;
        background: var(--paper);
        border-bottom: 1px solid var(--line);
        padding: 0.875rem 1.5rem 1.5rem;
    }

    .nav-list.open {
        display: flex;
        animation: menu-in 0.18s ease;
    }

    .xp-row {
        grid-template-columns: minmax(0, 1fr) 1rem;
        gap: 0.25rem 1rem;
    }

    .xp-when { grid-column: 1; grid-row: 1; }
    .xp-title { grid-column: 1; grid-row: 2; }
    .xp-chev { grid-column: 2; grid-row: 1 / 4; }

    .xp-org {
        grid-column: 1;
        grid-row: 3;
        justify-content: flex-start;
        margin-top: 0.375rem;
    }

    .xp-body {
        margin-left: 0;
    }
}

@keyframes menu-in {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
}

@media (max-width: 480px) {
    .intro-portrait {
        width: min(280px, 100%);
    }

    .feature-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.625rem;
    }
}
