/* ============================================================
   Leonid Gremyachikh — personal site
   Tokens → base → layout → components → responsive
   ============================================================ */

/* ---------- tokens ---------- */
:root {
  --bg:        #FBFAF7;
  --bg-soft:   #F3F1EA;
  --fg:        #16150F;
  --fg-2:      #56534A;
  --fg-3:      #8C887A;
  --line:      #E3E0D6;
  --line-soft: #EDEBE2;
  --accent:    #6B7700;
  --accent-bg: rgba(107, 119, 0, .09);
  --shadow:    0 1px 2px rgba(20, 19, 12, .04), 0 8px 24px -12px rgba(20, 19, 12, .10);

  --max:  1080px;
  --gut:  clamp(1.25rem, 5vw, 4rem);
  --sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --ease: cubic-bezier(.22, .61, .36, 1);
}

:root:not([data-theme="light"]) {
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:        #0C0C0A;
    --bg-soft:   #141410;
    --fg:        #EDEBE2;
    --fg-2:      #A29E93;
    --fg-3:      #6C695F;
    --line:      #262520;
    --line-soft: #1C1B17;
    --accent:    #C4D129;
    --accent-bg: rgba(196, 209, 41, .11);
    --shadow:    0 1px 2px rgba(0, 0, 0, .5), 0 8px 24px -12px rgba(0, 0, 0, .8);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg:        #0C0C0A;
  --bg-soft:   #141410;
  --fg:        #EDEBE2;
  --fg-2:      #A29E93;
  --fg-3:      #6C695F;
  --line:      #262520;
  --line-soft: #1C1B17;
  --accent:    #C4D129;
  --accent-bg: rgba(196, 209, 41, .11);
  --shadow:    0 1px 2px rgba(0, 0, 0, .5), 0 8px 24px -12px rgba(0, 0, 0, .8);
  color-scheme: dark;
}

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

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: 6rem; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  font-feature-settings: "cv02", "cv03", "cv04", "ss01";
  -webkit-font-smoothing: antialiased;
  transition: background-color .35s var(--ease), color .35s var(--ease);
}

h1, h2, h3 { margin: 0; font-weight: 500; line-height: 1.15; letter-spacing: -.01em; }
p  { margin: 0 0 1em; }
ul, ol { margin: 0; padding: 0; }
img { max-width: 100%; height: auto; display: block; }

a { color: inherit; text-decoration: none; }
a:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 3px;
}

.skip {
  position: absolute; left: -9999px; top: 0;
  padding: .6rem 1rem; background: var(--fg); color: var(--bg); z-index: 100;
}
.skip:focus { left: 1rem; top: 1rem; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid transparent;
  transition: border-color .3s var(--ease);
}
.topbar.is-stuck { border-bottom-color: var(--line); }

.topbar-inner {
  max-width: var(--max); margin: 0 auto; padding: .9rem var(--gut);
  display: flex; align-items: center; gap: 1.5rem;
}

.brand { display: flex; align-items: center; gap: .55rem; margin-right: auto; }
.brand-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent); flex: none;
}
.brand-name {
  font-family: var(--mono); font-size: .78rem; letter-spacing: .02em;
  color: var(--fg); white-space: nowrap;
}

.nav { display: flex; gap: 1.35rem; }
.nav a {
  font-family: var(--mono); font-size: .74rem; letter-spacing: .04em;
  color: var(--fg-3); position: relative; padding: .15rem 0;
  transition: color .2s var(--ease);
}
.nav a:hover { color: var(--fg); }
.nav a.is-active { color: var(--fg); }
.nav a.is-active::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -2px;
  height: 1px; background: var(--accent);
}

.theme-toggle {
  appearance: none; border: 1px solid var(--line); background: transparent;
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  display: grid; place-items: center; cursor: pointer; color: var(--fg-2);
  transition: color .2s var(--ease), border-color .2s var(--ease), transform .2s var(--ease);
}
.theme-toggle:hover { color: var(--fg); border-color: var(--fg-3); transform: rotate(15deg); }
.theme-toggle svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
.theme-toggle .i-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .i-sun,
:root:not([data-theme="light"]) .theme-toggle .i-sun { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .i-sun  { display: none; }
  :root:not([data-theme="light"]) .theme-toggle .i-moon { display: block; }
}
:root[data-theme="dark"] .theme-toggle .i-sun  { display: none; }
:root[data-theme="dark"] .theme-toggle .i-moon { display: block; }
:root[data-theme="light"] .theme-toggle .i-sun  { display: block; }
:root[data-theme="light"] .theme-toggle .i-moon { display: none; }

/* ---------- layout ---------- */
main { max-width: var(--max); margin: 0 auto; padding: 0 var(--gut); }

.section {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  gap: 0 3rem;
  padding: clamp(1.9rem, 3.2vw, 2.7rem) 0;
  border-top: 1px solid var(--line-soft);
}

.label {
  font-family: var(--mono); font-size: .86rem; font-weight: 500;
  line-height: 1.6; letter-spacing: .03em; text-transform: uppercase; color: var(--fg);
  position: sticky; top: 5.5rem;
}

.section-intro { color: var(--fg-2); max-width: 46ch; margin-bottom: 1.5rem; font-size: .92rem; }
.sub {
  font-family: var(--mono); font-size: .72rem; letter-spacing: .06em;
  text-transform: uppercase; color: var(--fg-3);
  margin: 2rem 0 .75rem;
}

/* ---------- hero ---------- */
.hero { padding: clamp(2rem, 4.5vw, 3.25rem) 0 clamp(1.5rem, 3vw, 2.2rem); }

.hero-grid {
  display: grid; grid-template-columns: minmax(0, 1fr) 168px;
  gap: 3rem; align-items: start;
}

.kicker {
  font-family: var(--mono); font-size: .74rem; letter-spacing: .06em;
  text-transform: uppercase; color: var(--fg-3); margin-bottom: 1.5rem;
}

.display {
  font-family: var(--sans); font-weight: 600;
  font-size: clamp(1.7rem, 3.6vw, 2.25rem);
  line-height: 1.1; letter-spacing: -.025em;
  margin-bottom: .5rem;
}

.lead {
  font-size: clamp(1rem, 1.5vw, 1.1rem);
  line-height: 1.65; color: var(--fg-2); max-width: 56ch;
}

.status {
  display: inline-flex; align-items: center; gap: .55rem;
  font-family: var(--mono); font-size: .74rem; letter-spacing: .01em;
  color: var(--fg-2); background: var(--accent-bg);
  border-radius: 999px; padding: .4rem .85rem .4rem .7rem;
  margin: .4rem 0 1.5rem;
}
.status a { color: var(--fg-2); border-bottom: 1px solid var(--line); }
.status a:hover { color: var(--accent); border-color: var(--accent); }

.pulse {
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none;
  box-shadow: 0 0 0 0 var(--accent); animation: pulse 2.4s var(--ease) infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 55%, transparent); }
  70%  { box-shadow: 0 0 0 7px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
@media (prefers-reduced-motion: reduce) { .status a { color: var(--fg-2); border-bottom: 1px solid var(--line); }
.status a:hover { color: var(--accent); border-color: var(--accent); }

.pulse { animation: none; } }

.hero-portrait img {
  width: 100%; border-radius: 14px; box-shadow: var(--shadow);
}

.links { list-style: none; display: grid; gap: .5rem; }
.links li {
  display: grid; grid-template-columns: 68px minmax(0, 1fr);
  align-items: baseline; column-gap: 1rem;
}
.links span {
  font-family: var(--mono); font-size: .68rem; letter-spacing: .07em;
  text-transform: uppercase; color: var(--fg-3);
}
.links a {
  font-family: var(--mono); font-size: .82rem; justify-self: start;
  border-bottom: 1px solid var(--line); padding-bottom: 2px;
  transition: color .2s var(--ease), border-color .2s var(--ease);
}
.links a:hover { color: var(--accent); border-color: var(--accent); }
.links.big { gap: .7rem; }
.links.big li { grid-template-columns: 78px minmax(0, 1fr); }
.links.big a { font-size: .95rem; }

.facts {
  margin: clamp(1.75rem, 3.2vw, 2.5rem) 0 0;
  padding-top: 1.6rem; border-top: 1px solid var(--line-soft);
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 2.5rem;
}
.facts > div { min-width: 0; }
.facts dt {
  font-family: var(--mono); font-size: .68rem; letter-spacing: .07em;
  text-transform: uppercase; color: var(--fg-3); margin-bottom: .5rem;
}
.facts dd { margin: 0; font-size: .9rem; color: var(--fg-2); line-height: 1.55; }
.facts dd a { border-bottom: 1px solid var(--line); }
.facts dd a:hover { color: var(--accent); border-color: var(--accent); }

/* ---------- expandable items ---------- */
.items { border-top: 1px solid var(--line-soft); }

.item { border-bottom: 1px solid var(--line-soft); }

.item > summary {
  list-style: none; cursor: pointer;
  display: flex; align-items: baseline; gap: .85rem;
  padding: .8rem 0;
  transition: opacity .2s var(--ease);
}
.item > summary::-webkit-details-marker { display: none; }
.item > summary:hover .item-title { color: var(--accent); }

.item-head {
  flex: 1 1 auto; min-width: 0;
  display: flex; flex-wrap: wrap; align-items: baseline; gap: .15rem .7rem;
}
.item-title {
  font-size: .98rem; font-weight: 500; letter-spacing: -.008em; line-height: 1.35;
  transition: color .2s var(--ease);
}
.item-org {
  font-family: var(--mono); font-size: .71rem; color: var(--fg-3); line-height: 1.4;
}
.item-year {
  font-family: var(--mono); font-size: .71rem; color: var(--fg-3);
  white-space: nowrap; flex: none; margin-left: auto;
  width: 11ch; text-align: left;      /* start-aligned so the em dashes line up */
}

.chev {
  width: 11px; height: 11px; position: relative; flex: none; align-self: center;
}
.chev::before, .chev::after {
  content: ""; position: absolute; background: var(--fg-3);
  transition: transform .3s var(--ease), background-color .2s var(--ease);
}
.chev::before { left: 0; right: 0; top: 5px; height: 1px; }
.chev::after  { top: 0; bottom: 0; left: 5px; width: 1px; }
.item[open] .chev::after { transform: scaleY(0); }
.item[open] .chev::before { background: var(--accent); }
.item > summary:hover .chev::before,
.item > summary:hover .chev::after { background: var(--accent); }

.item-body { overflow: hidden; }
.item-inner {
  padding: .1rem 0 1.5rem;
  max-width: 62ch;
  color: var(--fg-2);
  font-size: .95rem;
}
.item-inner p:last-child { margin-bottom: 0; }
.item-inner b { color: var(--fg); font-weight: 500; }
.item-inner ul { list-style: none; margin: 0 0 1.2rem; }
.item-inner li {
  position: relative; padding-left: 1.15rem; margin-bottom: .55rem; line-height: 1.6;
}
.item-inner li::before {
  content: ""; position: absolute; left: 0; top: .68em;
  width: 5px; height: 1px; background: var(--fg-3);
}
.item-inner a {
  color: var(--fg); border-bottom: 1px solid var(--line);
  transition: color .2s var(--ease), border-color .2s var(--ease);
}
.item-inner a:hover { color: var(--accent); border-color: var(--accent); }

.tags { display: flex; flex-wrap: wrap; gap: .4rem; margin: 1.25rem 0 0; }
.tags span {
  font-family: var(--mono); font-size: .67rem; letter-spacing: .02em;
  color: var(--fg-3); border: 1px solid var(--line);
  border-radius: 999px; padding: .22rem .6rem;
}

/* ---------- research ids ---------- */
.ids {
  list-style: none; margin-top: 1.6rem;
  display: flex; flex-wrap: wrap; gap: .8rem 2.2rem;
}
.ids li { font-family: var(--mono); font-size: .68rem; }
.ids span { display: block; color: var(--fg-3); margin-bottom: .15rem; }
.ids a { color: var(--fg-2); border-bottom: 1px solid var(--line); }
.ids a:hover { color: var(--accent); border-color: var(--accent); }


/* ---------- skills ---------- */
.skills {
  font-family: var(--mono); font-size: .78rem; line-height: 2;
  color: var(--fg-2); max-width: 62ch; margin-bottom: .6rem;
}
.skills.muted { color: var(--fg-3); }


/* ---------- contact ---------- */
.contact-lead {
  font-family: var(--sans); font-weight: 500;
  font-size: clamp(1.1rem, 1.9vw, 1.35rem);
  line-height: 1.45; letter-spacing: -.015em; color: var(--fg);
  max-width: 46ch; margin-bottom: 0;
}
.contact-lead a { border-bottom: 1px solid var(--accent); color: var(--accent); }

.note {
  font-family: var(--mono); font-size: .72rem; color: var(--fg-3); margin: 1.1rem 0 0;
}

/* ---------- footer ---------- */
.footer {
  max-width: var(--max); margin: 0 auto;
  padding: 2rem var(--gut) 3rem;
  border-top: 1px solid var(--line-soft);
  display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  font-family: var(--mono); font-size: .72rem; color: var(--fg-3);
}
.footer p { margin: 0; }
.footer a:hover { color: var(--accent); }

/* ---------- reveal on scroll ---------- */
.js .reveal { opacity: 0; transform: translateY(14px); }
.js .reveal.is-in {
  opacity: 1; transform: none;
  transition: opacity .7s var(--ease), transform .7s var(--ease);
}
@media (prefers-reduced-motion: reduce) {
  .js .reveal { opacity: 1; transform: none; transition: none; }
}

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .section { grid-template-columns: 1fr; gap: 1.5rem 0; }
  .label { position: static; }
  .hero-grid { grid-template-columns: minmax(0, 1fr) 120px; gap: 1.75rem; }
  .facts { grid-template-columns: 1fr; gap: 1.5rem; }
}

@media (max-width: 620px) {
  .nav { display: none; }
  .hero-grid { grid-template-columns: 1fr; }
  .hero-portrait { order: -1; width: 96px; }
  .hero-portrait img { border-radius: 10px; }
  /* the two roles get a line each instead of an ugly single-word wrap */
  .kicker span { display: block; }
  .kicker .sep { display: none; }

  .item > summary {
    flex-wrap: wrap; position: relative;
    padding-right: 22px; column-gap: .75rem; row-gap: .2rem;
  }
  .item-head  { flex: 1 1 100%; }
  .item-title { flex: 1 1 100%; }
  .item-year  { flex: 1 1 100%; margin-left: 0; width: auto; }
  .chev { position: absolute; right: 0; top: 1.05rem; }
}
