:root {
  --ink: #06080d;
  --ink-2: #0b0f17;
  --panel: rgba(11, 15, 23, .88);
  --line: #232c3c;
  --line-hot: #3a4762;
  --text: #e2e8f3;
  --muted: #8593ab;
  --dim: #5c6883;
  --brass: #d9a441;
  --brass-dim: #8d6c2c;
  --cyan: #5fd0e0;
  --rose: #e3779b;
  --panel-w: 352px;
  --hud-h: 58px;
  --r: 3px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: "Inter", system-ui, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--ink);
  color: var(--text);
  font-family: var(--sans);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

button, input, select { font: inherit; color: inherit; }
::selection { background: var(--brass); color: #120c02; }

:focus-visible {
  outline: 1px solid var(--cyan);
  outline-offset: 2px;
}

/* ---------- layout ---------- */

.app {
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--panel-w);
}
.app.collapsed { grid-template-columns: minmax(0, 1fr) 0; }

.stage {
  position: relative;
  min-width: 0;
  overflow: hidden;
  background: #04060a;
}

#view {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
#view.dragging { cursor: grabbing; }
#view.picking { cursor: crosshair; }

.film {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(130% 100% at 50% 50%, transparent 52%, rgba(0, 0, 0, .55) 100%),
    linear-gradient(rgba(255, 255, 255, .012) 50%, transparent 50%);
  background-size: auto, 100% 3px;
  mix-blend-mode: normal;
  opacity: .9;
}
body:not(.rich) .film { background-image: radial-gradient(130% 100% at 50% 50%, transparent 58%, rgba(0, 0, 0, .45) 100%); }

.reticle {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  pointer-events: none;
  border: 1px solid rgba(217, 164, 65, .5);
  border-radius: 50%;
}
.reticle::before, .reticle::after {
  content: "";
  position: absolute;
  background: rgba(217, 164, 65, .5);
}
.reticle::before { left: 50%; top: -12px; bottom: -12px; width: 1px; }
.reticle::after { top: 50%; left: -12px; right: -12px; height: 1px; }

/* ---------- hud ---------- */

.hud {
  position: absolute;
  inset: 0 0 auto 0;
  height: var(--hud-h);
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 14px 0 16px;
  background: linear-gradient(rgba(6, 8, 13, .82), rgba(6, 8, 13, 0));
  pointer-events: none;
}
.hud > * { pointer-events: auto; }

.brand { display: flex; align-items: center; gap: 10px; flex: none; }
.brand-mark {
  width: 22px;
  height: 22px;
  border: 1px solid var(--brass);
  border-radius: 50%;
  position: relative;
  flex: none;
}
.brand-mark::after {
  content: "";
  position: absolute;
  inset: 34%;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 7px var(--cyan);
}
body.rich .brand-mark::before {
  content: "";
  position: absolute;
  inset: -4px;
  border: 1px solid rgba(217, 164, 65, .35);
  border-radius: 50%;
  transform: scaleY(.42) rotate(-24deg);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-text b { font-size: 13px; letter-spacing: .28em; font-weight: 600; }
.brand-text i { font-size: 8.5px; letter-spacing: .16em; color: var(--dim); font-style: normal; text-transform: uppercase; white-space: nowrap; }

.title-plate {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 5px 16px;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  min-width: 0;
}
.plate-label { font-size: 8px; letter-spacing: .26em; text-transform: uppercase; color: var(--dim); }
.title-plate strong { font-size: 15px; letter-spacing: .02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plate-sub { font-family: var(--mono); font-size: 10px; color: var(--brass-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.hud-actions { margin-left: auto; display: flex; gap: 4px; }

.icon-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  width: 46px;
  padding: 5px 0 4px;
  background: rgba(13, 17, 26, .55);
  border: 1px solid var(--line);
  border-radius: var(--r);
  cursor: pointer;
  color: var(--muted);
}
.icon-btn span { font-size: 13px; line-height: 1; }
.icon-btn em { font-size: 8px; letter-spacing: .14em; text-transform: uppercase; font-style: normal; }
.icon-btn:hover { color: var(--text); border-color: var(--line-hot); background: rgba(26, 33, 48, .8); }
.icon-btn[aria-pressed="true"] { color: var(--brass); border-color: var(--brass-dim); background: rgba(217, 164, 65, .1); }
body.rich .icon-btn[aria-pressed="true"] { box-shadow: inset 0 0 12px rgba(217, 164, 65, .22); }

/* ---------- status bar ---------- */

.statusbar {
  position: absolute;
  inset: auto 0 0 0;
  height: 32px;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 10px calc(env(safe-area-inset-bottom, 0px) / 2) 12px;
  font-family: var(--mono);
  font-size: 10.5px;
  background: linear-gradient(rgba(6, 8, 13, 0), rgba(6, 8, 13, .8));
  pointer-events: none;
  white-space: nowrap;
}
.readout { display: flex; gap: 6px; padding: 0 10px 0 0; align-items: baseline; }
.readout span { color: var(--dim); font-size: 9px; text-transform: uppercase; letter-spacing: .12em; }
.readout b { color: var(--muted); font-weight: 500; }
.readout.wide { min-width: 96px; }
.perf { margin-left: auto; display: flex; align-items: center; gap: 7px; pointer-events: auto; }
#perf-graph { width: 72px; height: 20px; border: 1px solid var(--line); border-radius: 2px; opacity: .85; }
#ro-fps { color: var(--cyan); }
.tier {
  color: var(--brass);
  border: 1px solid var(--brass-dim);
  border-radius: 2px;
  padding: 1px 5px;
  font-size: 9px;
  letter-spacing: .1em;
  text-transform: uppercase;
}

/* ---------- console panel ---------- */

.panel {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow: hidden;
}
body.rich .panel { backdrop-filter: blur(16px); }
.app.collapsed .panel { border-left-color: transparent; }

.panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--hud-h);
  padding: 0 16px;
  flex: none;
  border-bottom: 1px solid var(--line);
}
.panel-head h1 {
  margin: 0;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .32em;
  text-transform: uppercase;
  color: var(--brass);
}
.panel-head .rule { flex: 1; height: 1px; background: linear-gradient(90deg, transparent, var(--line-hot)); }
.panel-head .rule:last-child { background: linear-gradient(90deg, var(--line-hot), transparent); }

.panel-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line-hot) transparent;
}
.panel-body::-webkit-scrollbar { width: 8px; }
.panel-body::-webkit-scrollbar-thumb { background: var(--line-hot); border-radius: 4px; }

.panel-foot {
  flex: none;
  display: flex;
  gap: 8px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line);
}

.ghost-btn {
  flex: 1;
  padding: 8px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--r);
  color: var(--muted);
  font-size: 10px;
  letter-spacing: .16em;
  text-transform: uppercase;
  cursor: pointer;
}
.ghost-btn:hover { color: var(--brass); border-color: var(--brass-dim); }

.panel-tab {
  position: absolute;
  right: 0;
  top: calc(50% - 26px);
  width: 20px;
  height: 52px;
  border: 1px solid var(--line);
  border-right: 0;
  border-radius: var(--r) 0 0 var(--r);
  background: rgba(11, 15, 23, .85);
  color: var(--muted);
  cursor: pointer;
  z-index: 3;
}
.panel-tab:hover { color: var(--brass); }

/* ---------- sections ---------- */

.sec { border-bottom: 1px solid var(--line); }
.sec-head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 14px;
  background: none;
  border: 0;
  cursor: pointer;
  text-align: left;
  color: var(--text);
}
.sec-head:hover { background: rgba(255, 255, 255, .025); }
.sec-head .glyph { color: var(--brass); font-size: 12px; width: 14px; text-align: center; }
.sec-head h2 { margin: 0; font-size: 10.5px; font-weight: 600; letter-spacing: .2em; text-transform: uppercase; flex: 1; }
.sec-head .chev { color: var(--dim); font-size: 9px; transition: transform .18s ease; }
.sec[data-open="false"] .chev { transform: rotate(-90deg); }
.sec-body { padding: 2px 14px 14px; display: grid; gap: 11px; }
.sec[data-open="false"] .sec-body { display: none; }

/* ---------- controls ---------- */

.ctl { display: grid; gap: 5px; }
.ctl-top { display: flex; align-items: baseline; gap: 8px; }
.ctl-top label, .ctl-top .lbl {
  font-size: 10px;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--muted);
  flex: 1;
  min-width: 0;
}
.ctl-val { font-family: var(--mono); font-size: 10.5px; color: var(--brass); }
.ctl[data-locked="true"] { opacity: .35; pointer-events: none; }
.hint { font-size: 9.5px; color: var(--dim); line-height: 1.4; margin: -2px 0 0; }

input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 18px;
  background: none;
  cursor: ew-resize;
  margin: 0;
  display: block;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 2px;
  background:
    linear-gradient(90deg, var(--brass) var(--fill, 0%), rgba(255, 255, 255, .09) var(--fill, 0%));
}
input[type=range]::-moz-range-track { height: 3px; border-radius: 2px; background: rgba(255, 255, 255, .09); }
input[type=range]::-moz-range-progress { height: 3px; border-radius: 2px; background: var(--brass); }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 11px;
  height: 11px;
  margin-top: -4px;
  border-radius: 50%;
  background: #f0d59a;
  border: 1px solid #6b4f16;
}
input[type=range]::-moz-range-thumb {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #f0d59a;
  border: 1px solid #6b4f16;
}
body.rich input[type=range]::-webkit-slider-thumb { box-shadow: 0 0 8px rgba(240, 213, 154, .55); }
input[type=range]:active::-webkit-slider-thumb { background: #fff3d6; }

.ticks {
  height: 5px;
  margin-top: -3px;
  background-image: repeating-linear-gradient(90deg, var(--line-hot) 0 1px, transparent 1px 25%);
  background-size: calc(100% - 1px) 100%;
  opacity: .5;
}

.seg { display: flex; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.seg button {
  flex: 1;
  padding: 6px 2px;
  background: transparent;
  border: 0;
  border-right: 1px solid var(--line);
  color: var(--muted);
  font-size: 9.5px;
  letter-spacing: .1em;
  text-transform: uppercase;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.seg button:last-child { border-right: 0; }
.seg button:hover { background: rgba(255, 255, 255, .04); color: var(--text); }
.seg button[aria-pressed="true"] { background: rgba(217, 164, 65, .16); color: var(--brass); }

.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 7px 9px;
  background: rgba(255, 255, 255, .02);
  border: 1px solid var(--line);
  border-radius: var(--r);
  cursor: pointer;
  text-align: left;
}
.switch .lbl { font-size: 10px; letter-spacing: .13em; text-transform: uppercase; color: var(--muted); }
.switch:hover { border-color: var(--line-hot); }
.switch .lever {
  flex: none;
  width: 30px;
  height: 14px;
  border: 1px solid var(--line-hot);
  border-radius: 8px;
  position: relative;
  background: rgba(0, 0, 0, .35);
}
.switch .lever::after {
  content: "";
  position: absolute;
  top: 1px;
  left: 1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--dim);
  transition: transform .16s ease, background .16s ease;
}
.switch[aria-pressed="true"] .lbl { color: var(--text); }
.switch[aria-pressed="true"] .lever { border-color: var(--brass-dim); background: rgba(217, 164, 65, .16); }
.switch[aria-pressed="true"] .lever::after { transform: translateX(16px); background: var(--brass); }
body.rich .switch[aria-pressed="true"] .lever::after { box-shadow: 0 0 6px var(--brass); }

select {
  width: 100%;
  padding: 6px 8px;
  background: rgba(0, 0, 0, .3);
  border: 1px solid var(--line);
  border-radius: var(--r);
  font-size: 11px;
  cursor: pointer;
}
select:hover { border-color: var(--line-hot); }

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* fractal picker */

.grid-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.pick {
  position: relative;
  padding: 0 0 4px;
  background: rgba(0, 0, 0, .3);
  border: 1px solid var(--line);
  border-radius: var(--r);
  cursor: pointer;
  overflow: hidden;
  color: var(--muted);
}
.pick canvas {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  image-rendering: auto;
  background: #05070b;
  opacity: .82;
}
.pick .nm {
  display: block;
  padding: 4px 2px 0;
  font-size: 8.5px;
  letter-spacing: .08em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pick .key {
  position: absolute;
  top: 2px;
  left: 3px;
  font-family: var(--mono);
  font-size: 8px;
  color: rgba(226, 232, 243, .55);
  text-shadow: 0 0 4px #000;
}
.pick:hover { border-color: var(--line-hot); color: var(--text); }
.pick:hover canvas { opacity: 1; }
.pick[aria-pressed="true"] { border-color: var(--brass); color: var(--brass); }
.pick[aria-pressed="true"] canvas { opacity: 1; }
body.rich .pick[aria-pressed="true"] { box-shadow: 0 0 0 1px rgba(217, 164, 65, .3), 0 0 14px rgba(217, 164, 65, .18); }

/* palette strip */

.pal-list { display: grid; gap: 4px; }
.pal {
  display: grid;
  grid-template-columns: 74px 1fr;
  align-items: center;
  gap: 8px;
  padding: 3px 4px 3px 6px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r);
  cursor: pointer;
  color: var(--muted);
}
.pal span { font-size: 9.5px; letter-spacing: .1em; text-transform: uppercase; text-align: left; }
.pal canvas { display: block; width: 100%; height: 14px; border-radius: 2px; border: 1px solid rgba(0, 0, 0, .5); }
.pal:hover { border-color: var(--line); color: var(--text); }
.pal[aria-pressed="true"] { border-color: var(--brass-dim); color: var(--brass); background: rgba(217, 164, 65, .08); }

/* xy pad */

.pad {
  position: relative;
  width: 100%;
  aspect-ratio: 1.6;
  background:
    linear-gradient(rgba(95, 208, 224, .05), rgba(95, 208, 224, .01)),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, .05) 0 1px, transparent 1px 25%),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, .05) 0 1px, transparent 1px 25%);
  border: 1px solid var(--line);
  border-radius: var(--r);
  cursor: crosshair;
  touch-action: none;
  overflow: hidden;
}
.pad .dot {
  position: absolute;
  width: 9px;
  height: 9px;
  margin: -5px 0 0 -5px;
  border-radius: 50%;
  background: var(--cyan);
  border: 1px solid #06232a;
  pointer-events: none;
}
body.rich .pad .dot { box-shadow: 0 0 10px var(--cyan); }
.pad .cross { position: absolute; background: rgba(255, 255, 255, .08); pointer-events: none; }
.pad .cross.h { left: 0; right: 0; height: 1px; }
.pad .cross.v { top: 0; bottom: 0; width: 1px; }

/* meters */

.meter { height: 3px; background: rgba(255, 255, 255, .07); border-radius: 2px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--cyan); width: 0; transition: width .2s linear; }

/* ---------- modal, toast, boot ---------- */

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(3, 5, 9, .72);
  z-index: 40;
  padding: 20px;
}
body.rich .modal { backdrop-filter: blur(5px); }
.modal[hidden] { display: none; }
.modal-card {
  position: relative;
  width: min(640px, 100%);
  max-height: 86vh;
  overflow: auto;
  padding: 26px 28px 22px;
  background: #0a0e16;
  border: 1px solid var(--line-hot);
  border-radius: 5px;
}
.modal-card h2 { margin: 0 0 4px; font-size: 20px; letter-spacing: .22em; color: var(--brass); font-weight: 600; }
.lede { margin: 0 0 18px; color: var(--muted); font-size: 12.5px; line-height: 1.65; max-width: 54ch; }
.help-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.help-cols h3 { margin: 0 0 8px; font-size: 9.5px; letter-spacing: .24em; text-transform: uppercase; color: var(--cyan); }
.help-cols dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 11.5px; }
.help-cols dt { font-family: var(--mono); color: var(--text); white-space: nowrap; }
.help-cols dd { margin: 0; color: var(--muted); }
.fineprint { white-space: pre-line; margin: 20px 0 0; padding-top: 12px; border-top: 1px solid var(--line); font-family: var(--mono); font-size: 10px; color: var(--dim); line-height: 1.6; }
.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 28px;
  height: 28px;
  background: none;
  border: 0;
  color: var(--dim);
  font-size: 20px;
  cursor: pointer;
}
.modal-close:hover { color: var(--text); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 54px;
  transform: translate(-50%, 12px);
  padding: 8px 16px;
  background: rgba(10, 14, 22, .95);
  border: 1px solid var(--brass-dim);
  border-radius: var(--r);
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--brass);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 50;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

.boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 18px;
  background: var(--ink);
  z-index: 60;
  transition: opacity .5s ease;
}
body:not(.booting) .boot { opacity: 0; pointer-events: none; }
.boot-ring {
  width: 54px;
  height: 54px;
  border: 1px solid var(--brass-dim);
  border-top-color: var(--brass);
  border-radius: 50%;
  animation: spin 1.1s linear infinite;
}
.boot p { margin: 0; font-family: var(--mono); font-size: 10px; letter-spacing: .28em; text-transform: uppercase; color: var(--dim); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- narrow screens ---------- */

@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .app.collapsed { grid-template-rows: minmax(0, 1fr) 0; }
  .panel {
    border-left: 0;
    border-top: 1px solid var(--line);
    max-height: 46vh;
  }
  .panel-head { height: 44px; }
  .panel-tab { top: auto; bottom: 34px; right: 8px; width: 54px; height: 22px; border: 1px solid var(--line); border-radius: var(--r); background: rgba(11, 15, 23, .92); }
  .hud { gap: 8px; padding: 0 6px; }
  .title-plate { border: 0; padding: 0; flex: 1; min-width: 0; }
  .brand-text { display: none; }
  .icon-btn { width: 33px; }
  .icon-btn em { display: none; }
  .statusbar { font-size: 9.5px; overflow: hidden; }
  .readout.wide, #perf-graph { display: none; }
  .help-cols { grid-template-columns: 1fr; }
  .grid-pick { grid-template-columns: repeat(4, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
