:root {
  --bg: #0b0c10;
  --bg-soft: #0f1117;
  --card: #12141c;
  --text: #e8e8ef;
  --muted: #a7a7b4;
  --line: #23262f;
  --brand: #7c5cff;
  --accent: #00e0ff;
  --success: #2de3a0;
  --error: #ff6b6b;
  --error-bg: rgba(255, 77, 79, .12);
  --error-border: rgba(255, 77, 79, .35);
  --shadow: 0 20px 60px rgba(0,0,0,.4);
}

[data-theme="light"] {
  --bg: #f7f7fb;
  --bg-soft: #ffffff;
  --card: #ffffff;
  --text: #171717;
  --muted: #5a5a6b;
  --line: #e8e8ef;
  --brand: #5b34ff;
  /* Adjusted accent for AA contrast on white */
  --accent: #00708a;
  --success: #12b886;
  /* Improve error readability on light backgrounds */
  --error: #9b1c1c;
  --error-bg: #ffe9ea;
  --error-border: #f19999;
}

* { box-sizing: border-box }
html, body { height: 100% }
html { scroll-behavior: smooth }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  color: var(--text);
  background: radial-gradient(1200px 800px at 70% -10%, rgba(124,92,255,.15), transparent 50%), var(--bg);
}

/* Accessibility helpers */
.skip-link { position: absolute; left: -9999px; top: auto; width: 1px; height: 1px; overflow: hidden }
.skip-link:focus { left: 12px; top: 12px; width: auto; height: auto; padding: 10px 12px; background: #fff; color: #111; border-radius: 8px; z-index: 10000 }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px }
a:focus-visible, button:focus-visible { box-shadow: 0 0 0 3px rgba(0,224,255,.35) }

/* Ink underline for text links (tasteful, minimal) */
a[data-hover]:not(.btn):not(.dock__nav a):not(.dock__bar a) {
  background-image: linear-gradient(currentColor, currentColor);
  background-repeat: no-repeat;
  background-size: 0% 1px;
  background-position: 0 100%;
  transition: background-size .25s cubic-bezier(.2,.7,.2,1);
}
a[data-hover]:not(.btn):not(.dock__nav a):not(.dock__bar a):hover {
  background-size: 100% 1px;
}

.noise { position: fixed; inset: -50px; pointer-events: none; z-index: 0; background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="140" height="140" viewBox="0 0 140 140"><filter id="n"><feTurbulence type="fractalNoise" baseFrequency="0.8" numOctaves="4" stitchTiles="stitch"/></filter><rect width="100%" height="100%" filter="url(%23n)" opacity=".035"/></svg>') repeat; mix-blend-mode: soft-light }

#cursor { position: fixed; width: 16px; height: 16px; border-radius: 50%; background: radial-gradient(circle at 30% 30%, var(--accent), var(--brand)); transform: translate(-50%, -50%); pointer-events: none; z-index: 9999; filter: blur(0.2px); opacity: .6 }
@media (pointer: coarse) { #cursor { display: none } }

.dock { position: fixed; z-index: 5; left: 18px; right: 18px; bottom: 18px; height: 72px; border-radius: 16px; background: linear-gradient(180deg, rgba(255,255,255,.08), rgba(255,255,255,.02)); border: 1px solid var(--line); backdrop-filter: blur(12px); box-shadow: var(--shadow); display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 12px; padding: 10px 12px }
.dock__logo { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 12px; background: linear-gradient(135deg, var(--brand), var(--accent)); color: white; font: 800 18px Syne, sans-serif; letter-spacing: .5px; text-decoration: none }
.dock__nav { display: none; gap: 6px; margin-top: 0 }
.dock__bar { display: flex; align-items: center; justify-content: center; gap: 22px }
.dock__bar a { display: inline-grid; place-items: center; width: 48px; height: 48px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255,255,255,.08); color: var(--text) }
.dock__bar a > svg, .dock__bar a > i { width: 22px; height: 22px; line-height: 1 }
.dock__bar a { transform: translate(var(--mx, 0), var(--my, 0)); transition: transform .12s ease }
.dock__bar a:hover { background: rgba(255,255,255,.14) }
.dock__nav a { color: var(--text); text-decoration: none; padding: 8px 10px; border-radius: 10px; transition: background .2s ease }
.dock__nav a:hover { background: rgba(255,255,255,.06) }
.dock__actions { position: fixed; left: 18px; bottom: 18px; display: grid; gap: 10px; z-index: 6 }
.dock__actions a, .dock__actions button { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--text) }
.dock__actions button { cursor: pointer }
.dock__actions .sun { display: none }
[data-theme="light"] .dock__actions .sun { display: inline }
[data-theme="light"] .dock__actions .moon { display: none }

/* Magnetic logo */
.dock__logo { transform: translate(var(--mx, 0), var(--my, 0)); transition: transform .12s ease }

.page { position: relative; z-index: 1; padding-left: 0; padding-bottom: 120px }

.hero { position: relative; min-height: 92svh; display: grid; align-items: center; overflow: clip }
.hero__inner { padding: 8vw 6vw 4vw }
.hero__title { margin: 0 0 18px; font: 800 clamp(36px, 7vw, 96px) Syne, sans-serif; line-height: .95 }
.gradient { display: block; background: linear-gradient(135deg, var(--accent), var(--brand)); -webkit-background-clip: text; background-clip: text; color: transparent; background-size: 200% 200%; background-position: 0% 50%; transition: background-position .8s cubic-bezier(.2,.7,.2,1) }
.gradient:hover { background-position: 100% 50% }
@media (forced-colors: active) { .gradient { color: currentColor; background: none } }
.hero__subtitle { margin: 0 0 28px; color: var(--muted); font-size: clamp(16px, 2.2vw, 22px) }
.hero__actions { display: flex; gap: 12px; flex-wrap: wrap }

.btn { --ring: rgba(124,92,255,.4); display: inline-flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: 14px; border: 1px solid var(--line); text-decoration: none; color: var(--text); background: var(--card); transition: transform .08s ease, box-shadow .08s ease; transform: translate(var(--mx, 0), var(--my, 0)) }
.btn:hover { transform: translate(calc(var(--mx, 0)), calc(-1px + var(--my, 0))); box-shadow: 0 8px 22px rgba(0,0,0,.25) }
.btn--primary { background: linear-gradient(135deg, var(--brand), var(--accent)); color: #fff; border-color: transparent }
.btn--ghost { background: transparent }

.hero__marquee { position: absolute; bottom: 0; left: 0; right: 0; padding: 16px 0; border-top: 1px solid var(--line); background: linear-gradient(0deg, rgba(0,0,0,.25), transparent), var(--bg-soft) }
.marquee { display: flex; gap: 48px; white-space: nowrap; animation: ticker 28s linear infinite; font: 700 14px/1 Syne, sans-serif; letter-spacing: .06em; text-transform: uppercase; color: var(--muted) }
.marquee span { opacity: .8 }
@keyframes ticker { from { transform: translateX(0) } to { transform: translateX(-50%) } }
@media (prefers-reduced-motion: reduce) { .marquee { animation: none } }

.section__head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 24px 6vw 8px }
.section__head h2 { margin: 0; font: 800 clamp(22px, 4vw, 42px) Syne, sans-serif }
.filters { display: flex; gap: 10px; flex-wrap: wrap }
.chip { border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 999px; padding: 10px 12px; cursor: pointer }
.chip.is-active, .chip:hover { background: linear-gradient(135deg, rgba(124,92,255,.25), rgba(0,224,255,.25)) }

.grid { list-style: none; display: grid; grid-template-columns: repeat(6, 1fr); gap: 16px; padding: 16px 6vw 60px; margin: 0 }
.grid { contain: layout }
.card { grid-column: span 6; position: relative; overflow: hidden; border-radius: 18px; background: transparent; border: 1px solid var(--line); box-shadow: var(--shadow); transform: translateZ(0) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)); transition: transform .18s ease }
.card--w6 { grid-column: span 6 }
/* robust preview ratio with fallback */
.card__img { position: relative; background: #0a0a0d; overflow: hidden; z-index: 1; min-height: 360px; background-size: cover; background-position: center }
.card__img img { display: block; width: 100%; height: auto; filter: saturate(1.05) contrast(1.05); transform: scale(1.0); transition: transform .5s cubic-bezier(.2,.7,.2,1); z-index: 1; opacity: 1; visibility: visible }
.card:hover .card__img img { transform: scale(1.08) }
.card__body { position: absolute; left: 0; right: 0; bottom: 0; padding: 16px; background: linear-gradient(180deg, rgba(0,0,0,0) 0%, rgba(0,0,0,.25) 40%, rgba(0,0,0,.55) 100%); z-index: 3 }
.card__title { margin: 0 0 6px; font: 800 18px/1.2 Inter, sans-serif; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.6) }
.card__meta { margin: 0; color: rgba(255,255,255,.85); font-size: 13px }
.card__mask { position: absolute; inset: 0; background: radial-gradient(300px 200px at var(--mx,50%) var(--my,50%), rgba(124,92,255,.25), transparent 70%); opacity: 0; transition: opacity .25s ease; z-index: 2 }
/* ensure single, absolute-positioned body overlay (remove duplicate rule) */
.card:hover .card__mask { opacity: 1 }
.card__hit { position: absolute; inset: 0; z-index: 5; background: none; border: 0; appearance: none; cursor: pointer }

@media (min-width: 720px) {
  .grid { grid-template-columns: repeat(12, 1fr) }
  .card { grid-column: span 6 }
  .card--w6 { grid-column: span 8 }
  .dock { inset: auto 18px 18px 18px; width: auto; height: 72px; flex-direction: row; padding: 10px 12px; border-radius: 16px }
  .dock__nav { display: none }
  .dock__logo { width: 48px; height: 48px }
}
@media (min-width: 1200px) {
  .page { padding-left: 120px }
  .dock { left: 18px; top: 18px; bottom: 18px; right: auto; width: 84px; height: auto; display: flex; flex-direction: column; padding: 14px; border-radius: 22px }
  .dock__logo { width: 56px; height: 56px; border-radius: 14px }
  .dock__nav { display: grid }
  .dock__bar { display: none }
  .grid { grid-template-columns: repeat(12, 1fr) }
  .card { grid-column: span 4 }
  .card--w6 { grid-column: span 6 }
}

@media (max-width: 1199px) {
  /* keep actions above the mobile dock bar */
  .dock__actions {
    bottom: 96px;
    left: auto;
    right: max(18px, env(safe-area-inset-right));
  }
}

/* Improve mobile dock bar contrast */
@media (max-width: 1199px) {
  .dock__bar a {
    background: rgba(255,255,255,.92);
    border-color: rgba(0,0,0,.08);
    color: #000; /* ensure icons (currentColor) are black */
  }
  .dock__bar a:hover { background: #fff }
}

.about, .contact { padding: 32px 0 60px }
.about__content { max-width: 860px; color: var(--muted); font-size: 18px }
.about__content, .contact__cta { padding: 0 6vw }
.badges { display: flex; gap: 10px; flex-wrap: wrap; padding: 14px 0 0; margin: 0; list-style: none }
.badges li { border: 1px dashed var(--line); color: var(--text); border-radius: 999px; padding: 8px 12px; background: rgba(255,255,255,.02) }

.contact__cta { display: flex; gap: 12px; flex-wrap: wrap }

.footer { padding: 40px 6vw 80px; color: var(--muted); border-top: 1px solid var(--line) }

.overlay { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.55); opacity: 0; pointer-events: none; transform: translateY(6px); transition: opacity .2s ease, transform .2s ease; z-index: 20 }
.overlay.is-open { opacity: 1; pointer-events: auto; transform: translateY(0) }
.overlay__content { position: relative; width: min(980px, 92vw); max-height: 86svh; background: var(--bg-soft); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); overflow: hidden; display: grid; grid-template-columns: 1.2fr 1fr }
.overlay__media { margin: 0; background: #0a0a0d }
.overlay__media img { width: 100%; height: 100%; object-fit: cover }
.overlay__body { padding: 18px 18px 20px; overflow: auto }
.overlay__body h3 { margin: 0 0 8px; font: 800 26px/1.15 Syne, sans-serif; color: var(--text) }
/* Ensure modal text inherits high-contrast color */
.overlay__content, .overlay__body, .overlay__body .form__label { color: var(--text) }
/* Avoid title overlap with close button on desktop */
@media (min-width: 981px) {
  .overlay__body { padding-top: 64px }
}
.overlay__body p { color: var(--muted) }
.overlay__tags { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0 14px }
.overlay__tags .chip { padding: 6px 10px; font-size: 12px }
.overlay__links { display: flex; gap: 10px; flex-wrap: wrap }

/* Close button inside modal */
.overlay__close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 3;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  border: 1px solid rgba(0,0,0,.08);
  background: #fff;
  color: #000;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.overlay__close:hover { background: #f3f3f3 }
@media (max-width: 980px) {
  .overlay__close { top: 8px; right: 8px }
}
@media (forced-colors: active) {
  .overlay__close { background: ButtonFace; color: ButtonText }
}

@media (max-width: 980px) {
  /* Add safe-area padding and ensure true centering on mobile */
  .overlay {
    padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
             max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    align-content: center;
    justify-content: center;
  }
  .overlay__content {
    grid-template-columns: 1fr;
    width: 100%; /* honor overlay padding for perfect centering */
    max-height: calc(100svh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 24px);
  }
}

/* Narrow modal variant for forms */
.overlay__content--narrow { grid-template-columns: 1fr !important; width: min(560px, 92vw); }

/* On small phones, let the narrow dialog use full available width minus padding */
@media (max-width: 640px) {
  .overlay__content--narrow { width: 100%; border-radius: 16px }
  .overlay__body { -webkit-overflow-scrolling: touch }
}

/* Form styles */
.form { display: grid; gap: 12px; margin-top: 6px }
.form__row { display: grid; gap: 6px }
.form__label { font-weight: 600 }
.form__input { 
  appearance: none; width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg-soft); color: var(--text);
}
.form__input:focus { outline: 3px solid var(--accent); outline-offset: 2px }
.form__check { margin-top: 4px }
.form__checklabel { display: inline-flex; align-items: flex-start; gap: 8px; font-size: 14px; color: var(--muted) }
.form__actions { display: flex; gap: 10px; align-items: center; margin-top: 4px }
.form__hint { margin: 6px 0 0 }
.form .hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden }
.form__error { margin: 0; padding: 8px 10px; border-radius: 10px; background: var(--error-bg); color: var(--error); border: 1px solid var(--error-border) }

/* Inline linklike button in labels */
.linklike { background: none; border: none; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; font: inherit }
.linklike:hover { text-decoration: none }

/* Details / Privacy policy */
.form__policy { border: 1px dashed var(--line); border-radius: 12px; background: rgba(255,255,255,.02); padding: 8px 10px }
.form__policy summary { cursor: pointer; list-style: none; font-weight: 700 }
.form__policy summary::-webkit-details-marker { display: none }
.form__policy[open] summary { margin-bottom: 6px }
.form__policybody { color: var(--muted); display: grid; gap: 8px; max-height: 260px; overflow: auto; padding-right: 6px }
.form__policybody a { color: var(--accent) }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important }
}

/* View Transitions for grid filter changes */
@supports (view-transition-name: none) {
  #grid { view-transition-name: grid }
  /* Keep it subtle: rely on UA cross-fade */
  ::view-transition-old(grid) { animation: none }
  ::view-transition-new(grid) { animation: none }
}

/* ===== CV Section ===== */
.cv { position: relative; padding: 40px 0 80px; overflow: visible; --cv-top: 84px }
.cv:before { content: ""; position: absolute; inset: 0 -20% -40% -20%; z-index: 0; pointer-events: none; opacity: .25; background:
  radial-gradient(900px 600px at 120% -20%, rgba(124,92,255,.18), transparent 60%),
  radial-gradient(700px 500px at -10% 10%, rgba(0,224,255,.14), transparent 60%)
}
.cv .section__head { position: sticky; top: 0; z-index: 2; backdrop-filter: blur(6px); background: linear-gradient(180deg, rgba(15,17,23,.92), rgba(15,17,23,.64) 70%, transparent); padding: 20px 6vw 10px; border-bottom: 1px solid var(--line) }
.cv__actions { display: flex; gap: 10px; align-items: center }
.cv__wrap { position: relative; z-index: 1; display: grid; grid-template-columns: 2fr 1fr; gap: 24px; padding: 14px 6vw 0 }
.cv__column { display: grid; align-content: start; gap: 16px }
.cv__subhead { margin: 6px 0; font: 800 22px/1.2 Syne, sans-serif }

/* Experience timeline */
.timeline { list-style: none; margin: 0; padding: 0; position: relative }
.tl__item { position: relative; border: 1px solid var(--line); border-radius: 14px; background: var(--card); margin: 14px 0; overflow: hidden }
.tl__card { all: unset; display: block; width: 100%; cursor: pointer }
.tl__card:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px }
.tl__head { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 14px 14px 10px }
.tl__role { font: 700 18px/1.2 Syne, sans-serif }
.tl__org { color: var(--muted); font-size: 14px }
.tl__org em { font-style: normal; color: var(--text) }
.tl__dates { align-self: center; color: var(--muted); font-size: 13px; white-space: nowrap }
.tl__line { position: relative; height: 3px; background: rgba(255,255,255,.06) }
.tl__line span { position: absolute; inset: 0; transform-origin: left; transform: scaleX(0); background: linear-gradient(90deg, var(--accent), var(--brand)) }
.tl__body { padding: 10px 14px 14px; border-top: 1px dashed var(--line); background: linear-gradient(180deg, rgba(255,255,255,.02), transparent) }
.tl__bullets { margin: 8px 0 10px 18px; padding: 0; color: var(--muted) }
.tl__bullets li { margin: 6px 0 }
.tl__tags { display: flex; gap: 8px; flex-wrap: wrap }
.tl__tags .chip { padding: 6px 10px; font-size: 12px }

/* Education */
.edu { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px }
.edu__item { border: 1px dashed var(--line); border-radius: 12px; padding: 10px 12px; background: rgba(255,255,255,.02) }
.edu__title { font-weight: 600 }
.edu__org { color: var(--muted); font-size: 14px }
.edu__dates { color: var(--muted); font-size: 13px }

/* Languages */
.langs { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px }
.lang { display: grid; grid-template-columns: 94px 1fr; gap: 10px; align-items: center; border: 1px solid var(--line); padding: 10px; border-radius: 12px; background: var(--card) }
.lang__meter { display: block }
.lang__meter .bg { fill: none; stroke: rgba(255,255,255,.12); stroke-width: 10 }
.lang__meter .fg { fill: none; stroke: url('#gradCV'); stroke: var(--accent); stroke-linecap: round; stroke-width: 10; transform: rotate(-90deg); transform-origin: 50% 50% }
.lang__label strong { display: block; font-weight: 700 }
.lang__label span { color: var(--muted); font-size: 14px }

/* Skills */
.skills { display: grid; gap: 12px }
.skillg { border: 1px dashed var(--line); border-radius: 12px; padding: 10px 12px; background: rgba(255,255,255,.02) }
.skillg__title { font-weight: 700; margin-bottom: 8px }
.skillg__items { display: flex; flex-wrap: wrap; gap: 8px }
.chip--float { position: relative; animation: floaty calc(6s + var(--d,0s)) ease-in-out infinite alternate }
@keyframes floaty { from { transform: translateY(0) } to { transform: translateY(-6px) } }

@media (max-width: 980px) {
  .cv__wrap { grid-template-columns: 1fr }
  .langs { grid-template-columns: 1fr }
}

/* Sticky experience column on desktop */
@media (min-width: 981px) {
  .cv__column--sticky {
    position: sticky;
    top: var(--cv-top, 84px);
    align-self: start;
    max-height: calc(100svh - var(--cv-top, 84px) - 20px);
    overflow: auto;
    padding-right: 4px;
    scrollbar-width: thin;
    overscroll-behavior: contain;
  }
  .cv__column--sticky::-webkit-scrollbar { width: 8px }
  .cv__column--sticky::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-radius: 999px }
  .cv__column--sticky::-webkit-scrollbar-track { background: transparent }
}
