/* DreamFlyLab — main stylesheet
   Layers: reset → tokens → base → layout → components → utilities.
   No inline styles anywhere: the CSP forbids them. */

@layer reset, tokens, base, layout, components, utilities;

/* ---------- Fonts (self-hosted, OFL-1.1) ---------- */
@font-face {
  font-family: "Unbounded";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("../fonts/unbounded-cyrillic-500-normal.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Unbounded";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("../fonts/unbounded-latin-500-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Golos Text";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/golos-text-cyrillic-400-normal.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Golos Text";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/golos-text-latin-400-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Golos Text";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("../fonts/golos-text-cyrillic-600-normal.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Golos Text";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("../fonts/golos-text-latin-600-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ---------- Reset ---------- */
@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  * { margin: 0; }
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  img, svg, picture { display: block; max-width: 100%; }
  button { font: inherit; color: inherit; }
  ul[role="list"], ol[role="list"] { list-style: none; padding: 0; }
}

/* ---------- Tokens ---------- */
@layer tokens {
  :root {
    --paper: #eef2f5;
    --surface: #ffffff;
    --ink: #102a43;
    --ink-2: #486581;
    --rule: #c9d4de;
    --grid: #dde5ec;
    --action: #0b63be;
    --action-hover: #094f98;
    --action-ink: #ffffff;
    --signal: #f59e0b;
    --ok: #1c8a4c;
    --bad: #c53b3b;

    --font-display: "Unbounded", "Golos Text", system-ui, sans-serif;
    --font-text: "Golos Text", system-ui, -apple-system, "Segoe UI", sans-serif;

    --step--1: 0.875rem;
    --step-0: 1.0625rem;
    --step-1: 1.25rem;
    --step-2: clamp(1.5rem, 1.1rem + 1.6vw, 2.25rem);
    --step-3: clamp(2.1rem, 1.2rem + 3.6vw, 4rem);

    --space-1: 0.5rem;
    --space-2: 1rem;
    --space-3: 1.5rem;
    --space-4: 2.5rem;
    --space-5: clamp(3.5rem, 2rem + 6vw, 7rem);

    --measure: 34rem;
    --page: 72rem;
    --gutter: clamp(1rem, 0.5rem + 2.5vw, 2.5rem);
    --radius-s: 6px;
    --radius-l: 18px;
  }

  @media (prefers-color-scheme: dark) {
    :root {
      --paper: #0d1925;
      --surface: #13222f;
      --ink: #e4ecf3;
      --ink-2: #9fb3c8;
      --rule: #2b3d4f;
      --grid: #182938;
      --action: #5aa9f0;
      --action-hover: #7dbcf4;
      --action-ink: #06121d;
      --ok: #4cc785;
      --bad: #ef7b7b;
    }
  }
}

/* ---------- Base ---------- */
@layer base {
  html { color-scheme: light dark; scroll-behavior: smooth; }
  @media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

  body {
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font-text);
    font-size: var(--step-0);
    line-height: 1.6;
    font-kerning: normal;
    -webkit-font-smoothing: antialiased;
  }

  h1, h2 {
    font-family: var(--font-display);
    font-weight: 500;
    line-height: 1.1;
    letter-spacing: -0.015em;
    text-wrap: balance;
  }
  h1 { font-size: var(--step-3); }
  h2 { font-size: var(--step-2); }
  h3 { font-size: var(--step-1); font-weight: 600; line-height: 1.3; }
  p { max-width: var(--measure); text-wrap: pretty; }

  a { color: var(--action); text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
  a:hover { color: var(--action-hover); text-decoration-thickness: 2px; }

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

  ::selection { background: var(--signal); color: #102a43; }
}

/* ---------- Layout ---------- */
@layer layout {
  .wrap {
    width: min(100% - 2 * var(--gutter), var(--page));
    margin-inline: auto;
  }

  .section { padding-block: var(--space-5); }
  .section + .section { border-top: 1px solid var(--rule); }

  .split {
    display: grid;
    gap: var(--space-4);
    align-items: start;
  }
  @media (min-width: 60rem) {
    .split { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: var(--space-5); }
    .split--reverse { grid-template-columns: minmax(0, 6fr) minmax(0, 5fr); }
  }

  .stack > * + * { margin-top: var(--space-2); }
  .stack-l > * + * { margin-top: var(--space-3); }
}

/* ---------- Components ---------- */
@layer components {

  /* Skip link */
  .skip {
    position: absolute;
    left: var(--gutter);
    top: -4rem;
    padding: var(--space-1) var(--space-2);
    background: var(--ink);
    color: var(--paper);
    border-radius: var(--radius-s);
    z-index: 10;
  }
  .skip:focus { top: var(--space-1); color: var(--paper); }

  /* Header */
  .site-header { padding-block: var(--space-3); }
  .site-header .wrap {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    flex-wrap: wrap;
  }
  .brand {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--ink);
    text-decoration: none;
    font-family: var(--font-display);
    font-size: 1.05rem;
    letter-spacing: -0.01em;
  }
  .brand:hover { color: var(--ink); }
  .brand svg { width: 30px; height: 30px; }
  .nav ul { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; }
  .nav a { color: var(--ink); text-decoration: none; font-weight: 500; }
  .nav a:hover { text-decoration: underline; color: var(--ink); }
  .lang { display: inline-flex; border: 1px solid var(--rule); border-radius: 999px; padding: 2px; }
  .lang a, .lang span {
    padding: 0.15rem 0.6rem;
    border-radius: 999px;
    font-size: var(--step--1);
    text-decoration: none;
    color: var(--ink-2);
  }
  .lang [aria-current="true"] { background: var(--ink); color: var(--paper); }
  @media (max-width: 40rem) { .nav-links { display: none; } }

  /* Hero */
  .hero { padding-block: var(--space-4); }
  @media (min-width: 60rem) {
    .hero .split { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: center; }
  }
  .hero h1 { max-width: 13ch; }
  .lead { font-size: var(--step-1); line-height: 1.5; color: var(--ink-2); max-width: 30rem; }
  .actions { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }

  .btn {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    min-height: 48px;
    padding: 0.7rem 1.3rem;
    border-radius: var(--radius-s);
    font-weight: 600;
    text-decoration: none;
    border: 1.5px solid transparent;
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  }
  .btn svg { width: 20px; height: 20px; flex: none; }
  .btn--primary { background: var(--action); color: var(--action-ink); }
  .btn--primary:hover { background: var(--action-hover); color: var(--action-ink); }
  .btn--ghost { border-color: var(--ink); color: var(--ink); }
  .btn--ghost:hover { background: var(--ink); color: var(--paper); }

  /* Ping bench — the one interactive moment of the page */
  .bench {
    position: relative;
    background-color: var(--surface);
    background-image:
      linear-gradient(var(--grid) 1px, transparent 1px),
      linear-gradient(90deg, var(--grid) 1px, transparent 1px);
    background-size: 24px 24px;
    background-position: -1px -1px;
    border: 1px solid var(--rule);
    border-radius: var(--radius-l);
    overflow: hidden;
  }
  .bench__map { width: 100%; height: auto; touch-action: manipulation; }
  .bench__hint {
    padding: var(--space-2) var(--space-3) 0;
    font-size: var(--step--1);
    color: var(--ink-2);
    max-width: none;
  }

  .dev { cursor: default; }
  .dev__plate { fill: var(--surface); stroke: var(--ink); stroke-width: 1.5; }
  .dev__glyph { fill: none; stroke: var(--ink); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
  .dev__label { fill: var(--ink); font: 600 13px var(--font-text); }
  .dev__ip { fill: var(--ink-2); font: 400 12px var(--font-text); }
  .dev--host { cursor: pointer; }
  .dev--host:hover .dev__plate, .dev--host:focus-visible .dev__plate { stroke: var(--action); stroke-width: 2.5; }
  .dev--host:focus, .cable-group:focus { outline: none; }
  .dev--host.is-busy .dev__plate { stroke: var(--signal); stroke-width: 2.5; }

  .cable { stroke: var(--ink-2); stroke-width: 2; stroke-linecap: round; fill: none; }
  .cable-hit { stroke: transparent; stroke-width: 26; fill: none; cursor: pointer; }
  .cable-group:hover .cable, .cable-group:focus-visible .cable { stroke: var(--action); stroke-width: 3; }
  .cable-group.is-cut .cable { stroke: var(--bad); stroke-dasharray: 3 7; }
  .port { fill: var(--ok); }
  .cable-group.is-cut .port { fill: var(--bad); }

  @media (max-width: 40rem) {
    .dev__label { font-size: 17px; }
    .dev__ip { font-size: 15px; }
  }

  .packet { fill: var(--signal); stroke: var(--surface); stroke-width: 2; }

  .console {
    margin: var(--space-2) var(--space-3) var(--space-3);
    padding: var(--space-2);
    min-height: 8.5rem;
    background: #0f2236;
    border: 1px solid transparent;
    color: #d7e3ee;
    border-radius: var(--radius-s);
    font: 400 0.875rem/1.55 ui-monospace, "Cascadia Mono", "Segoe UI Mono", Menlo, Consolas, monospace;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
  }
  @media (prefers-color-scheme: dark) { .console { background: #081520; border-color: var(--rule); } }
  .console__line { display: block; }
  .console__cmd { color: #ffffff; }
  .console__ok { color: #8be0a9; }
  .console__bad { color: #ff9d9d; }
  .console__dim { color: #8aa2b8; }

  /* SetiLab */
  .app-head { display: flex; align-items: center; gap: var(--space-2); }
  .app-head img { width: 64px; height: 64px; border-radius: 15px; }
  .app-head p { color: var(--ink-2); margin-top: 0.15rem; }

  .facts { display: grid; gap: var(--space-3); padding: 0; }
  .facts dt { font-weight: 600; }
  .facts dd { margin: 0.2rem 0 0; color: var(--ink-2); max-width: var(--measure); }

  .shots {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--space-2);
    align-items: start;
  }
  .shot { margin: 0; }
  .shot:nth-child(2) { margin-top: var(--space-4); }
  .shot:nth-child(3) { margin-top: var(--space-2); }
  .shot img {
    width: 100%;
    height: auto;
    border-radius: 14px;
    border: 1px solid var(--rule);
    background: var(--surface);
  }
  .shot figcaption { margin-top: var(--space-1); font-size: var(--step--1); color: var(--ink-2); }
  @media (max-width: 40rem) {
    .shots {
      grid-template-columns: repeat(3, 70%);
      overflow-x: auto;
      scroll-snap-type: x mandatory;
      padding-bottom: var(--space-1);
      margin-inline: calc(-1 * var(--gutter));
      padding-inline: var(--gutter);
    }
    .shot { scroll-snap-align: start; }
    .shot:nth-child(n) { margin-top: 0; }
  }

  .steps { counter-reset: step; display: grid; gap: var(--space-2); padding: 0; }
  .steps li { counter-increment: step; display: grid; grid-template-columns: 2rem 1fr; gap: var(--space-1); align-items: baseline; }
  .steps li::before {
    content: counter(step);
    display: inline-grid;
    place-items: center;
    width: 1.7rem;
    height: 1.7rem;
    border-radius: 50%;
    border: 1.5px solid var(--ink);
    font-size: var(--step--1);
    font-weight: 600;
  }
  .note {
    padding: var(--space-2) var(--space-3);
    border-left: 3px solid var(--signal);
    background: var(--surface);
    border-radius: 0 var(--radius-s) var(--radius-s) 0;
    max-width: 38rem;
  }

  /* Studio + links */
  .channels { padding: 0; border-top: 1px solid var(--rule); }
  .channels li { border-bottom: 1px solid var(--rule); }
  .channel {
    display: grid;
    grid-template-columns: 2.5rem 1fr auto;
    gap: var(--space-2);
    align-items: center;
    padding: var(--space-3) 0;
    color: var(--ink);
    text-decoration: none;
  }
  .channel:hover { color: var(--ink); }
  .channel:hover .channel__name { text-decoration: underline; }
  .channel svg { width: 28px; height: 28px; }
  .channel__name { font-weight: 600; font-size: var(--step-1); }
  .channel__meta { display: block; color: var(--ink-2); font-size: var(--step--1); }
  .channel__go { width: 20px; height: 20px; color: var(--ink-2); }

  /* Footer */
  .site-footer { padding-block: var(--space-4); border-top: 1px solid var(--rule); font-size: var(--step--1); color: var(--ink-2); }
  .site-footer .wrap { display: grid; gap: var(--space-3); }
  @media (min-width: 48rem) { .site-footer .wrap { grid-template-columns: 1fr auto; align-items: end; } }
  .site-footer ul { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-3); padding: 0; }
  .site-footer a { color: var(--ink-2); }
  .site-footer a:hover { color: var(--ink); }

  /* 404 */
  .lost { min-height: 70vh; display: grid; align-content: center; gap: var(--space-3); }
}

/* ---------- Utilities ---------- */
@layer utilities {
  .visually-hidden {
    position: absolute !important;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0);
    white-space: nowrap; border: 0;
  }
  .muted { color: var(--ink-2); }
  .mt-4 { margin-top: var(--space-4); }
}
