/* =========================================================
   ALEKSANDR KOVYNEV — Portfolio
   Style: zheeshee-inspired minimal + glassmorphism accents
   ========================================================= */

:root {
  --bg: #ffffff;
  --bg-soft: #f5f5f5;
  --ink: #0a0a0a;
  --ink-soft: #6b6b6b;
  --line: #ececec;
  --accent: #ff4a1c;
  --surface: #ffffff;

  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;

  --radius: 18px;
  --ease: cubic-bezier(0.7, 0, 0.2, 1);
}

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

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  touch-action: pan-x pan-y; /* allow scroll, block pinch-zoom */
}

a { color: inherit; text-decoration: none; }

img, svg { display: block; max-width: 100%; }

i { font-style: italic; font-family: "Inter", serif; }

/* ---------- NAV ---------- */
.nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 24px 32px;
  z-index: 100;
  font-family: var(--font-mono);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  mix-blend-mode: difference;
  color: #fff;
}
.nav__logo { font-weight: 600; font-size: 14px; }
.nav__logo span { font-size: 10px; vertical-align: super; margin-left: 2px; opacity: 0.6; }
.nav__menu { display: flex; gap: 28px; justify-self: center; }
.nav__menu a { position: relative; padding: 4px 0; }
.nav__menu a::after {
  content: ""; position: absolute; left: 0; bottom: 0;
  height: 1px; width: 0; background: currentColor;
  transition: width 0.4s var(--ease);
}
.nav__menu a:hover::after { width: 100%; }
.nav__status { justify-self: end; display: flex; align-items: center; gap: 8px; }
.dot {
  display: inline-block; width: 8px; height: 8px;
  background: #4ade80; border-radius: 50%;
  box-shadow: 0 0 8px #4ade80; animation: pulse 2s infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ---------- HERO ---------- */
.hero {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh; /* respects iOS Safari URL bar height */
  padding: 120px 32px 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
}

.hero__title h1 {
  font-size: clamp(60px, 14vw, 220px);
  line-height: 0.88;
  font-weight: 700;
  letter-spacing: -0.04em;
}
.hero__title .line { display: block; }
.hero__title .italic { font-style: italic; font-weight: 300; }

.hero__meta {
  position: absolute;
  top: 120px;
  right: 32px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  text-align: right;
  font-family: var(--font-mono);
}
.meta-block { display: flex; flex-direction: column; gap: 4px; }
.meta-label {
  font-size: 10px; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--ink-soft);
}
.meta-value { font-size: 13px; line-height: 1.3; color: var(--ink); }

/* Character */
.character-wrap {
  position: relative; width: 100%;
  margin-top: auto;
  display: flex; justify-content: center; align-items: flex-end;
  cursor: pointer;
  user-select: none;
}
#character {
  width: 100%;
  max-width: 1400px;
  height: auto;
  transition: transform 0.25s var(--ease);
}
.character-wrap:hover #character { transform: scale(1.03); }

/* Face state transitions */
.face-base { transition: fill 0.4s ease; }
.mouth-happy, .mouth-angry, .brows-angry { transition: opacity 0.2s ease; }
.mouth-angry, .brows-angry { opacity: 0; }

/* Angry state: red face, frown shows, brows show, smile hides */
#character.is-angry .face-base { fill: #ff4040; }
#character.is-angry .mouth-happy { opacity: 0; }
#character.is-angry .mouth-angry { opacity: 1; }
#character.is-angry .brows-angry { opacity: 1; }

/* Click shake */
@keyframes char-shake {
  0%, 100% { transform: translateX(0) rotate(0); }
  20% { transform: translateX(-6px) rotate(-1.2deg); }
  60% { transform: translateX(6px) rotate(1.2deg); }
  80% { transform: translateX(-3px) rotate(-0.4deg); }
}
#character.is-shaking { animation: char-shake 0.28s ease; }
.character-wrap:hover #character.is-shaking { /* override hover scale during shake */
  transform: none;
  animation: char-shake 0.28s ease;
}

/* "ПРАВКИ" popup */
.edit-pop {
  position: fixed;
  pointer-events: none;
  z-index: 9000;
  font-family: var(--font-mono);
  font-size: clamp(20px, 2.4vw, 36px);
  font-weight: 700;
  color: #ff2020;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  text-shadow: 0 4px 20px rgba(255, 32, 32, 0.4);
  transform: translate(-50%, -50%);
  animation: edit-pop 1.1s var(--ease) forwards;
}
@keyframes edit-pop {
  0%   { opacity: 0; transform: translate(-50%, 10px) scale(0.4) rotate(var(--rot, 0deg)); }
  18%  { opacity: 1; transform: translate(-50%, -12px) scale(1.15) rotate(var(--rot, 0deg)); }
  35%  { transform: translate(-50%, -32px) scale(1) rotate(var(--rot, 0deg)); }
  100% { opacity: 0; transform: translate(-50%, -120px) scale(0.85) rotate(var(--rot, 0deg)); }
}

/* Marquee */
.marquee {
  width: 100%;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  overflow: hidden;
  padding: 18px 0;
  margin-top: 32px;
}
.marquee__track {
  display: flex;
  gap: 40px;
  white-space: nowrap;
  animation: scroll 50s linear infinite;
  font-family: var(--font-mono);
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
}
.marquee__track span:nth-child(odd) { color: var(--ink); font-weight: 500; }
@keyframes scroll { to { transform: translateX(-50%); } }

/* ---------- SECTION HEAD ---------- */
.section-head {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  padding: 0 32px;
  margin-bottom: 60px;
}
.section-num {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.section-head h2 {
  grid-column: 1 / -1;
  margin-top: 16px;
  font-size: clamp(48px, 9vw, 140px);
  font-weight: 700;
  line-height: 0.9;
  letter-spacing: -0.04em;
}
.section-head h2 i { font-weight: 300; }

/* ---------- WORK GRID ---------- */
.work { padding: 100px 0 80px; }

/* Wrapper holds both the grid and the password overlay */
.work__wrapper {
  position: relative;
}

.work__grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  padding: 0 32px;
  transition: filter 0.8s var(--ease);
}
/* Locked state: heavy blur + desaturate + no clicks */
.work__grid--locked {
  filter: blur(18px) saturate(0.3) brightness(0.85);
  pointer-events: none;
  user-select: none;
}

/* ---------- PASSWORD OVERLAY (glass card) ---------- */
.pw-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  transition: opacity 0.6s var(--ease), visibility 0.6s;
}
.pw-overlay.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* Glass card */
.pw-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 44px 48px 40px;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.45);
  backdrop-filter: blur(24px) saturate(1.6);
  -webkit-backdrop-filter: blur(24px) saturate(1.6);
  border: 1px solid rgba(255, 255, 255, 0.6);
  box-shadow:
    0 8px 40px rgba(0, 0, 0, 0.08),
    0 1.5px 0 rgba(255, 255, 255, 0.7) inset;
  min-width: 320px;
  animation: pw-float 0.5s var(--ease) both;
}
@keyframes pw-float {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.pw-icon {
  width: 52px; height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  color: var(--ink);
  margin-bottom: 4px;
}

.pw-title {
  font-family: var(--font-sans);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.pw-hint {
  font-size: 13px;
  color: var(--ink-soft);
  font-weight: 400;
  margin-bottom: 4px;
}

/* Input + button row */
.pw-field {
  display: flex;
  gap: 8px;
  width: 100%;
}

.pw-input {
  flex: 1;
  height: 44px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  background: rgba(255, 255, 255, 0.7);
  font-family: var(--font-mono);
  font-size: 15px;
  letter-spacing: 2px;
  color: var(--ink);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.pw-input:focus {
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(10, 10, 10, 0.06);
}
.pw-input.is-error {
  border-color: #e74c3c;
  box-shadow: 0 0 0 3px rgba(231, 76, 60, 0.1);
  animation: pw-shake 0.4s ease;
}

.pw-btn {
  width: 44px; height: 44px;
  flex-shrink: 0;
  border-radius: 12px;
  border: none;
  background: var(--ink);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.15s;
}
.pw-btn:hover {
  background: #333;
  transform: scale(1.05);
}
.pw-btn:active {
  transform: scale(0.96);
}

.pw-error {
  font-size: 12px;
  color: #e74c3c;
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.25s;
  height: 16px;
}
.pw-error.is-visible {
  opacity: 1;
}

@keyframes pw-shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-8px); }
  40%      { transform: translateX(8px); }
  60%      { transform: translateX(-5px); }
  80%      { transform: translateX(5px); }
}

/* Unlock animation on cards */
@keyframes card-reveal {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.work__grid--unlocked .card {
  animation: card-reveal 0.6s var(--ease) both;
}
.work__grid--unlocked .card:nth-child(2) { animation-delay: 0.08s; }
.work__grid--unlocked .card:nth-child(3) { animation-delay: 0.16s; }
.work__grid--unlocked .card:nth-child(4) { animation-delay: 0.24s; }
.work__grid--unlocked .card:nth-child(5) { animation-delay: 0.32s; }
.work__grid--unlocked .card:nth-child(6) { animation-delay: 0.40s; }

@media (max-width: 600px) {
  .pw-card {
    min-width: unset;
    width: calc(100% - 40px);
    padding: 32px 24px 28px;
  }
}
.card { display: block; position: relative; }
.card--lg { grid-column: span 2; }

.card__media {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #1a1a1a;
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform 0.6s var(--ease);
  isolation: isolate;
}

.card__media img,
.card__media video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.8s var(--ease), filter 0.5s var(--ease), opacity 0.35s ease;
  display: block;
}
.card__media img { z-index: 1; }
.card__media video {
  z-index: 2;
  opacity: 0; /* video sits on top, hidden until hover */
}
.card:hover .card__media img,
.card:hover .card__media video {
  transform: scale(1.04);
  filter: brightness(0.85);
}
.card:hover .card__media video { opacity: 1; }

/* dark gradient at bottom for title legibility */
.card__overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  background:
    linear-gradient(to top, rgba(0,0,0,0.55) 0%, rgba(0,0,0,0) 45%),
    linear-gradient(to bottom, rgba(0,0,0,0.25) 0%, rgba(0,0,0,0) 30%);
  pointer-events: none;
}

/* glassmorphism role pill (single — for cards with one role) */
.card__role {
  position: absolute;
  top: 18px;
  left: 18px;
  z-index: 3;
  padding: 9px 16px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 100px;
  box-shadow:
    0 4px 16px rgba(0, 0, 0, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
  white-space: nowrap;
}

/* container for multiple role pills */
.card__roles {
  position: absolute;
  top: 18px;
  left: 18px;
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.card__roles .card__role {
  position: static; /* override absolute */
  top: auto; left: auto;
}

/* external link indicator (top-right) */
.card__external-mark {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 3;
  padding: 9px 14px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.05em;
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 100px;
  box-shadow:
    0 4px 16px rgba(0, 0, 0, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
  white-space: nowrap;
  opacity: 0;
  transform: translateX(8px);
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
}
.card--external:hover .card__external-mark {
  opacity: 1;
  transform: translateX(0);
}

/* hide the ▶ play icon on external (link) cards */
.card--external .card__media::after { display: none; }

.card__title {
  position: absolute;
  left: 20px;
  bottom: 16px;
  z-index: 3;
  color: #fff;
  font-size: clamp(18px, 1.7vw, 26px);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.05;
  text-shadow: 0 2px 24px rgba(0, 0, 0, 0.4);
  max-width: 80%;
}

/* play indicator (glass circle with triangle), shown on hover */
.card__media::after {
  content: "▶";
  position: absolute;
  right: 22px;
  bottom: 18px;
  z-index: 3;
  width: 56px; height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #fff;
  background: rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 50%;
  box-shadow:
    0 4px 18px rgba(0, 0, 0, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
  transform: scale(0.9);
  opacity: 0;
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
  pointer-events: none;
  padding-left: 4px; /* visual centering of triangle */
}
.card:hover .card__media::after {
  opacity: 1;
  transform: scale(1);
}

.all-projects {
  display: inline-block;
  margin: 80px 32px 0;
  padding: 18px 32px;
  border: 1px solid var(--ink);
  border-radius: 100px;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.3s var(--ease), color 0.3s var(--ease);
}
.all-projects:hover { background: var(--ink); color: var(--bg); }

/* ---------- ABOUT ---------- */
.about {
  padding: 120px 0;
  border-top: 1px solid var(--line);
}
.about__grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 80px;
  padding: 0 32px;
  align-items: start;
}
.about__main {
  display: flex;
  flex-direction: column;
  gap: 48px;
}
.about__heading {
  font-size: clamp(48px, 9vw, 140px);
  font-weight: 700;
  line-height: 0.9;
  letter-spacing: -0.04em;
}
.about__heading i { font-weight: 300; }
.about__text {
  display: flex; flex-direction: column; gap: 24px;
  font-size: clamp(17px, 1.4vw, 20px);
  line-height: 1.55;
  max-width: 560px;
  color: var(--ink-soft);
}
.about__text p { color: var(--ink); }

/* ---------- STACK GLASS PANEL ---------- */
.stack-panel {
  position: sticky;
  top: 100px;
  padding: 36px 32px;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(28px) saturate(180%);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
  border: 1px solid rgba(0, 0, 0, 0.06);
  box-shadow:
    0 14px 40px rgba(0, 0, 0, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.95),
    inset 0 0 0 1px rgba(255, 255, 255, 0.5);
  overflow: hidden;
  isolation: isolate;
}

/* coloured blobs sit BEHIND the glass — give backdrop-filter something to actually blur */
.stack-blob {
  position: absolute;
  z-index: -1;
  filter: blur(50px);
  opacity: 0.55;
  pointer-events: none;
}
.stack-blob--a {
  width: 280px; height: 280px;
  top: -80px; right: -60px;
  background: radial-gradient(closest-side, #ff8a4c, transparent 70%);
}
.stack-blob--b {
  width: 320px; height: 320px;
  bottom: -120px; left: -80px;
  background: radial-gradient(closest-side, #4f8aff, transparent 70%);
}

.stack-section { display: flex; flex-direction: column; gap: 18px; }

.stack-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.07);
}
.stack-label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.stack-count {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  color: rgba(10, 10, 10, 0.4);
}

.stack-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.stack-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 6px 0;
  transition: transform 0.3s var(--ease);
}
.stack-item:hover {
  transform: translateX(4px);
}
.stack-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

/* image-based icon variant — same square footprint, no gradient padding */
.stack-mark--img {
  background: transparent;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  object-fit: cover;
  /* SVG already has its own rounded corners + bg colour */
  border-radius: 8px;
}
.stack-name {
  font-size: 15px;
  font-weight: 500;
  color: var(--ink);
  letter-spacing: -0.005em;
}

.stack-divider {
  height: 1px;
  margin: 28px 0;
  background: linear-gradient(to right, transparent, rgba(0, 0, 0, 0.1), transparent);
}

/* ---------- CONTACT ---------- */
.contact {
  padding: 120px 32px;
  border-top: 1px solid var(--line);
  text-align: center;
}
.contact__cta {
  display: inline-block;
  font-size: clamp(56px, 12vw, 180px);
  font-weight: 700;
  line-height: 0.9;
  letter-spacing: -0.04em;
  margin: 40px 0;
  transition: color 0.3s var(--ease);
}
.contact__cta:hover { color: var(--accent); }
.contact__cta i { font-weight: 300; }
.contact__links {
  display: flex; justify-content: center; gap: 32px;
  flex-wrap: wrap; margin-top: 40px;
  font-family: var(--font-mono); font-size: 13px;
}
.contact__links a {
  position: relative; padding-bottom: 2px;
  border-bottom: 1px solid currentColor;
}

/* ---------- FOOTER ---------- */
.footer {
  display: flex; justify-content: space-between;
  padding: 24px 32px;
  border-top: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--ink-soft);
}

/* ---------- LIGHTBOX ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 10, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.35s var(--ease), visibility 0.35s var(--ease);
}
.lightbox.is-open { opacity: 1; visibility: visible; }
.lightbox__close {
  position: absolute;
  top: 24px; right: 32px;
  background: none; border: none;
  color: #fff;
  font-size: 40px;
  line-height: 1;
  cursor: none;
  z-index: 2;
}
.lightbox__frame {
  position: relative;
  width: min(92vw, 1280px);
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 14px;
  overflow: hidden;
  transform: scale(0.96);
  transition: transform 0.35s var(--ease);
}
.lightbox.is-open .lightbox__frame { transform: scale(1); }
.lightbox__frame iframe,
.lightbox__frame video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
}

/* ---------- BREAKDOWNS ---------- */
.breakdowns {
  padding: 100px 0 80px;
  border-top: 1px solid var(--line);
}

/* ---------- BALLOON TITLE (per-letter PNGs) ---------- */
.balloon-title {
  position: relative;
  grid-column: 1 / -1;
  margin-top: 16px;
  display: flex;
  flex-wrap: nowrap;
  align-items: flex-end;
  justify-content: flex-start;
  gap: clamp(2px, 0.4vw, 8px);
  font-size: 0;
  line-height: 0;
  letter-spacing: 0;
  filter: drop-shadow(0 30px 36px rgba(0, 0, 0, 0.22));
  overflow: visible;
  padding: 30px 0 10px;
}

.bal-letter {
  display: block;
  /* Canvases are uniform (~1000px sq) — per-letter sizing baked into PNGs */
  height: clamp(90px, 14vw, 200px);
  width: auto;
  cursor: pointer;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: auto;
  transform-origin: center 85%;
  will-change: transform;
}

/* Forced wrap point between "Break" and "Downs" — visible only on small screens */
.bal-break { display: none; }

/* "Released balloon" — floats up, drifts sideways, settles */
@keyframes bal-fly {
  0%   { transform: translate(0, 0) rotate(0deg) scale(1, 1); }
  18%  { transform: translate(calc(var(--dx, 0) * 0.6px), -12px) rotate(calc(var(--rot, 3) * 0.6deg)) scale(1.04, 0.97); }
  38%  { transform: translate(calc(var(--dx, 0) * 1px), -24px)   rotate(calc(var(--rot, 3) * -0.5deg)) scale(0.96, 1.06); }
  58%  { transform: translate(calc(var(--dx, 0) * 0.7px), -14px) rotate(calc(var(--rot, 3) * 0.35deg)) scale(1.02, 0.98); }
  78%  { transform: translate(calc(var(--dx, 0) * 0.3px), -5px)  rotate(calc(var(--rot, 3) * -0.1deg)) scale(1, 1); }
  100% { transform: translate(0, 0) rotate(0deg) scale(1, 1); }
}

/* Smaller, softer wobble for neighbouring letters */
@keyframes bal-fly-sm {
  0%   { transform: translate(0, 0) rotate(0deg) scale(1, 1); }
  30%  { transform: translate(0, -10px) rotate(calc(var(--rot, 1) * 0.5deg)) scale(1.02, 0.98); }
  60%  { transform: translate(0, -4px)  rotate(calc(var(--rot, 1) * -0.2deg)) scale(1, 1); }
  100% { transform: translate(0, 0)     rotate(0deg) scale(1, 1); }
}

.bal-letter.is-flying    { animation: bal-fly 1.1s cubic-bezier(0.34, 1.4, 0.64, 1) forwards; }
.bal-letter.is-flying-sm { animation: bal-fly-sm 0.75s cubic-bezier(0.34, 1.4, 0.64, 1) forwards; }

.bd-trigger {
  display: flex;
  justify-content: center;
  padding: 0 32px;
}
.bd-trigger.is-hidden { display: none; }

.bd-btn {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 20px 40px;
  border: none;
  border-radius: 100px;
  background: var(--ink);
  color: #fff;
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: transform 0.3s var(--ease), box-shadow 0.3s var(--ease), background 0.3s var(--ease);
}
.bd-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(10, 10, 10, 0.25);
  background: #222;
}
.bd-btn:active {
  transform: translateY(0) scale(0.97);
}
.bd-btn__arrow {
  transition: transform 0.3s var(--ease);
}
.bd-btn:hover .bd-btn__arrow {
  transform: translateX(4px);
}

/* Breakdowns grid */
.bd-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  padding: 0 32px;
}
.bd-grid.is-hidden { display: none; }

/* Breakdown cards reuse .card styles from the work grid */
.card__title--code {
  font-family: var(--font-mono);
  font-size: clamp(11px, 0.95vw, 14px);
  font-weight: 500;
  letter-spacing: -0.005em;
  word-break: break-all;
  max-width: 88%;
}

/* ---------- BREAKDOWNS LOADER ---------- */
.bd-loading {
  position: fixed;
  inset: 0;
  z-index: 9500;
  background: #0a0a0a;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.5s var(--ease), visibility 0.5s;
}
.bd-loading.is-active {
  opacity: 1;
  visibility: visible;
}
.bd-loading.is-done {
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.6s var(--ease) 0.1s, visibility 0.6s 0.1s;
}

.bd-loading__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  width: min(400px, 80vw);
}

.bd-loading__icon {
  width: 88px;
  height: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.bd-loading__icon svg {
  width: 100%;
  height: 100%;
  animation: bd-icon-float 2.5s ease-in-out infinite;
}
@keyframes bd-icon-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.bd-loading__pct {
  font-family: var(--font-mono);
  font-size: 42px;
  font-weight: 700;
  color: #fff;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  letter-spacing: -0.02em;
}

.bd-loading__track {
  width: 100%;
  height: 3px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 2px;
  overflow: hidden;
}

.bd-loading__fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ff4a1c, #ff8a4c);
  border-radius: 2px;
  transition: width 0.08s linear;
  box-shadow: 0 0 20px rgba(255, 74, 28, 0.5);
}

.bd-loading__msg {
  font-family: var(--font-mono);
  font-size: 13px;
  color: rgba(255, 255, 255, 0.4);
  text-transform: lowercase;
  letter-spacing: 0.04em;
  text-align: center;
  transition: opacity 0.3s ease;
  min-height: 20px;
}

/* Breakdowns responsive */
@media (max-width: 1100px) {
  .bd-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 900px) {
  .breakdowns { padding: 80px 0; }
  .bd-trigger { padding: 0 20px; }
  .bd-grid { grid-template-columns: 1fr; padding: 0 20px; }
  .bd-loading__pct { font-size: 32px; }
  .bd-loading__icon { width: 72px; height: 72px; }
}

/* ---------- RESPONSIVE ---------- */
@media (max-width: 1100px) {
  .work__grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px) {
  .nav { padding: 16px 20px; grid-template-columns: 1fr 1fr; }
  .nav__menu { display: none; }
  .nav__status { font-size: 10px; }
  .hero { padding: 100px 20px 0; }
  .hero__meta {
    position: static; align-items: flex-start; text-align: left;
    margin-top: 32px; flex-direction: row; flex-wrap: wrap; gap: 24px 40px;
  }
  .work { padding: 80px 0; }
  .work__grid { grid-template-columns: 1fr; padding: 0 20px; gap: 16px; }
  .card__media { aspect-ratio: 16 / 9; }
  .section-head { padding: 0 20px; }
  .about { padding: 80px 0; }
  .about__grid { grid-template-columns: 1fr; gap: 48px; padding: 0 20px; }
  .about__main { gap: 32px; }
  .stack-panel { position: static; padding: 28px 24px; }
  .contact { padding: 80px 20px; }
  .footer { flex-direction: column; gap: 8px; padding: 20px; text-align: center; }
  .lightbox__close { top: 16px; right: 20px; }
}

/* ---------- TABLET (≤ 700) — wrap "BreakDowns" to two lines ---------- */
@media (max-width: 700px) {
  .balloon-title {
    flex-wrap: wrap;
    justify-content: flex-start;
    row-gap: 6px;
    column-gap: 2px;
  }
  .bal-break {
    display: block;
    flex-basis: 100%;
    width: 100%;
    height: 0;
    pointer-events: none;
  }
  .bal-letter {
    height: clamp(56px, 16vw, 140px);
  }
}

/* ---------- MOBILE PHONES (≤ 600) — tight layout, big tap targets ---------- */
@media (max-width: 600px) {
  .nav {
    padding: 14px 18px;
    grid-template-columns: auto 1fr;
    gap: 12px;
  }
  .nav__logo { font-size: 13px; }
  .nav__status { font-size: 10px; gap: 6px; }

  /* Hero */
  .hero {
    padding: 86px 18px 24px;
  }
  .hero__title h1 {
    font-size: clamp(52px, 17vw, 90px);
  }
  .hero__meta {
    flex-direction: column;
    gap: 14px;
    margin-top: 26px;
  }
  .meta-value { font-size: 12px; }
  #character {
    max-width: 320px;
    margin: 0 auto;
  }

  /* Section heads */
  .section-head {
    padding: 0 18px;
    margin-bottom: 32px;
  }
  .section-head h2 {
    font-size: clamp(40px, 13vw, 80px);
    margin-top: 10px;
  }
  .section-num { font-size: 10px; }

  /* Work + breakdown grids */
  .work { padding: 64px 0; }
  .work__grid { padding: 0 18px; gap: 12px; }
  .breakdowns { padding: 64px 0; }
  .bd-grid { padding: 0 18px; gap: 12px; }

  /* Cards — tighter chrome */
  .card__title {
    font-size: clamp(16px, 4.6vw, 22px);
    left: 16px;
    bottom: 14px;
  }
  .card__title--code {
    font-size: clamp(11px, 3.2vw, 14px);
  }
  .card__role {
    font-size: 11px;
    padding: 7px 12px;
    top: 12px;
    left: 12px;
  }
  .card__external-mark {
    font-size: 10px;
    padding: 7px 10px;
    top: 12px;
    right: 12px;
    opacity: 1;
    transform: none;
  }
  .card__media::after {
    width: 44px;
    height: 44px;
    font-size: 13px;
    right: 14px;
    bottom: 14px;
  }

  .all-projects {
    display: block;
    margin: 48px 18px 0;
    padding: 16px 24px;
    font-size: 13px;
    text-align: center;
  }

  /* Breakdown trigger */
  .bd-trigger { padding: 0 18px; }
  .bd-btn {
    width: 100%;
    justify-content: center;
    padding: 18px 28px;
    font-size: 14px;
  }

  /* Loader */
  .bd-loading__inner {
    width: 86vw;
    gap: 18px;
  }
  .bd-loading__icon { width: 64px; height: 64px; }
  .bd-loading__pct { font-size: 28px; }
  .bd-loading__msg { font-size: 12px; }

  /* Balloon title — even smaller on phones */
  .bal-letter {
    height: clamp(48px, 16vw, 100px);
  }

  /* About */
  .about { padding: 72px 0; }
  .about__grid {
    padding: 0 18px;
    gap: 36px;
  }
  .about__heading {
    font-size: clamp(40px, 13vw, 80px);
  }
  .about__text {
    font-size: 15px;
    line-height: 1.55;
  }
  .stack-panel {
    padding: 24px 20px;
    border-radius: 20px;
  }
  .stack-name { font-size: 14px; }

  /* Contact */
  .contact { padding: 72px 18px; }
  .contact__cta {
    font-size: clamp(52px, 17vw, 110px);
    margin: 28px 0;
  }
  .contact__links {
    flex-direction: column;
    gap: 14px;
    margin-top: 28px;
    align-items: center;
  }

  /* Footer */
  .footer { padding: 18px; font-size: 10px; }

  /* Password gate */
  .pw-card {
    min-width: 0;
    width: calc(100vw - 36px);
    padding: 28px 22px 24px;
  }
  .pw-title { font-size: 17px; }
  .pw-hint { font-size: 12px; }
}

/* ---------- VERY NARROW (≤ 380) ---------- */
@media (max-width: 380px) {
  .nav { padding: 12px 14px; }
  .nav__status { font-size: 9px; }
  .hero { padding: 78px 14px 24px; }
  .section-head { padding: 0 14px; }
  .work__grid, .bd-grid { padding: 0 14px; }
  .all-projects { margin: 40px 14px 0; }
  .bal-letter { height: clamp(42px, 16vw, 80px); }
  .contact { padding: 64px 14px; }
}

/* ---------- SAFE-AREA insets for notched phones ---------- */
@supports (padding: max(0px)) {
  .nav {
    padding-left: max(18px, env(safe-area-inset-left));
    padding-right: max(18px, env(safe-area-inset-right));
  }
  .footer {
    padding-bottom: max(18px, env(safe-area-inset-bottom));
  }
}
