:root {
    --bg: #FAF8F4;
    --bg-2: #F2EEE6;
    --ink: #1A1814;
    --ink-2: #3A342C;
    --muted: #7A7267;
    --rule: #D9D2C4;
    --rule-soft: #E8E2D4;
    --paper: #FFFFFF;
    --accent: #B4552A;
    --accent-soft: color-mix(in oklch, var(--accent) 12%, transparent);
    --serif: "Source Serif 4", Georgia, serif;
    --sans: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
    --mono: "JetBrains Mono", ui-monospace, monospace;
    --max: 1180px;
    --gutter: clamp(20px, 4vw, 56px);
    --unit: 8px;
  }
  html[data-theme="dark"] {
    --bg: #14130F;
    --bg-2: #1B1A15;
    --ink: #F2EEE6;
    --ink-2: #D1CAB9;
    --muted: #8A8272;
    --rule: #2B2821;
    --rule-soft: #23211B;
    --paper: #1B1A15;
  }
  html[data-density="compact"] {
    --gutter: clamp(16px, 3vw, 40px);
  }
  * { box-sizing: border-box; }
  html, body { margin: 0; padding: 0; }
  html { scroll-behavior: smooth; }
  body {
    background: var(--bg);
    color: var(--ink);
    font-family: var(--serif);
    font-size: 18px;
    line-height: 1.6;
    font-feature-settings: "kern", "liga", "onum";
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color .4s ease, color .4s ease;
  }
  ::selection { background: var(--accent); color: var(--bg); }
  a { color: inherit; text-underline-offset: 3px; text-decoration-thickness: 1px; }

  .wrap { max-width: var(--max); margin: 0 auto; padding: 0 var(--gutter); }

  /* ---------- Nav ---------- */
  .nav {
    position: sticky; top: 0; z-index: 50;
    background: color-mix(in oklch, var(--bg) 85%, transparent);
    backdrop-filter: saturate(140%) blur(10px);
    -webkit-backdrop-filter: saturate(140%) blur(10px);
    border-bottom: 1px solid var(--rule-soft);
  }
  .nav-inner {
    display: flex; align-items: center; justify-content: space-between;
    height: 64px;
  }
  .brand {
    font-family: var(--mono);
    font-size: 12px;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--muted);
  }
  .brand b { color: var(--ink); font-weight: 500; }
  .nav-links { display: flex; gap: 28px; align-items: center; }
  .nav-links a {
    font-family: var(--sans); font-size: 13px; color: var(--ink-2);
    text-decoration: none; letter-spacing: .01em;
    transition: color .2s;
  }
  .nav-links a:hover { color: var(--accent); }
  .nav-links .num { font-family: var(--mono); font-size: 10px; color: var(--muted); margin-right: 6px; }

  .theme-toggle {
    width: 34px; height: 34px;
    border: 1px solid var(--rule);
    background: transparent;
    border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer; color: var(--ink-2);
    transition: border-color .2s, color .2s, background-color .2s;
  }
  .theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
  .theme-toggle svg { width: 15px; height: 15px; }
  html[data-theme="dark"] .theme-toggle .sun { display: block; }
  html[data-theme="dark"] .theme-toggle .moon { display: none; }
  .theme-toggle .sun { display: none; }

  /* ---------- Hero ---------- */
  .hero { padding: clamp(72px, 14vh, 160px) 0 clamp(80px, 12vh, 140px); position: relative; overflow: hidden; }
  .eyebrow {
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--muted);
    display: inline-flex; align-items: center; gap: 10px;
    margin-bottom: 40px;
  }
  .eyebrow::before {
    content: ""; width: 24px; height: 1px; background: var(--muted);
  }
  .hero h1 {
    font-family: var(--serif);
    font-weight: 300;
    font-size: clamp(52px, 9vw, 128px);
    line-height: 0.96;
    letter-spacing: -0.03em;
    margin: 0 0 32px;
    font-variation-settings: "opsz" 60;
  }
  .hero h1 em {
    font-style: italic;
    font-weight: 300;
    color: var(--ink-2);
  }
  .hero .title {
    font-family: var(--sans);
    font-size: clamp(16px, 1.6vw, 20px);
    font-weight: 500;
    letter-spacing: -0.01em;
    color: var(--ink);
    margin-bottom: 18px;
  }
  .hero .lede {
    font-family: var(--serif);
    font-size: clamp(19px, 2vw, 24px);
    line-height: 1.45;
    color: var(--ink-2);
    max-width: 640px;
    font-weight: 400;
  }
  .hero-meta {
    display: flex; gap: 48px; margin-top: 64px;
    font-family: var(--mono); font-size: 11px;
    color: var(--muted); letter-spacing: .08em; text-transform: uppercase;
  }
  .hero-meta .label { display: block; margin-bottom: 6px; }
  .hero-meta .val { color: var(--ink); font-family: var(--sans); font-size: 13px; text-transform: none; letter-spacing: 0; font-weight: 500; }
  .hero-meta .dot { width: 6px; height: 6px; border-radius: 50%; background: #22A06B; display: inline-block; margin-right: 8px; vertical-align: 1px; box-shadow: 0 0 0 3px color-mix(in oklch, #22A06B 20%, transparent); }

  .network {
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 1;
    mask-image: radial-gradient(ellipse 85% 95% at 70% 50%, #000 55%, transparent 95%);
    -webkit-mask-image: radial-gradient(ellipse 85% 95% at 70% 50%, #000 55%, transparent 95%);
  }
  .hero::before {
    content: "";
    position: absolute; inset: 0;
    background-image:
      linear-gradient(to right, var(--rule-soft) 1px, transparent 1px),
      linear-gradient(to bottom, var(--rule-soft) 1px, transparent 1px);
    background-size: 80px 80px;
    background-position: 0 0;
    opacity: .5;
    mask-image: radial-gradient(ellipse 80% 100% at 50% 50%, #000 10%, transparent 80%);
    -webkit-mask-image: radial-gradient(ellipse 80% 100% at 50% 50%, #000 10%, transparent 80%);
    pointer-events: none;
  }
  .hero::after {
    content: "";
    position: absolute;
    top: 0; right: 0;
    width: 520px; height: 520px;
    background: radial-gradient(circle, color-mix(in oklch, var(--accent) 20%, transparent), transparent 70%);
    pointer-events: none;
    filter: blur(40px);
    opacity: .8;
    animation: heroGlow 8s ease-in-out infinite alternate;
  }
  @keyframes heroGlow {
    0% { transform: translate(20%, -20%) scale(.9); opacity: .5; }
    100% { transform: translate(-10%, 10%) scale(1.15); opacity: .9; }
  }
  .hero .wrap { position: relative; z-index: 1; }

  /* ---------- Section scaffolding ---------- */
  section { padding: clamp(60px, 10vh, 120px) 0; position: relative; }
  .section-head {
    display: grid;
    grid-template-columns: 120px 1fr;
    gap: 32px;
    align-items: baseline;
    margin-bottom: 56px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--rule);
  }
  .section-num {
    font-family: var(--mono); font-size: 11px; color: var(--muted);
    letter-spacing: .14em; text-transform: uppercase;
  }
  .section-head h2 {
    font-family: var(--serif);
    font-weight: 300;
    font-size: clamp(36px, 5vw, 56px);
    line-height: 1.05;
    letter-spacing: -0.02em;
    margin: 0;
  }
  .section-head h2 em { font-style: italic; color: var(--ink-2); }

  /* ---------- About ---------- */
  .about-grid {
    display: grid;
    grid-template-columns: 120px 1fr 280px;
    gap: 32px;
    align-items: start;
  }
  .about-body p {
    font-size: clamp(17px, 1.5vw, 20px);
    line-height: 1.65;
    color: var(--ink-2);
    margin: 0 0 20px;
    max-width: 640px;
  }
  .about-body p + p { margin-top: 24px; }
  .about-body .highlight {
    color: var(--ink);
    box-shadow: inset 0 -0.35em 0 var(--accent-soft);
  }
  .portrait {
    aspect-ratio: 4 / 5;
    background: var(--bg-2);
    border: 1px solid var(--rule);
    display: flex; align-items: flex-end; justify-content: space-between;
    padding: 14px;
    font-family: var(--mono); font-size: 10px; color: var(--muted);
    letter-spacing: .08em; text-transform: uppercase;
    position: relative;
    overflow: hidden;
  }
  .portrait::before {
    content: "";
    position: absolute; inset: 0;
    background-image: repeating-linear-gradient(135deg, var(--rule-soft) 0, var(--rule-soft) 1px, transparent 1px, transparent 10px);
    opacity: .6;
    z-index: 0;
  }
  .portrait img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 8%;
    z-index: 1;
  }
  .portrait .corner {
    position: relative; z-index: 2;
    background: color-mix(in oklch, var(--bg) 75%, transparent);
    padding: 4px 8px;
    backdrop-filter: blur(4px);
  }

  /* ---------- Skills ---------- */
  .skills-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1px;
    background: var(--rule);
    border: 1px solid var(--rule);
  }
  .skill {
    background: var(--bg);
    padding: 32px 28px;
    display: flex; flex-direction: column;
    min-height: 260px;
    transition: background-color .3s;
    position: relative;
  }
  .skill:hover { background: var(--paper); }
  .skill-num {
    font-family: var(--mono); font-size: 10px; color: var(--muted);
    letter-spacing: .14em; margin-bottom: 20px;
  }
  .skill-icon {
    width: 28px; height: 28px; margin-bottom: 20px;
    color: var(--accent);
    stroke: currentColor; fill: none; stroke-width: 1.25;
  }
  .skill h3 {
    font-family: var(--serif);
    font-weight: 400;
    font-size: 22px;
    line-height: 1.2;
    letter-spacing: -0.01em;
    margin: 0 0 14px;
  }
  .skill ul {
    margin: 0 0 20px; padding: 0; list-style: none;
    font-family: var(--sans); font-size: 14px; line-height: 1.55;
    color: var(--ink-2);
  }
  .skill ul li {
    padding-left: 16px; position: relative; margin-bottom: 4px;
  }
  .skill ul li::before {
    content: ""; position: absolute; left: 0; top: .7em;
    width: 6px; height: 1px; background: var(--muted);
  }
  .skill-tags {
    margin-top: auto; padding-top: 16px;
    border-top: 1px solid var(--rule-soft);
    display: flex; flex-wrap: wrap; gap: 6px;
  }
  .tag {
    font-family: var(--mono); font-size: 10px;
    letter-spacing: .04em;
    padding: 4px 8px;
    border: 1px solid var(--rule);
    color: var(--ink-2);
    border-radius: 2px;
  }

  /* 7th card spans full row */
  .skill.full { grid-column: 1 / -1; }
  .skill.full { min-height: auto; }
  .skill.full h3 { font-size: 26px; max-width: 520px; }
  .skill.full ul { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px 32px; max-width: 900px; }
  @media (max-width: 860px) {
    .skill.full ul { grid-template-columns: 1fr; }
  }

  /* ---------- Case studies ---------- */
  .case {
    display: grid;
    grid-template-columns: 120px 1fr;
    gap: 32px;
    padding: 48px 0;
    border-top: 1px solid var(--rule);
  }
  .case:last-child { border-bottom: 1px solid var(--rule); }
  .case-num {
    font-family: var(--mono); font-size: 11px;
    color: var(--muted); letter-spacing: .14em;
  }
  .case h3 {
    font-family: var(--serif);
    font-weight: 400;
    font-size: clamp(26px, 3vw, 36px);
    line-height: 1.15;
    letter-spacing: -0.015em;
    margin: 0 0 20px;
    max-width: 720px;
  }
  .case-intro {
    font-family: var(--serif);
    font-size: 19px; line-height: 1.55;
    color: var(--ink-2);
    max-width: 680px;
    margin: 0 0 28px;
  }
  .case-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 48px;
    margin-top: 8px;
    max-width: 860px;
  }
  .case-grid h4 {
    font-family: var(--mono); font-size: 10px;
    color: var(--muted); letter-spacing: .14em; text-transform: uppercase;
    margin: 0 0 12px; font-weight: 500;
  }
  .case-grid ul {
    margin: 0; padding: 0; list-style: none;
    font-family: var(--sans); font-size: 14.5px; line-height: 1.55;
    color: var(--ink-2);
  }
  .case-grid ul li {
    padding-left: 14px; position: relative; margin-bottom: 6px;
  }
  .case-grid ul li::before {
    content: ""; position: absolute; left: 0; top: .65em;
    width: 6px; height: 1px; background: var(--accent);
  }
  .effect {
    background: var(--bg-2);
    border-left: 2px solid var(--accent);
    padding: 18px 22px;
    font-family: var(--serif);
    font-size: 16.5px; line-height: 1.55;
    color: var(--ink);
  }
  .case-foot {
    margin-top: 24px;
    font-family: var(--mono); font-size: 12px;
    color: var(--muted); letter-spacing: .04em;
  }
  .case-foot a { color: var(--ink); text-decoration: none; border-bottom: 1px solid var(--rule); padding-bottom: 2px; transition: border-color .2s; }
  .case-foot a:hover { border-color: var(--accent); color: var(--accent); }

  /* ---------- Collaboration ---------- */
  .collab {
    background: var(--bg-2);
    margin: 0 calc(var(--gutter) * -1);
    padding: clamp(60px, 10vh, 120px) var(--gutter);
  }
  .collab-grid {
    display: grid;
    grid-template-columns: 120px 1fr;
    gap: 32px;
  }
  .collab p {
    font-family: var(--serif); font-size: clamp(18px, 1.6vw, 22px);
    color: var(--ink-2); line-height: 1.55;
    margin: 0 0 32px; max-width: 640px;
  }
  .collab-list {
    display: grid; gap: 1px;
    background: var(--rule);
    border-top: 1px solid var(--rule);
    border-bottom: 1px solid var(--rule);
  }
  .collab-item {
    background: var(--bg-2);
    padding: 24px 0;
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: baseline;
    gap: 24px;
  }
  .collab-item h4 {
    font-family: var(--serif); font-weight: 400;
    font-size: clamp(20px, 2vw, 26px);
    margin: 0; letter-spacing: -0.01em;
  }
  .collab-item span {
    font-family: var(--mono); font-size: 11px;
    color: var(--muted); letter-spacing: .08em;
    text-align: right;
  }
  .collab-note {
    margin-top: 36px !important;
    font-size: 16px !important;
    color: var(--muted) !important;
    font-style: italic;
  }

  /* ---------- Contact ---------- */
  .contact { padding-bottom: clamp(80px, 14vh, 160px); }
  .contact h2 {
    font-family: var(--serif); font-weight: 300;
    font-size: clamp(44px, 7vw, 88px);
    line-height: 1;
    letter-spacing: -0.025em;
    margin: 0 0 48px;
  }
  .contact h2 em { font-style: italic; color: var(--ink-2); }
  .contact-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1px;
    background: var(--rule);
    border-top: 1px solid var(--rule);
    border-bottom: 1px solid var(--rule);
  }
  .contact-item {
    background: var(--bg);
    padding: 28px 0 28px 0;
    display: flex; flex-direction: column;
    cursor: pointer;
    position: relative;
    transition: background-color .3s;
  }
  .contact-item:nth-child(odd) { padding-right: 24px; }
  .contact-item:nth-child(even) { padding-left: 24px; }
  .contact-item:hover { background: var(--paper); }
  .contact-item .label {
    font-family: var(--mono); font-size: 10px;
    color: var(--muted); letter-spacing: .14em; text-transform: uppercase;
    margin-bottom: 10px;
  }
  .contact-item .val {
    font-family: var(--serif);
    font-size: clamp(20px, 2.2vw, 28px);
    color: var(--ink);
    word-break: break-all;
    display: flex; align-items: center; gap: 12px;
    font-weight: 400;
  }
  .contact-item .copy {
    font-family: var(--mono); font-size: 10px;
    color: var(--muted); letter-spacing: .1em; text-transform: uppercase;
    opacity: 0; transition: opacity .2s, color .2s;
    margin-left: auto;
  }
  .contact-item:hover .copy { opacity: 1; }
  .contact-item.copied .copy { opacity: 1; color: var(--accent); }

  /* ---------- Footer ---------- */
  footer {
    border-top: 1px solid var(--rule);
    padding: 32px 0 48px;
    font-family: var(--mono); font-size: 11px;
    color: var(--muted); letter-spacing: .04em;
    display: flex; justify-content: space-between; flex-wrap: wrap; gap: 16px;
  }

  /* ---------- Reveal ---------- */
  .reveal {
    opacity: 0;
    transform: translateY(16px);
    transition: opacity .9s cubic-bezier(.2,.7,.2,1), transform .9s cubic-bezier(.2,.7,.2,1);
  }
  .reveal.in { opacity: 1; transform: none; }
  .reveal.d1 { transition-delay: .06s; }
  .reveal.d2 { transition-delay: .12s; }
  .reveal.d3 { transition-delay: .18s; }

  @media (prefers-reduced-motion: reduce) {
    .reveal { opacity: 1; transform: none; transition: none; }
    html { scroll-behavior: auto; }
  }

  /* ---------- Responsive ---------- */
  @media (max-width: 960px) {
    .nav-links a:not(:last-child):not(.theme-toggle) { display: none; }
    .about-grid { grid-template-columns: 1fr; }
    .portrait { max-width: 280px; }
    .skills-grid { grid-template-columns: repeat(2, 1fr); }
    .section-head { grid-template-columns: 1fr; gap: 12px; }
    .case { grid-template-columns: 1fr; gap: 12px; }
    .case-grid { grid-template-columns: 1fr; gap: 28px; }
    .collab-grid { grid-template-columns: 1fr; }
    .contact-list { grid-template-columns: 1fr; }
    .contact-item:nth-child(odd), .contact-item:nth-child(even) { padding-left: 0; padding-right: 0; }
    .hero-meta { flex-wrap: wrap; gap: 24px; }
  }
  @media (max-width: 560px) {
    .skills-grid { grid-template-columns: 1fr; }
  }

  /* ---------- Tweaks Panel ---------- */
  .tweaks-panel {
    position: fixed; bottom: 20px; right: 20px;
    background: var(--paper);
    border: 1px solid var(--rule);
    padding: 18px 20px;
    width: 260px;
    font-family: var(--sans); font-size: 13px;
    z-index: 100;
    box-shadow: 0 20px 60px -20px rgba(0,0,0,.15);
    display: none;
  }
  .tweaks-panel.on { display: block; }
  .tweaks-panel h5 {
    font-family: var(--mono); font-size: 10px; letter-spacing: .14em;
    text-transform: uppercase; color: var(--muted);
    margin: 0 0 14px; font-weight: 500;
    display: flex; justify-content: space-between;
  }
  .tweaks-row { margin-bottom: 14px; }
  .tweaks-row label {
    display: block; font-size: 11px; color: var(--muted);
    margin-bottom: 6px; letter-spacing: .04em;
  }
  .tweaks-row .swatches { display: flex; gap: 6px; }
  .tweaks-row .sw {
    width: 22px; height: 22px; border-radius: 50%;
    cursor: pointer; border: 1px solid var(--rule);
    transition: transform .15s;
  }
  .tweaks-row .sw:hover { transform: scale(1.1); }
  .tweaks-row .sw.on { box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px var(--ink); }
  .tweaks-row .seg { display: flex; border: 1px solid var(--rule); border-radius: 2px; overflow: hidden; }
  .tweaks-row .seg button {
    flex: 1; background: transparent; border: 0;
    padding: 6px 8px; font-family: var(--mono); font-size: 10px;
    color: var(--ink-2); cursor: pointer; letter-spacing: .06em;
    text-transform: uppercase;
  }
  .tweaks-row .seg button.on { background: var(--ink); color: var(--bg); }
  .tweaks-version { color: var(--muted); }

  /* ---------- Inline-style replacements (security: CSP no unsafe-inline) ---------- */
  #collab .section-head { margin-bottom: 40px; }
  #contact .section-head { border-bottom: 0; padding-bottom: 0; margin-bottom: 32px; }
  a.contact-item { text-decoration: none; }
  footer .wrap { display: flex; justify-content: space-between; width: 100%; flex-wrap: wrap; gap: 16px; }
  .skill-tags:empty { border-top: 0; }

  /* Swatch colors */
  .sw[data-color="#B4552A"] { background: #B4552A; }
  .sw[data-color="#1F6F5C"] { background: #1F6F5C; }
  .sw[data-color="#2B4EA8"] { background: #2B4EA8; }
  .sw[data-color="#8B2F3F"] { background: #8B2F3F; }
  .sw[data-color="#6B4EA8"] { background: #6B4EA8; }
  .sw[data-color="#1A1814"] { background: #1A1814; }