:root {
  --bg: #ffffff;
  --surface: #f5f6f8;
  --text: #1a1d23;
  --muted: #5b6270;
  --accent: #2563eb;
  --border: #e2e5ea;
  --max: 960px;
}

[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #181b21;
  --text: #e8eaee;
  --muted: #9aa1ae;
  --accent: #6ea0ff;
  --border: #2a2f38;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 72px; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

section, .hero, footer { max-width: var(--max); margin: 0 auto; padding: 4rem 1.5rem; }
h2 { font-size: 1.75rem; margin: 0 0 1.5rem; }
h3 { margin: 0 0 .5rem; font-size: 1.1rem; }

/* Header */
.site-header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: .75rem 1.5rem;
  background: var(--bg); border-bottom: 1px solid var(--border);
}
.logo { font-weight: 700; font-size: 1.2rem; color: var(--text); }
nav { display: flex; align-items: center; gap: 1.25rem; }
nav a { color: var(--muted); font-size: .95rem; }
nav a:hover { color: var(--text); text-decoration: none; }
#theme-toggle, .nav-toggle {
  background: none; border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: .25rem .6rem; cursor: pointer; font-size: 1rem;
}
.nav-toggle { display: none; }

/* Hero */
.hero {
  display: grid; grid-template-columns: 1.2fr 1fr; gap: 3rem; align-items: center;
  min-height: 70vh; padding-top: 3rem; padding-bottom: 3rem;
}
.hero h1 { font-size: clamp(2.6rem, 7vw, 4.5rem); margin: 0 0 1.5rem; line-height: 1.05; font-weight: 600; }
.tagline { font-size: 1.1rem; color: var(--muted); max-width: 30rem; margin: 0; }
.hero-photo {
  width: min(340px, 100%); aspect-ratio: 1 / 1; object-fit: cover; object-position: center 15%;
  border-radius: 50%; justify-self: center;
}

/* Buttons */
.cta { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: 1.5rem; }
.btn {
  display: inline-block; padding: .6rem 1.2rem; border-radius: 8px;
  border: 1px solid var(--border); color: var(--text); font-weight: 500;
}
.btn:hover { text-decoration: none; border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
[data-theme="dark"] .btn.primary { color: #0f1115; }

/* Projects */
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 2rem 1.5rem; }
.tile { display: block; color: var(--text); }
.tile:hover { text-decoration: none; }
.tile img {
  width: 100%; aspect-ratio: 16 / 10; object-fit: cover; display: block;
  border-radius: 12px; border: 1px solid var(--border); transition: transform .2s;
}
.tile:hover img { transform: translateY(-4px); }
.tile h3 { margin: .9rem 0 .2rem; }
.tile p { margin: 0; color: var(--muted); font-size: .9rem; }
.tags { list-style: none; padding: 0; margin: 1.5rem 0 0; display: flex; flex-wrap: wrap; gap: .4rem; }
.tags li { font-size: .8rem; padding: .15rem .6rem; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--muted); }

/* Project detail pages */
.project-page { max-width: 860px; margin: 0 auto; padding: 3rem 1.5rem 4rem; }
.project-page .lead { font-size: 1.15rem; color: var(--text); }
.project-page h3 { margin: 1.75rem 0 .5rem; }
.project-page p { color: var(--muted); }
.project-page strong { color: var(--text); }

.soft-demo { margin: 1rem 0 2rem; }
.project-page .soft-demo h1 { color: var(--text); text-align: left; margin: 0 0 .6rem; padding: 0; font-size: clamp(1.4rem, 3.4vw, 2.3rem); }
.project-page .soft-demo .meta { color: var(--muted); text-align: left; margin: 0; padding: 0; font-size: .9rem; }
.soft-demo { position: relative; }
.soft-title { position: absolute; top: 2rem; right: 2rem; width: 44%; z-index: 1; pointer-events: none; }
@media (max-width: 640px) {
  .soft-title { position: static; width: auto; padding: 1.25rem 1.25rem 0; }
}
.soft-demo canvas { display: block; width: 100%; height: 820px; touch-action: none; }
.soft-demo .soft-hint { color: var(--text); text-align: center; font-size: clamp(1.05rem, 2.2vw, 1.3rem); line-height: 1.5; max-width: 40rem; margin: .5rem auto 0; padding: 0 1rem; min-height: 4.5em; }

.figure { margin: 1.5rem 0; }
.figure img { width: 100%; display: block; border-radius: 10px; border: 1px solid var(--border); background: #fff; }
.figure figcaption, .caption { margin-top: .5rem; font-size: .85rem; color: var(--muted); }
.figure.narrow { max-width: 560px; }
.figure-grid { display: grid; gap: 1rem; margin: 1.5rem 0 0; }
.figure-grid .figure { margin: 0; }
.figure-grid.three { grid-template-columns: repeat(3, 1fr); }
.figure-grid.four { grid-template-columns: repeat(4, 1fr); }
.figure-grid + .caption { margin: .5rem 0 1.5rem; }

.glance { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; margin: 2rem 0; }
.glance div { border-top: 2px solid var(--accent); padding-top: .6rem; }
.glance strong { display: block; font-size: 1.4rem; line-height: 1.2; }
.glance span { font-size: .85rem; color: var(--muted); }

.table-wrap { overflow-x: auto; margin: 1rem 0 1.5rem; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { text-align: left; padding: .5rem .75rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; }
.project-page .back { color: var(--muted); font-size: .95rem; }
.project-page h1 { font-size: clamp(2rem, 5vw, 2.8rem); line-height: 1.1; margin: 1.25rem 0 .5rem; }
.project-page .meta { color: var(--muted); margin: 0 0 1.5rem; }
.project-page h2 { font-size: 1.25rem; margin: 2rem 0 .5rem; }
.project-page ul:not(.tags) { padding-left: 1.2rem; color: var(--muted); }
.project-page li + li { margin-top: .4rem; }
.project-hero { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 12px; border: 1px solid var(--border); }

/* Experience */
.entry { display: grid; grid-template-columns: 10rem 1fr; gap: 1rem; padding: 1.25rem 0; border-top: 1px solid var(--border); }
.when { color: var(--muted); font-size: .95rem; }
.entry ul { margin: 0; padding-left: 1.2rem; color: var(--muted); }

/* Skills */
.skills { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1.5rem; }
.skills p { margin: 0; color: var(--muted); }

footer { text-align: center; color: var(--muted); border-top: 1px solid var(--border); padding-top: 2rem; padding-bottom: 2rem; }

/* Mobile */
@media (max-width: 640px) {
  .nav-toggle { display: block; }
  nav {
    display: none; position: absolute; top: 100%; left: 0; right: 0;
    flex-direction: column; align-items: flex-start; gap: 1rem;
    padding: 1rem 1.5rem; background: var(--bg); border-bottom: 1px solid var(--border);
  }
  nav.open { display: flex; }
  .entry { grid-template-columns: 1fr; gap: .25rem; }
  .hero { grid-template-columns: 1fr; gap: 2rem; min-height: 0; padding-top: 2.5rem; }
  .hero-photo { order: -1; width: 220px; }
  .figure-grid.three, .figure-grid.four { grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .tile img { transition: none; }
}
