/* EMG Monitor project page (projects/university/biomedical-technology/).
   Idea: the page is a recording strip. Graph paper underneath, one live
   EMG channel in the hero, and a name that flexes with the signal.
   Colours follow the EMG Monitor app: grey raw trace, blue at rest,
   red inside a contraction. */

@layer base, layout, components, pages, responsive, print;

@font-face {
  font-family: "Commissioner";
  src: url("../fonts/commissioner-var.woff2") format("woff2");
  font-weight: 300 800;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "JetBrains Mono";
  src: url("../fonts/jetbrains-mono-var.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

/* ---------- tokens ---------- */

:root {
  color-scheme: light;
  --paper: #f4efe6;
  --paper-2: #ebe4d8;
  --card: #fbf8f2;
  --card-2: #fffdf9;
  --glass: rgba(251, 248, 242, 0.78);
  --line: rgba(23, 19, 15, 0.12);
  --line-strong: rgba(23, 19, 15, 0.24);
  --grid-minor: rgba(209, 40, 30, 0.055);
  --grid-major: rgba(209, 40, 30, 0.12);
  --ink: #17130f;
  --ink-2: #463f37;
  --ink-3: #685f55;
  --signal: #c8241b;          /* text-safe red on paper (5.0:1) */
  --signal-fill: #d1281e;     /* the app's contraction red, for fills and traces */
  --rest: #2557c4;            /* the app's resting blue */
  --raw: #a7a29b;             /* raw trace grey */
  --on-signal: #ffffff;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset, 0 18px 40px -24px rgba(60, 30, 10, 0.35);
  --radius: 18px;
  --radius-lg: 28px;
  --gutter: clamp(16px, 5vw, 120px);
  --wrap: 1200px;
  --wrap-wide: 1560px;
  --font-display: "Commissioner", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-body: "Commissioner", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --paper: #0f0e0d;
    --paper-2: #171513;
    --card: #1a1816;
    --card-2: #201d1a;
    --glass: rgba(26, 24, 22, 0.78);
    --line: rgba(242, 236, 226, 0.12);
    --line-strong: rgba(242, 236, 226, 0.26);
    --grid-minor: rgba(255, 90, 71, 0.045);
    --grid-major: rgba(255, 90, 71, 0.1);
    --ink: #f2ece2;
    --ink-2: #cfc6b9;
    --ink-3: #a59b8e;
    --signal: #ff6a58;
    --signal-fill: #ff4a3a;
    --rest: #7ea2ff;
    --raw: #5d5852;
    --on-signal: #160806;
    --shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 18px 40px -24px rgba(0, 0, 0, 0.8);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #0f0e0d;
  --paper-2: #171513;
  --card: #1a1816;
  --card-2: #201d1a;
  --glass: rgba(26, 24, 22, 0.78);
  --line: rgba(242, 236, 226, 0.12);
  --line-strong: rgba(242, 236, 226, 0.26);
  --grid-minor: rgba(255, 90, 71, 0.045);
  --grid-major: rgba(255, 90, 71, 0.1);
  --ink: #f2ece2;
  --ink-2: #cfc6b9;
  --ink-3: #a59b8e;
  --signal: #ff6a58;
  --signal-fill: #ff4a3a;
  --rest: #7ea2ff;
  --raw: #5d5852;
  --on-signal: #160806;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 18px 40px -24px rgba(0, 0, 0, 0.8);
}

/* ---------- base ---------- */

@layer base {
  *, *::before, *::after { box-sizing: border-box; }

  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: smooth;
    scroll-padding-top: 96px;
  }

  body {
    margin: 0;
    min-height: 100vh;
    background-color: var(--paper);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 17px;
    line-height: 1.6;
    font-weight: 400;
    overflow-x: hidden;
    overflow-wrap: anywhere;
    -webkit-font-smoothing: antialiased;
  }

  /* The graph paper: 8 px minor squares, 40 px major squares, fixed while content scrolls. */
  body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background-color: var(--paper);
    background-image:
      linear-gradient(var(--grid-major) 1px, transparent 1px),
      linear-gradient(90deg, var(--grid-major) 1px, transparent 1px),
      linear-gradient(var(--grid-minor) 1px, transparent 1px),
      linear-gradient(90deg, var(--grid-minor) 1px, transparent 1px);
    background-size: 40px 40px, 40px 40px, 8px 8px, 8px 8px;
    background-position: -1px -1px;
  }

  img, svg, canvas { display: block; max-width: 100%; }
  figure { margin: 0; }
  img { height: auto; }

  a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 3px; }
  a:hover { color: var(--signal); }

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

  h1, h2, h3 {
    font-family: var(--font-display);
    line-height: 1.12;
    margin: 0;
    font-weight: 650;
    letter-spacing: -0.01em;
  }

  p { margin: 0; }

  .mono {
    font-family: var(--font-mono);
    font-size: 13px;
    letter-spacing: 0.02em;
    line-height: 1.5;
  }

  .visually-hidden {
    position: absolute !important;
    width: 1px; height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .skip {
    position: absolute;
    left: 12px; top: 12px;
    z-index: 100;
    padding: 12px 18px;
    background: var(--ink);
    color: var(--paper);
    border-radius: 999px;
    text-decoration: none;
    clip-path: inset(50%);
  }
  .skip:focus { clip-path: none; color: var(--paper); }

  .sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
}

/* ---------- layout ---------- */

@layer layout {
  .wrap {
    width: min(var(--wrap), 100%);
    margin-inline: auto;
    padding-inline: var(--gutter);
    box-sizing: content-box;
    max-width: calc(100% - 2 * var(--gutter));
  }

  .wrap-wide {
    width: min(var(--wrap-wide), 100%);
    margin-inline: auto;
    padding-inline: var(--gutter);
    box-sizing: content-box;
    max-width: calc(100% - 2 * var(--gutter));
  }

  section { padding-block: 112px 24px; }

  .section-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: 24px;
    margin-bottom: 40px;
    border-bottom: 1px solid var(--line-strong);
    padding-bottom: 20px;
  }

  .section-head h2 {
    font-size: clamp(2.1rem, 1.3rem + 2.8vw, 3.6rem);
    font-weight: 700;
    font-variation-settings: "FLAR" 60;
  }

  .section-head .lede {
    margin-top: 12px;
    color: var(--ink-2);
    max-width: 60ch;
  }

  .label {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-family: var(--font-mono);
    font-size: 13px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-3);
    margin-bottom: 14px;
  }
  .label::before {
    content: "";
    width: 22px;
    height: 2px;
    background: var(--signal-fill);
  }
}

/* ---------- components ---------- */

@layer components {
  /* Header pill */
  .site-header {
    position: sticky;
    top: 12px;
    z-index: 50;
    padding-inline: var(--gutter);
    margin-top: 12px;
  }

  .site-header .bar {
    width: min(var(--wrap), 100%);
    margin-inline: auto;
    display: flex;
    align-items: center;
    gap: 16px;
    min-height: 60px;
    padding: 8px 8px 8px 18px;
    border-radius: 999px;
    background: var(--glass);
    border: 1px solid var(--line);
    -webkit-backdrop-filter: blur(14px) saturate(1.2);
    backdrop-filter: blur(14px) saturate(1.2);
    box-shadow: var(--shadow);
  }

  .brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    font-weight: 700;
    font-variation-settings: "FLAR" 100;
    white-space: nowrap;
    min-height: 48px;
  }
  .brand svg { width: 34px; height: 34px; }
  .brand:hover { color: var(--ink); }

  .site-header nav { margin-left: auto; min-width: 0; }
  .nav {
    display: flex;
    gap: 2px;
    list-style: none;
    padding: 0;
    margin-block: 0;
  }
  .nav a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0 14px;
    border-radius: 999px;
    text-decoration: none;
    font-size: 15px;
    white-space: nowrap;
    color: var(--ink-2);
  }
  .nav a:hover { background: var(--paper-2); color: var(--ink); }

  .icon-btn {
    display: inline-grid;
    place-items: center;
    width: 48px;
    height: 48px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--ink);
    cursor: pointer;
    flex: none;
  }
  .icon-btn:hover { border-color: var(--line-strong); }
  .icon-btn svg { width: 20px; height: 20px; }
  .icon-btn .i-sun, .icon-btn .i-moon, .icon-btn .i-auto { display: none; }
  .icon-btn[data-mode="light"] .i-sun,
  .icon-btn[data-mode="dark"] .i-moon,
  .icon-btn[data-mode="auto"] .i-auto { display: block; }

  /* Buttons */
  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 52px;
    padding: 0 24px;
    border-radius: 999px;
    font-weight: 600;
    font-size: 16px;
    text-decoration: none;
    border: 1px solid transparent;
    cursor: pointer;
    transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease), background 0.2s var(--ease);
    white-space: nowrap;
  }
  .btn svg { width: 18px; height: 18px; }
  .btn-primary {
    background: var(--signal-fill);
    color: var(--on-signal);
    box-shadow: 0 10px 30px -12px var(--signal-fill);
  }
  .btn-primary:hover { color: var(--on-signal); transform: translateY(-1px); }
  .btn-ghost {
    background: var(--glass);
    color: var(--ink);
    border-color: var(--line-strong);
  }
  .btn-ghost:hover { color: var(--ink); background: var(--card); }

  /* Chips and readouts */
  .chips { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; padding: 0; margin: 0; }
  .chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--card);
    font-family: var(--font-mono);
    font-size: 12.5px;
    color: var(--ink-2);
    line-height: 1.4;
  }
  .chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--rest); flex: none; }
  .chip .dot.red { background: var(--signal-fill); }

  .status {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-family: var(--font-mono);
    font-size: 12px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ink-2);
  }
  .status::before {
    content: "";
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--rest);
  }
  .status.live::before { background: var(--signal-fill); box-shadow: 0 0 0 4px color-mix(in srgb, var(--signal-fill) 20%, transparent); }
  .status.done::before { background: var(--ink-3); }

  /* Segmented filter */
  .segmented {
    display: inline-flex;
    padding: 4px;
    gap: 4px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--glass);
  }
  .segmented button {
    min-height: 44px;
    padding: 0 16px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--ink-2);
    font: 500 15px/1 var(--font-body);
    cursor: pointer;
  }
  .segmented button[aria-pressed="true"] {
    background: var(--ink);
    color: var(--paper);
  }

  /* Project cards */
  .grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 20px;
  }

  .card {
    position: relative;
    grid-column: span 6;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 24px;
    border-radius: var(--radius-lg);
    background: var(--card);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    transition: transform 0.25s var(--ease), border-color 0.25s var(--ease);
  }
  .card:hover { transform: translateY(-2px); border-color: var(--line-strong); }
  .card[hidden] { display: none; }

  .card .meta {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 8px 16px;
    font-family: var(--font-mono);
    font-size: 12.5px;
    color: var(--ink-3);
    letter-spacing: 0.02em;
  }
  .card .meta .ch { color: var(--signal); font-weight: 600; }

  .card h3 {
    font-size: clamp(1.5rem, 1.2rem + 0.9vw, 2rem);
    font-weight: 700;
    font-variation-settings: "FLAR" 80;
  }
  .card h3 a { text-decoration: none; }
  .card h3 a::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
  .card .context { font-size: 15px; color: var(--ink-3); margin-top: -8px; }
  .card p.desc { color: var(--ink-2); }

  .card .foot {
    margin-top: auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-top: 6px;
  }
  .card .more {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--ink-3);
  }
  .card .more.go { color: var(--signal); font-weight: 600; }

  /* The small recording each card carries. Drawn by site.js from data-seed. */
  .trace {
    height: 56px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background-color: var(--card-2);
    background-image:
      linear-gradient(var(--grid-minor) 1px, transparent 1px),
      linear-gradient(90deg, var(--grid-minor) 1px, transparent 1px);
    background-size: 8px 8px;
    overflow: hidden;
  }
  .trace svg { width: 100%; height: 100%; }
  .trace .raw { fill: none; stroke: var(--raw); stroke-width: 1; vector-effect: non-scaling-stroke; }
  .trace .env { fill: none; stroke: var(--rest); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
  .trace .hot { fill: none; stroke: var(--signal-fill); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
  .trace .dots { fill: none; stroke: var(--rest); stroke-width: 3.4; stroke-linecap: round; vector-effect: non-scaling-stroke; }
  .trace .dots.hot { stroke: var(--signal-fill); stroke-width: 3.4; }

  /* Featured card */
  .card.featured {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
    gap: 28px;
    padding: 32px;
  }
  .card.featured .body { display: flex; flex-direction: column; gap: 16px; }
  .card.featured h3 { font-size: clamp(2rem, 1.4rem + 2vw, 3rem); }

  .phones {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    align-items: start;
    padding: 18px;
    border-radius: var(--radius);
    background: var(--paper-2);
    border: 1px solid var(--line);
  }
  .phones picture:nth-child(2) { transform: translateY(-14px); }
  .phones img {
    border-radius: 16px;
    border: 1px solid var(--line-strong);
    box-shadow: 0 16px 30px -18px rgba(0, 0, 0, 0.45);
  }

  /* Small tools list */
  .tools {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0;
    border-radius: var(--radius-lg);
    border: 1px solid var(--line);
    background: var(--card);
    overflow: hidden;
  }
  .tools > div { padding: 20px 24px; border-left: 1px solid var(--line); }
  .tools > div:first-child { border-left: 0; }
  .tools h4 { margin: 4px 0 6px; font-size: 17px; font-weight: 650; }
  .tools p { color: var(--ink-2); font-size: 15px; }
  .tools[hidden] { display: none; }
}

/* ---------- pages ---------- */

@layer pages {
  /* Hero: the recording strip */
  .hero { padding-block: 56px 32px; }

  .rec-line {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 18px;
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--ink-3);
    letter-spacing: 0.04em;
  }
  .rec-line .rec {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--signal);
    font-weight: 600;
  }
  .rec-line .rec::before {
    content: "";
    width: 9px; height: 9px;
    border-radius: 50%;
    background: var(--signal-fill);
    animation: blink 1.6s steps(2, start) infinite;
  }

  .name {
    margin: 22px 0 0;
    font-family: var(--font-display);
    font-size: clamp(3.5rem, 0.5rem + 14.2vw, 15rem);
    line-height: 0.9;
    letter-spacing: -0.035em;
    font-weight: 700;
    font-variation-settings: "FLAR" 100, "VOLM" 0;
  }
  .name span { display: block; white-space: nowrap; }
  .name .second { color: transparent; -webkit-text-stroke: 2px var(--ink); }
  .name .greek {
    display: block;
    margin-top: 18px;
    font-family: var(--font-mono);
    font-size: clamp(14px, 0.7rem + 0.4vw, 17px);
    letter-spacing: 0.06em;
    font-weight: 500;
    line-height: 1.4;
    color: var(--ink-3);
    -webkit-text-stroke: 0;
    white-space: normal;
  }

  .strip {
    position: relative;
    margin-top: 36px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--line-strong);
    background: var(--card);
    box-shadow: var(--shadow);
    overflow: hidden;
  }
  .strip-top, .strip-bottom {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 8px 16px;
    padding: 12px 18px;
    font-family: var(--font-mono);
    font-size: 12.5px;
    color: var(--ink-3);
  }
  .strip-top { border-bottom: 1px solid var(--line); }
  .strip-bottom { border-top: 1px solid var(--line); }
  .strip-top strong, .strip-bottom strong { color: var(--ink); font-weight: 600; }
  .strip .mode { color: var(--rest); font-weight: 600; }
  .strip .mode.hot { color: var(--signal); }

  .strip-canvas {
    position: relative;
    height: clamp(150px, 18vw, 240px);
    background-image:
      linear-gradient(var(--grid-major) 1px, transparent 1px),
      linear-gradient(90deg, var(--grid-major) 1px, transparent 1px),
      linear-gradient(var(--grid-minor) 1px, transparent 1px),
      linear-gradient(90deg, var(--grid-minor) 1px, transparent 1px);
    background-size: 40px 40px, 40px 40px, 8px 8px, 8px 8px;
  }
  .strip-canvas canvas { width: 100%; height: 100%; }
  .strip-canvas .fallback { position: absolute; inset: 0; width: 100%; height: 100%; }
  .js .strip-canvas .fallback { display: none; }
  .fallback .raw { fill: none; stroke: var(--raw); stroke-width: 1.2; }
  .fallback .env { fill: none; stroke: var(--signal-fill); stroke-width: 2.5; }

  .flex-btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: 48px;
    padding: 0 18px;
    border-radius: 999px;
    border: 1px solid var(--line-strong);
    background: var(--card-2);
    color: var(--ink);
    font: 600 14px/1 var(--font-mono);
    letter-spacing: 0.02em;
    cursor: pointer;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
  }
  .flex-btn::before {
    content: "";
    width: 12px; height: 12px;
    border-radius: 50%;
    border: 2px solid var(--signal-fill);
    transition: background 0.15s;
  }
  .flex-btn[aria-pressed="true"] { border-color: var(--signal-fill); color: var(--signal); }
  .flex-btn[aria-pressed="true"]::before { background: var(--signal-fill); }
  .no-js .flex-btn { display: none; }

  .hero-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
    gap: 40px;
    align-items: end;
    margin-top: 40px;
  }
  .intro {
    font-size: clamp(1.2rem, 1rem + 0.7vw, 1.55rem);
    line-height: 1.45;
    font-weight: 400;
    color: var(--ink-2);
    max-width: 34ch;
  }
  .intro strong { color: var(--ink); font-weight: 650; }
  .hero-side { display: flex; flex-direction: column; gap: 20px; align-items: flex-start; }
  .cta { display: flex; flex-wrap: wrap; gap: 12px; }

  /* University timeline */
  .terms {
    position: relative;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 20px;
    list-style: none;
    margin: 0;
    padding: 0;
  }
  .term {
    position: relative;
    padding: 28px 24px 24px;
    border-radius: var(--radius-lg);
    background: var(--card);
    border: 1px solid var(--line);
  }
  .term .when { font-family: var(--font-mono); font-size: 12.5px; color: var(--ink-3); }
  .term h3 { font-size: 1.45rem; margin: 6px 0 14px; font-weight: 700; font-variation-settings: "FLAR" 70; }
  .term ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 12px; }
  .term li { display: grid; gap: 2px; padding-left: 18px; position: relative; }
  .term li::before {
    content: "";
    position: absolute; left: 0; top: 10px;
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--rest);
  }
  .term li.now::before { background: var(--signal-fill); }
  .term li a { font-weight: 600; }
  .term li span { font-size: 14.5px; color: var(--ink-3); }
  .term.next { background: transparent; border-style: dashed; border-color: var(--line-strong); }

  /* Endurance log */
  .log {
    border-radius: var(--radius-lg);
    border: 1px solid var(--line);
    background: var(--card);
    overflow: hidden;
  }
  .log-row {
    display: grid;
    grid-template-columns: 110px minmax(0, 1.25fr) minmax(0, 1.6fr) 120px;
    align-items: center;
    gap: 20px;
    padding: 18px 24px;
    border-top: 1px solid var(--line);
  }
  .log-row:first-child { border-top: 0; }
  .log-row .date { font-family: var(--font-mono); font-size: 13px; color: var(--ink-3); }
  .log-row .what strong { display: block; font-size: 17px; font-weight: 650; }
  .log-row .what span { font-size: 14.5px; color: var(--ink-3); }
  .log-row .stat {
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: 15px;
    text-align: right;
    white-space: nowrap;
  }
  .dist { width: 100%; height: 16px; overflow: visible; }
  .dist .track { fill: var(--line); }
  .dist .ticks { stroke: var(--line-strong); stroke-width: 1; vector-effect: non-scaling-stroke; }
  .dist .fill { fill: var(--rest); }
  .dist .fill.hot { fill: var(--signal-fill); }
  .scale {
    display: flex;
    justify-content: space-between;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--ink-3);
    padding: 12px 24px;
    border-top: 1px solid var(--line);
    background: var(--paper-2);
  }

  .lesson {
    margin-top: 20px;
    padding: 24px 28px;
    border-radius: var(--radius-lg);
    border: 1px dashed var(--line-strong);
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 18px;
    align-items: start;
  }
  .lesson .tag {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.06em;
    padding: 6px 10px;
    border-radius: 8px;
    background: var(--ink);
    color: var(--paper);
  }
  .lesson p { color: var(--ink-2); max-width: 70ch; }

  /* About */
  .about-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
    gap: 40px;
    align-items: start;
  }
  .prose { display: grid; gap: 18px; font-size: 18px; color: var(--ink-2); max-width: 62ch; }
  .prose strong { color: var(--ink); font-weight: 650; }
  .side-stack { display: grid; gap: 20px; }
  .panel {
    padding: 24px;
    border-radius: var(--radius-lg);
    background: var(--card);
    border: 1px solid var(--line);
  }
  .panel h3 { font-size: 1.15rem; margin-bottom: 14px; font-weight: 700; }
  .panel dl { margin: 0; display: grid; gap: 12px; }
  .panel dt { font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-3); }
  .panel dd { margin: 2px 0 0; color: var(--ink-2); }
  .panel.now { border-color: color-mix(in srgb, var(--signal-fill) 45%, transparent); }
  .panel.now ul { margin: 0; padding-left: 18px; display: grid; gap: 8px; color: var(--ink-2); }

  /* Contact */
  .contact {
    padding: clamp(32px, 6vw, 72px);
    border-radius: 36px;
    background: var(--ink);
    color: var(--paper);
    display: grid;
    gap: 24px;
    position: relative;
    overflow: hidden;
  }
  .contact h2 {
    font-size: clamp(2.4rem, 1.2rem + 5vw, 5.5rem);
    font-weight: 800;
    line-height: 0.95;
    font-variation-settings: "FLAR" 100;
    max-width: 14ch;
  }
  .contact p { color: color-mix(in srgb, var(--paper) 80%, var(--ink)); max-width: 52ch; font-size: 18px; }
  .contact .btn-ghost { background: transparent; color: var(--paper); border-color: color-mix(in srgb, var(--paper) 40%, transparent); }
  .contact .btn-ghost:hover { background: color-mix(in srgb, var(--paper) 10%, transparent); color: var(--paper); }
  .contact svg.wave { position: absolute; right: -2%; bottom: 0; width: 70%; height: 55%; opacity: 0.5; pointer-events: none; }
  .contact .wave path { fill: none; stroke: var(--signal-fill); stroke-width: 2; }

  /* Footer always on the night palette */
  .site-footer {
    margin-top: 96px;
    padding-block: 40px;
    background: #0f0e0d;
    color: #cfc6b9;
    font-size: 14px;
  }
  .site-footer .wrap { display: flex; flex-wrap: wrap; gap: 12px 32px; justify-content: space-between; align-items: center; }
  .site-footer a { color: #f2ece2; }
  .site-footer a:hover { color: #ff6a58; }
  .site-footer .mono { color: #a59b8e; }

  /* Case-study page */
  .crumbs { font-family: var(--font-mono); font-size: 13px; color: var(--ink-3); }
  .crumbs a { color: var(--ink-2); }
  .cs-title {
    font-size: clamp(3rem, 1rem + 9vw, 9rem);
    line-height: 0.92;
    letter-spacing: -0.03em;
    font-weight: 800;
    font-variation-settings: "FLAR" 100;
    margin-top: 18px;
  }
  .cs-sub { margin-top: 20px; font-size: clamp(1.15rem, 1rem + 0.6vw, 1.5rem); color: var(--ink-2); max-width: 46ch; line-height: 1.45; }
  .facts {
    margin-top: 36px;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    border-radius: var(--radius-lg);
    border: 1px solid var(--line);
    background: var(--card);
    overflow: hidden;
  }
  .facts > div { padding: 18px 20px; border-left: 1px solid var(--line); }
  .facts > div:first-child { border-left: 0; }
  .facts dt { font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-3); }
  .facts dd { margin: 4px 0 0; font-weight: 600; }

  .chain { margin-top: 8px; border-radius: var(--radius-lg); border: 1px solid var(--line); background: var(--card); padding: 24px; overflow-x: auto; }
  .chain svg { min-width: 760px; width: 100%; height: auto; }
  .chain .box { fill: var(--card-2); stroke: var(--line-strong); stroke-width: 1.2; }
  .chain .box.hot { stroke: var(--signal-fill); stroke-width: 1.8; }
  .chain .t1 { font: 600 14px var(--font-body); fill: var(--ink); }
  .chain .t2 { font: 400 11.5px var(--font-mono); fill: var(--ink-3); }
  .chain .arrow { stroke: var(--ink-3); stroke-width: 1.5; fill: none; }
  .chain .head { fill: var(--ink-3); }

  .section-title {
    font-size: clamp(2rem, 1.3rem + 2.4vw, 3.2rem);
    font-weight: 700;
    font-variation-settings: "FLAR" 60;
    margin-bottom: 20px;
  }
  ul.plain { margin: 0; padding-left: 18px; display: grid; gap: 8px; color: var(--ink-2); }
  .formula sub { font-size: 0.7em; }

  .two-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 40px; align-items: start; }
  .formula {
    font-family: var(--font-mono);
    font-size: clamp(15px, 0.8rem + 0.5vw, 19px);
    padding: 20px 22px;
    border-radius: var(--radius);
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--ink);
  }
  .formula .v { color: var(--signal); font-weight: 600; }
  .gallery {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 18px;
  }
  .gallery figure { margin: 0; display: grid; gap: 10px; }
  .gallery img { border-radius: 18px; border: 1px solid var(--line-strong); box-shadow: var(--shadow); }
  .gallery figcaption { font-size: 14px; color: var(--ink-3); }
  .notice {
    padding: 18px 22px;
    border-radius: var(--radius);
    border-left: 4px solid var(--signal-fill);
    background: var(--card);
    color: var(--ink-2);
  }

  @keyframes blink { to { visibility: hidden; } }
}

/* ---------- responsive ---------- */

@layer responsive {
  @media (min-width: 1800px) {
    body { font-size: 18px; }
    .wrap { width: 1320px; }
  }

  @media (max-width: 1120px) {
    .card.featured { grid-template-columns: minmax(0, 1fr); }
    .terms { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .log-row { grid-template-columns: 96px minmax(0, 1fr) 110px; }
    .log-row .dist { grid-column: 2 / -1; grid-row: 2; }
  }

  @media (max-width: 900px) {
    .hero-grid, .about-grid, .two-col { grid-template-columns: minmax(0, 1fr); gap: 28px; }
    .card { grid-column: 1 / -1; }
    .tools { grid-template-columns: minmax(0, 1fr); }
    .tools > div { border-left: 0; border-top: 1px solid var(--line); }
    .tools > div:first-child { border-top: 0; }
    .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .facts > div:nth-child(3) { border-left: 0; }
    .facts > div:nth-child(n+3) { border-top: 1px solid var(--line); }
    .gallery { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .section-head { grid-template-columns: minmax(0, 1fr); }
  }

  @media (max-width: 760px) {
    .site-header { top: 0; margin-top: 0; padding-inline: 0; }
    .site-header .bar {
      border-radius: 0;
      border-width: 0 0 1px;
      flex-wrap: wrap;
      gap: 4px 8px;
      padding: 6px 12px;
    }
    .site-header nav {
      order: 3;
      width: 100%;
      margin-left: 0;
      overflow-x: auto;
      scrollbar-width: none;
    }
    .nav a { padding: 0 9px; font-size: 14px; }
    .brand { margin-right: auto; }
    section { padding-block: 80px 16px; }
    .terms { grid-template-columns: minmax(0, 1fr); }
    .card, .card.featured { padding: 20px; }
    .phones { padding: 12px; gap: 10px; }
  }

  @media (max-width: 560px) {
    body { font-size: 16px; }
    .log-row { grid-template-columns: minmax(0, 1fr) auto; gap: 8px 12px; padding: 16px 18px; }
    .log-row .date { grid-column: 1 / -1; }
    .log-row .dist { grid-column: 1 / -1; grid-row: auto; }
    .lesson { grid-template-columns: minmax(0, 1fr); }
    .facts { grid-template-columns: minmax(0, 1fr); }
    .facts > div { border-left: 0; border-top: 1px solid var(--line); }
    .facts > div:first-child { border-top: 0; }
    .segmented button { padding: 0 12px; }
    .name .second { -webkit-text-stroke-width: 1.5px; }
    .strip-top .scale-note { display: none; }
  }

  @media (max-width: 380px) {
    .nav a { padding: 0 7px; }
  }

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

@layer print {
  @media print {
    body::before, .site-header, .strip, .flex-btn, .contact svg.wave { display: none; }
    body { background: #fff; color: #000; }
    .card, .panel, .term, .log { box-shadow: none; break-inside: avoid; }
  }
}
