@layer reset, theme, shell, components, modules, responsive;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  :where(html, body) { margin: 0; min-width: 300px; min-height: 100%; }
  html { background: #080c12; scroll-behavior: smooth; }
  body { min-height: 100dvh; overflow: hidden; }
  :where(button, input, textarea, select) { font: inherit; }
  :where(button, a, input, textarea, select) { -webkit-tap-highlight-color: transparent; }
  :where(button, select, input[type="range"], input[type="checkbox"], input[type="color"]) { cursor: pointer; }
  :where(button) { border: 0; }
  :where(a) { color: inherit; text-decoration: none; }
  :where(h1, h2, h3, p, dl, dd, ol) { margin: 0; }
  :where(button, a, input, textarea, select):focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
  :where(canvas) { display: block; }
  :where([hidden]) { display: none !important; }
}

@layer theme {
  :root {
    color-scheme: dark;
    --bg: #080c12;
    --bg-deep: #05070b;
    --surface: #0d121a;
    --surface-2: #111823;
    --surface-3: #151e2b;
    --panel: rgba(13, 18, 26, .94);
    --line: #243040;
    --line-soft: #192331;
    --line-bright: #35475d;
    --text: #e7edf5;
    --text-2: #b7c2d0;
    --muted: #718096;
    --muted-2: #4e5d70;
    --green: #3fb950;
    --green-rgb: 63, 185, 80;
    --blue: #58a6ff;
    --blue-rgb: 88, 166, 255;
    --orange: #f0883e;
    --orange-rgb: 240, 136, 62;
    --purple: #d2a8ff;
    --purple-rgb: 210, 168, 255;
    --red: #f85149;
    --cyan: #39c5cf;
    --mono: "SFMono-Regular", "Roboto Mono", "Cascadia Code", Consolas, "Liberation Mono", monospace;
    --sans: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --topbar-h: 48px;
    --status-h: 25px;
    --rail-w: 70px;
    --radius: 7px;
    --shadow: 0 18px 60px rgba(0, 0, 0, .28);
  }

  body {
    background:
      radial-gradient(circle at 72% -10%, rgba(var(--blue-rgb), .08), transparent 32rem),
      radial-gradient(circle at 10% 90%, rgba(var(--green-rgb), .04), transparent 34rem),
      var(--bg);
    color: var(--text);
    font-family: var(--sans);
    font-size: 13px;
    line-height: 1.45;
    letter-spacing: .005em;
  }

  ::selection { background: rgba(var(--blue-rgb), .28); color: white; }
  ::-webkit-scrollbar { width: 8px; height: 8px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { border: 2px solid transparent; border-radius: 99px; background: #354357; background-clip: padding-box; }
}

@layer shell {
  #ambient-canvas {
    position: fixed;
    inset: 0;
    z-index: -3;
    width: 100%;
    height: 100%;
    opacity: .7;
    pointer-events: none;
  }

  .noise {
    position: fixed;
    inset: 0;
    z-index: -2;
    opacity: .025;
    pointer-events: none;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.95' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.9'/%3E%3C/svg%3E");
  }

  .skip-link {
    position: fixed;
    top: 6px;
    left: 8px;
    z-index: 1000;
    padding: 7px 10px;
    border: 1px solid var(--blue);
    border-radius: 4px;
    background: var(--surface-2);
    color: var(--text);
    transform: translateY(-160%);
  }
  .skip-link:focus { transform: none; }

  .topbar {
    position: fixed;
    inset: 0 0 auto;
    z-index: 50;
    height: var(--topbar-h);
    display: grid;
    grid-template-columns: minmax(180px, 1fr) auto minmax(180px, 1fr);
    align-items: center;
    padding: 0 max(10px, env(safe-area-inset-left));
    border-bottom: 1px solid var(--line);
    background: rgba(5, 8, 13, .9);
    backdrop-filter: blur(18px) saturate(130%);
  }

  .brand { width: fit-content; display: inline-flex; align-items: center; gap: 9px; }
  .brand-glyph {
    min-width: 35px;
    height: 27px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(var(--green-rgb), .48);
    border-radius: 4px;
    background: rgba(var(--green-rgb), .06);
    color: var(--green);
    font: 750 10px/1 var(--mono);
    letter-spacing: -.08em;
    box-shadow: inset 0 0 14px rgba(var(--green-rgb), .05);
  }
  .brand-copy { display: flex; align-items: baseline; gap: 8px; white-space: nowrap; }
  .brand-copy b { font: 800 12px/1 var(--mono); letter-spacing: .18em; }
  .brand-copy small { color: var(--muted); font: 9px/1 var(--mono); letter-spacing: .06em; }

  .topbar-center {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: var(--muted);
    font: 9px/1 var(--mono);
    letter-spacing: .08em;
  }
  .live-dot, .online-indicator {
    width: 6px;
    height: 6px;
    display: inline-block;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 0 3px rgba(var(--green-rgb), .09), 0 0 10px rgba(var(--green-rgb), .65);
  }
  .live-dot { animation: live-pulse 2.4s infinite; }
  .topbar-divider { width: 1px; height: 10px; background: var(--line); }

  .topbar-actions { justify-self: end; display: flex; align-items: center; gap: 5px; }
  .icon-button {
    height: 29px;
    min-width: 29px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 0 8px;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: var(--surface);
    color: var(--text-2);
    font: 700 11px/1 var(--mono);
  }
  .icon-button:hover { border-color: var(--line-bright); background: var(--surface-2); color: white; }
  .icon-button kbd { color: var(--muted); font: 8px/1 var(--mono); }

  .app-shell {
    height: calc(100dvh - var(--topbar-h) - var(--status-h));
    display: grid;
    grid-template-columns: var(--rail-w) minmax(0, 1fr);
    margin-top: var(--topbar-h);
  }

  .rail {
    z-index: 20;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 8px 6px;
    border-right: 1px solid var(--line-soft);
    background: rgba(7, 10, 15, .76);
    backdrop-filter: blur(14px);
  }
  .rail-item {
    min-height: 53px;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 3px;
    padding: 4px 2px;
    border-left: 2px solid transparent;
    border-radius: 4px;
    background: transparent;
    color: var(--muted);
    font: 8px/1 var(--mono);
    letter-spacing: .05em;
    text-transform: uppercase;
  }
  .rail-icon { color: var(--text-2); font: 17px/1 var(--mono); transition: transform 140ms ease; }
  .rail-item:hover { background: rgba(255,255,255,.025); color: var(--text-2); }
  .rail-item:hover .rail-icon { transform: translateY(-1px); color: var(--blue); }
  .rail-item.active { border-left-color: var(--blue); background: rgba(var(--blue-rgb), .07); color: var(--blue); }
  .rail-item.active .rail-icon { color: var(--blue); text-shadow: 0 0 14px rgba(var(--blue-rgb), .45); }
  .rail-spacer { flex: 1; }
  .rail-compact { min-height: 43px; }

  .workspace {
    min-width: 0;
    overflow: auto;
    overscroll-behavior: contain;
    scroll-behavior: smooth;
  }
  .view { min-height: 100%; padding: clamp(14px, 2vw, 26px); }
  .view:not(.active) { display: none; }

  .statusbar {
    position: fixed;
    inset: auto 0 0;
    z-index: 60;
    height: var(--status-h);
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 0 max(11px, env(safe-area-inset-left));
    border-top: 1px solid var(--line);
    background: #06090e;
    color: var(--muted);
    font: 8px/1 var(--mono);
    letter-spacing: .08em;
  }
  .statusbar > span { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
  .statusbar b { color: var(--text-2); font-weight: 650; }
  .status-message { flex: 1; justify-content: center; overflow: hidden; text-overflow: ellipsis; }
  .status-time { margin-left: auto; color: var(--text-2); }

  body.focus-mode .rail, body.focus-mode .topbar-center, body.focus-mode .statusbar > span:not(.status-message) { display: none; }
  body.focus-mode .app-shell { grid-template-columns: 1fr; }
}

@layer components {
  .view-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 28px;
    margin-bottom: 16px;
  }
  .console-heading { align-items: end; min-height: 138px; margin-bottom: 22px; }
  .eyebrow { margin-bottom: 8px; color: var(--green); font: 700 9px/1 var(--mono); letter-spacing: .16em; }
  .view-header h1 { max-width: 790px; font-size: clamp(30px, 5vw, 68px); line-height: .98; letter-spacing: -.052em; text-wrap: balance; }
  .view-header h2 { font-size: clamp(24px, 3vw, 40px); line-height: 1; letter-spacing: -.035em; }
  .view-header p:not(.eyebrow) { max-width: 730px; margin-top: 10px; color: var(--muted); font-size: clamp(11px, 1.1vw, 14px); }
  .view-header .lede { max-width: 820px !important; color: var(--text-2) !important; line-height: 1.55; }
  .compact-heading { min-height: 76px; }
  .hero-actions, .view-actions { flex: 0 0 auto; display: flex; align-items: center; gap: 7px; }

  .primary-action, .secondary-action, .file-action {
    min-height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 7px 12px;
    border: 1px solid var(--line-bright);
    border-radius: 5px;
    background: var(--surface-2);
    color: var(--text-2);
    font: 700 9px/1 var(--mono);
    letter-spacing: .05em;
    text-transform: uppercase;
    white-space: nowrap;
  }
  .primary-action { border-color: rgba(var(--green-rgb), .62); background: var(--green); color: #07120a; }
  .primary-action:hover { filter: brightness(1.12); box-shadow: 0 0 22px rgba(var(--green-rgb), .18); }
  .secondary-action:hover, .file-action:hover { border-color: var(--blue); color: var(--blue); }
  .primary-action.compact { min-height: 32px; padding-inline: 10px; }
  .primary-action b { font-size: 13px; }
  .secondary-action kbd { padding: 2px 4px; border: 1px solid var(--line); border-radius: 3px; color: var(--muted); font-size: 7px; }
  .secondary-action.full, .file-action.full { width: 100%; }
  .file-action.centered { margin-top: 7px; }

  .panel {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: linear-gradient(160deg, rgba(18, 25, 36, .96), rgba(10, 15, 22, .96));
    box-shadow: inset 0 1px rgba(255,255,255,.018), 0 8px 30px rgba(0,0,0,.12);
    overflow: hidden;
  }
  .panel-header {
    min-height: 35px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 7px 10px;
    border-bottom: 1px solid var(--line-soft);
    background: rgba(5, 9, 14, .55);
    color: var(--muted);
    font: 8px/1 var(--mono);
    letter-spacing: .08em;
  }
  .panel-header > div { min-width: 0; display: flex; align-items: center; gap: 7px; }
  .panel-header b { color: var(--text-2); font-weight: 700; }
  .panel-meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .status-light { width: 5px; height: 5px; display: inline-block; border-radius: 50%; background: currentColor; box-shadow: 0 0 8px currentColor; }
  .status-light.green { color: var(--green); }
  .status-light.blue { color: var(--blue); }
  .status-light.orange { color: var(--orange); }
  .status-light.purple { color: var(--purple); }
  .panel-tools { margin-left: auto; color: var(--muted); }
  .text-button { padding: 3px 4px; background: transparent; color: var(--muted); font: 8px/1 var(--mono); text-transform: uppercase; }
  .text-button:hover { color: var(--blue); }
  .text-button.danger:hover { color: var(--red); }

  .segmented { display: inline-flex !important; gap: 0 !important; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
  .segmented button, .mode-toggle button {
    padding: 5px 7px;
    background: var(--surface);
    color: var(--muted);
    font: 7px/1 var(--mono);
    letter-spacing: .04em;
  }
  .segmented button + button { border-left: 1px solid var(--line); }
  .segmented button.active { background: rgba(var(--blue-rgb), .12); color: var(--blue); }

  .range-control, .color-control {
    display: grid;
    gap: 7px;
    padding: 10px;
    border-bottom: 1px solid var(--line-soft);
  }
  .range-control > span, .color-control > span { display: flex; justify-content: space-between; color: var(--muted); font: 8px/1 var(--mono); letter-spacing: .05em; }
  .range-control b, .color-control b { color: var(--text-2); }
  .range-control output, .color-control output { color: var(--blue); }
  input[type="range"] {
    width: 100%;
    height: 3px;
    appearance: none;
    border-radius: 99px;
    background: linear-gradient(90deg, var(--blue) 0 var(--range-fill, 50%), var(--line) var(--range-fill, 50%));
  }
  input[type="range"]::-webkit-slider-thumb { width: 11px; height: 11px; appearance: none; border: 2px solid var(--surface); border-radius: 50%; background: var(--blue); box-shadow: 0 0 0 1px var(--blue); }
  input[type="range"]::-moz-range-thumb { width: 9px; height: 9px; border: 2px solid var(--surface); border-radius: 50%; background: var(--blue); box-shadow: 0 0 0 1px var(--blue); }
  input[type="checkbox"][role="switch"] {
    width: 28px;
    height: 14px;
    appearance: none;
    border: 1px solid var(--line-bright);
    border-radius: 99px;
    background: var(--surface);
    transition: .15s ease;
  }
  input[type="checkbox"][role="switch"]::before { content: ""; width: 8px; height: 8px; display: block; margin: 2px; border-radius: 50%; background: var(--muted); transition: .15s ease; }
  input[type="checkbox"][role="switch"]:checked { border-color: rgba(var(--green-rgb),.6); background: rgba(var(--green-rgb),.15); }
  input[type="checkbox"][role="switch"]:checked::before { background: var(--green); transform: translateX(13px); box-shadow: 0 0 7px rgba(var(--green-rgb),.5); }
  select, input[type="number"], input[type="text"], input[type="search"] {
    border: 1px solid var(--line);
    border-radius: 4px;
    outline: 0;
    background: var(--surface);
    color: var(--text-2);
  }
  select:focus, input:focus, textarea:focus { border-color: rgba(var(--blue-rgb), .72); }

  .switch-row, .scale-row {
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--line-soft);
    color: var(--muted);
    font: 8px/1.25 var(--mono);
  }
  .switch-row span, .scale-row span { display: grid; gap: 4px; }
  .switch-row b, .scale-row b { color: var(--text-2); }
  .switch-row small { color: var(--muted-2); font-size: 7px; }
  .switch-row select, .scale-row select { max-width: 135px; padding: 5px; font: 7px/1 var(--mono); }

  .command-dialog {
    width: min(650px, calc(100% - 24px));
    max-height: min(650px, calc(100dvh - 40px));
    margin: 10vh auto 0;
    padding: 0;
    border: 1px solid var(--line-bright);
    border-radius: 8px;
    background: rgba(10, 15, 22, .98);
    color: var(--text);
    box-shadow: 0 30px 100px #000, 0 0 0 1px rgba(var(--blue-rgb), .08);
    overflow: hidden;
  }
  .command-dialog::backdrop { background: rgba(1,4,8,.68); backdrop-filter: blur(5px); }
  .command-shell > header { display: grid; grid-template-columns: 25px 1fr auto; align-items: center; padding: 10px; border-bottom: 1px solid var(--line); }
  .command-shell > header label { color: var(--green); font: 18px/1 var(--mono); }
  .command-shell > header input { min-width: 0; padding: 4px 2px; border: 0; background: transparent; color: var(--text); font: 13px/1.3 var(--mono); }
  .command-shell > header button { padding: 4px 6px; border: 1px solid var(--line); border-radius: 3px; background: var(--surface); color: var(--muted); font: 7px/1 var(--mono); }
  .command-context { display: flex; justify-content: space-between; padding: 6px 10px; border-bottom: 1px solid var(--line-soft); color: var(--muted); font: 7px/1 var(--mono); }
  #command-results { max-height: 430px; padding: 6px; list-style: none; overflow: auto; }
  #command-results li button { width: 100%; display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 8px; padding: 8px; border-radius: 4px; background: transparent; color: var(--text-2); text-align: left; }
  #command-results li button:hover, #command-results li.active button { background: rgba(var(--blue-rgb), .09); color: white; }
  #command-results .command-icon { color: var(--blue); font: 12px/1 var(--mono); text-align: center; }
  #command-results b { display: block; font: 600 10px/1.3 var(--mono); }
  #command-results small { display: block; margin-top: 3px; color: var(--muted); font: 7px/1.3 var(--mono); }
  #command-results kbd { color: var(--muted); font: 7px/1 var(--mono); }

  .system-popover {
    position: fixed;
    inset: var(--topbar-h) 10px auto auto;
    width: min(290px, calc(100% - 20px));
    margin: 8px 0 0;
    padding: 0;
    border: 1px solid var(--line-bright);
    border-radius: 6px;
    background: rgba(10,15,22,.98);
    color: var(--text);
    box-shadow: var(--shadow);
  }
  .system-popover > header { display: flex; justify-content: space-between; padding: 9px 10px; border-bottom: 1px solid var(--line); font: 9px/1 var(--mono); }
  .system-popover > header button { background: transparent; color: var(--muted); }
  .system-popover dl { padding: 7px 10px; }
  .system-popover dl div { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid var(--line-soft); font: 8px/1 var(--mono); }
  .system-popover dt { color: var(--muted); }
  .system-popover dd { color: var(--green); }
  .system-popover p { padding: 8px 10px 10px; color: var(--muted); font: 8px/1.5 var(--mono); }

  #toast-region { position: fixed; right: 12px; bottom: calc(var(--status-h) + 10px); z-index: 100; display: grid; gap: 6px; pointer-events: none; }
  .toast { min-width: 230px; display: flex; align-items: center; gap: 8px; padding: 9px 10px; border: 1px solid var(--line-bright); border-radius: 5px; background: rgba(12,18,26,.96); box-shadow: var(--shadow); color: var(--text-2); font: 9px/1.2 var(--mono); animation: toast-in .2s ease both; }
  .toast i { width: 6px; height: 6px; border-radius: 50%; background: var(--green); box-shadow: 0 0 8px var(--green); }
  .toast.out { animation: toast-out .2s ease both; }

  @keyframes live-pulse { 50% { opacity: .45; box-shadow: 0 0 0 5px transparent, 0 0 4px rgba(var(--green-rgb), .3); } }
  @keyframes toast-in { from { opacity: 0; transform: translateX(15px); } }
  @keyframes toast-out { to { opacity: 0; transform: translateX(15px); } }
}

@layer modules {
  /* Console */
  .console-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
  .span-2 { grid-column: span 2; }
  .span-3 { grid-column: 1 / -1; }
  .hero-visual { position: relative; min-height: 300px; }
  .hero-visual canvas { width: 100%; height: calc(100% - 35px); min-height: 265px; background: radial-gradient(circle at center, rgba(var(--blue-rgb), .035), transparent 65%); touch-action: none; }
  .visual-overlay { position: absolute; right: 10px; bottom: 9px; display: flex; gap: 12px; padding: 5px 7px; border: 1px solid rgba(var(--blue-rgb), .15); border-radius: 4px; background: rgba(5,9,14,.72); color: var(--muted); font: 7px/1 var(--mono); backdrop-filter: blur(6px); }
  .visual-overlay b { color: var(--blue); }
  .metric-stack { padding: 5px 10px 8px; }
  .metric-stack > div { min-height: 38px; display: flex; align-items: center; justify-content: space-between; gap: 10px; border-bottom: 1px solid var(--line-soft); }
  .metric-stack > div:last-child { border-bottom: 0; }
  .metric-stack span { color: var(--muted); font: 8px/1 var(--mono); }
  .metric-stack b { color: var(--green); font: 9px/1 var(--mono); }
  .engines-panel { min-height: 182px; }
  .engine-grid { display: grid; grid-template-columns: repeat(5, minmax(0,1fr)); }
  .engine-card { position: relative; min-height: 145px; display: grid; align-content: start; gap: 7px; padding: 13px; border-right: 1px solid var(--line-soft); background: transparent; color: var(--text); text-align: left; overflow: hidden; }
  .engine-card:last-child { border-right: 0; }
  .engine-card::after { content: ""; position: absolute; inset: auto 10px 0; height: 1px; background: var(--blue); transform: scaleX(0); transform-origin: left; transition: transform .18s ease; }
  .engine-card:hover { background: rgba(var(--blue-rgb), .035); }
  .engine-card:hover::after { transform: scaleX(1); }
  .engine-number { color: var(--blue); font: 8px/1 var(--mono); }
  .engine-card b { font: 750 10px/1.1 var(--mono); letter-spacing: .04em; }
  .engine-card small { color: var(--muted); font: 9px/1.45 var(--sans); }
  .engine-readout { align-self: end; margin-top: auto; color: var(--muted-2); font: 7px/1 var(--mono); }
  .quick-terminal { min-height: 182px; }
  #session-log { height: 105px; padding: 7px 10px; list-style: none; overflow: auto; color: var(--text-2); font: 8px/1.6 var(--mono); }
  #session-log li { display: grid; grid-template-columns: 58px 1fr; gap: 7px; }
  #session-log time { color: var(--muted-2); }
  #session-log span::before { content: "› "; color: var(--green); }
  .terminal-input { height: 37px; display: grid; grid-template-columns: 18px 1fr; align-items: center; padding: 0 10px; border-top: 1px solid var(--line-soft); }
  .terminal-input label { color: var(--green); font: 10px/1 var(--mono); }
  .terminal-input input { width: 100%; padding: 0; border: 0; background: transparent; color: var(--text-2); font: 8px/1 var(--mono); }
  .pulse-strip { min-height: 86px; display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); }
  signal-spark { min-width: 0; min-height: 84px; display: grid; grid-template-columns: 55px 1fr; align-items: center; padding: 8px; border-right: 1px solid var(--line-soft); }
  signal-spark:last-child { border-right: 0; }
  signal-spark span { color: var(--muted); font: 7px/1 var(--mono); }
  signal-spark b { display: block; margin-top: 5px; color: var(--text-2); font: 10px/1 var(--mono); }
  signal-spark canvas { width: 100%; height: 50px; }

  /* CNC */
  .cnc-layout { height: calc(100dvh - var(--topbar-h) - var(--status-h) - 124px); min-height: 580px; display: grid; grid-template-columns: minmax(230px, .72fr) minmax(400px, 1.5fr) minmax(220px, .68fr); gap: 9px; }
  .code-panel, .plot-panel, .program-trace-panel { display: grid; grid-template-rows: auto minmax(0,1fr); }
  #gcode-input { width: 100%; height: 100%; resize: none; padding: 11px 12px 40vh; border: 0; outline: 0; background: #070b10; color: #c9d1d9; tab-size: 2; font: 10px/1.55 var(--mono); white-space: pre; overflow: auto; }
  .plot-panel { grid-template-rows: auto minmax(0,1fr) auto; }
  .plot-stage { position: relative; min-height: 0; overflow: hidden; background-color: #05090e; background-image: linear-gradient(rgba(var(--blue-rgb),.035) 1px,transparent 1px),linear-gradient(90deg,rgba(var(--blue-rgb),.035) 1px,transparent 1px); background-size: 20px 20px; }
  #cnc-canvas { width: 100%; height: 100%; touch-action: none; }
  .axis-cube { position: absolute; top: 12px; left: 12px; width: 32px; height: 32px; color: var(--muted); font: 7px/1 var(--mono); pointer-events: none; }
  .axis-cube::before, .axis-cube::after { content: ""; position: absolute; left: 50%; bottom: 7px; height: 1px; width: 22px; background: var(--line-bright); transform-origin: left; }
  .axis-cube::after { transform: rotate(-90deg); }
  .axis-cube i { position: absolute; font-style: normal; }
  .axis-cube .x { right: -1px; bottom: 3px; color: var(--red); }
  .axis-cube .y { left: 12px; top: -1px; color: var(--green); }
  .axis-cube .z { left: 0; bottom: 0; color: var(--blue); }
  .plot-hud { position: absolute; right: 8px; bottom: 8px; display: flex; gap: 10px; padding: 5px 7px; border: 1px solid var(--line-soft); border-radius: 4px; background: rgba(5,9,14,.8); color: var(--muted); font: 7px/1 var(--mono); pointer-events: none; }
  .plot-hud b { color: var(--text-2); }
  .transport { min-height: 40px; display: grid; grid-template-columns: auto auto 1fr auto auto; align-items: center; gap: 7px; padding: 6px 8px; border-top: 1px solid var(--line); background: #080d13; }
  .transport button { min-width: 30px; height: 25px; border: 1px solid var(--line); border-radius: 3px; background: var(--surface); color: var(--muted); font: 8px/1 var(--mono); }
  .transport button:hover { border-color: var(--blue); color: var(--blue); }
  .transport label { display: flex; align-items: center; gap: 4px; color: var(--muted); font: 7px/1 var(--mono); }
  .transport select { padding: 4px; font: 7px/1 var(--mono); }
  .cnc-inspector { min-height: 0; display: grid; grid-template-rows: auto minmax(170px,1fr) auto; gap: 9px; }
  .dro-grid { display: grid; grid-template-columns: repeat(2,1fr); }
  .dro-grid > div { min-height: 42px; display: grid; grid-template-columns: 18px 1fr; align-items: center; padding: 6px 8px; border-right: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft); }
  .dro-grid > div:nth-child(2n) { border-right: 0; }
  .dro-grid span { color: var(--muted); font: 8px/1 var(--mono); }
  .dro-grid b { color: var(--green); font: 10px/1 var(--mono); text-align: right; }
  #cnc-trace-lines { min-height: 0; padding: 6px 0 45%; list-style: none; overflow: auto; counter-reset: cnc-line; background: #070b10; font: 8px/1.5 var(--mono); }
  #cnc-trace-lines li { display: grid; grid-template-columns: 35px 1fr; gap: 7px; min-height: 19px; padding: 2px 8px 2px 0; color: var(--muted); white-space: pre; }
  #cnc-trace-lines li::before { counter-increment: cnc-line; content: counter(cnc-line); color: var(--muted-2); text-align: right; }
  #cnc-trace-lines li.active { background: rgba(var(--blue-rgb),.11); color: var(--text); }
  #cnc-trace-lines .g { color: var(--blue); }
  #cnc-trace-lines .m { color: var(--purple); }
  #cnc-trace-lines .axis { color: var(--green); }
  #cnc-trace-lines .number { color: var(--orange); }
  #cnc-trace-lines .comment { color: var(--muted-2); }
  #cnc-intelligence { padding: 5px 9px 8px; }
  #cnc-intelligence div { min-height: 25px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line-soft); font: 7px/1 var(--mono); }
  #cnc-intelligence div:last-child { border: 0; }
  #cnc-intelligence dt { color: var(--muted); }
  #cnc-intelligence dd { color: var(--text-2); }

  /* Field */
  .field-layout { height: calc(100dvh - var(--topbar-h) - var(--status-h) - 124px); min-height: 570px; display: grid; grid-template-columns: minmax(0,1fr) 260px; gap: 9px; }
  .field-stage-panel { display: grid; grid-template-rows: auto minmax(0,1fr); }
  .field-stats { display: flex !important; gap: 10px !important; }
  .field-stats b { color: var(--green); }
  .field-stage { position: relative; min-height: 0; overflow: hidden; background: #03070b; }
  .field-stage canvas { width: 100%; height: 100%; touch-action: none; }
  #launch-vector { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
  #launch-vector line { stroke: var(--green); stroke-width: 1; stroke-dasharray: 5 4; }
  #launch-vector circle { fill: var(--green); }
  .field-hint { position: absolute; left: 50%; bottom: 12px; padding: 5px 7px; border: 1px solid var(--line-soft); border-radius: 4px; background: rgba(5,9,14,.7); color: var(--muted); font: 7px/1 var(--mono); transform: translateX(-50%); pointer-events: none; transition: opacity .3s ease; }
  .field-controls { min-height: 0; display: flex; flex-direction: column; gap: 9px; overflow: auto; }
  .mode-toggle { display: grid; grid-template-columns: repeat(3,1fr); padding: 8px; }
  .mode-toggle button { min-height: 27px; border: 1px solid var(--line); }
  .mode-toggle button + button { border-left: 0; }
  .mode-toggle button:first-child { border-radius: 4px 0 0 4px; }
  .mode-toggle button:last-child { border-radius: 0 4px 4px 0; }
  .mode-toggle button.active { background: rgba(var(--green-rgb),.11); color: var(--green); }
  .color-control { grid-template-columns: 1fr auto; align-items: center; }
  .color-control span { display: grid; gap: 5px; }
  .color-control input[type="color"] { width: 35px; height: 25px; padding: 2px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); }
  .source-list-panel { margin-bottom: 1px; }
  #source-list { padding: 4px 8px 8px; }
  .source-row { min-height: 30px; display: grid; grid-template-columns: 8px 25px 1fr auto; align-items: center; gap: 6px; padding: 3px 2px; border-bottom: 1px solid var(--line-soft); color: var(--muted); font: 7px/1 var(--mono); cursor: pointer; }
  .source-row:hover, .source-row.active { color: var(--text); }
  .source-row i { width: 6px; height: 6px; border-radius: 50%; background: var(--source-color); box-shadow: 0 0 8px var(--source-color); }
  .source-row b { color: var(--text-2); }
  .source-row output { color: var(--blue); }

  /* Motion */
  .motion-layout { min-height: calc(100dvh - var(--topbar-h) - var(--status-h) - 124px); display: grid; grid-template-columns: minmax(0,1.55fr) minmax(260px,.65fr); gap: 9px; }
  .motion-stage-panel { min-height: 570px; display: grid; grid-template-rows: auto minmax(0,1fr) auto; }
  .motion-stage { position: relative; min-height: 0; overflow: hidden; background: radial-gradient(circle at center, rgba(var(--purple-rgb),.055), transparent 55%), #05080e; touch-action: none; }
  #motion-canvas { width: 100%; height: 100%; }
  .motion-reticle { position: absolute; top: 50%; left: 50%; width: 40px; height: 40px; border: 1px solid rgba(var(--purple-rgb),.65); border-radius: 50%; transform: translate(-50%,-50%); box-shadow: 0 0 22px rgba(var(--purple-rgb),.18); pointer-events: none; }
  .motion-reticle::before, .motion-reticle::after { content: ""; position: absolute; top: 50%; left: 50%; width: 62px; height: 1px; background: linear-gradient(90deg,transparent,rgba(var(--purple-rgb),.4),transparent); transform: translate(-50%,-50%); }
  .motion-reticle::after { transform: translate(-50%,-50%) rotate(90deg); }
  .motion-reticle i { position: absolute; inset: 10px; border: 1px solid rgba(var(--green-rgb),.45); border-radius: 50%; }
  .motion-reticle span { position: absolute; inset: 18px; border-radius: 50%; background: white; box-shadow: 0 0 10px var(--purple); }
  .motion-readout { position: absolute; left: 9px; bottom: 9px; display: flex; gap: 11px; padding: 5px 7px; border: 1px solid var(--line-soft); border-radius: 4px; background: rgba(5,9,14,.78); color: var(--muted); font: 7px/1 var(--mono); }
  .motion-readout b { color: var(--purple); }
  .hold-mute { min-height: 52px; display: grid; place-items: center; align-content: center; gap: 4px; border-top: 1px solid var(--line); background: linear-gradient(90deg,rgba(248,81,73,0),rgba(248,81,73,.09),rgba(248,81,73,0)); color: var(--text-2); user-select: none; touch-action: none; }
  .hold-mute span { font: 750 9px/1 var(--mono); letter-spacing: .16em; }
  .hold-mute small { color: var(--muted); font: 7px/1 var(--mono); }
  .hold-mute.pressed { background: rgba(248,81,73,.16); color: var(--red); }
  .voice-rack { min-height: 0; display: flex; flex-direction: column; gap: 9px; }
  .voice-list { display: grid; gap: 7px; }
  .voice { overflow: visible; }
  .voice-header { min-height: 34px; display: flex; align-items: center; justify-content: space-between; padding: 6px 9px; border-bottom: 1px solid var(--line-soft); }
  .voice-header label { display: flex; align-items: center; gap: 7px; color: var(--text-2); font: 8px/1 var(--mono); }
  .voice-header b { color: var(--purple); font: 8px/1 var(--mono); }
  .voice-grid { display: grid; grid-template-columns: .85fr 1.15fr; gap: 8px; padding: 8px 9px 4px; }
  .voice-grid label { min-width: 0; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 5px; color: var(--muted); font: 7px/1 var(--mono); }
  .voice-grid select { min-width: 0; padding: 4px; font: 7px/1 var(--mono); }
  .voice-grid output { color: var(--blue); }
  .voice-range { display: flex; align-items: center; gap: 5px; padding: 3px 9px 7px; color: var(--muted); font: 7px/1 var(--mono); }
  .voice-range label { display: flex; align-items: center; gap: 4px; }
  .voice-range input { width: 52px; padding: 3px 4px; color: var(--green); font: 7px/1 var(--mono); }
  .raw-meter { height: 5px; position: relative; background: var(--surface); overflow: hidden; }
  .raw-meter i { width: var(--value); height: 100%; display: block; background: linear-gradient(90deg,var(--blue),var(--purple)); transition: width 80ms linear; }
  .raw-meter output { position: absolute; right: 5px; bottom: 7px; color: var(--muted); font: 6px/1 var(--mono); }
  .sample-panel p { padding: 8px 10px; color: var(--muted); font: 8px/1.45 var(--mono); }
  .sample-panel .secondary-action { border-width: 1px 0 0; border-radius: 0; }

  /* Indexer */
  .indexer-layout { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 9px; }
  .dial-panel { min-height: 288px; }
  .rpm-dial { width: 155px; aspect-ratio: 1; display: grid; place-items: center; margin: 17px auto 10px; border: 1px solid var(--line); border-radius: 50%; background: conic-gradient(from -135deg, var(--green) 0 var(--dial), var(--line) var(--dial) 270deg, transparent 270deg), radial-gradient(circle,var(--surface) 62%,transparent 63%); filter: drop-shadow(0 0 12px rgba(var(--green-rgb),.07)); }
  .rpm-dial::before { content: ""; position: absolute; width: 130px; aspect-ratio: 1; border: 1px dashed var(--line-bright); border-radius: 50%; opacity: .45; }
  .rpm-dial > div { z-index: 1; display: grid; place-items: center; }
  .rpm-dial b { color: var(--green); font: 34px/.9 var(--mono); letter-spacing: -.06em; }
  .rpm-dial span { margin-top: 8px; color: var(--muted); font: 8px/1 var(--mono); letter-spacing: .12em; }
  .dial-panel > input { width: calc(100% - 24px); margin: 0 12px 15px; }
  .preset-row { display: flex; justify-content: center; gap: 4px; padding: 0 8px 12px; }
  .preset-row button { min-width: 32px; padding: 5px; border: 1px solid var(--line); border-radius: 3px; background: var(--surface); color: var(--muted); font: 7px/1 var(--mono); }
  .preset-row button.active { border-color: var(--green); color: var(--green); }
  .pulse-panel { min-height: 288px; display: grid; grid-template-rows: auto minmax(0,1fr) auto; }
  #pulse-canvas { width: 100%; height: 170px; }
  .pulse-metrics { display: grid; grid-template-columns: repeat(5,1fr); border-top: 1px solid var(--line); }
  .pulse-metrics div { min-width: 0; display: grid; gap: 5px; padding: 9px; border-right: 1px solid var(--line-soft); }
  .pulse-metrics div:last-child { border-right: 0; }
  .pulse-metrics span { color: var(--muted); font: 7px/1 var(--mono); }
  .pulse-metrics b { overflow: hidden; color: var(--blue); font: 9px/1 var(--mono); text-overflow: ellipsis; }
  .configuration-panel { min-height: 230px; }
  .form-grid { display: grid; grid-template-columns: repeat(2,1fr); padding: 5px 9px 10px; }
  .form-grid label { position: relative; display: grid; gap: 4px; padding: 7px 4px; color: var(--muted); font: 7px/1 var(--mono); }
  .form-grid select, .form-grid input { width: 100%; padding: 6px; color: var(--text-2); font: 8px/1 var(--mono); }
  .form-grid label span { position: absolute; right: 9px; bottom: 14px; color: var(--muted); }
  .cycle-panel { min-height: 230px; }
  .cycle-track { position: relative; height: 92px; display: flex; gap: 2px; margin: 22px 12px 10px; overflow: hidden; }
  .cycle-block { width: var(--span); display: grid; place-items: center; align-content: center; gap: 6px; border: 1px solid currentColor; background: color-mix(in srgb,currentColor 9%,transparent); color: var(--blue); clip-path: polygon(0 0,calc(100% - 8px) 0,100% 50%,calc(100% - 8px) 100%,0 100%,8px 50%); }
  .cycle-block:first-child { clip-path: polygon(0 0,calc(100% - 8px) 0,100% 50%,calc(100% - 8px) 100%,0 100%); }
  .cycle-block.mark { color: var(--purple); }
  .cycle-block.dwell { color: var(--muted); }
  .cycle-block.rotate { color: var(--green); }
  .cycle-block b { font: 750 8px/1 var(--mono); }
  .cycle-block span { opacity: .7; font: 7px/1 var(--mono); }
  #cycle-cursor { position: absolute; top: 0; bottom: 0; left: 0; width: 1px; background: white; box-shadow: 0 0 9px white; opacity: 0; }
  .cycle-track.running #cycle-cursor { opacity: 1; animation: cycle-run var(--cycle-duration,2.5s) linear forwards; }
  .io-row { display: flex; flex-wrap: wrap; gap: 10px 18px; padding: 10px 13px; border-top: 1px solid var(--line-soft); color: var(--muted); font: 7px/1 var(--mono); }
  .io-row span { display: inline-flex; align-items: center; gap: 5px; }
  .io-row i { width: 6px; height: 6px; border-radius: 50%; background: var(--line-bright); }
  .io-row i.on { background: var(--green); box-shadow: 0 0 8px var(--green); }
  .code-output-panel { max-height: 330px; }
  #arduino-code { max-height: 286px; padding: 11px 13px 50px; background: #060a0f; color: #c9d1d9; font: 8px/1.5 var(--mono); overflow: auto; }
  #arduino-code .token-key { color: var(--blue); }
  #arduino-code .token-number { color: var(--orange); }
  #arduino-code .token-comment { color: var(--muted-2); }
  @keyframes cycle-run { to { left: 100%; } }

  /* Vault */
  .vault-heading { align-items: center; }
  .vault-count { display: flex; align-items: baseline; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface); }
  .vault-count b { color: var(--green); font: 23px/1 var(--mono); }
  .vault-count span { color: var(--muted); font: 7px/1 var(--mono); }
  .vault-toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 11px; }
  .vault-search { min-width: 210px; flex: 1; height: 34px; display: grid; grid-template-columns: 25px 1fr auto; align-items: center; border: 1px solid var(--line); border-radius: 5px; background: var(--surface); }
  .vault-search label { color: var(--green); text-align: center; }
  .vault-search input { width: 100%; padding: 0 3px; border: 0; background: transparent; color: var(--text); font: 9px/1 var(--mono); }
  .vault-search kbd { margin-right: 6px; padding: 3px 5px; border: 1px solid var(--line); border-radius: 3px; color: var(--muted); font: 7px/1 var(--mono); }
  .filter-chips { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
  .filter-chips button { flex: 0 0 auto; height: 30px; padding: 0 8px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); color: var(--muted); font: 7px/1 var(--mono); }
  .filter-chips button.active { border-color: rgba(var(--blue-rgb),.6); background: rgba(var(--blue-rgb),.09); color: var(--blue); }
  .favorite-filter { flex: 0 0 auto; display: flex; align-items: center; gap: 6px; color: var(--muted); font: 7px/1 var(--mono); }
  .vault-layout { display: grid; grid-template-columns: minmax(0,1fr) 245px; gap: 9px; align-items: start; }
  .vault-grid { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 7px; }
  .tool-card { min-height: 124px; display: grid; grid-template-rows: auto 1fr auto; border: 1px solid var(--line); border-radius: 5px; background: linear-gradient(145deg,var(--surface-2),var(--surface)); overflow: hidden; content-visibility: auto; contain-intrinsic-size: 124px; }
  .tool-card:hover { border-color: var(--line-bright); background: var(--surface-2); transform: translateY(-1px); }
  .tool-card > header { display: flex; align-items: center; justify-content: space-between; padding: 7px 8px 2px; }
  .tool-kind { color: var(--blue); font: 7px/1 var(--mono); text-transform: uppercase; }
  .favorite-button { padding: 2px; background: transparent; color: var(--muted); font-size: 14px; line-height: 1; }
  .favorite-button.active { color: var(--orange); }
  .tool-link { min-width: 0; display: grid; align-content: center; gap: 5px; padding: 7px 9px; }
  .tool-link b { overflow: hidden; color: var(--text); font: 700 10px/1.25 var(--mono); text-overflow: ellipsis; }
  .tool-link span { overflow: hidden; color: var(--muted); font: 7px/1.3 var(--mono); text-overflow: ellipsis; white-space: nowrap; }
  .tool-card > footer { display: flex; justify-content: space-between; padding: 6px 8px; border-top: 1px solid var(--line-soft); color: var(--muted-2); }
  .tool-card footer small { overflow: hidden; font: 6px/1 var(--mono); text-overflow: ellipsis; white-space: nowrap; }
  .tool-card footer i { color: var(--green); font-style: normal; }
  .vault-sidebar { display: grid; gap: 9px; }
  .scratch-panel textarea { width: 100%; min-height: 210px; resize: vertical; padding: 9px 10px; border: 0; outline: 0; background: #070b10; color: var(--text-2); font: 8px/1.55 var(--mono); }
  .scratch-actions { display: flex; justify-content: flex-end; gap: 6px; padding: 6px 8px; border-top: 1px solid var(--line-soft); }
  .session-panel { padding-bottom: 9px; }
  .session-panel .secondary-action { width: calc(100% - 18px); margin: 9px 9px 0; }
  .session-panel .file-action { width: calc(100% - 18px); margin: 6px 9px 0; }
  .session-panel p { padding: 9px 10px 2px; color: var(--muted); font: 7px/1.5 var(--mono); }
  .vault-empty { grid-column: 1/-1; padding: 40px; border: 1px dashed var(--line); border-radius: 5px; color: var(--muted); font: 9px/1.4 var(--mono); text-align: center; }
}

@layer responsive {
  @container (max-width: 460px) {
    .pulse-metrics { grid-template-columns: repeat(2,1fr); }
  }

  @media (max-width: 1180px) {
    .engine-grid { grid-template-columns: repeat(3,1fr); }
    .engine-card { border-bottom: 1px solid var(--line-soft); }
    .cnc-layout { grid-template-columns: minmax(220px,.7fr) minmax(390px,1.3fr); grid-template-rows: minmax(450px,1fr) auto; height: auto; }
    .cnc-inspector { grid-column: 1/-1; grid-template-columns: .8fr 1.4fr .8fr; grid-template-rows: 250px; }
    .vault-grid { grid-template-columns: repeat(3,1fr); }
  }

  @media (max-width: 900px) {
    :root { --rail-w: 61px; }
    .topbar { grid-template-columns: 1fr auto; }
    .topbar-center { display: none; }
    .brand-copy small { display: none; }
    .console-heading { min-height: 110px; }
    .console-grid { grid-template-columns: repeat(2,1fr); }
    .console-grid .hero-visual { grid-column: 1/-1; }
    .console-grid .engines-panel { grid-column: 1/-1; }
    .pulse-strip { grid-column: 1/-1; }
    .cnc-layout { grid-template-columns: minmax(0,.75fr) minmax(0,1.25fr); }
    .field-layout { grid-template-columns: minmax(0,1fr) 235px; }
    .motion-layout { grid-template-columns: minmax(0,1fr) 245px; }
    .indexer-layout { grid-template-columns: repeat(2,minmax(0,1fr)); }
    .indexer-layout .span-2 { grid-column: span 1; }
    .indexer-layout .span-3 { grid-column: 1/-1; }
    .pulse-metrics { grid-template-columns: repeat(3,1fr); }
    .cycle-panel { min-height: 288px; }
    .vault-layout { grid-template-columns: minmax(0,1fr) 220px; }
    .vault-grid { grid-template-columns: repeat(2,1fr); }
    .filter-chips { max-width: 43vw; }
  }

  @media (max-width: 720px) {
    :root { --rail-w: 0px; --status-h: 26px; }
    body { overflow: hidden; }
    .topbar { height: 44px; padding-inline: 8px; }
    .topbar .command-trigger kbd { display: none; }
    .app-shell { height: calc(100dvh - 44px - var(--status-h) - 56px - env(safe-area-inset-bottom)); grid-template-columns: 1fr; margin-top: 44px; }
    .rail {
      position: fixed;
      inset: auto 0 calc(var(--status-h) + env(safe-area-inset-bottom));
      z-index: 55;
      height: 56px;
      display: grid;
      grid-template-columns: repeat(6,1fr);
      padding: 3px 4px;
      border: 1px solid var(--line);
      border-width: 1px 0 0;
      background: rgba(5,8,13,.96);
    }
    .rail-item { min-height: 48px; border: 0; border-bottom: 2px solid transparent; }
    .rail-item.active { border-bottom-color: var(--blue); border-left-color: transparent; }
    .rail-icon { font-size: 15px; }
    .rail-spacer, .rail-compact { display: none; }
    .statusbar { bottom: env(safe-area-inset-bottom); gap: 8px; }
    .statusbar > span:nth-child(2), .status-time { display: none; }
    .status-message { justify-content: flex-end; }
    .view { padding: 12px 8px 18px; }
    .view-header, .console-heading { min-height: 0; display: grid; gap: 12px; align-items: start; margin-bottom: 14px; }
    .view-header h1 { font-size: clamp(29px,11vw,48px); }
    .view-header h2 { font-size: 26px; }
    .hero-actions, .view-actions { width: 100%; overflow-x: auto; }
    .hero-actions > *, .view-actions > * { flex: 0 0 auto; }
    .console-grid { display: grid; grid-template-columns: 1fr; }
    .console-grid > *, .console-grid .span-2, .console-grid .span-3 { grid-column: 1; }
    .hero-visual { min-height: 265px; }
    .hero-visual canvas { min-height: 230px; }
    .engine-grid { grid-template-columns: repeat(2,1fr); }
    .engine-card { min-height: 128px; }
    .pulse-strip { grid-template-columns: repeat(2,1fr); }
    signal-spark:nth-child(2n) { border-right: 0; }
    signal-spark:nth-child(-n+2) { border-bottom: 1px solid var(--line-soft); }

    .cnc-layout, .field-layout, .motion-layout { height: auto; min-height: 0; display: grid; grid-template-columns: 1fr; }
    .code-panel { height: 310px; }
    .plot-panel { height: 430px; }
    .cnc-inspector { grid-column: 1; display: grid; grid-template-columns: 1fr; grid-template-rows: auto 280px auto; }
    .field-stage-panel { height: min(62dvh,560px); min-height: 390px; }
    .field-controls { overflow: visible; }
    .field-controls .environment-panel, .field-controls .source-list-panel { display: block; }
    .motion-stage-panel { min-height: 530px; }
    .motion-stage { min-height: 390px; }
    .voice-rack { overflow: visible; }
    .voice-list { grid-template-columns: 1fr; }
    .indexer-layout { grid-template-columns: 1fr; }
    .indexer-layout .span-2, .indexer-layout .span-3 { grid-column: 1; }
    .pulse-panel, .cycle-panel { min-height: 260px; }
    .pulse-metrics { grid-template-columns: repeat(2,1fr); }
    .pulse-metrics div:nth-child(2n) { border-right: 0; }
    .cycle-track { height: 78px; }
    .vault-toolbar { align-items: stretch; flex-wrap: wrap; }
    .vault-search { flex-basis: 100%; }
    .filter-chips { flex: 1; max-width: none; }
    .vault-layout { grid-template-columns: 1fr; }
    .vault-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
    .vault-sidebar { grid-template-columns: repeat(2,1fr); }
    .scratch-panel textarea { min-height: 150px; }
    .system-popover { top: 44px; }
    #toast-region { right: 8px; left: 8px; bottom: calc(var(--status-h) + 62px + env(safe-area-inset-bottom)); }
    .toast { width: 100%; min-width: 0; }
  }

  @media (max-width: 430px) {
    .brand-copy b { font-size: 10px; }
    .topbar-actions { gap: 3px; }
    .icon-button { min-width: 27px; height: 27px; padding-inline: 6px; }
    .rail-item { font-size: 6px; }
    .rail-icon { font-size: 14px; }
    .visual-overlay { left: 8px; right: auto; gap: 7px; }
    .engine-grid { grid-template-columns: 1fr; }
    .engine-card { min-height: 102px; }
    .pulse-strip { grid-template-columns: 1fr; }
    signal-spark { min-height: 72px; border-right: 0; border-bottom: 1px solid var(--line-soft); }
    .segmented button { padding-inline: 5px; font-size: 6px; }
    .plot-panel { height: 390px; }
    .transport { grid-template-columns: auto auto 1fr auto; }
    .transport label { display: none; }
    .motion-stage-panel { min-height: 485px; }
    .motion-stage { min-height: 345px; }
    .motion-readout { right: 7px; gap: 6px; }
    .voice-grid { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr 1fr; }
    .cycle-block b { font-size: 6px; }
    .cycle-block span { font-size: 6px; }
    .vault-count { display: none; }
    .vault-grid { grid-template-columns: 1fr; }
    .vault-sidebar { grid-template-columns: 1fr; }
    .tool-card { min-height: 105px; }
    .favorite-filter { padding-right: 3px; }
    .command-dialog { margin-top: 5vh; }
  }

  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  }

  @media (prefers-contrast: more) {
    :root { --line: #4c5c70; --muted: #9aa8b9; }
  }
}
