/* =====================================================================
   OSE · Cockpit · styles/components/cockpit.css
   ---------------------------------------------------------------------
   The home hero seen from inside the ship, from 64em: thin pillars and a
   top rail around the window, and a dashboard of controls along the foot
   (key banks, toggles, knobs, faders, status lights, the throttle) with
   the Phóng control in the middle. On the cream surface, like the nav
   above it: nav, pillars and dashboard read as one cockpit, no seams, no
   dividing lines. Space stays the biggest thing on screen. Component
   tokens only: --cockpit-*.

   Markup — generated: write <!-- cockpit --><!-- /cockpit --> inside the
   hero (after .sky) and run node scripts/make-cockpit.mjs:
     <div class="cockpit" data-part="cockpit">
       <p class="cockpit__readout" aria-live="polite" data-charging="…" data-early="…" data-liftoff="…"><span class="cockpit__readout-text">…</span><span class="cockpit__cursor" aria-hidden="true">_</span></p>
       <svg class="cockpit__frame" data-surface="cream" viewBox="0 0 1600 900" preserveAspectRatio="none" aria-hidden="true">…</svg>
       <div class="cockpit__dash" data-surface="cream">
         <svg class="cockpit__svg" viewBox="0 0 1600 130" role="group" aria-label="Bảng điều khiển">
           <g aria-hidden="true">…panel, keys, toggles, knobs, lights, faders, throttle…</g>
           <a class="cockpit__launch" href="#lo-trinh" draggable="false" aria-label="Giữ để phóng: bay tới Lộ trình" data-cockpit-launch>…</a>
         </svg>
       </div>
     </div>

   Box      covers the hero (inset 0), in front of the planet (--cockpit-z),
            click-through except the Phóng control. The frame stretches;
            the dashboard is one drawing scaled to the hero's width, as tall
            as --cockpit-dash-height (the hero keeps that room at its foot).
            Only from --bp-lg (64em): below, the hero stacks the planet over
            the headline and has no cockpit (no room for a dashboard).
   Phóng    an <a href="#lo-trinh">: without JS, with reduced motion or a
            failed scene it is a plain jump to Lộ trình. The through-ring
            scene makes it hold-to-launch: .is-charging (cap down), the
            charge ring draws on from 12 o'clock (one circle, one gradient,
            round caps; .is-lit while any of it shows), the throttle lever
            rises, .is-fired, ignition, lift-off. Everything it says shows
            in the readout (the scene swaps its text: charging, "GIỮ THÊM
            CHÚT NỮA" after a short click, the countdown, lift-off), all
            at the same quiet size (John). Never draggable, never selects text.
   Focus    the lilac ring around the control (:focus-visible).
   Motion   at rest: status lights blink in three rhythms, a lit key
            breathes in each bank, a light bar scans along each row of
            status dots, Phóng's mint ring breathes until pressed; paused
            once the flight starts (.sky.is-still), off with reduced motion.
   Sound    the ÂM THANH switch and the ÂM LƯỢNG fader are real controls
            (js/components/sound-controls.js, js/sound/engine.js).
   ===================================================================== */

@layer components {
  .cockpit {
    position: absolute;
    inset: 0;
    z-index: var(--cockpit-z);
    pointer-events: none;
  }

  @media (width < 64em) {
    .cockpit {
      display: none;
    }
  }

  /* Both carry data-surface="cream" for the nav's colours; the surface
     must not paint their boxes (only the drawings show). */
  .cockpit__frame,
  .cockpit__dash {
    background-color: var(--cockpit-clear);
  }

  .cockpit__frame {
    position: absolute;
    inset: 0;
    display: block;
    inline-size: 100%;
    block-size: 100%;
    transform-origin: center;
  }

  /* The bleed: cream drawn past every edge of the frame and the dashboard
     (offscreen, under the nav, below the hero), so when the launch shakes
     the whole view nothing but cream ever shows at the nav or the screen's
     edges. Only on the full motion path (html.motion), where the view
     shakes: without it the hero sits in the flow and its bleed would cover
     the chapter below. */
  .cockpit__bleed {
    display: none;
    fill: var(--cockpit-panel);
  }

  .motion .cockpit__bleed {
    display: inline;
  }

  .motion .cockpit__frame {
    overflow: visible;
  }

  .cockpit__dash {
    position: absolute;
    inset: auto 0 0;
  }

  .cockpit__svg {
    display: block;
    inline-size: 100%;
    block-size: auto;
    overflow: visible;
  }

  /* ---- Surfaces: one cream, no lines between frame and dashboard ---- */
  .cockpit__panel {
    fill: var(--cockpit-panel);
  }

  .cockpit__well,
  .cockpit__key {
    fill: var(--cockpit-well);
  }

  .cockpit__key--lit {
    fill: var(--cockpit-key-lit);
  }

  .cockpit__toggle {
    fill: var(--cockpit-control-off);
  }

  .cockpit__toggle.is-up,
  .cockpit__knob,
  .cockpit__grip {
    fill: var(--cockpit-control);
  }

  .cockpit__knob-mark {
    stroke: var(--cockpit-panel);
  }

  .cockpit__light {
    fill: var(--cockpit-light-off);
  }

  .cockpit__light--on {
    fill: var(--cockpit-light-on);
  }

  .cockpit__light--blink,
  .cockpit__light--blink2 {
    fill: var(--cockpit-light-blink);
  }

  .cockpit__light--blink3 {
    fill: var(--cockpit-light-on);
  }

  .cockpit__dot {
    fill: var(--cockpit-dot);
  }

  .cockpit__scan {
    fill: var(--cockpit-scan-color);
    opacity: var(--cockpit-scan-glow);
  }

  .cockpit__beacon {
    stroke: var(--cockpit-beacon-color);
    opacity: var(--cockpit-hidden);
  }

  .cockpit__label,
  .cockpit__plate-text {
    font-family: var(--cockpit-font-data);
    font-weight: var(--cockpit-data-weight);
    letter-spacing: var(--cockpit-tracking);
  }

  .cockpit__label {
    fill: var(--cockpit-label);
  }

  /* ---- The Phóng control ------------------------------------------- */
  .cockpit__launch {
    pointer-events: auto;
    cursor: pointer;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    -webkit-user-drag: none;
    -webkit-touch-callout: none;
    touch-action: none;
  }

  .cockpit__focus {
    stroke: var(--cockpit-focus);
    opacity: var(--cockpit-hidden);
  }

  .cockpit__launch:focus-visible .cockpit__focus,
  .cockpit__launch.is-focus-visible .cockpit__focus {
    opacity: var(--cockpit-shown);
  }

  .cockpit__track {
    stroke: var(--cockpit-track);
  }

  /* The charge ring: one circle drawn on by its dash. Hidden while empty
     (a round cap would leave a dot). */
  .cockpit__charge {
    opacity: var(--cockpit-hidden);
  }

  .cockpit__launch.is-lit .cockpit__charge {
    opacity: var(--cockpit-shown);
  }

  .cockpit__stop-a {
    stop-color: var(--cockpit-charge-a);
  }

  .cockpit__stop-b {
    stop-color: var(--cockpit-charge-b);
  }

  .cockpit__cap {
    transform-box: fill-box;
    transform-origin: center;
    transition: transform var(--cockpit-press) var(--cockpit-blink-ease);
  }

  /* Phóng: a flat red glass key in a navy bezel. */
  .cockpit__bezel {
    fill: var(--cockpit-bezel);
  }

  .cockpit__cap-face {
    fill: var(--cockpit-cap);
  }

  .cockpit__rim {
    stroke: var(--cockpit-rim);
    stroke-opacity: var(--cockpit-glass);
  }

  .cockpit__glint {
    fill: var(--cockpit-rim);
    opacity: var(--cockpit-glass);
  }

  .cockpit__key-text {
    fill: var(--cockpit-key-text);
    font-family: var(--cockpit-key-font);
    font-weight: var(--cockpit-key-weight);
    letter-spacing: var(--cockpit-key-tracking);
  }

  .cockpit__launch:active .cockpit__cap,
  .cockpit__launch.is-charging .cockpit__cap {
    transform: scale(var(--cockpit-press-scale));
  }

  .cockpit__plate {
    fill: var(--cockpit-panel);
    stroke: var(--cockpit-plate);
    stroke-width: var(--cockpit-edge-width);
    vector-effect: non-scaling-stroke;
  }

  .cockpit__plate-text {
    fill: var(--cockpit-plate-text);
  }

  /* ---- The real controls: ÂM THANH and ÂM LƯỢNG ------------------- */
  /* Each sits in a transparent hit area of at least 44px; the rest of the
     dashboard stays click-through. */
  .cockpit__switch,
  .cockpit__fader {
    pointer-events: auto;
    cursor: pointer;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
  }

  .cockpit__hit {
    fill: var(--cockpit-clear);
    pointer-events: all;
  }

  .cockpit__ctl-focus {
    stroke: var(--cockpit-focus);
    opacity: var(--cockpit-hidden);
  }

  .cockpit__switch:focus-visible .cockpit__ctl-focus,
  .cockpit__switch.is-focus-visible .cockpit__ctl-focus,
  .cockpit__fader:focus-visible .cockpit__ctl-focus,
  .cockpit__fader.is-focus-visible .cockpit__ctl-focus {
    opacity: var(--cockpit-shown);
  }

  /* The labels: a speaker (crossed out when off, waves when on), TẮT /
     BẬT under the switch, a scale and the level beside the fader. */
  .cockpit__speaker {
    stroke: var(--cockpit-control);
  }

  .cockpit__speaker-on,
  .cockpit__switch[aria-checked="true"] .cockpit__speaker-off {
    display: none;
  }

  .cockpit__switch[aria-checked="true"] .cockpit__speaker-on {
    display: inline;
  }

  .cockpit__switch-state,
  .cockpit__fader-value {
    fill: var(--cockpit-label);
    font-family: var(--cockpit-font-data);
    font-weight: var(--cockpit-data-weight);
    letter-spacing: var(--cockpit-tracking);
  }

  .cockpit__switch[aria-checked="true"] .cockpit__switch-state {
    fill: var(--cockpit-control);
  }

  .cockpit__tick {
    fill: var(--cockpit-dot);
  }

  /* The switch's lever: down and muted when off, up when sound is on. */
  .cockpit__switch-knob {
    fill: var(--cockpit-control-off);
    transition:
      transform var(--cockpit-press) var(--cockpit-blink-ease),
      fill var(--cockpit-press) var(--cockpit-blink-ease);
  }

  .cockpit__switch[aria-checked="true"] .cockpit__switch-knob {
    fill: var(--cockpit-control);
    transform: translateY(var(--cockpit-switch-travel));
  }

  @media (prefers-reduced-motion: reduce) {
    .cockpit__switch-knob {
      transition: none;
    }
  }

  /* ---- The readout (in the window, above Phóng) -------------------- */
  .cockpit__readout {
    position: absolute;
    inset-inline-start: 50%;
    inset-block-end: calc(var(--cockpit-dash-height) + var(--cockpit-readout-gap));
    translate: -50% 0;
    margin: 0;
    padding: var(--cockpit-readout-pad-block) var(--cockpit-readout-pad-inline);
    color: var(--cockpit-readout);
    font: var(--cockpit-readout-font);
    letter-spacing: var(--cockpit-readout-tracking);
    text-align: center;
    white-space: nowrap;
    pointer-events: none;
    transition: opacity var(--cockpit-readout-fade) var(--cockpit-blink-ease);
  }

  .cockpit__readout::before,
  .cockpit__readout::after {
    content: "";
    position: absolute;
    inset-block: 0;
    inline-size: var(--cockpit-readout-bracket);
    border: var(--cockpit-readout-line) solid currentColor;
  }

  .cockpit__readout::before {
    inset-inline-start: 0;
    border-inline-end: 0;
  }

  .cockpit__readout::after {
    inset-inline-end: 0;
    border-inline-start: 0;
  }

  /* Gone once the flight starts. */
  .sky.is-still ~ .cockpit .cockpit__readout {
    opacity: var(--cockpit-hidden);
  }

  @keyframes cockpit-cursor {
    to {
      opacity: var(--cockpit-hidden);
    }
  }

  @media (prefers-reduced-motion: no-preference) {
    .cockpit__cursor {
      animation: cockpit-cursor var(--cockpit-blink) var(--cockpit-cursor-ease) infinite alternate;
    }
  }

  /* ---- At rest the dashboard lives (transform and opacity only) ---- */
  /* Status lights blink in three rhythms, a lit key breathes in each bank,
     a light bar scans along each row of status dots (with JS) and Phóng's
     ring breathes until it is pressed. All of it pauses once the flight
     starts (.sky.is-still, set by the through-ring scene) and stays still
     with reduced motion. */
  @keyframes cockpit-blink {
    from {
      opacity: var(--cockpit-shown);
    }

    to {
      opacity: var(--cockpit-blink-low);
    }
  }

  @keyframes cockpit-scan {
    to {
      transform: translateX(var(--cockpit-scan-travel));
    }
  }

  @keyframes cockpit-beacon {
    to {
      opacity: var(--cockpit-beacon-peak);
    }
  }

  @media (prefers-reduced-motion: no-preference) {
    .cockpit__light--blink {
      animation: cockpit-blink var(--cockpit-blink) var(--cockpit-blink-ease) infinite alternate;
    }

    .cockpit__light--blink2 {
      animation: cockpit-blink var(--cockpit-blink-b) var(--cockpit-blink-ease) infinite alternate;
    }

    .cockpit__light--blink3 {
      animation: cockpit-blink var(--cockpit-blink-c) var(--cockpit-blink-ease) infinite alternate;
    }

    .cockpit__key--pulse {
      animation: cockpit-blink var(--cockpit-pulse) var(--cockpit-blink-ease) infinite alternate;
    }

    .motion .cockpit__scan {
      animation: cockpit-scan var(--cockpit-scan) var(--cockpit-blink-ease) infinite alternate;
    }

    .motion .cockpit__scan--reverse {
      animation-direction: alternate-reverse;
    }

    .motion .cockpit__launch:not(.is-charging, .is-fired, .is-lit) .cockpit__beacon {
      animation: cockpit-beacon var(--cockpit-beacon) var(--cockpit-blink-ease) infinite alternate;
    }

    .sky.is-still ~ .cockpit .cockpit__light--blink,
    .sky.is-still ~ .cockpit .cockpit__light--blink2,
    .sky.is-still ~ .cockpit .cockpit__light--blink3,
    .sky.is-still ~ .cockpit .cockpit__key--pulse,
    .sky.is-still ~ .cockpit .cockpit__scan,
    .sky.is-still ~ .cockpit .cockpit__beacon {
      animation-play-state: paused;
    }
  }
}
