/* Modern academic theme for the public site.
 *
 * Loaded AFTER styles.css by the public pages only (index, research,
 * publications, open source, experience, cv, and the paper detail pages).
 * Every rule here sits inside @media screen, so print output, the visa CV,
 * the LaTeX CV, and the resumes (which share styles.css) are unaffected.
 * Existing class names are kept; this file only restyles them.
 */

@media screen {
  :root {
    color-scheme: light dark;

    --page: #ffffff;
    --surface: #f6f7f9;
    --ink: #1a1d21;
    --muted: #5a6472;
    --rule: #e2e5ea;
    --link: #1d4ed8;
    --link-visited: #1d4ed8;
    --accent: #1d4ed8;
    --accent-soft: #e8efff;
    --soft: #f6f7f9;
    --tab-bg: transparent;
    --tab-active: #e8efff;
    --header-bg: rgba(255, 255, 255, 0.82);
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 8px 24px rgba(16, 24, 40, 0.07);

    --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
      "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    --wrap: 960px;
  }

  /* Theme: an explicit choice (data-theme, set by the toggle or the head
     script) wins; with no data-theme (scripts blocked) the system setting
     applies. */
  :root[data-theme="light"] {
    color-scheme: light;
  }

  :root[data-theme="dark"] {
    color-scheme: dark;
    --page: #0f1216;
    --surface: #171b21;
    --ink: #e8eaed;
    --muted: #9aa4b0;
    --rule: #2a3038;
    --link: #8ab4ff;
    --link-visited: #8ab4ff;
    --accent: #8ab4ff;
    --accent-soft: #1b2638;
    --soft: #171b21;
    --tab-active: #1b2638;
    --header-bg: rgba(15, 18, 22, 0.82);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  }

  :root[data-theme="dark"] .award-badge {
    background: rgba(74, 222, 128, 0.12);
    color: #86efac;
    border-color: rgba(74, 222, 128, 0.35);
  }

  :root[data-theme="dark"] .pub-thumb img,
  :root[data-theme="dark"] .flip-front {
    filter: brightness(0.92);
  }

  @media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
      --page: #0f1216;
      --surface: #171b21;
      --ink: #e8eaed;
      --muted: #9aa4b0;
      --rule: #2a3038;
      --link: #8ab4ff;
      --link-visited: #8ab4ff;
      --accent: #8ab4ff;
      --accent-soft: #1b2638;
      --soft: #171b21;
      --tab-active: #1b2638;
      --header-bg: rgba(15, 18, 22, 0.82);
      --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
    }

    :root:not([data-theme]) .award-badge {
      background: rgba(74, 222, 128, 0.12);
      color: #86efac;
      border-color: rgba(74, 222, 128, 0.35);
    }

    :root:not([data-theme]) .pub-thumb img,
    :root:not([data-theme]) .flip-front {
      filter: brightness(0.92);
    }
  }

  /* ---- Base ---------------------------------------------------------- */
  html {
    scroll-padding-top: 4.5rem;
  }

  body {
    font-family: var(--font-sans);
    font-size: 17px;
    line-height: 1.65;
    -webkit-font-smoothing: antialiased;
  }

  a {
    text-underline-offset: 0.18em;
    text-decoration-thickness: 1px;
  }

  a:focus-visible,
  summary:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
  }

  main {
    max-width: var(--wrap);
    padding: 2rem 1.25rem 3rem;
  }

  h1,
  h2,
  h3 {
    font-family: var(--font-sans);
    letter-spacing: -0.015em;
    font-weight: 650;
  }

  h1 {
    font-size: 2.2rem;
    line-height: 1.15;
  }

  main h2 {
    margin: 2.4rem 0 0.8rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--rule);
    font-size: 1.3rem;
  }

  /* ---- Header / navigation ------------------------------------------- */
  .site-header {
    position: sticky;
    top: 0;
    z-index: 20;
    max-width: none;
    margin: 0;
    padding: 0.7rem max(1.25rem, calc((100vw - var(--wrap)) / 2 + 1.25rem));
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 1rem;
    background: var(--header-bg);
    -webkit-backdrop-filter: saturate(160%) blur(10px);
    backdrop-filter: saturate(160%) blur(10px);
    border-bottom: 1px solid var(--rule);
  }

  .brand {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    white-space: nowrap;
  }

  .site-header nav {
    margin: 0 0 0 auto;
    gap: 0.15rem;
  }

  .theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 2.1rem;
    height: 2.1rem;
    padding: 0;
    border: 1px solid var(--rule);
    border-radius: 999px;
    background: var(--page);
    color: var(--muted);
    cursor: pointer;
  }

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

  .theme-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }

  .theme-toggle .icon-sun {
    display: none;
  }

  :root[data-theme="dark"] .theme-toggle .icon-moon {
    display: none;
  }

  :root[data-theme="dark"] .theme-toggle .icon-sun {
    display: block;
  }

  .site-header nav a {
    border: 0;
    border-radius: 999px;
    background: transparent;
    padding: 0.35rem 0.8rem;
    color: var(--muted);
    font-size: 0.93rem;
    font-weight: 500;
  }

  .site-header nav a:hover {
    background: var(--surface);
    color: var(--ink);
  }

  .site-header nav a.active {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
  }

  /* ---- Homepage hero ------------------------------------------------- */
  .hero-profile {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 250px;
    grid-template-areas:
      "copy photo"
      "interests interests"
      "cta cta";
    column-gap: 2.75rem;
    align-items: start;
  }

  .hero-copy {
    grid-area: copy;
    order: 0;
  }

  .hero-copy p:first-of-type {
    font-size: 1.1rem;
  }

  /* Two-sided card: the photo in front, a tarot illustration behind. */
  .profile-photo {
    grid-area: photo;
    order: 0;
    float: none;
    width: 100%;
    margin: 0.3rem 0 0;
    padding: 0;
    border: 0;
    background: transparent;
    aspect-ratio: 2 / 3;
    perspective: 1200px;
    cursor: pointer;
    border-radius: 18px;
  }

  .profile-photo:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 4px;
  }

  .flip-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
  }

  .profile-photo img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    aspect-ratio: auto;
    object-fit: cover;
    border-radius: 18px;
    box-shadow: var(--shadow);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
  }

  .flip-front {
    object-position: center 30%;
  }

  .flip-back {
    transform: rotateY(180deg);
    object-position: center;
  }

  @media (hover: hover) {
    .profile-photo:hover .flip-inner {
      transform: rotateY(180deg);
    }
  }

  .profile-photo:focus-visible .flip-inner,
  .profile-photo.is-flipped .flip-inner {
    transform: rotateY(180deg);
  }

  .terminal-card {
    grid-area: interests;
    order: 0;
    max-width: none;
    margin: 1.4rem 0 0.4rem;
    padding: 0;
    border: 0;
  }

  .terminal-line {
    margin-bottom: 0.55rem;
    font-family: var(--font-sans);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.09em;
    color: var(--muted);
  }

  .focus-grid span {
    border: 0;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    padding: 0.2rem 0.75rem;
    font-size: 0.88rem;
    font-weight: 500;
  }

  .cta-row {
    grid-area: cta;
    order: 0;
    gap: 0.55rem;
    margin-top: 0.9rem;
  }

  a.btn {
    border: 1px solid var(--rule);
    border-radius: 999px;
    background: var(--page);
    color: var(--ink);
    padding: 0.32rem 0.95rem;
    font-size: 0.9rem;
    font-weight: 500;
  }

  a.btn:visited {
    color: var(--ink);
  }

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

  /* ---- News ---------------------------------------------------------- */
  .news-list li {
    gap: 1.1rem;
    margin: 0;
    padding: 0.55rem 0;
    border-bottom: 1px solid var(--rule);
  }

  .news-list li:last-child {
    border-bottom: 0;
  }

  .news-date {
    flex: 0 0 5.4rem;
    font-size: 0.88rem;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
  }

  .news-more summary {
    margin-top: 0.4rem;
    font-size: 0.9rem;
    font-weight: 500;
  }

  /* ---- Cards: research, open source, experience --------------------- */
  .project-card,
  .timeline-item {
    border: 1px solid var(--rule);
    border-radius: 14px;
    background: var(--surface);
    padding: 1rem 1.25rem;
    margin: 0 0 0.9rem;
  }

  details.project-card {
    border-bottom: 1px solid var(--rule);
    padding-bottom: 1rem;
  }

  summary.project-kicker {
    font-weight: 600;
  }

  .paper-note {
    margin: 0.8rem 0 0.1rem;
    padding: 0.7rem 0.95rem;
    border: 0;
    border-left: 3px solid var(--accent);
    border-radius: 0 10px 10px 0;
    background: var(--page);
  }

  .paper-label {
    font-family: var(--font-sans);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.09em;
  }

  .role-row {
    border-bottom: 0;
    margin-bottom: 0.2rem;
  }

  .role-row h3 {
    margin-bottom: 0.1rem;
  }

  /* ---- Publications -------------------------------------------------- */
  ol.pub-list {
    list-style: none;
    padding: 0;
  }

  .pub-list li.pub {
    display: grid;
    grid-template-columns: 190px minmax(0, 1fr);
    gap: 1.15rem;
    margin: 0.9rem 0;
    padding: 1rem;
    border: 1px solid var(--rule);
    border-radius: 14px;
    background: var(--surface);
  }

  .pub-thumb {
    display: block;
    align-self: start;
  }

  .pub-thumb img {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    object-position: top;
    border: 1px solid var(--rule);
    border-radius: 8px;
    background: #ffffff;
  }

  .pub-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.6rem;
    font-size: 0.85rem;
  }

  .pub-links a {
    border: 1px solid var(--rule);
    border-radius: 999px;
    background: var(--page);
    padding: 0.08rem 0.7rem;
    text-decoration: none;
    font-weight: 500;
  }

  .pub-links a:not(:last-child)::after {
    content: none;
  }

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

  .award-badge {
    margin-left: 0.2rem;
  }

  pre {
    margin: 0.6rem 0 1rem;
    padding: 0.9rem 1.1rem;
    overflow-x: auto;
    border: 1px solid var(--rule);
    border-radius: 12px;
    background: var(--surface);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    line-height: 1.55;
  }

  /* ---- CV page (screen only) ----------------------------------------- */
  .cv-date {
    font-size: 0.92rem;
    font-variant-numeric: tabular-nums;
  }

  .cv-project {
    border-left-color: var(--rule);
  }

  /* ---- Mobile -------------------------------------------------------- */
  @media (max-width: 640px) {
    body {
      font-size: 16.5px;
    }

    main {
      padding: 1.25rem 1rem 2.5rem;
    }

    h1 {
      font-size: 1.85rem;
    }

    .site-header {
      position: relative;
      flex-direction: column;
      align-items: flex-start;
      gap: 0.25rem;
      padding: 0.6rem 1rem 0.4rem;
    }

    .theme-toggle {
      position: absolute;
      top: 0.5rem;
      right: 1rem;
    }

    .site-header nav {
      width: 100%;
      flex-wrap: nowrap;
      overflow-x: auto;
      margin: 0 -0.25rem;
      padding-bottom: 0.2rem;
      scrollbar-width: none;
    }

    .site-header nav::-webkit-scrollbar {
      display: none;
    }

    .site-header nav a {
      flex: 0 0 auto;
    }

    .hero-profile {
      display: grid;
      grid-template-columns: 1fr;
      grid-template-areas:
        "photo"
        "copy"
        "interests"
        "cta";
    }

    .profile-photo {
      width: 132px;
      aspect-ratio: 1 / 1;
      margin: 0 0 1rem;
      border-radius: 50%;
    }

    .profile-photo img {
      border-radius: 50%;
    }

    .flip-front {
      object-position: center 30%;
    }

    .flip-back {
      object-position: 50% 12%;
    }

    .news-list li {
      flex-direction: column;
      gap: 0.1rem;
    }

    .news-date {
      flex: 0 0 auto;
    }

    .pub-list li.pub {
      grid-template-columns: 1fr;
    }

    .pub-thumb {
      max-width: 280px;
    }

    .project-card,
    .timeline-item {
      padding: 0.9rem 1rem;
    }
  }

  /* ---- Subtle motion -------------------------------------------------- */
  @media (prefers-reduced-motion: no-preference) {
    @keyframes page-in {
      from {
        opacity: 0.55;
        transform: translateY(6px);
      }
      to {
        opacity: 1;
        transform: none;
      }
    }

    main {
      animation: page-in 0.35s ease-out both;
    }

    .flip-inner {
      transition: transform 0.7s cubic-bezier(0.2, 0.7, 0.2, 1);
    }

    a.btn,
    .pub-links a,
    .site-header nav a,
    .theme-toggle,
    .project-card,
    .pub-list li.pub {
      transition: border-color 0.15s ease, background-color 0.15s ease,
        color 0.15s ease, box-shadow 0.15s ease;
    }

    .pub-list li.pub:hover,
    details.project-card:hover {
      border-color: var(--accent);
    }
  }
}
