/*
  Portfolio styles.
  Colors and fonts live under :root, so the whole look can be changed there.
  Every text color below passes WCAG AA contrast (4.5:1) on its background, in both themes.
  The dark theme follows the visitor's system setting unless they pick one with the
  moon/sun button (data-theme on <html>, remembered in localStorage).
*/

:root {
  /* Page */
  --color-bg:        #f5f4fa;   /* soft lavender paper */
  --color-surface:   #ffffff;   /* cards */
  --color-text:      #1d1c2e;   /* main text (about 16:1 on the page) */
  --color-muted:     #55547a;   /* secondary text (about 6.5:1) */
  --color-line:      #dddbea;   /* borders */

  /* Brand */
  --color-accent:    #3b36b8;   /* links and buttons (about 7.9:1) */
  --color-accent-dk: #2c2891;   /* button hover */
  --color-hero-1:    #66658e;   /* hero gradient: the original site color */
  --color-hero-2:    #2e2c55;
  --color-spark:     #f2b84b;   /* warm highlight, used on the dark hero only */

  /* Tags and pills */
  --color-pill:      #ebe9f6;
  --color-pill-text: #2f2d6e;

  /* Theme helpers */
  --color-on-accent: #ffffff;   /* text on accent buttons */
  --color-monogram:  #2e2c55;
  --nav-bg:          rgba(245, 244, 250, .88);
  --raw-text:        #000000;   /* the browser-default look while the page builds */
  --raw-link:        #0000ee;

  /* The SafeMaps mini map */
  --map-water:       #cfe0f3;
  --map-merge:       #d97706;
  --map-street:      #dcdae9;
  --map-standard:    #8a89a6;
  --map-risk:        #c43535;

  --font-head: 'Merriweather', Georgia, 'Times New Roman', serif;
  --font-body: 'Source Sans 3', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-code: ui-monospace, 'Cascadia Code', 'SF Mono', Menlo, Consolas, monospace;

  /* Code panels (the build editor and the button peeks); text about 14:1 on --code-bg */
  --code-bg:      #16152a;
  --code-bar:     #0f0e1e;
  --code-line:    #2b2a48;
  --code-text:    #e6e4f5;
  --code-muted:   #9896bd;   /* comments and line numbers (about 6.3:1) */

  --max-width: 1040px;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(29, 28, 46, .06), 0 8px 24px rgba(29, 28, 46, .06);
  --shadow-lift: 0 2px 4px rgba(29, 28, 46, .08), 0 18px 40px rgba(46, 44, 85, .16);
  color-scheme: light;
}

/* Dark theme: the system setting, unless the visitor chose light */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-bg: #121120; --color-surface: #1c1b2f; --color-text: #ecebf7; --color-muted: #aeadcc;
    --color-line: #302f4c; --color-accent: #aaa6ff; --color-accent-dk: #cac7ff;
    --color-hero-1: #4f4e78; --color-hero-2: #232145;
    --color-pill: #282748; --color-pill-text: #d6d4ff;
    --color-on-accent: #121120; --color-monogram: #3b36b8; --nav-bg: rgba(18, 17, 32, .86);
    --raw-text: #ececec; --raw-link: #9db0ff;
    --map-street: #2c2b45; --map-standard: #8f8eae; --map-risk: #ff6b6b; --map-water: #1d3150; --map-merge: #f59e0b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    --shadow-lift: 0 2px 4px rgba(0, 0, 0, .35), 0 18px 40px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --color-bg: #121120; --color-surface: #1c1b2f; --color-text: #ecebf7; --color-muted: #aeadcc;
  --color-line: #302f4c; --color-accent: #aaa6ff; --color-accent-dk: #cac7ff;
  --color-hero-1: #4f4e78; --color-hero-2: #232145;
  --color-pill: #282748; --color-pill-text: #d6d4ff;
  --color-on-accent: #121120; --color-monogram: #3b36b8; --nav-bg: rgba(18, 17, 32, .86);
  --raw-text: #ececec; --raw-link: #9db0ff;
  --map-street: #2c2b45; --map-standard: #8f8eae; --map-risk: #ff6b6b; --map-water: #1d3150; --map-merge: #f59e0b;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  --shadow-lift: 0 2px 4px rgba(0, 0, 0, .35), 0 18px 40px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

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

html { scroll-behavior: smooth; scroll-padding-top: 5rem; }

body {
  font-family: var(--font-body);
  font-size: 1.0625rem;
  color: var(--color-text);
  background-color: var(--color-bg);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--font-head); line-height: 1.2; }

img { display: block; max-width: 100%; height: auto; }

a { color: var(--color-accent); text-decoration-thickness: 2px; text-underline-offset: 3px; }
a:hover { color: var(--color-accent-dk); }

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

.skip-link {
  position: absolute; left: 1rem; top: -3rem;
  background: var(--color-accent); color: var(--color-on-accent);
  padding: .5rem 1rem; border-radius: 8px; z-index: 100;
}
.skip-link:focus { top: 1rem; color: var(--color-on-accent); }

/* -------- Navigation -------- */
.navbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: .75rem clamp(1rem, 4vw, 2rem);
  background: var(--nav-bg);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--color-line);
}

.nav-logo {
  display: inline-flex; align-items: center; gap: .65rem;
  color: var(--color-text); text-decoration: none; font-weight: 700;
}
.nav-logo:hover { color: var(--color-text); }

.monogram {
  display: inline-grid; place-items: center;
  width: 2.4rem; height: 2.4rem; border-radius: 10px;
  background: var(--color-monogram); color: #fff;
  font-family: var(--font-head); font-weight: 900; font-size: 1rem; letter-spacing: -.02em;
  transition: transform .25s ease, background .25s ease;
}
.nav-logo:hover .monogram { transform: rotate(-6deg); background: #3b36b8; }
.monogram.is-spinning { animation: monogram-spin .7s cubic-bezier(.3, 1.4, .5, 1); }
@keyframes monogram-spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }

.nav-right { display: flex; align-items: center; gap: 1.25rem; }

.nav-links { display: flex; gap: 1.25rem; }
.nav-links a { color: var(--color-text); text-decoration: none; font-weight: 600; white-space: nowrap; }
.nav-links a:hover { color: var(--color-accent); text-decoration: underline; }

.lang-toggle {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--color-pill); border-radius: 999px;
}
.lang-toggle button {
  font: inherit; font-size: .85rem; font-weight: 700; letter-spacing: .04em;
  border: 0; border-radius: 999px; padding: .2rem .7rem; cursor: pointer;
  background: transparent; color: var(--color-pill-text);
}
.lang-toggle button[aria-pressed="true"] { background: var(--color-accent); color: var(--color-on-accent); }

/* Round icon buttons: the theme switch and the command palette */
.icon-btn {
  display: inline-grid; place-items: center;
  width: 2.1rem; height: 2.1rem; border-radius: 50%;
  border: 0; cursor: pointer; background: var(--color-pill); color: var(--color-pill-text);
  font: 700 .8rem/1 var(--font-code);
}
.icon-btn:hover { background: var(--color-accent); color: var(--color-on-accent); }
.icon-btn svg { width: 1.05rem; height: 1.05rem; }
.theme-toggle .sun { display: none; }
.theme-toggle[aria-pressed="true"] .sun { display: block; }
.theme-toggle[aria-pressed="true"] .moon { display: none; }
.nav-tools { display: flex; align-items: center; gap: .4rem; }

/* -------- Hero -------- */
.hero {
  position: relative; overflow: hidden;
  color: #fff;
  background:
    radial-gradient(circle at 1px 1px, rgba(255, 255, 255, .09) 1px, transparent 0) 0 0 / 22px 22px,
    radial-gradient(60rem 30rem at 85% -10%, rgba(242, 184, 75, .18), transparent 60%),
    linear-gradient(135deg, var(--color-hero-1), var(--color-hero-2));
  padding: clamp(4rem, 12vw, 7.5rem) 0;
}

/* Same width and side padding as .section, so the hero text lines up with the content below. */
.hero-inner { position: relative; max-width: var(--max-width); margin: 0 auto; padding: 0 clamp(1rem, 4vw, 2rem); }

/* The dots light up around the cursor (features.js sets --mx and --my) */
.hero-glow {
  position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .4s ease;
  background: radial-gradient(circle at 1px 1px, rgba(255, 255, 255, .6) 1.2px, transparent 0) 0 0 / 22px 22px;
  -webkit-mask-image: radial-gradient(240px circle at var(--mx, 50%) var(--my, 50%), #000, transparent 70%);
  mask-image: radial-gradient(240px circle at var(--mx, 50%) var(--my, 50%), #000, transparent 70%);
}
.hero.is-glowing .hero-glow { opacity: 1; }

.eyebrow {
  display: inline-block;
  font-size: .9rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: #fff; background: rgba(255, 255, 255, .12);
  border: 1px solid rgba(255, 255, 255, .22);
  padding: .3rem .8rem; border-radius: 999px; margin-bottom: 1.25rem;
}

.hero h1 {
  font-size: clamp(2.4rem, 7vw, 4.25rem);
  font-weight: 900; letter-spacing: -.02em;
  margin-bottom: 1rem;
}

.lead {
  max-width: 40rem;
  font-size: clamp(1.1rem, 2.2vw, 1.3rem);
  color: #f1f0f8;
  margin-bottom: 2rem;
}

.hero-actions { display: flex; flex-wrap: wrap; gap: .75rem; }

/* -------- Buttons -------- */
.button {
  display: inline-block;
  background: var(--color-accent); color: var(--color-on-accent);
  padding: .75rem 1.4rem; border-radius: 10px;
  font-weight: 700; text-decoration: none;
  border: 2px solid var(--color-accent);
  transition: transform .15s ease, background .15s ease, box-shadow .15s ease;
}
.button:hover { background: var(--color-accent-dk); border-color: var(--color-accent-dk); color: var(--color-on-accent); transform: translateY(-2px); }

.hero .button { background: #fff; color: var(--color-hero-2); border-color: #fff; }
.hero .button:hover { background: var(--color-spark); border-color: var(--color-spark); color: var(--color-hero-2); }
.hero .button-ghost { background: transparent; color: #fff; border-color: rgba(255, 255, 255, .6); }
.hero .button-ghost:hover { background: rgba(255, 255, 255, .12); border-color: #fff; color: #fff; }

.button-outline { background: transparent; color: var(--color-accent); }
.button-outline:hover { background: var(--color-accent); color: var(--color-on-accent); }

/* -------- Sections -------- */
.section {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: clamp(3rem, 8vw, 5rem) clamp(1rem, 4vw, 2rem);
}

.section h2 {
  font-size: clamp(1.7rem, 4vw, 2.2rem);
  margin-bottom: 1.25rem;
}
.section h2::after {
  content: ""; display: block;
  width: 3rem; height: 4px; border-radius: 4px; margin-top: .6rem;
  background: linear-gradient(90deg, var(--color-accent), var(--color-spark));
}

.section-intro { color: var(--color-muted); margin-top: -.25rem; }

/* -------- About -------- */
.about-grid {
  display: grid; gap: 2rem;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  align-items: start;
}
.about-text p + p { margin-top: 1rem; }
.about-sub { font-size: 1.2rem; margin: 2rem 0 .6rem; }

.pull-quote {
  position: relative;
  background: var(--color-surface);
  border-left: 5px solid var(--color-accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 1.5rem 1.5rem 1.5rem 1.75rem;
  box-shadow: var(--shadow);
}
.pull-quote::before {
  content: "\201C";
  position: absolute; top: -.6rem; right: 1rem;
  font-family: var(--font-head); font-size: 5rem; line-height: 1;
  color: var(--color-pill);
}
.pull-quote p {
  position: relative;
  font-family: var(--font-head); font-size: 1.1rem; line-height: 1.55;
}
.about-side { display: grid; gap: 2rem; }
/* The code keeps its white background in the dark theme, so phones can still read it. */
.about-qr { display: flex; align-items: center; gap: 1rem; margin: 0; }
.about-qr img {
  width: 9.5rem; height: auto; flex: none;
  background: #fff; border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.about-qr figcaption { color: var(--color-muted); font-size: .95rem; line-height: 1.45; }

/* -------- Skills -------- */
.skills-title { font-size: 1.25rem; margin: 3rem 0 1rem; }

.skills-groups {
  display: grid; gap: 1.25rem 2rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.skills-group h4 {
  font-size: .8rem; letter-spacing: .1em; text-transform: uppercase;
  color: var(--color-muted); margin-bottom: .5rem;
}

.skills-list { list-style: none; display: flex; flex-wrap: wrap; gap: .45rem; }
.skills-list li {
  background: var(--color-surface);
  border: 1px solid var(--color-line);
  padding: .3rem .8rem; border-radius: 999px;
  font-size: .95rem;
}

/* -------- Projects -------- */
.project-grid {
  display: grid; gap: 1.75rem; margin-top: 2rem;
  grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr));
}

.project-card {
  display: flex; flex-direction: column;
  background: var(--color-surface);
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform .25s ease, box-shadow .25s ease;
}
.project-card:hover { transform: translateY(-6px); box-shadow: var(--shadow-lift); }

.project-media {
  position: relative; display: block; aspect-ratio: 16 / 10; overflow: hidden;
  border-bottom: 1px solid var(--color-line);
  background: var(--color-pill);
}
.project-media img {
  width: 100%; height: 100%; object-fit: cover; object-position: left top;
  transition: transform .5s ease;
}
.project-card:hover .project-media img { transform: scale(1.04); }
.project-media > a { display: block; width: 100%; height: 100%; }
.project-media video {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; object-position: left top; pointer-events: none;
  opacity: 0; transition: opacity .35s ease;
}
.project-media video.is-playing { opacity: 1; }

.project-body { display: flex; flex-direction: column; flex: 1; padding: 1.4rem 1.5rem 1.5rem; }
.project-body h3 { font-size: 1.3rem; margin-bottom: .6rem; }
.project-body p + p { margin-top: .75rem; }

.tags { list-style: none; display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: .9rem; }
.tags li {
  font-size: .78rem; font-weight: 700;
  background: var(--color-pill); color: var(--color-pill-text);
  padding: .15rem .55rem; border-radius: 6px;
}

.highlight {
  font-size: .97rem;
  padding-left: .85rem;
  border-left: 3px solid var(--color-spark);
}
.note { font-size: .9rem; color: var(--color-muted); }

.project-links { margin-top: auto; padding-top: 1.1rem; display: flex; flex-wrap: wrap; gap: .4rem 1.25rem; }
.project-link { font-weight: 700; text-decoration: none; }
.project-link::after { content: " \2192"; display: inline-block; transition: transform .2s ease; }
.project-link:hover { text-decoration: underline; }
.project-link:hover::after { transform: translateX(4px); }

/* Guernica card art: the 6 × 3 puzzle grid in the painting's black, white and grey,
   with one piece still out of place. Drawn in CSS so no copyrighted image is used. */
.guernica-art {
  position: relative; display: grid; place-items: center;
  background: radial-gradient(circle at 70% 30%, #3a3a37, #151513 70%);
  text-decoration: none;
}
.guernica-art .pieces {
  position: absolute; inset: 12%;
  display: grid; grid-template-columns: repeat(6, 1fr); grid-template-rows: repeat(3, 1fr); gap: 4px;
}
.guernica-art .pieces i { background: rgba(255, 255, 255, .07); border-radius: 3px; }
.guernica-art .pieces i:nth-child(3n) { background: rgba(255, 255, 255, .12); }
.guernica-art .pieces i:nth-child(5n) { background: rgba(255, 255, 255, .04); }
.guernica-art .pieces .missing {
  border: 0; padding: 0; border-radius: 3px; cursor: grab; touch-action: none;
  background: #e9e7e1;
  transform: translate(20%, -28%) rotate(9deg);
  box-shadow: 0 10px 24px rgba(0, 0, 0, .5);
  transition: transform .45s cubic-bezier(.3, 1.3, .5, 1), box-shadow .3s ease;
  z-index: 2;
}
.guernica-art .pieces .missing:hover { box-shadow: 0 14px 30px rgba(0, 0, 0, .6), 0 0 0 3px rgba(242, 184, 75, .7); }
.guernica-art .pieces .missing:focus-visible { outline: 3px solid var(--color-spark); outline-offset: 2px; }
.guernica-art .pieces .missing.is-dragging { cursor: grabbing; transition: none; }
.guernica-art .pieces .missing.is-placed { transform: none; cursor: default; animation: piece-flash .9s ease; }
@keyframes piece-flash { from { box-shadow: 0 0 0 0 rgba(242, 184, 75, .95); } to { box-shadow: 0 0 0 16px rgba(242, 184, 75, 0); } }
.guernica-hint {
  position: absolute; left: 0; right: 0; bottom: .55rem; z-index: 1;
  text-align: center; font-size: .78rem; font-weight: 600; letter-spacing: .03em; color: #cfccc3;
}
.guernica-verse {
  position: absolute; inset: 0; z-index: 3;
  display: grid; place-content: center; gap: .15rem; text-align: center;
  padding: 1rem 1.25rem; background: rgba(16, 16, 14, .96); color: #f4f2ec;
  opacity: 0; visibility: hidden; transition: opacity .6s ease, visibility .6s;
}
.guernica-verse.is-shown { opacity: 1; visibility: visible; }
.guernica-verse p { font-family: var(--font-head); font-size: clamp(.92rem, 2.4vw, 1.05rem); line-height: 1.5; }
.guernica-verse .verse-en { font-family: var(--font-body); font-style: italic; font-size: .85rem; color: #d9d6cd; margin-top: .3rem; }
.guernica-verse cite { margin-top: .55rem; font-style: normal; font-size: .74rem; letter-spacing: .05em; color: #d9d6cd; }
.guernica-verse button {
  justify-self: center; margin-top: .6rem;
  font: 600 .78rem/1 var(--font-body); padding: .35rem .7rem; border-radius: 999px; cursor: pointer;
  background: transparent; color: #f4f2ec; border: 1px solid rgba(244, 242, 236, .45);
}
.guernica-verse button:hover { border-color: var(--color-spark); color: var(--color-spark); }
.guernica-label {
  position: relative; text-align: center;
  font-family: var(--font-head); font-weight: 900; font-size: clamp(1.6rem, 4vw, 2.1rem);
  color: #f4f2ec; letter-spacing: .02em;
  text-shadow: 0 2px 12px rgba(0, 0, 0, .7);
}
.guernica-label small {
  display: block; font-family: var(--font-body); font-weight: 700;
  font-size: .8rem; letter-spacing: .25em; color: #cfccc3;
}

/* -------- Experience -------- */
.timeline { list-style: none; position: relative; margin-top: 1.5rem; }
.timeline::before {
  content: ""; position: absolute; left: 7px; top: .5rem; bottom: .5rem;
  width: 2px; background: var(--color-line);
}

.job { position: relative; padding-left: 2.25rem; }
.job + .job { margin-top: 2rem; }
.job::before {
  content: ""; position: absolute; left: 0; top: .45rem; z-index: 1;
  transition: border-color .3s ease, background-color .3s ease;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--color-bg); border: 3px solid var(--color-accent);
}
.job:first-child::before { background: var(--color-accent); box-shadow: 0 0 0 4px var(--color-pill); }

/* The timeline drawn as a route: a dashed line grows as you scroll (features.js sets --route) */
.timeline::after {
  content: ""; position: absolute; left: 6px; top: .5rem; bottom: .5rem; width: 4px; border-radius: 2px;
  background: repeating-linear-gradient(to bottom, var(--color-spark) 0 10px, transparent 10px 16px);
  transform: scaleY(var(--route, 1)); transform-origin: top;
}
.job.reached::before { border-color: var(--color-spark); }
.job:first-child.reached::before { background: var(--color-spark); animation: here-pulse 2.2s ease-out infinite; }
@keyframes here-pulse { 0% { box-shadow: 0 0 0 0 rgba(242, 184, 75, .6); } 100% { box-shadow: 0 0 0 14px rgba(242, 184, 75, 0); } }
.you-are-here {
  display: inline-block; vertical-align: .2em; margin-left: .5rem;
  font: 700 .7rem/1 var(--font-body); letter-spacing: .08em; text-transform: uppercase;
  background: var(--color-spark); color: #2e2c55; padding: .32rem .55rem; border-radius: 999px;
}
.route-start { margin-top: 1.4rem; padding-left: 2.25rem; font-size: .9rem; font-weight: 600; color: var(--color-muted); }

.job-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.job-head h3 { font-size: 1.15rem; }
.job-dates { font-size: .95rem; font-weight: 600; color: var(--color-muted); white-space: nowrap; }
.job-org { font-weight: 700; color: var(--color-pill-text); margin: .1rem 0 .5rem; }

.job ul { padding-left: 1.1rem; }
.job li + li { margin-top: .3rem; }
.job li::marker { color: var(--color-accent); }

.cert {
  display: inline-flex; align-items: center; gap: .6rem;
  margin-top: 2.25rem; padding: .6rem 1rem .6rem .6rem;
  background: var(--color-surface); border: 1px solid var(--color-line);
  border-radius: 999px; box-shadow: var(--shadow); font-weight: 600;
}
.cert-badge {
  display: inline-grid; place-items: center;
  width: 2rem; height: 2rem; border-radius: 50%;
  background: var(--color-monogram); color: #fff;
  font-family: var(--font-head); font-weight: 900; font-size: .8rem;
}

/* -------- Contact -------- */
.contact .contact-where { color: var(--color-muted); font-size: 1rem; margin-top: .25rem; }

.contact { text-align: center; }
.contact h2::after { margin-left: auto; margin-right: auto; }
.contact p { font-size: 1.15rem; }

.contact-list {
  list-style: none;
  display: flex; flex-wrap: wrap; justify-content: center; gap: .75rem;
  margin-top: 1.5rem;
}

/* -------- Footer -------- */
.footer {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--color-muted);
  border-top: 1px solid var(--color-line);
  font-size: .95rem;
}

.rebuild {
  margin-top: .4rem;
  font: inherit; font-size: .9rem; font-weight: 600;
  background: none; border: 0; padding: .2rem .4rem; cursor: pointer;
  color: var(--color-accent); text-decoration: underline; text-underline-offset: 3px;
}
.rebuild:hover { color: var(--color-accent-dk); }

/* -------- The page building itself (build.js) --------
   index.html adds .building and the raw-* classes before the first paint. Elements stay
   hidden until their line of code is typed (.b-in), and each raw-* class gives them the
   browser's plain default look until the CSS rule that styles them is typed. */
html.building :is(.nav-logo, .nav-links, .nav-tools, .eyebrow, .hero h1, .lead, .hero-actions, main, .footer):not(.b-in) {
  visibility: hidden;
}
html.building :is(.nav-logo, .nav-links, .nav-tools, .eyebrow, .hero h1, .lead, .hero-actions).b-in {
  animation: b-pop .3s ease both;
}
@keyframes b-pop { from { opacity: 0; transform: translateY(6px); } }

html.building :is(.navbar, .navbar *, .hero, .hero *) {
  transition: background-color .7s ease, color .7s ease, border-color .7s ease, border-radius .7s ease,
              padding .7s ease, letter-spacing .7s ease, box-shadow .7s ease;
}

/* raw-colors: the hero has no background yet (a page-colored layer fades away) */
html.building .hero::before {
  content: ""; position: absolute; inset: 0;
  background: var(--color-bg); opacity: 0; pointer-events: none;
  transition: opacity .9s ease;
}
html.raw-colors .hero::before { opacity: 1; }
html.building .hero-inner { position: relative; }
html.raw-colors :is(.hero, .lead, .eyebrow) { color: var(--raw-text); }
html.raw-colors .eyebrow { background-color: transparent; border-color: transparent; }

/* raw-type: the browser's default serif */
html.raw-type :is(.navbar, .hero) * { font-family: 'Times New Roman', Times, serif; }
html.raw-type .eyebrow { text-transform: none; letter-spacing: 0; font-weight: 400; }
html.raw-type .hero h1 { letter-spacing: 0; font-weight: 700; }

/* raw-buttons: the hero's links are plain blue links */
html.raw-buttons .hero :is(.button, .button-ghost) {
  background-color: transparent; border-color: transparent; border-radius: 0;
  color: var(--raw-link); text-decoration: underline; font-weight: 400; padding-left: 0; padding-right: .5rem;
}

/* raw-nav: a plain row of links and grey buttons */
html.raw-nav .navbar {
  background-color: transparent; border-bottom-color: transparent;
  -webkit-backdrop-filter: none; backdrop-filter: none;
}
html.raw-nav .nav-logo { color: var(--raw-text); font-weight: 400; }
html.raw-nav .monogram { background-color: transparent; color: var(--raw-text); }
html.raw-nav .nav-links a { color: var(--raw-link); text-decoration: underline; font-weight: 400; }
html.raw-nav .icon-btn { background-color: #efefef; color: #000; border: 1px solid #767676; border-radius: 3px; }
html.raw-nav .lang-toggle { background-color: transparent; }
html.raw-nav .lang-toggle button,
html.raw-nav .lang-toggle button[aria-pressed="true"] {
  background-color: #efefef; color: #000; border: 1px solid #767676; border-radius: 3px; font-weight: 400;
}

/* The editor panel that types the code */
.builder {
  position: fixed; z-index: 60;
  right: clamp(1rem, 3vw, 2rem); bottom: clamp(1rem, 3vw, 2rem);
  width: min(31rem, calc(100vw - 2rem));
  background: var(--code-bg); color: var(--code-text);
  border: 1px solid var(--code-line); border-radius: 12px; overflow: hidden;
  box-shadow: 0 24px 60px rgba(10, 9, 30, .4);
  font: 13px/1.6 var(--font-code); font-variant-ligatures: none;
  opacity: 0; transform: translateY(16px) scale(.98);
  transition: opacity .45s ease, transform .45s ease;
}
.builder.is-open { opacity: 1; transform: none; }

.builder-bar { display: flex; align-items: stretch; background: var(--code-bar); font-size: 12px; }
.builder-dots { display: flex; align-items: center; gap: 6px; padding: 0 .8rem; }
.builder-dots i { width: 10px; height: 10px; border-radius: 50%; background: #ff6b6b; }
.builder-dots i:nth-child(2) { background: var(--color-spark); }
.builder-dots i:nth-child(3) { background: #5fd38d; }
.builder-tab {
  padding: .45rem .85rem; color: var(--code-muted);
  border-top: 2px solid transparent; white-space: nowrap;
}
.builder-tab.is-active { background: var(--code-bg); color: var(--code-text); border-top-color: var(--color-spark); }

.builder-code {
  height: 14.5rem; overflow: auto; margin: 0; padding: .7rem .9rem .7rem 0;
  font: inherit; white-space: pre-wrap; overflow-wrap: anywhere;
  scrollbar-width: thin; scrollbar-color: var(--code-line) transparent;
}
.b-line { display: block; padding-left: 3.1rem; text-indent: -3.1rem; }
.b-ln {
  display: inline-block; width: 2.3rem; margin-right: .8rem; text-indent: 0;
  text-align: right; color: var(--code-muted); opacity: .7; user-select: none;
}
.b-caret {
  display: inline-block; width: .55em; height: 1.15em; margin-left: 1px; vertical-align: -.2em;
  background: var(--color-spark); animation: b-blink 1s steps(1) infinite;
}
@keyframes b-blink { 50% { opacity: 0; } }

.builder-status {
  display: flex; align-items: center; gap: .5rem;
  padding: .5rem .9rem; border-top: 1px solid var(--code-line);
}
.builder-spin { width: 1em; text-align: center; color: var(--color-spark); font-size: 1.05em; }
.builder-phrase { color: var(--code-text); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.builder-meta { color: var(--code-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.builder-skip {
  margin-left: auto; flex-shrink: 0;
  font: inherit; font-size: 12px; cursor: pointer;
  background: transparent; color: var(--code-text);
  border: 1px solid var(--code-line); border-radius: 6px; padding: .15rem .6rem;
}
.builder-skip:hover { border-color: var(--color-spark); color: var(--color-spark); }
.builder-skip:focus-visible { outline-color: var(--color-spark); }

/* Syntax colors, shared with the peeks (each at least 7:1 on --code-bg) */
.t-com  { color: var(--code-muted); font-style: italic; }
.t-str  { color: #f4c66e; }
.t-tag  { color: #8cc8ff; }
.t-num  { color: #ffae94; }
.t-kw   { color: #c9adff; }
.t-fn   { color: #7fe0c8; }
.t-attr { color: #b6c2ff; }

/* The code behind a button, on hover or keyboard focus */
.peek {
  position: fixed; z-index: 70; top: 0; left: 0;
  max-width: min(36rem, calc(100vw - 1rem));
  padding: .55rem .8rem .65rem;
  background: var(--code-bg); color: var(--code-text);
  border: 1px solid var(--code-line); border-radius: 10px;
  box-shadow: 0 14px 34px rgba(10, 9, 30, .35);
  font: 12.5px/1.55 var(--font-code); font-variant-ligatures: none;
  pointer-events: none; opacity: 0; transform: translateY(4px);
  transition: opacity .15s ease, transform .15s ease;
}
.peek.is-open { opacity: 1; transform: none; }
.peek-file { display: flex; align-items: center; gap: .45rem; margin-bottom: .3rem; font-size: 11.5px; color: var(--code-muted); }
.peek-icon { color: var(--color-spark); font-weight: 700; }
.peek pre { margin: 0; font: inherit; white-space: pre-wrap; overflow-wrap: anywhere; }

/* -------- Numbers under the hero (count up once seen) -------- */
.stats {
  position: relative; z-index: 2;
  max-width: var(--max-width); margin: -2.75rem auto 0; padding: 0 clamp(1rem, 4vw, 2rem);
}
.stats ul {
  list-style: none; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px;
  background: var(--color-line); border: 1px solid var(--color-line);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
.stats li { background: var(--color-surface); padding: 1.1rem 1.25rem; }
.stat-num {
  display: block; font-family: var(--font-head); font-weight: 900; line-height: 1.15;
  font-size: clamp(1.55rem, 3.2vw, 2.1rem); color: var(--color-accent); font-variant-numeric: tabular-nums;
}
.stat-vs { font: 700 .9rem var(--font-body); color: var(--color-muted); margin: 0 .3rem; }
.stat-label { display: block; margin-top: .35rem; font-size: .93rem; line-height: 1.4; color: var(--color-muted); }

/* -------- Playable cards -------- */
.try-here {
  position: absolute; right: .7rem; bottom: .7rem; z-index: 3;
  font: 700 .85rem/1 var(--font-body); padding: .55rem .85rem; border-radius: 999px; border: 0; cursor: pointer;
  background: rgba(22, 21, 42, .88); color: #fff; box-shadow: 0 4px 14px rgba(0, 0, 0, .25);
  transition: background .2s ease, transform .2s ease;
}
.try-here:hover { background: #3b36b8; transform: translateY(-1px); }
.mini {
  position: absolute; inset: 0; z-index: 4;
  display: flex; flex-direction: column;
  background: var(--color-surface); color: var(--color-text);
}
.mini[hidden] { display: none; }
.mini-close {
  position: absolute; top: .45rem; right: .45rem; z-index: 2;
  width: 1.8rem; height: 1.8rem; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--color-pill); color: var(--color-pill-text); font: 700 1rem/1 var(--font-body);
}
.mini-close:hover { background: var(--color-accent); color: var(--color-on-accent); }

/* SafeMaps: two routes across a little city */
.mini-map { position: relative; flex: 1; min-height: 0; }
.mini-map svg { display: block; width: 100%; height: 100%; }
/* Drawn in a 640-unit-wide viewBox of real streets (safemaps-minimap.js) */
.mini-map .river { stroke: var(--map-water); stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; fill: none; }
.mini-map .street { stroke: var(--map-street); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; fill: none; }
.mini-map .street.motorway { stroke-width: 6; }
.mini-map .route { fill: none; stroke-width: 8; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 1; stroke-dashoffset: 1; }
.mini-map .route.standard { stroke: var(--map-standard); transition: stroke-dashoffset 1.3s ease; }
.mini-map .route.safer { stroke: var(--color-spark); stroke-width: 9; transition: stroke-dashoffset 1.6s ease .9s; }
.mini-map.is-planned .route { stroke-dashoffset: 0; }
.mini-map :is(.risk, .merge) { opacity: 0; transition: opacity .3s ease; stroke: var(--color-surface); stroke-width: 3; }
.mini-map .risk { fill: var(--map-risk); }
.mini-map .merge { fill: var(--map-merge); }
.mini-map.is-planned :is(.risk, .merge) { opacity: 1; transition-delay: 1.2s; }
.mini-map :is(.risk-ring, .merge-ring) { fill: none; stroke-width: 3; opacity: 0; transform-box: fill-box; transform-origin: center; }
.mini-map .risk-ring { stroke: var(--map-risk); }
.mini-map .merge-ring { stroke: var(--map-merge); }
.mini-map.is-planned :is(.risk-ring, .merge-ring) { animation: risk-ring 1.6s ease-out 1.4s infinite; }
@keyframes risk-ring { 0% { opacity: .9; transform: scale(1); } 100% { opacity: 0; transform: scale(2.4); } }
.mini-map .pin { fill: var(--color-text); stroke: var(--color-surface); stroke-width: 3; }
.mini-map .pin-label { fill: var(--color-surface); font: 700 16px var(--font-body); text-anchor: middle; dominant-baseline: central; }
.mini-map .place {
  fill: var(--color-text); font: 700 19px var(--font-body);
  paint-order: stroke; stroke: var(--color-surface); stroke-width: 5px; stroke-linejoin: round;
}
.mini-plan {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  font: 700 .9rem/1 var(--font-body); padding: .65rem 1rem; border-radius: 999px; border: 0; cursor: pointer;
  background: var(--color-accent); color: var(--color-on-accent); box-shadow: var(--shadow-lift);
}
.mini-map.is-planned .mini-plan { display: none; }
.mini-legend {
  display: grid; grid-template-columns: 1fr; gap: .1rem .8rem;
  padding: .45rem .8rem .5rem; font-size: .78rem; line-height: 1.35; border-top: 1px solid var(--color-line);
}
.mini-legend b { font-variant-numeric: tabular-nums; }
.mini-legend .leg::before {
  content: ""; display: inline-block; width: 14px; height: 4px; border-radius: 2px; margin-right: .35rem; vertical-align: middle;
}
.mini-legend .leg-std::before { background: var(--map-standard); }
.mini-legend .leg-safe::before { background: var(--color-spark); }
.mini-legend .leg-note { grid-column: 1 / -1; color: var(--color-muted); }

/* OneTouch: ask the scripted assistant */
.mini-chat { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; gap: .45rem; padding: .65rem 2.6rem .6rem .75rem; font-size: .85rem; line-height: 1.4; }
.chat-q {
  align-self: flex-end; max-width: 88%; padding: .35rem .7rem;
  background: var(--color-accent); color: var(--color-on-accent); border-radius: 12px 12px 3px 12px;
}
.chat-a { align-self: flex-start; width: 100%; padding: .5rem .7rem; background: var(--color-pill); border-radius: 12px 12px 12px 3px; }
.chat-thinking { font: .78rem var(--font-code); color: var(--color-muted); font-variant-ligatures: none; }
.bar-row { display: grid; grid-template-columns: 6.2rem 1fr 1.8rem; align-items: center; gap: .45rem; font-size: .78rem; }
.bar-row + .bar-row { margin-top: .2rem; }
.bar { height: .55rem; border-radius: 3px; background: var(--color-accent); transform-origin: left; animation: bar-grow .7s cubic-bezier(.3, 1, .4, 1) both; }
.bar-row:nth-child(2) .bar { animation-delay: .08s; }
.bar-row:nth-child(3) .bar { animation-delay: .16s; }
.bar-row:nth-child(4) .bar { animation-delay: .24s; }
@keyframes bar-grow { from { transform: scaleX(0); } }
.bar-val { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.chat-table { width: 100%; border-collapse: collapse; font-size: .76rem; }
.chat-table th, .chat-table td { text-align: left; padding: .15rem .3rem .15rem 0; border-bottom: 1px solid var(--color-line); }
.chat-chips { display: flex; flex-wrap: wrap; gap: .35rem; padding: .5rem .75rem .6rem; border-top: 1px solid var(--color-line); }
.chat-chips button {
  font: inherit; font-size: .76rem; line-height: 1.25; padding: .3rem .6rem; border-radius: 999px; cursor: pointer; text-align: left;
  border: 1px solid var(--color-line); background: var(--color-surface); color: var(--color-text);
}
.chat-chips button:hover { border-color: var(--color-accent); color: var(--color-accent); }
.chat-chips button:disabled { opacity: .55; cursor: default; }
.chat-note { font-size: .72rem; color: var(--color-muted); }

/* -------- Command palette (press / or Ctrl+K) -------- */
.palette {
  width: min(38rem, calc(100vw - 2rem)); max-height: min(34rem, calc(100vh - 4rem));
  margin: 12vh auto auto; padding: 0; overflow: hidden;
  background: var(--code-bg); color: var(--code-text);
  border: 1px solid var(--code-line); border-radius: 12px; box-shadow: 0 30px 80px rgba(0, 0, 0, .5);
  font: 14px/1.6 var(--font-code); font-variant-ligatures: none;
}
.palette[open] { display: flex; flex-direction: column; }
.palette::backdrop { background: rgba(10, 9, 30, .55); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.palette-out { flex: 0 1 auto; overflow: auto; max-height: 13rem; padding: .7rem 1rem 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.palette-out:empty { display: none; }
.palette-out .p-cmd { color: var(--code-muted); }
.palette-out .p-ok { color: #7fe0c8; }
.palette-out .p-err { color: #ffae94; }
.palette-form { display: flex; align-items: center; gap: .55rem; padding: .7rem 1rem; }
.palette-form label { color: var(--color-spark); font-weight: 700; }
.palette-form input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: inherit; font: inherit; caret-color: var(--color-spark); }
.palette-form:focus-within { box-shadow: inset 0 -2px 0 var(--color-spark); }
.palette-list { list-style: none; flex: 1 1 auto; overflow: auto; padding: .35rem; border-top: 1px solid var(--code-line); }
.palette-list li { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; padding: .35rem .65rem; border-radius: 6px; cursor: pointer; }
.palette-list li[aria-selected="true"] { background: var(--code-line); }
.palette-list .p-desc { font: .85rem/1.4 var(--font-body); color: var(--code-muted); text-align: right; }
.palette-foot { padding: .45rem 1rem; font-size: 11.5px; color: var(--code-muted); border-top: 1px solid var(--code-line); }
.palette-foot kbd { font: inherit; padding: 0 .3rem; border: 1px solid var(--code-line); border-radius: 4px; }

/* -------- View source: every part of the page labeled with the tag that makes it -------- */
html.view-source :is(.hero, main > section, .project-card, .footer) { position: relative; outline: 1px dashed rgba(170, 166, 255, .75); outline-offset: -1px; }
html.view-source .navbar { outline: 1px dashed rgba(170, 166, 255, .75); outline-offset: -1px; }
.src-tag {
  position: absolute; top: 0; left: 0; z-index: 5; max-width: 100%;
  padding: .15rem .55rem; border-radius: 0 0 6px 0;
  background: var(--code-bg); color: var(--code-text);
  font: 11.5px/1.5 var(--font-code); font-variant-ligatures: none; text-align: left;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none;
}
.navbar > .src-tag { top: 100%; left: auto; right: 0; border-radius: 0 0 0 6px; }
.footer-tools { display: flex; flex-wrap: wrap; justify-content: center; gap: .25rem 1rem; margin-top: .4rem; }
.footer-tools .rebuild { margin-top: 0; }

/* -------- Case studies (work/*.html) -------- */
.hero.case-hero { padding: clamp(3rem, 9vw, 5.5rem) 0 clamp(3rem, 8vw, 4.5rem); }
.case-hero h1 { font-size: clamp(2.1rem, 5.5vw, 3.4rem); }
.case-hero .tags { margin: 1.25rem 0 0; }
.case-hero .tags li { background: rgba(255, 255, 255, .14); color: #fff; }
.case-hero .hero-actions { margin-top: 1.75rem; }
.back-link { font-weight: 600; text-decoration: none; color: var(--color-text); white-space: nowrap; }
.back-link:hover { color: var(--color-accent); text-decoration: underline; }
.case { max-width: 780px; margin: 0 auto; padding: clamp(2.5rem, 6vw, 4rem) clamp(1rem, 4vw, 2rem); }
.case h2 { font-size: clamp(1.35rem, 3vw, 1.6rem); margin: 0 0 .85rem; }
.case section + section { margin-top: 3rem; }
.case h2::after { content: ""; display: block; width: 2.5rem; height: 4px; border-radius: 4px; margin-top: .5rem; background: linear-gradient(90deg, var(--color-accent), var(--color-spark)); }
.case p + p, .case p + ul:not(.case-results), .case p + ol { margin-top: .9rem; }
.case ol, .case ul:not(.case-results) { padding-left: 1.3rem; }
.case li + li { margin-top: .5rem; }
.case li::marker { color: var(--color-accent); font-weight: 700; }
.case-results { list-style: none; display: grid; grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr)); gap: .75rem; margin-top: 1.1rem; }
.case-results li { margin: 0 !important; padding: .9rem 1rem; background: var(--color-surface); border: 1px solid var(--color-line); border-radius: 12px; }
.case-results b { display: block; font-family: var(--font-head); font-size: 1.45rem; line-height: 1.2; color: var(--color-accent); }
.case-results span { display: block; margin-top: .2rem; font-size: .92rem; line-height: 1.4; color: var(--color-muted); }
.case-callout {
  margin-top: 1.1rem; padding: 1rem 1.25rem;
  background: var(--color-surface); border-left: 4px solid var(--color-spark); border-radius: 0 12px 12px 0; box-shadow: var(--shadow);
}
.case code { font: .92em var(--font-code); background: var(--color-pill); color: var(--color-pill-text); padding: .05rem .3rem; border-radius: 4px; }
.case-note { margin-top: 1rem; font-size: .92rem; color: var(--color-muted); }
.case-next { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: 2.75rem; }

/* -------- Scroll reveal (added by script.js, so nothing hides without JavaScript) -------- */
.reveal { opacity: 0; transform: translateY(18px); transition: opacity .6s ease, transform .6s ease; }
.reveal.is-visible { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; animation: none !important; }
  .reveal { opacity: 1; transform: none; }
}

/* -------- Narrow screens -------- */
@media (max-width: 760px) {
  .about-grid { grid-template-columns: 1fr; }
}

/* Phones: logo and language toggle on the first row, links on a second row. */
@media (max-width: 640px) {
  .navbar { flex-wrap: wrap; row-gap: .4rem; }
  .nav-right { display: contents; }
  .nav-links { order: 2; width: 100%; justify-content: space-between; gap: .5rem; font-size: .95rem; }
  .job-head { flex-direction: column; gap: 0; }
  .builder { font-size: 12px; }
  .builder-code { height: 7.5rem; }
  .builder-meta { display: none; }
  .nav-tools { order: 1; gap: .3rem; }
  .icon-btn { width: 1.95rem; height: 1.95rem; }
}
@media (max-width: 760px) {
  .stats ul { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 380px) {
  .nav-name { display: none; }
}

/* -------- Small additions for the playable cards and the timeline -------- */
.guernica-label { pointer-events: none; }

/* Each card opens its project when clicked (features.js); its own buttons, links and
   mini apps keep working. On Guernica's art, clicks go through the drawn pieces to the
   puzzle's link underneath, except on the loose piece, which can still be dragged in. */
.project-card { cursor: pointer; }
.project-card .mini { cursor: auto; }
.project-card:has(.project-link:focus-visible) { transform: translateY(-6px); box-shadow: var(--shadow-lift); }
.guernica-art .art-link { position: absolute; inset: 0; z-index: 1; }
.guernica-art .pieces { z-index: 2; pointer-events: none; }
.guernica-art .pieces .missing { pointer-events: auto; }
.guernica-art .guernica-hint { pointer-events: none; z-index: 2; }
.job-title { display: flex; align-items: center; flex-wrap: wrap; gap: .25rem .55rem; }
.job-title .you-are-here { margin-left: 0; }
.footer-hint { margin-top: .35rem; font-size: .85rem; }
@media (hover: none) { .footer-hint { display: none; } }
/* An open little app, or the Lorca verse, gets more room than the 16:10 picture */
.project-media.has-mini { aspect-ratio: auto; height: 21rem; }
.guernica-art.has-verse { aspect-ratio: auto; height: 18rem; }
.guernica-art.has-verse .guernica-hint { visibility: hidden; }
.mini-map .rail { stroke: var(--color-text); stroke-width: 3; stroke-linecap: round; opacity: 0; transition: opacity .3s ease 2.2s; }
.mini-map.is-planned .rail { opacity: .85; }
