/* ==========================================================================
   Aksel — Portfolio Site Stylesheet
   Premium dark portfolio, Antigravity-style restraint.
   System fonts only. Zero third-party requests. Mobile-first, accessible.
   ========================================================================== */

/* ==========================================================================
   1. DESIGN TOKENS
   ========================================================================== */

:root {
  --bg: #0a0a0a;
  --surface: #121214;
  --surface-2: #17171a;
  --text: #f5f5f5;
  --muted: #8b8b93;
  --accent: #22d3ee;
  --accent-dim: #0e7490;
  --border: rgba(255, 255, 255, 0.08);
  --border-bright: rgba(255, 255, 255, 0.16);
  --maxw: 1200px;
  --radius: 8px;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

/* ==========================================================================
   2. RESET
   ========================================================================== */

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

html {
  -webkit-text-size-adjust: 100%;
}

@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

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

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

a {
  color: inherit;
}

ul,
ol {
  list-style: none;
}

/* ==========================================================================
   3. BASE / GLOBAL
   ========================================================================== */

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 17px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection {
  background: var(--accent);
  color: #041014;
}

/* Focus visibility — clear accent outline on all interactive elements */
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

h1,
h2,
h3,
h4 {
  font-weight: 700;
  line-height: 1.15;
}

p {
  max-width: 70ch;
}

/* ==========================================================================
   4. NAV
   ========================================================================== */

.nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 64px;
  display: flex;
  align-items: center;
  z-index: 40;
  background: rgba(10, 10, 10, 0.72);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  transition: transform 0.35s ease;
}

.nav.is-hidden {
  transform: translateY(-100%);
}

.nav__inner {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding-inline: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav__brand {
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.01em;
  text-decoration: none;
  color: var(--text);
}

.nav__links {
  display: flex;
  align-items: center;
  gap: 28px;
}

.nav__links a {
  font-size: 0.9rem;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.2s ease;
}

.nav__links a:hover {
  color: var(--text);
}

/* ==========================================================================
   5. SCROLL PROGRESS BAR
   ========================================================================== */

.progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  width: 0%;
  background: var(--accent);
  z-index: 50;
  transition: width 0.1s linear;
}

/* ==========================================================================
   6. SCENE / LAYOUT SHELL
   ========================================================================== */

.scene {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  padding-block: 96px;
}

.scene--hero {
  min-height: 100vh;
  padding-block: 140px 96px;
}

.scene__inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding-inline: 24px;
  width: 100%;
  position: relative;
  z-index: 1;
}

/* ==========================================================================
   7. BACKGROUND VIDEO + SCRIM
   ========================================================================== */

.bgvid {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
  opacity: 0.35;
  pointer-events: none;
}

.bgvid-scrim {
  position: absolute;
  inset: 0;
  z-index: 0;
  background:
    linear-gradient(to bottom, var(--bg) 0%, transparent 18%, transparent 82%, var(--bg) 100%),
    linear-gradient(to right, var(--bg) 0%, transparent 15%, transparent 85%, var(--bg) 100%);
  pointer-events: none;
}

/* ==========================================================================
   8. TYPOGRAPHY — HERO / SECTION / COPY
   ========================================================================== */

.hero h1,
h1 {
  font-size: clamp(2.75rem, 8vw, 6rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.02;
}

h2 {
  font-size: clamp(1.75rem, 4vw, 3rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.eyebrow {
  display: block;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.18em;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 16px;
}

.lede {
  font-size: clamp(1.05rem, 2vw, 1.35rem);
  color: var(--muted);
  max-width: 62ch;
}

/* ==========================================================================
   9. SCROLL REVEAL
   ========================================================================== */

.reveal {
  opacity: 0;
  transform: translateY(24px);
  transition:
    opacity 0.7s ease,
    transform 0.7s cubic-bezier(0.16, 1, 0.3, 1);
}

.reveal.is-visible {
  opacity: 1;
  transform: none;
}

.reveal--d1 {
  transition-delay: 90ms;
}

.reveal--d2 {
  transition-delay: 180ms;
}

.reveal--d3 {
  transition-delay: 270ms;
}

/* ==========================================================================
   10. GRID / CARD
   ========================================================================== */

.grid {
  display: grid;
  gap: 24px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  transition:
    transform 0.3s ease,
    border-color 0.3s ease,
    box-shadow 0.3s ease;
}

.card:hover {
  transform: translateY(-4px);
  border-color: var(--border-bright);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
}

.card__title {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: 10px;
}

.card__body {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.65;
}

/* ==========================================================================
   11. CODE BLOCK
   ========================================================================== */

.code {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-family: var(--font-mono);
  max-width: 100%;
}

.code__bar {
  height: 38px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-inline: 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.code__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.code__dot:nth-child(1) {
  background: #ff5f57;
}

.code__dot:nth-child(2) {
  background: #febc2e;
}

.code__dot:nth-child(3) {
  background: #28c840;
}

.code__file {
  margin-left: 10px;
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.code__body {
  padding: 20px 22px;
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.7;
  white-space: pre;
  -webkit-overflow-scrolling: touch;
}

/* Syntax token colors — harmonious on dark background */
.tok-kw {
  color: #c586c0; /* keyword — violet */
}

.tok-str {
  color: #a5d6ff; /* string — soft blue */
}

.tok-num {
  color: #f2b280; /* number — warm amber */
}

.tok-fn {
  color: #7ee3f5; /* function name — cyan, near accent */
}

.tok-com {
  color: var(--muted);
  font-style: italic;
}

.tok-op {
  color: #d4d4d8; /* operator — near-white grey */
}

/* ==========================================================================
   12. TERMINAL
   ========================================================================== */

.terminal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-family: var(--font-mono);
  max-width: 100%;
}

.terminal .code__body,
.terminal__body {
  background: #0b0b0d;
  padding: 20px 22px;
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

.term__line {
  opacity: 0;
  transition: opacity 0.25s ease;
  display: block;
}

.term__line.is-visible {
  opacity: 1;
}

.term__ok {
  color: #28c840;
}

.term__dim {
  color: var(--muted);
}

/* ==========================================================================
   13. METRICS
   ========================================================================== */

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 20px;
}

.metric {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.metric__value {
  font-size: clamp(2rem, 5vw, 3.25rem);
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.metric__label {
  font-size: 0.85rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* ==========================================================================
   14. BUTTONS
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 13px 24px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  border: 1px solid transparent;
  cursor: pointer;
  transition:
    filter 0.2s ease,
    border-color 0.2s ease,
    color 0.2s ease,
    background-color 0.2s ease;
}

.btn--primary {
  background: var(--accent);
  color: #041014;
}

.btn--primary:hover {
  filter: brightness(1.1);
}

.btn--ghost {
  background: transparent;
  border-color: var(--border-bright);
  color: var(--text);
}

.btn--ghost:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-row {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 32px;
}

/* ==========================================================================
   15. CHART
   ========================================================================== */

.chart {
  width: 100%;
  max-width: 720px;
}

.chart svg {
  width: 100%;
  height: auto;
}

/* ==========================================================================
   16. TAGS
   ========================================================================== */

.tag {
  display: inline-block;
  font-size: 0.72rem;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
}

.tag-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 18px;
}

/* ==========================================================================
   17. FOOTER
   ========================================================================== */

footer,
.footer {
  border-top: 1px solid var(--border);
  padding: 56px 0;
  color: var(--muted);
  font-size: 0.9rem;
}

/* ==========================================================================
   18. RESPONSIVE ADJUSTMENTS
   ========================================================================== */

@media (max-width: 640px) {
  .scene {
    padding-block: 72px;
  }

  .scene--hero {
    padding-block: 110px 72px;
  }

  .nav__links {
    gap: 16px;
  }

  .card {
    padding: 22px;
  }

  .code__body,
  .terminal .code__body,
  .terminal__body {
    padding: 16px 18px;
  }
}

/* Guard against any element forcing horizontal overflow on narrow viewports */
@media (max-width: 360px) {
  .scene__inner {
    padding-inline: 16px;
  }
}

/* ==========================================================================
   19. ACCESSIBILITY — REDUCED MOTION (non-negotiable)
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  * ,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    transition-delay: 0ms !important;
    scroll-behavior: auto !important;
  }

  .reveal,
  .reveal--d1,
  .reveal--d2,
  .reveal--d3 {
    opacity: 1;
    transform: none;
    transition: none;
  }

  .term__line {
    opacity: 1;
    transition: none;
  }

  .card:hover {
    transform: none;
  }
}

/* ============================================================
   19. CHART — inline SVG loss distribution
   Added at integration time: these classes are used by the
   #p2 aggregate-loss histogram in index.html.
   ============================================================ */

.chart svg { display: block; overflow: visible; }

/* Body of the distribution — muted, so the tail reads as the subject. */
.chart .bars rect {
  fill: var(--border-bright);
  transform-origin: bottom;
  transition: fill .4s ease;
}

/* The tail beyond VaR 99.5% — this is the part the whole model is about.
   NOTE the `rect` in the selector: `.chart .bars rect` above is (0,2,1),
   so `.chart .bar--tail` at (0,2,0) would lose and the tail would render
   grey. Match the specificity or the chart loses its subject. */
.chart .bars rect.bar--tail { fill: var(--accent); opacity: .9; }

/* Vertical threshold marker at the 99.5th percentile. */
.chart .var-line {
  stroke: var(--accent);
  stroke-width: 1.5;
  stroke-dasharray: 4 4;
  opacity: .9;
}

/* Baseline axis. */
.chart .axis { stroke: var(--border-bright); stroke-width: 1; }

.chart__label {
  fill: var(--muted);
  font-size: 11px;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: .06em;
}
.chart__label--tail { fill: var(--accent); opacity: .9; }

/* Bars grow up from the baseline as the section reveals. */
.reveal .bars rect { transform: scaleY(0); transition: transform .8s cubic-bezier(.16,1,.3,1); }
.reveal.is-visible .bars rect { transform: scaleY(1); }
.reveal.is-visible .bars rect:nth-child(n+1)  { transition-delay: calc(var(--i, 0) * 12ms); }

/* ============================================================
   20. TYPEWRITER CARET
   ============================================================ */

.tw-caret {
  display: inline-block;
  width: .06em;
  min-width: 2px;
  height: 1em;
  margin-left: .06em;
  background: var(--accent);
  vertical-align: -.08em;
  animation: tw-blink 1s step-end infinite;
}
@keyframes tw-blink { 50% { opacity: 0; } }

/* ============================================================
   21. REDUCED MOTION — reassert for everything added above.
   Anything introduced after the original reduced-motion block
   must be re-covered here, or it silently escapes the guard.
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
  .reveal .bars rect,
  .reveal.is-visible .bars rect { transform: none !important; transition: none !important; }
  .tw-caret { animation: none; opacity: 1; }
}

/* ============================================================
   22. NAV — small-screen collision fix
   At <=640px the brand and the link list overlap. The hero
   already carries Email / GitHub / See-the-work as buttons, so
   the link list is redundant on phones — drop it rather than
   shrink it into illegibility.
   ============================================================ */

@media (max-width: 640px) {
  .nav__links { display: none; }
  .nav__brand { font-size: 1rem; }
}

/* SVG text scales with the viewBox, so 11px becomes unreadable once the
   900-unit chart is squeezed into a 342px phone. Scale the labels up in
   viewBox units to keep the rendered size roughly constant. */
@media (max-width: 640px) {
  .chart__label { font-size: 22px; }
}

/* Background videos are decorative and must never expose native controls —
   with JS disabled Chromium will otherwise render a play/scrub bar over the
   hero. Belt-and-braces across engines. */
.bgvid::-webkit-media-controls,
.bgvid::-webkit-media-controls-enclosure,
.bgvid::-webkit-media-controls-panel { display: none !important; }
.bgvid::-moz-media-controls { display: none !important; }
.bgvid { pointer-events: none; }

/* ============================================================
   23. "LESS BLACK" — v3 revision
   Jan: the page read as too dark and static. The new clips are
   code/terminal themed and colourful, so let more of them show
   and pull the scrim back from the centre of the frame.
   ============================================================ */

.bgvid { opacity: .55; }

.bgvid-scrim {
  background:
    linear-gradient(to bottom, var(--bg) 0%, rgba(10,10,10,.55) 12%, rgba(10,10,10,.35) 50%, rgba(10,10,10,.55) 88%, var(--bg) 100%),
    linear-gradient(to right, var(--bg) 0%, rgba(10,10,10,.30) 22%, rgba(10,10,10,.30) 78%, var(--bg) 100%);
}

/* Copy sits directly on moving, colourful video now — give it its own
   readability floor rather than relying on the scrim alone. */
.scene__inner h1,
.scene__inner h2,
.scene__inner .lede,
.scene__inner .eyebrow {
  text-shadow: 0 2px 24px rgba(0,0,0,.75), 0 1px 4px rgba(0,0,0,.6);
}

/* A quiet accent wash so sections without video are not flat black either. */
.scene::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background: radial-gradient(120% 80% at 15% 0%, rgba(34,211,238,.07) 0%, transparent 60%);
}
.scene--hero::after { background: radial-gradient(120% 80% at 15% 0%, rgba(34,211,238,.10) 0%, transparent 62%); }

@media (prefers-reduced-motion: reduce) {
  .bgvid { opacity: .35; }
}

/* The generated clips contain garbled pseudo-text (the model produces
   letter-like shapes despite being told not to). At full sharpness it reads
   as sloppy. A small blur turns it into colour-and-motion texture, which is
   all a background is for, and costs nothing. */
.bgvid { filter: blur(3px) saturate(1.15); transform: scale(1.06); }

/* ============================================================
   24. STATUS BADGES — "Live" vs "In progress"
   Jan's standing rule: nothing on this page may read as shipped
   when it isn't. These badges carry that distinction visibly,
   so the honest label is part of the design rather than a
   disclaimer buried in prose.
   ============================================================ */

.status {
  display: inline-block;
  vertical-align: middle;
  margin-left: 10px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: .62rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  line-height: 1.4;
  white-space: nowrap;
  border: 1px solid transparent;
}

.status--live {
  color: #4ade80;
  background: rgba(74, 222, 128, .10);
  border-color: rgba(74, 222, 128, .30);
}

.status--wip {
  color: #fbbf24;
  background: rgba(251, 191, 36, .10);
  border-color: rgba(251, 191, 36, .30);
}

.card__title .status { font-size: .58rem; margin-left: 8px; }
