:root {
  --bg: #07090d;
  --panel: #0f131b;
  --panel-2: #151b26;
  --line: #222b3a;
  --text: #dfe6f0;
  --muted: #8693a8;
  --accent: #f0a742;
  --accent-2: #ffcf87;
  --radius: 8px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

button, select, input { font: inherit; color: inherit; }

button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: #3a475d; background: #1b2332; }
button:disabled { opacity: 0.4; cursor: default; }

select {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 6px;
  max-width: 60%;
}

/* ---- layout ---- */

.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #0d1119, #0a0d13);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 22px; color: var(--accent); text-shadow: 0 0 12px rgba(240, 167, 66, 0.6); }
.brand h1 { font-size: 16px; margin: 0; font-weight: 600; letter-spacing: 0.2px; }
.tag { color: var(--muted); font-size: 12px; }
.tag a { color: inherit; }
.tag a:hover { color: var(--accent-2); }
.actions { display: flex; gap: 8px; }

.layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 330px;
  height: calc(100vh - 56px);
}

.panel {
  overflow-y: auto;
  background: var(--panel);
  padding: 4px 14px 24px;
  scrollbar-width: thin;
  scrollbar-color: #2a3446 transparent;
}
.panel.left { border-right: 1px solid var(--line); }
.panel.right { border-left: 1px solid var(--line); }

.group { padding: 12px 0; border-bottom: 1px solid var(--line); }
.group:last-child { border-bottom: 0; }
.group h3 {
  margin: 0 0 10px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--accent-2);
  font-weight: 600;
}
.h-sub { text-transform: none; letter-spacing: 0; color: var(--muted); font-weight: 400; margin-left: 6px; }
.group-footer { display: flex; align-items: center; gap: 8px; color: var(--muted); margin-top: 6px; }
.swatch { width: 18px; height: 18px; border-radius: 50%; box-shadow: 0 0 10px currentColor; display: inline-block; }

/* ---- controls ---- */

.ctl { display: block; margin: 8px 0 12px; }
.ctl[hidden] { display: none; }
.ctl-head { display: flex; align-items: center; gap: 6px; color: var(--text); margin-bottom: 2px; }
.ctl-inline { display: flex; align-items: center; gap: 8px; }
.ctl-check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.grow { flex: 1; }
.unit { color: var(--muted); min-width: 22px; font-size: 12px; }
.ctl-info { color: var(--muted); font-size: 11.5px; margin-top: 1px; }

.num {
  width: 74px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 2px 6px;
  text-align: right;
}

input[type="range"] {
  width: 100%;
  margin: 4px 0 0;
  accent-color: var(--accent);
  height: 18px;
}

input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button {
  flex: 1;
  border: 0;
  border-radius: 0;
  border-right: 1px solid var(--line);
  padding: 5px 4px;
  background: transparent;
  white-space: nowrap;
}
.seg button:last-child { border-right: 0; }
.seg button.on { background: rgba(240, 167, 66, 0.18); color: var(--accent-2); }

/* ---- presets ---- */

.presets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.preset {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 2px 5px;
  gap: 1px;
  line-height: 1.15;
  text-align: center;
}
.preset canvas { width: 48px; height: 48px; border-radius: 50%; margin-bottom: 4px; }
.preset .p-name { font-size: 11px; }
.preset .p-sub { font-size: 10px; color: var(--muted); }
.preset.on { border-color: var(--accent); background: rgba(240, 167, 66, 0.1); }

/* ---- viewer ---- */

.viewer { display: flex; flex-direction: column; min-width: 0; background: #000; }

.viewbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 6px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.viewbar-controls .group { display: flex; align-items: center; gap: 18px; padding: 0; border: 0; flex-wrap: wrap; }
.viewbar-controls { flex: 1; min-width: 0; }
.viewbar-controls .ctl { margin: 0; min-width: 150px; }
.viewbar-controls .ctl-head { margin: 0; }
.viewbar-controls .seg button { padding: 3px 8px; }
.zoom { display: flex; gap: 4px; }
.zoom button { min-width: 32px; }

.stage { position: relative; flex: 1; min-height: 0; cursor: crosshair; touch-action: none; overflow: hidden; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#overlay { pointer-events: none; }
.status {
  position: absolute;
  right: 12px;
  top: 10px;
  color: var(--muted);
  font-size: 12px;
  pointer-events: none;
}
.error {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 40px;
  text-align: center;
  color: #ff9c8a;
  font-size: 15px;
}
.readout {
  padding: 6px 14px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  background: var(--panel);
  border-top: 1px solid var(--line);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- right panel ---- */

.pupil {
  width: 100%;
  max-width: 380px;
  margin: 0 auto;
  aspect-ratio: 1;
  display: block;
  border-radius: var(--radius);
  background: #06080c;
  cursor: crosshair;
  touch-action: none;
}
#tools .group { padding: 4px 0 0; border: 0; }
#tools .ctl { margin: 8px 0; }
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.btn-row button { flex: 1; padding: 4px 6px; }
.hint { color: var(--muted); font-size: 12px; margin: 10px 0 0; }
kbd {
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 4px;
  font-size: 11px;
}

.stats { display: grid; grid-template-columns: auto auto; gap: 4px 12px; margin: 0; }
.stats dt { color: var(--muted); }
.stats dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.stats small { color: var(--muted); }

.mtf { width: 100%; height: 190px; display: block; }
.mtf-axis { color: var(--muted); font-size: 11px; text-align: center; margin: 2px 0 6px; }
.mtf-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--muted); font-size: 11.5px; margin-bottom: 6px; }
.mtf-legend span { display: inline-flex; align-items: center; gap: 5px; }
.key { display: inline-block; width: 16px; height: 0; border-top: 2px solid var(--accent); }
.key-band { height: 8px; border: 0; background: rgba(240, 167, 66, 0.22); }
.key-ref { border-top: 2px dashed rgba(223, 230, 240, 0.55); }

.learn p { margin: 0 0 10px; color: #c4cede; }
.learn b { color: var(--text); }

/* ---- narrow screens ---- */

@media (max-width: 1100px) {
  .layout { grid-template-columns: 280px minmax(0, 1fr); grid-template-rows: auto auto; height: auto; }
  .panel.left { grid-row: span 2; }
  .viewer { height: 70vh; }
  .panel.right { border-left: 0; border-top: 1px solid var(--line); }
}

@media (max-width: 760px) {
  .topbar { height: auto; flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
  .layout { display: flex; flex-direction: column; }
  .viewer { height: 80vw; min-height: 340px; order: -1; }
  .panel { overflow: visible; }
  .viewbar { flex-wrap: wrap; }
}
