/* ============================================================
   Pasha Kalachev — portfolio
   Minimal, typographic, animated canvas backdrop.
   ============================================================ */

:root {
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "IBM Plex Mono", "SF Mono", Menlo, monospace;
  --font-body: var(--font-sans);

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --frame: clamp(42px, 6vw, 76px);
  --page-pad: calc(var(--frame) + clamp(20px, 3vw, 40px));
}

html[data-theme="dark"] {
  --bg: #0c0d10;
  --fg: #eceae4;
  --fg-dim: rgba(236, 234, 228, 0.45);
  --line: rgba(236, 234, 228, 0.14);
  --accent: #8ea8ff;
  --dot: #97968f;
}

html[data-theme="light"] {
  --bg: #eeece8;
  --fg: #171716;
  --fg-dim: rgba(23, 23, 22, 0.45);
  --line: rgba(23, 23, 22, 0.16);
  --accent: #3f51b5;
  --dot: #62625c;
}

html[data-theme="mono"] {
  --bg: #0a0c0a;
  --fg: #d8ddd6;
  --fg-dim: rgba(216, 221, 214, 0.45);
  --line: rgba(216, 221, 214, 0.14);
  --accent: #7fd99a;
  --dot: #8b9089;
  --font-body: var(--font-mono);
}

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

html, body { height: 100%; }

body {
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  font-weight: 400;
  color: var(--fg);
  background: var(--bg);
  transition: background 0.6s var(--ease-out), color 0.6s var(--ease-out);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--fg);
  text-decoration: none;
}

::selection { background: var(--fg); color: var(--bg); }

/* ---------- background canvas ---------- */

/* the backdrop lives inside the frame; the gutters stay clean */
#bg {
  position: fixed;
  inset: var(--frame);
  z-index: 0;
  pointer-events: none;
}

/* the hairline frame around the viewport. The outward shadow paints the
   gutters solid, so scrolling content is clipped at the border instead of
   drifting through it — the frame reads as a window, not an overlay. */
.frame {
  position: fixed;
  inset: var(--frame);
  border: 1px solid var(--line);
  box-shadow: 0 0 0 100vmax var(--bg);
  pointer-events: none;
  z-index: 20;
  transition: border-color 0.6s var(--ease-out), box-shadow 0.6s var(--ease-out);
}
/* ---------- underline hover (shared) ---------- */

.u, .site-nav a, .home-links a, .contact-socials a, .project-links a, .wordmark {
  position: relative;
  display: inline-block;
}

.site-nav a::after,
.home-links a::after,
.contact-socials a::after,
.project-links a::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -2px;
  width: 100%;
  height: 1px;
  background: currentColor;
  transform: scaleX(0);
  transform-origin: right center;
  transition: transform 0.5s var(--ease-out);
}

.site-nav a:hover::after,
.site-nav a[aria-current="page"]::after,
.home-links a:hover::after,
.contact-socials a:hover::after,
.project-links a:hover::after {
  transform: scaleX(1);
  transform-origin: left center;
}

/* ---------- header ---------- */

.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--frame) + clamp(16px, 2vw, 26px)) var(--page-pad);
}

/* scrolling content dissolves before it reaches the nav — solid through
   the wordmark's own line, then fading out over the padding below it, so
   the type never collides with type. Only present once the page is
   scrolled; at rest it would crop the top of the dot field for nothing. */
.site-header::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.35s var(--ease-out);
  background: linear-gradient(
    to bottom,
    var(--bg) 0,
    var(--bg) calc(var(--frame) + clamp(16px, 2vw, 26px) + 1.6em),
    transparent 100%
  );
}

html[data-scrolled] .site-header::before { opacity: 1; }

.wordmark {
  font-weight: 500;
  letter-spacing: 0.01em;
}

.site-nav {
  display: flex;
  gap: clamp(16px, 2.5vw, 32px);
}

.site-nav a {
  color: var(--fg-dim);
  transition: color 0.4s var(--ease-out);
}

.site-nav a:hover,
.site-nav a[aria-current="page"] {
  color: var(--fg);
}

/* ---------- pages ---------- */

main {
  position: relative;
  z-index: 1;
}

.page {
  min-height: 100vh;
  min-height: 100svh;
  padding: calc(var(--page-pad) + 64px) var(--page-pad) calc(var(--page-pad) + 64px);
  display: none;
  flex-direction: column;
  justify-content: center;
}

.page.is-active { display: flex; }

/* enter animation */
.page > * {
  opacity: 0;
  transform: translateY(24px);
}

.page.is-entering > * {
  animation: page-in 0.9s var(--ease-out) forwards;
}

.page.is-entering > *:nth-child(1) { animation-delay: 0.05s; }
.page.is-entering > *:nth-child(2) { animation-delay: 0.15s; }
.page.is-entering > *:nth-child(3) { animation-delay: 0.25s; }

.page.is-shown > * { opacity: 1; transform: none; }

@keyframes page-in {
  to { opacity: 1; transform: none; }
}

.page-title {
  font-size: 13px;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--fg-dim);
  margin-bottom: clamp(28px, 5vh, 56px);
}

/* ---------- home ---------- */

.home-hero {
  max-width: 900px;
}

.home-title {
  font-size: clamp(44px, 9vw, 108px);
  line-height: 1.02;
  font-weight: 400;
  letter-spacing: -0.02em;
  margin-bottom: clamp(20px, 4vh, 40px);
}

.home-title .line {
  display: block;
  overflow: hidden;
}

.home-title .line > span {
  display: inline-block;
}

.page.is-entering .home-title .line > span {
  transform: translateY(110%);
  animation: rise 1s var(--ease-out) forwards;
}

.page.is-entering .home-title .line:nth-child(2) > span { animation-delay: 0.08s; }

@keyframes rise {
  to { transform: translateY(0); }
}

.home-sub {
  color: var(--fg-dim);
  margin-bottom: clamp(24px, 4vh, 40px);
}

.home-links {
  display: flex;
  gap: 28px;
}

/* ---------- projects ---------- */

.project-list {
  list-style: none;
  max-width: 760px;
  width: 100%;
}

.project-list li {
  border-top: 1px solid var(--line);
}

.project-list li:last-child {
  border-bottom: 1px solid var(--line);
}

.project {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: baseline;
  gap: 24px;
  width: 100%;
  padding: 18px 0;
  border: 0;
  background: none;
  color: var(--fg);
  font: inherit;
  line-height: inherit;
  text-align: left;
  cursor: pointer;
  transition: padding-left 0.5s var(--ease-out), opacity 0.4s var(--ease-out);
}

.project-name {
  font-size: clamp(17px, 2.2vw, 22px);
}

.project-meta {
  color: var(--fg-dim);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.project-year {
  color: var(--fg-dim);
  font-variant-numeric: tabular-nums;
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.project-year::after {
  content: "+";
  width: 12px;
  font-size: 16px;
  line-height: 1;
  text-align: center;
  transform-origin: center;
  transition: transform 0.45s var(--ease-out), color 0.4s var(--ease-out);
}

.project[aria-expanded="true"] .project-year::after {
  color: var(--fg);
  transform: rotate(45deg);
}

.project-detail {
  display: grid;
  grid-template-rows: 0fr;
  opacity: 0;
  transition: grid-template-rows 0.65s var(--ease-out), opacity 0.4s var(--ease-out);
}

.project-detail.is-open {
  grid-template-rows: 1fr;
  opacity: 1;
}

.project-detail-inner {
  overflow: hidden;
}

.project-detail p {
  max-width: 680px;
  padding: 0 0 24px;
  color: var(--fg);
  line-height: 1.65;
  opacity: 0.62;
}

.project-detail .project-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  padding: 0 0 26px;
  margin-top: -8px;
  opacity: 1;
  font-size: 14px;
}

/* dim siblings, indent hovered row */
@media (hover: hover) and (pointer: fine) {
  .project-list:hover .project { opacity: 0.35; }
  .project-list:hover .project:hover { opacity: 1; padding-left: 16px; }
}

@media (max-width: 600px) {
  .project { grid-template-columns: 1fr auto; }
  .project-meta { display: none; }
  .project-detail p { padding-bottom: 20px; }
}

/* ---------- info ---------- */

.info-body { max-width: 760px; }

.info-lead {
  font-size: clamp(19px, 2.6vw, 26px);
  line-height: 1.5;
  letter-spacing: -0.01em;
  margin-bottom: clamp(36px, 6vh, 64px);
}

.info-cols {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 32px;
}

.info-col h3 {
  font-size: 12px;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--fg-dim);
  margin-bottom: 14px;
}

.info-col ul { list-style: none; }
.info-col li { padding: 3px 0; }

.info-stack { margin-top: clamp(36px, 6vh, 64px); }

.info-stack h3 {
  font-size: 12px;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--fg-dim);
  margin-bottom: 14px;
}

.info-stack p { line-height: 1.7; }

/* ---------- contact ---------- */

.contact-body { max-width: 760px; }

.contact-lead {
  font-size: clamp(19px, 2.6vw, 26px);
  line-height: 1.5;
  letter-spacing: -0.01em;
  margin-bottom: clamp(24px, 4vh, 40px);
}

.contact-email {
  display: inline-block;
  font-size: clamp(22px, 4vw, 40px);
  letter-spacing: -0.01em;
  border-bottom: 1px solid var(--line);
  padding-bottom: 4px;
  margin-bottom: clamp(32px, 5vh, 56px);
  transition: border-color 0.4s var(--ease-out);
}

.contact-email:hover { border-color: var(--fg); }

.contact-socials {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  color: var(--fg-dim);
}

.contact-socials a {
  color: var(--fg-dim);
  transition: color 0.4s var(--ease-out);
}

.contact-socials a:hover { color: var(--fg); }

/* ---------- footer ---------- */

/* bottom gutter, outside the frame — above the frame's gutter fill */
.site-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--frame);
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--frame);
  pointer-events: none;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--fg-dim);
}

.site-footer > * { pointer-events: auto; }

/* left gutter, outside the frame, reading bottom-to-top */
.theme-switch {
  position: fixed;
  left: calc((var(--frame) - 15px) / 2);
  bottom: var(--frame);
  transform: rotate(-90deg);
  transform-origin: top left;
  display: flex;
  gap: 28px;
  white-space: nowrap;
  z-index: 30;
}

.theme-switch button {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  color: var(--fg-dim);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  transition: color 0.4s var(--ease-out);
}

/* the little checkbox square */
.theme-switch button::before {
  content: "";
  width: 7px;
  height: 7px;
  border: 1px solid currentColor;
  transition: background 0.3s var(--ease-out);
}

.theme-switch button:hover,
.theme-switch button.is-active {
  color: var(--fg);
}

.theme-switch button.is-active::before {
  background: currentColor;
}

.local-time {
  font-variant-numeric: tabular-nums;
}

/* ---------- mobile composition ---------- */

@media (max-width: 720px) {
  :root {
    --frame: 30px;
    --page-pad: calc(var(--frame) + 12px);
  }

  .site-header {
    display: grid;
    grid-template-columns: 1fr;
    align-items: start;
    gap: 14px;
    padding: calc(var(--frame) + 15px) var(--page-pad) 0;
  }

  .site-header::before {
    background: linear-gradient(
      to bottom,
      var(--bg) 0,
      var(--bg) calc(var(--frame) + 76px),
      transparent 100%
    );
  }

  .wordmark {
    width: max-content;
    max-width: 100%;
    font-size: 14px;
    line-height: 1.25;
    white-space: nowrap;
  }

  .site-nav {
    display: grid;
    grid-template-columns: repeat(4, auto);
    justify-content: space-between;
    width: 100%;
    gap: 8px;
    font-size: 13px;
    line-height: 1.2;
  }

  .site-nav a { white-space: nowrap; }

  .page {
    padding: 132px var(--page-pad) 76px;
  }

  .home-title {
    font-size: clamp(46px, 15vw, 64px);
    margin-bottom: 28px;
  }

  .home-sub {
    margin-bottom: 30px;
    line-height: 1.55;
  }

  .home-links {
    justify-content: space-between;
    gap: 16px;
  }

  .page-title { margin-bottom: 28px; }

  .contact-email {
    max-width: 100%;
    font-size: clamp(18px, 5.3vw, 24px);
    overflow-wrap: anywhere;
  }

  .site-footer {
    height: var(--frame);
    padding: 0 calc(var(--frame) + 2px);
    font-size: 8px;
    letter-spacing: 0.04em;
  }
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .page > *,
  .page.is-entering > *,
  .page.is-entering .home-title .line > span,
  .project-detail,
  .project-year::after {
    animation: none !important;
    transition: none !important;
    opacity: 1 !important;
    transform: none !important;
  }
}
