@layer reset, base, panels, controls, states;

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

  html,
  body {
    margin: 0;
    min-width: 20rem;
    min-height: 100%;
  }

  button,
  input,
  output {
    font: inherit;
  }
}

@layer base {
  /* Shared palette and type tokens are also read by the canvas renderer. */
  :root {
    color-scheme: dark;
    --ink: #050706;
    --ink-soft: #0b100d;
    --paper: #f2f0e8;
    --paper-muted: #a7aaa1;
    --acid: #d7ff3f;
    --cyan: #53e6ff;
    --flare: #ff5a36;
    --line: rgb(242 240 232 / 24%);
    --display: "Arial Narrow", "Aptos Narrow", "Roboto Condensed", "Helvetica Neue", sans-serif;
    --mono: "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  }

  body {
    overflow: hidden;
    color: var(--paper);
    background: var(--ink);
    font-family: var(--display);
    text-rendering: optimizeLegibility;
  }

  .experience {
    position: relative;
    min-height: 100svh;
    isolation: isolate;
    background:
      radial-gradient(circle at 68% 35%, rgb(83 230 255 / 7%), transparent 28%),
      var(--ink);
  }

  .experience::after {
    position: fixed;
    z-index: 3;
    inset: 0;
    content: "";
    pointer-events: none;
    background-image: radial-gradient(circle, rgb(242 240 232 / 42%) 0 0.45px, transparent 0.7px);
    background-size: 4px 4px;
    mix-blend-mode: screen;
    opacity: 0.055;
  }

  .experience::before {
    position: fixed;
    z-index: 3;
    inset: 1.125rem;
    content: "";
    pointer-events: none;
    border: 1px solid rgb(242 240 232 / 28%);
    background:
      linear-gradient(var(--acid), var(--acid)) top left / 1.75rem 2px no-repeat,
      linear-gradient(var(--acid), var(--acid)) bottom right / 1.75rem 2px no-repeat;
  }

  .field {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100svh;
    touch-action: none;
    cursor: crosshair;
    outline: none;
  }

  .field--visual {
    z-index: 1;
    background-color: var(--ink);
    background-image:
      linear-gradient(rgb(242 240 232 / 10%) 1px, transparent 1px),
      linear-gradient(90deg, rgb(242 240 232 / 10%) 1px, transparent 1px);
    background-size: max(44px, 5.26vw) max(44px, 5.26vw);
    pointer-events: none;
  }

  .field--panels {
    z-index: 2;
    pointer-events: none;
  }

  .field--source {
    z-index: 0;
  }

  .frame-labels {
    position: fixed;
    z-index: 4;
    top: 1.75rem;
    left: 1.65rem;
    display: flex;
    width: calc(100% - 3.3rem);
    justify-content: space-between;
    color: rgb(242 240 232 / 46%);
    font-family: var(--mono);
    font-size: 0.52rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    pointer-events: none;
  }

  .field.is-dragging {
    cursor: grabbing;
  }

  .field.is-dragging .panel {
    -webkit-user-select: none;
    user-select: none;
  }

  .panel {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 0;
    margin: 0;
    color: var(--paper);
    background:
      linear-gradient(135deg, rgb(255 255 255 / 7%), transparent 38%),
      rgb(7 11 9 / 94%);
    border: 1px solid var(--line);
    clip-path: polygon(0 0, calc(100% - 1rem) 0, 100% 1rem, 100% 100%, 1rem 100%, 0 calc(100% - 1rem));
    transform-origin: 0 0;
    pointer-events: none;
    user-select: text;
  }

  .panel::before {
    position: absolute;
    inset: 0 auto auto 0;
    width: 4.5rem;
    height: 2px;
    content: "";
    background: var(--panel-accent, var(--acid));
  }

  .panel-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--line);
    color: var(--paper-muted);
    font-family: var(--mono);
    font-size: 0.625rem;
    letter-spacing: 0.11em;
    text-transform: uppercase;
  }

  .panel-heading p,
  .panel-heading span {
    margin: 0;
  }

  .panel h2 {
    margin: 1.25rem 0 1rem;
    font-size: 0.875rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    line-height: 1;
    text-transform: uppercase;
  }
}

@layer panels {
  /* These are real DOM surfaces; Chrome snapshots their computed rendering. */
  .panel--hero {
    --panel-accent: var(--acid);
    width: min(48rem, calc(100vw - 2rem));
    padding: 1.5rem 2.15rem 1.75rem 2.35rem;
    background:
      linear-gradient(115deg, rgb(215 255 63 / 9%), transparent 34%),
      rgb(5 8 6 / 96%);
  }

  .eyebrow {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 0 0 1.25rem;
    color: var(--paper-muted);
    font-family: var(--mono);
    font-size: 0.625rem;
    letter-spacing: 0.13em;
    text-transform: uppercase;
  }

  .eyebrow span {
    padding: 0.3rem 0.45rem;
    color: var(--ink);
    background: var(--acid);
    font-weight: 800;
  }

  .panel--hero h1 {
    margin: 0;
    max-width: none;
    /* Keep ultra-bold condensed glyphs inside the panel border box —
       negative sidebearings were clipping the leading C (and trailing IC/Y)
       when HTML-in-Canvas snapshots the element. */
    font-size: clamp(3.1rem, 6.2vw, 6.55rem);
    font-stretch: condensed;
    font-weight: 900;
    letter-spacing: -0.06em;
    line-height: 0.72;
    text-transform: uppercase;
    overflow: visible;
    padding-inline: 0.02em;
  }

  .panel--hero h1 span {
    display: block;
    margin-left: 0.58em;
    color: transparent;
    -webkit-text-stroke: 1px var(--paper);
  }

  .hero-rule {
    width: 100%;
    height: 0.45rem;
    margin: 1.6rem 0 1.1rem;
    background:
      linear-gradient(90deg, var(--acid) 0 62%, transparent 62% 64%, var(--cyan) 64% 86%, transparent 86% 88%, var(--flare) 88%);
  }

  .hero-copy {
    max-width: 29rem;
    margin: 0;
    color: var(--paper-muted);
    font-size: 0.9rem;
    letter-spacing: 0.02em;
    line-height: 1.45;
  }

  .hero-index {
    position: absolute;
    right: 1.75rem;
    bottom: 1.5rem;
    margin: 0;
    color: var(--acid);
    font-family: var(--mono);
    font-size: 0.7rem;
    letter-spacing: 0.08em;
  }

  .panel--telemetry {
    --panel-accent: var(--cyan);
    width: 22rem;
    padding: 1.25rem;
  }

  .status-pip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    color: var(--acid);
  }

  .status-pip::before {
    width: 0.38rem;
    height: 0.38rem;
    content: "";
    background: currentColor;
    border-radius: 50%;
    box-shadow: 0 0 0.75rem currentColor;
  }

  .metric-grid {
    display: grid;
    grid-template-columns: 1.25fr 1fr 1fr;
    gap: 0;
    margin: 0;
    border-block: 1px solid var(--line);
  }

  .metric-grid div {
    padding: 0.85rem 0.6rem 0.8rem 0;
  }

  .metric-grid div + div {
    padding-left: 0.75rem;
    border-left: 1px solid var(--line);
  }

  .metric-grid dt {
    margin-bottom: 0.5rem;
    color: var(--paper-muted);
    font-family: var(--mono);
    font-size: 0.52rem;
    letter-spacing: 0.09em;
    text-transform: uppercase;
  }

  .metric-grid dd {
    margin: 0;
    font-family: var(--mono);
    font-size: 1.15rem;
    font-variant-numeric: tabular-nums;
  }

  .metric-grid dd span {
    color: var(--paper-muted);
    font-size: 0.62em;
  }

  .waveform {
    display: flex;
    align-items: center;
    gap: 0.22rem;
    height: 2.8rem;
    margin-top: 1rem;
    overflow: hidden;
  }

  .waveform i {
    width: 0.42rem;
    height: var(--wave-height, 24%);
    background: var(--cyan);
    box-shadow: 0 0 0.8rem rgb(83 230 255 / 45%);
  }

  .waveform i:nth-child(3n + 1) { --wave-height: 76%; }
  .waveform i:nth-child(4n + 2) { --wave-height: 42%; }
  .waveform i:nth-child(5n + 3) { --wave-height: 94%; }
  .waveform i:nth-child(7n + 4) { --wave-height: 58%; }

  .panel--log {
    --panel-accent: var(--flare);
    width: 25rem;
    padding: 1.25rem;
  }

  .transmission-list {
    display: grid;
    gap: 0.55rem;
    margin: 0;
    padding: 0;
    list-style: none;
    font-family: var(--mono);
    font-size: 0.63rem;
  }

  .transmission-list li {
    display: grid;
    grid-template-columns: 3.25rem 1fr;
    gap: 0.6rem;
  }

  .transmission-list time {
    color: var(--flare);
  }

  .transmission-list span {
    color: var(--paper-muted);
  }

  .panel--log blockquote {
    margin: 1.15rem 0 0;
    padding: 0.85rem 0 0 1rem;
    border-top: 1px solid var(--line);
    border-left: 2px solid var(--flare);
    font-size: 0.9rem;
    font-style: italic;
    line-height: 1.4;
  }

  .panel--spectrum {
    --panel-accent: var(--acid);
    width: 18.5rem;
    padding: 1.15rem;
  }

  .panel--contact {
    --panel-accent: var(--cyan);
    width: 21rem;
    padding: 1.15rem;
    pointer-events: auto;
    background:
      linear-gradient(125deg, rgb(83 230 255 / 8%), transparent 44%),
      rgb(7 11 9 / 97%);
  }

  .panel--contact h2 {
    margin-bottom: 0.75rem;
  }

  .panel--contact a {
    color: var(--paper-muted);
    font-family: var(--mono);
    font-size: 0.58rem;
    letter-spacing: 0.04em;
    text-decoration: none;
    text-transform: uppercase;
  }

  .panel--contact a:hover {
    color: var(--paper);
  }

  .panel--contact a:focus-visible {
    outline: 2px solid var(--cyan);
    outline-offset: 3px;
  }

  .panel--contact .contact-primary {
    display: inline-block;
    margin-bottom: 1rem;
    color: var(--cyan);
    font-size: 0.68rem;
    text-transform: lowercase;
  }

  .contact-links {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    border-top: 1px solid var(--line);
  }

  .contact-links a {
    padding: 0.65rem 0.5rem 0.55rem 0;
    border-bottom: 1px solid var(--line);
  }

  .contact-links a:nth-child(even) {
    padding-left: 0.65rem;
    border-left: 1px solid var(--line);
  }

  .spectrum-list {
    display: grid;
    gap: 0.7rem;
    margin: 0;
    padding: 0;
    list-style: none;
    font-family: var(--mono);
    font-size: 0.58rem;
    letter-spacing: 0.07em;
    text-transform: uppercase;
  }

  .spectrum-list li {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.75rem;
    align-items: end;
  }

  .spectrum-list span {
    position: relative;
    padding-bottom: 0.45rem;
  }

  .spectrum-list span::after {
    position: absolute;
    bottom: 0;
    left: 0;
    width: var(--band);
    height: 2px;
    content: "";
    background: currentColor;
  }

  .spectrum-list li:nth-child(1) { color: var(--cyan); }
  .spectrum-list li:nth-child(2) { color: var(--acid); }
  .spectrum-list li:nth-child(3) { color: var(--flare); }

  .spectrum-list b {
    color: var(--paper-muted);
    font-weight: 400;
  }

  .panel--marker {
    display: flex;
    width: 17rem;
    padding: 0.85rem 1rem;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    color: var(--paper-muted);
    background: rgb(5 7 6 / 88%);
    font-family: var(--mono);
    font-size: 0.56rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  .panel--marker b {
    color: var(--acid);
    font-weight: 500;
  }
}

@layer controls {
  /* Native controls remain focusable below the pointer-transparent canvas planes. */
  .panel--controls {
    --panel-accent: var(--acid);
    width: 24rem;
    padding: 1.25rem;
    pointer-events: auto;
    background:
      linear-gradient(120deg, rgb(215 255 63 / 8%), transparent 42%),
      rgb(7 11 9 / 98%);
  }

  .energy-control {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 1.1rem;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
  }

  .energy-control output {
    color: var(--acid);
    font-family: var(--mono);
    font-size: 1rem;
    font-variant-numeric: tabular-nums;
  }

  input[type="range"] {
    width: 100%;
    height: 1.8rem;
    margin: 0.55rem 0 0.85rem;
    padding: 0;
    appearance: none;
    color: var(--acid);
    background: transparent;
    cursor: ew-resize;
  }

  input[type="range"]::-webkit-slider-runnable-track {
    height: 2px;
    background: linear-gradient(90deg, currentColor var(--range-progress, 65%), var(--line) var(--range-progress, 65%));
  }

  input[type="range"]::-webkit-slider-thumb {
    width: 0.8rem;
    height: 1.25rem;
    margin-top: -0.58rem;
    appearance: none;
    background: currentColor;
    border: 2px solid var(--ink);
    border-radius: 0;
    box-shadow: 0 0 0 1px currentColor, 0 0 1rem rgb(215 255 63 / 45%);
  }

  input[type="range"]::-moz-range-track {
    height: 2px;
    background: var(--line);
  }

  input[type="range"]::-moz-range-progress {
    height: 2px;
    background: currentColor;
  }

  input[type="range"]::-moz-range-thumb {
    width: 0.8rem;
    height: 1.25rem;
    background: currentColor;
    border: 2px solid var(--ink);
    border-radius: 0;
  }

  .control-actions {
    display: grid;
    grid-template-columns: 1.3fr 1fr;
    gap: 0.55rem;
  }

  .control-actions button {
    min-height: 2.65rem;
    padding: 0.7rem 0.75rem;
    color: var(--paper);
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 0;
    font-family: var(--mono);
    font-size: 0.6rem;
    letter-spacing: 0.05em;
    text-align: left;
    text-transform: uppercase;
    cursor: pointer;
  }

  .control-actions button:first-child {
    color: var(--ink);
    background: var(--acid);
    border-color: var(--acid);
    font-weight: 800;
  }

  .control-actions button span {
    display: inline-block;
    margin-right: 0.35rem;
    font-size: 1rem;
    line-height: 0;
  }

  .control-actions button:hover {
    color: var(--ink);
    background: var(--paper);
    border-color: var(--paper);
  }

  .control-actions button:focus-visible,
  input[type="range"]:focus-visible {
    outline: 3px solid var(--cyan);
    outline-offset: 3px;
  }

  .control-hint {
    margin: 0.8rem 0 0;
    color: var(--paper-muted);
    font-family: var(--mono);
    font-size: 0.52rem;
    letter-spacing: 0.04em;
  }
}

@layer states {
  .compatibility {
    position: absolute;
    z-index: 5;
    top: 50%;
    left: 50%;
    width: min(42rem, calc(100% - 2rem));
    max-height: calc(100svh - 2rem);
    padding: clamp(1.5rem, 4vw, 3rem);
    overflow-y: auto;
    background:
      linear-gradient(120deg, rgb(215 255 63 / 10%), transparent 45%),
      var(--ink-soft);
    border: 1px solid var(--line);
    border-top: 3px solid var(--acid);
    transform: translate(-50%, -50%);
  }

  .compatibility[hidden] {
    display: none;
  }

  .compatibility-code {
    margin: 0 0 1.5rem;
    color: var(--acid);
    font-family: var(--mono);
    font-size: 0.65rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
  }

  .compatibility h1 {
    max-width: 11ch;
    margin: 0;
    font-size: clamp(2.6rem, 8vw, 5.5rem);
    letter-spacing: -0.06em;
    line-height: 0.86;
    text-transform: uppercase;
  }

  .compatibility p:not(.compatibility-code) {
    max-width: 37rem;
    margin: 1.75rem 0;
    color: var(--paper-muted);
    line-height: 1.6;
  }

  .compatibility code {
    color: var(--cyan);
    font-family: var(--mono);
    overflow-wrap: anywhere;
  }

  .compatibility a {
    display: inline-block;
    padding: 0.8rem 1rem;
    color: var(--ink);
    background: var(--acid);
    font-family: var(--mono);
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-decoration: none;
    text-transform: uppercase;
  }

  .compatibility a:focus-visible {
    outline: 3px solid var(--cyan);
    outline-offset: 4px;
  }

  .compatibility-contact {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--line);
    font-family: var(--mono);
    font-size: 0.62rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
  }

  .compatibility .compatibility-contact p {
    margin: 0 0 0.75rem;
    color: var(--paper-muted);
    line-height: 1.4;
  }

  .compatibility-contact strong {
    color: var(--paper);
    font-weight: 500;
  }

  .compatibility-contact nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.7rem 1rem;
  }

  .compatibility .compatibility-contact a {
    padding: 0;
    color: var(--cyan);
    background: transparent;
    font-size: inherit;
    font-weight: 500;
  }

  .compatibility .compatibility-contact a:hover {
    color: var(--paper);
  }

  .compatibility--noscript {
    display: block;
  }

  .experience.is-unsupported .field {
    display: none;
  }

  .experience.is-unsupported .frame-labels,
  .experience.is-unsupported::before,
  .experience.is-unsupported::after {
    display: none;
  }

  @media (max-width: 47.99rem) {
    .experience::before {
      inset: 1rem;
    }

    .frame-labels {
      top: 1.55rem;
      left: 1.35rem;
      width: calc(100% - 2.7rem);
      font-size: 0.45rem;
    }

    .panel--hero {
      width: min(24rem, calc(100vw - 1.5rem));
      padding: 1.1rem 1.35rem 1.25rem 1.45rem;
    }

    .panel--hero h1 {
      font-size: clamp(2.85rem, 12vw, 3.55rem);
      letter-spacing: -0.05em;
    }

    .panel--hero h1 span {
      margin-left: 0.42em;
    }

    .hero-copy {
      max-width: 15rem;
      font-size: 0.73rem;
    }

    .hero-index {
      right: 1.15rem;
      bottom: 1.1rem;
    }

    .panel--telemetry {
      width: 18rem;
    }

    .panel--log {
      width: 19rem;
    }

    .panel--spectrum {
      width: 16rem;
    }

    .panel--contact {
      width: 18rem;
    }

    .panel--controls {
      width: calc(100vw - 1.5rem);
      max-width: 22rem;
      padding: 1rem;
    }

    .panel--marker {
      width: 15rem;
    }

    .control-hint {
      display: none;
    }
  }

  @media (max-width: 24rem) {
    .control-actions {
      grid-template-columns: 1fr 1fr;
    }

    .control-actions button {
      font-size: 0.52rem;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .field {
      cursor: default;
    }
  }

  @media (forced-colors: active) {
    .panel,
    .compatibility {
      border: 2px solid CanvasText;
    }

    .panel::before,
    .hero-rule,
    .waveform i {
      background: CanvasText;
    }
  }
}
