/* ==========================================================
   Portfolio – style.css
   Themes are controlled by [data-theme="dark" | "light"] on <html>
   ========================================================== */

:root {
  --font-head: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --font-body: "DM Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --radius: 14px;
  --radius-sm: 8px;
  --header-h: 72px;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

/* Dark theme (higher specificity so it always beats the :root defaults) */
:root[data-theme="dark"] {
  --bg: #000000;
  --bg-alt: #141b2b;
  --surface: #1a2236;
  --text: #e8ecf6;
  --muted: #9aa5bf;
  --line: #27314a;
  --accent: #8ea8ff;
  --accent-ink: #0b1226;
  --accent-2: #ffd27a;
  --shadow: 0 18px 40px -18px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

/* Light theme (default) */
:root,
:root[data-theme="light"] {
  --bg: #f7f8fc;
  --bg-alt: #eceff8;
  --surface: #ffffff;
  --text: #151a2b;
  --muted: #5a6480;
  --line: #d9deee;
  --accent: #3a50d4;
  --accent-ink: #ffffff;
  --accent-2: #b8730a;
  --shadow: 0 18px 40px -22px rgba(30, 40, 90, .35);
  color-scheme: light;
}

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

html { scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + 8px); }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  transition: background-color .35s ease, color .35s ease;
  -webkit-font-smoothing: antialiased;
}

img, svg { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; margin: 0; padding: 0; }
h1, h2, h3, p { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }

h1, h2, h3 { font-family: var(--font-head); line-height: 1.12; letter-spacing: -.02em; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; border-radius: 4px; }

.container { width: min(1120px, 100% - 2.5rem); margin-inline: auto; }

.icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.skip-link {
  position: fixed; left: 1rem; top: -4rem; z-index: 200;
  background: var(--accent); color: var(--accent-ink);
  padding: .6rem 1rem; border-radius: var(--radius-sm); transition: top .2s;
}
.skip-link:focus { top: 1rem; }

/* Scroll progress */
.progress {
  position: fixed; inset: 0 auto auto 0; height: 3px; width: 0; z-index: 120;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

/* ---------- Header ---------- */
.site-header {
  position: fixed; inset: 0 0 auto 0; height: var(--header-h); z-index: 100;
  display: flex; align-items: center;
  transition: background-color .3s, box-shadow .3s, backdrop-filter .3s;
}
.site-header.scrolled {
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 1px 0 var(--line);
}
.nav { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }

.logo { font-family: var(--font-head); font-weight: 800; font-size: 1.35rem; letter-spacing: -.03em; }
.logo span { color: var(--accent); }

.nav-links { display: flex; gap: .25rem; }
.nav-link {
  position: relative; padding: .5rem .85rem; border-radius: 999px;
  color: var(--muted); font-weight: 500; font-size: .98rem;
  transition: color .2s, background-color .2s;
}
.nav-link:hover { color: var(--text); }
.nav-link.active { color: var(--text); background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }

.nav-actions { display: flex; align-items: center; gap: .5rem; }

.icon-btn {
  display: grid; place-items: center; width: 42px; height: 42px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 50%;
  transition: transform .2s var(--ease), border-color .2s, background-color .2s;
}
.icon-btn:hover { border-color: var(--accent); transform: translateY(-1px); }

/* Theme icon swap */
.icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: block; }

.menu-btn { display: none; flex-direction: column; gap: 4px; }
.menu-btn span { width: 18px; height: 2px; background: currentColor; border-radius: 2px; transition: transform .25s var(--ease), opacity .2s; }
.menu-btn[aria-expanded="true"] span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.menu-btn[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.menu-btn[aria-expanded="true"] span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: .85rem 1.5rem; border-radius: 999px; border: 1.5px solid transparent;
  font-weight: 700; font-size: 1rem; line-height: 1.2;
  transition: transform .2s var(--ease), background-color .2s, border-color .2s, box-shadow .2s;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 10px 24px -12px var(--accent); }
.btn-ghost { border-color: var(--line); background: transparent; }
.btn-ghost:hover { border-color: var(--accent); }
.btn[disabled] { opacity: .65; pointer-events: none; }

/* ---------- Hero ---------- */
.hero {
  position: relative; min-height: 100svh; display: flex; align-items: center;
  padding: calc(var(--header-h) + 2rem) 0 4rem; overflow: hidden;
}
.hero::before {
  content: ""; position: absolute; width: 640px; height: 640px; right: -180px; top: -120px;
  background: radial-gradient(circle, color-mix(in srgb, var(--accent) 28%, transparent), transparent 65%);
  pointer-events: none;
}
.hero-grid { position: relative; display: grid; grid-template-columns: 1.15fr .85fr; gap: 3rem; align-items: center; }

.hero-hello { color: var(--accent-2); font-weight: 700; margin-bottom: .75rem; }
.hero-title { font-size: clamp(2.8rem, 7.5vw, 5.6rem); font-weight: 800; letter-spacing: -.045em; }
.hero-title-line { display: block; color: var(--accent); }
.hero-role { margin-top: 1.25rem; font-size: clamp(1.15rem, 2.4vw, 1.6rem); font-family: var(--font-head); font-weight: 500; min-height: 1.6em; }
.typed { color: var(--accent-2); }
.cursor { margin-left: 2px; color: var(--accent); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.hero-lead { margin-top: 1.25rem; max-width: 52ch; color: var(--muted); }
.hero-cta { display: flex; flex-wrap: wrap; gap: .85rem; margin-top: 2rem; }

.socials { display: flex; gap: .75rem; margin-top: 2rem; }
.socials a {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--line); color: var(--muted);
  transition: color .2s, border-color .2s, transform .2s var(--ease);
}
.socials a:hover { color: var(--accent); border-color: var(--accent); transform: translateY(-3px); }

/* Single orchestrated entrance: hero only */
.hero-text > * { animation: rise .8s var(--ease) both; }
.hero-text > :nth-child(2) { animation-delay: .08s; }
.hero-text > :nth-child(3) { animation-delay: .16s; }
.hero-text > :nth-child(4) { animation-delay: .24s; }
.hero-text > :nth-child(5) { animation-delay: .32s; }
.hero-text > :nth-child(6) { animation-delay: .4s; }
@keyframes rise { from { opacity: 0; transform: translateY(22px); } to { opacity: 1; transform: none; } }

.code-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.1rem 1.4rem 1.4rem; box-shadow: var(--shadow);
  transform: rotate(2deg); transition: transform .4s var(--ease);
  animation: float 6s ease-in-out infinite;
}
.code-card:hover { transform: rotate(0); }
@keyframes float { 50% { translate: 0 -10px; } }
.code-dots { display: flex; gap: 6px; margin-bottom: 1rem; }
.code-dots i { width: 11px; height: 11px; border-radius: 50%; background: var(--line); }
.code-dots i:first-child { background: #ff6b6b; }
.code-dots i:nth-child(2) { background: #ffd166; }
.code-dots i:nth-child(3) { background: #5fd38d; }
.code-card pre { margin: 0; overflow-x: auto; font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: .92rem; line-height: 1.75; }
.c-k { color: #c792ea; } .c-v { color: var(--accent); } .c-p { color: var(--text); } .c-s { color: #7fd6a4; }
[data-theme="light"] .c-k { color: #7c3aed; } [data-theme="light"] .c-s { color: #0f8a4f; }

.scroll-hint {
  position: absolute; bottom: 1.5rem; left: 50%; translate: -50% 0;
  width: 26px; height: 42px; border: 2px solid var(--line); border-radius: 20px;
}
.scroll-hint span { position: absolute; left: 50%; top: 8px; width: 4px; height: 8px; margin-left: -2px; border-radius: 4px; background: var(--accent); animation: wheel 1.8s infinite; }
@keyframes wheel { 0% { opacity: 1; transform: translateY(0); } 100% { opacity: 0; transform: translateY(14px); } }

/* ---------- Sections ---------- */
.section { padding: clamp(4.5rem, 9vw, 7.5rem) 0; }
.section-alt { background: var(--bg-alt); transition: background-color .35s; }
.section-title { font-size: clamp(2rem, 4.5vw, 3.1rem); font-weight: 800; margin-bottom: 1rem; }
.section-sub { color: var(--muted); margin-bottom: 2.5rem; max-width: 56ch; }
.lead { font-size: 1.2rem; margin-bottom: 1rem; max-width: 56ch; }

/* About */
.about-grid { display: grid; grid-template-columns: .8fr 1.2fr; gap: 4rem; align-items: center; }
.avatar-wrap { display: grid; place-items: center; }
.avatar {
  width: min(320px, 80%); aspect-ratio: 1; border-radius: 38% 62% 55% 45% / 48% 40% 60% 52%;
  display: grid; place-items: center;
  font-family: var(--font-head); font-weight: 800; font-size: 5rem; letter-spacing: -.04em;
  color: var(--accent-ink); background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: var(--shadow); animation: morph 10s ease-in-out infinite;
}
@keyframes morph { 50% { border-radius: 55% 45% 40% 60% / 55% 58% 42% 45%; } }
.about-grid p + p { margin-top: .5rem; color: var(--muted); }

.stats { display: flex; flex-wrap: wrap; gap: 2.5rem; margin: 2rem 0; }
.stat strong { display: block; font-family: var(--font-head); font-size: 2.6rem; font-weight: 800; line-height: 1; color: var(--accent); }
.stat strong::after { content: "+"; }
.stat span { color: var(--muted); font-size: .95rem; }

/* Skills */
.skills-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.75rem 3rem; }
.skill-head { display: flex; justify-content: space-between; margin-bottom: .5rem; font-weight: 500; }
.skill-head b { color: var(--muted); font-weight: 500; }
.bar { height: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width 1.3s var(--ease); }

/* Projects */
.filters { display: flex; flex-wrap: wrap; gap: .6rem; margin-bottom: 2rem; }
.filter {
  padding: .5rem 1.15rem; border-radius: 999px; background: transparent;
  border: 1px solid var(--line); color: var(--muted); font-weight: 500;
  transition: all .2s;
}
.filter:hover { color: var(--text); border-color: var(--accent); }
.filter.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.projects-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1.5rem; }
.project {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem 1rem 1.4rem; cursor: pointer;
  transition: transform .3s var(--ease), border-color .3s, box-shadow .3s, opacity .3s;
}
.project:hover { transform: translateY(-6px); border-color: var(--accent); box-shadow: var(--shadow); }
.project.hide { display: none; }
.project h3 { font-size: 1.3rem; margin: 1.1rem .4rem .3rem; }
.project p { margin: 0 .4rem; color: var(--muted); font-size: .98rem; }
.thumb, .modal-thumb { height: 170px; border-radius: var(--radius-sm); display: flex; align-items: flex-end; padding: .8rem; position: relative; overflow: hidden; }
.thumb span { background: rgba(10, 14, 26, .65); color: #fff; font-size: .8rem; font-weight: 500; padding: .2rem .7rem; border-radius: 999px; backdrop-filter: blur(4px); }
.t1 { background: linear-gradient(135deg, #3a50d4, #8ea8ff); }
.t2 { background: linear-gradient(135deg, #b8730a, #ffd27a); }
.t3 { background: linear-gradient(135deg, #0f8a8a, #7fe0c8); }
.t4 { background: linear-gradient(135deg, #7c3aed, #d6a8ff); }
.t5 { background: linear-gradient(135deg, #1f2a4a, #5068b8); }
.t6 { background: linear-gradient(135deg, #c2410c, #ffb27a); }
.thumb::after, .modal-thumb::after { content: ""; position: absolute; inset: 0; background: repeating-linear-gradient(45deg, rgba(255,255,255,.07) 0 2px, transparent 2px 14px); }

/* Timeline (real chronological sequence) */
.timeline { position: relative; margin-top: 2rem; padding-left: 2rem; }
.timeline::before { content: ""; position: absolute; left: 6px; top: 8px; bottom: 8px; width: 2px; background: var(--line); }
.timeline li { position: relative; padding-bottom: 2.5rem; max-width: 70ch; }
.timeline li:last-child { padding-bottom: 0; }
.timeline li::before {
  content: ""; position: absolute; left: -2rem; top: .45rem; width: 14px; height: 14px;
  border-radius: 50%; background: var(--bg-alt); border: 3px solid var(--accent);
}
.timeline time { color: var(--accent-2); font-weight: 700; font-size: .95rem; }
.timeline h3 { font-size: 1.35rem; margin: .2rem 0; }
.timeline .org { color: var(--muted); font-weight: 500; margin-bottom: .4rem; }

/* Contact */
.contact-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4rem; align-items: start; }
.contact-list { margin-top: 1.5rem; display: grid; gap: .9rem; }
.contact-list li { display: flex; align-items: center; gap: .8rem; color: var(--muted); }
.contact-list svg { color: var(--accent); flex: none; }
.contact-list a:hover { color: var(--accent); }

.form { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.75rem; box-shadow: var(--shadow); display: grid; gap: 1.1rem; }
.field label { display: block; font-weight: 500; margin-bottom: .35rem; font-size: .95rem; }
.field input, .field textarea {
  width: 100%; padding: .8rem 1rem; font: inherit; color: var(--text);
  background: var(--bg); border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  transition: border-color .2s, box-shadow .2s;
}
.field textarea { resize: vertical; min-height: 120px; }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.field.invalid input, .field.invalid textarea { border-color: #ff6b6b; }
.error { display: block; min-height: 1.1em; margin-top: .3rem; color: #ff7b7b; font-size: .85rem; }
[data-theme="light"] .error { color: #c62828; }

/* Footer */
.footer { border-top: 1px solid var(--line); padding: 1.75rem 0; color: var(--muted); font-size: .95rem; }
.footer-inner { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .5rem; }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 300; display: grid; place-items: center; padding: 1.25rem; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(5, 8, 16, .7); backdrop-filter: blur(4px); animation: fade .25s both; }
.modal-box {
  position: relative; width: min(560px, 100%); max-height: 90vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.25rem 1.25rem 1.75rem; box-shadow: var(--shadow); animation: pop .3s var(--ease) both;
}
.modal-box h3 { font-size: 1.7rem; margin: 1.25rem .25rem .25rem; }
.modal-box p, .modal-box .btn { margin-inline: .25rem; }
.modal-tags { color: var(--accent-2); font-weight: 500; font-size: .95rem; margin-bottom: .75rem; }
.modal-box > p:not(.modal-tags) { color: var(--muted); margin-bottom: 1.5rem; }
.modal-thumb { height: 190px; }
.modal-close { position: absolute; top: 1.75rem; right: 1.75rem; z-index: 2; background: rgba(10, 14, 26, .7); border-color: transparent; color: #fff; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(16px) scale(.97); } }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 1.5rem; z-index: 400;
  translate: -50% 140%; opacity: 0;
  background: var(--text); color: var(--bg); padding: .85rem 1.4rem; border-radius: 999px;
  font-weight: 500; box-shadow: var(--shadow); max-width: calc(100% - 2rem);
  transition: translate .4s var(--ease), opacity .3s;
}
.toast.show { translate: -50% 0; opacity: 1; }

/* Back to top */
.to-top {
  position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 90;
  width: 48px; height: 48px; display: grid; place-items: center; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); border: 0; box-shadow: var(--shadow);
  opacity: 0; visibility: hidden; transform: translateY(12px);
  transition: opacity .3s, transform .3s var(--ease), visibility .3s;
}
.to-top.show { opacity: 1; visibility: visible; transform: none; }
.to-top:hover { transform: translateY(-3px); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .hero-grid, .about-grid, .contact-grid { grid-template-columns: 1fr; gap: 2.5rem; }
  .hero-card { max-width: 420px; }
  .avatar-wrap { order: -1; }
  .avatar { width: 220px; font-size: 3.6rem; }
  .skills-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .menu-btn { display: flex; }
  .nav-links {
    position: fixed; inset: var(--header-h) 0 auto 0; flex-direction: column; gap: .25rem;
    padding: 1rem 1.25rem 1.5rem; background: var(--bg); border-bottom: 1px solid var(--line);
    box-shadow: var(--shadow);
    transform: translateY(-110%); visibility: hidden;
    transition: transform .35s var(--ease), visibility .35s;
  }
  .nav-links.open { transform: none; visibility: visible; }
  .nav-link { display: block; padding: .8rem 1rem; border-radius: var(--radius-sm); }
  .scroll-hint { display: none; }
}

/* Respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

@media print {
  .site-header, .to-top, .progress, .toast, .scroll-hint { display: none !important; }
  body { background: #fff; color: #000; }
}
