:root {
  --bg: #080a0f;
  --surface: #10141f;
  --surface-2: #161c2b;
  --border: #252e42;
  --text: #e8eefc;
  --muted: #8b98b8;
  --neon: #ff4b24;
  --argon: #38b6ff;
  --emerald: #2eff8b;
  --amber: #ffc233;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  overflow: hidden;
  user-select: none;
}

.app-shell {
  display: grid;
  grid-template-rows: 48px 1fr 136px;
  grid-template-columns: 266px 1fr;
  grid-template-areas:
    "header header"
    "sidebar stage"
    "sidebar spectro";
  height: 100vh;
  width: 100vw;
}

/* Header */
.topbar {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  background: linear-gradient(180deg, #131826 0%, #0d111b 100%);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 6px;
  color: #fff3eb;
  background: rgba(255, 75, 36, 0.16);
  border: 1px solid rgba(255, 75, 36, 0.72);
  box-shadow: 0 0 12px rgba(255, 55, 20, 0.45);
}

.brand-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #fff4ee;
  text-shadow: 0 0 10px rgba(255, 75, 36, 0.75), 0 0 22px rgba(255, 30, 0, 0.35);
}

.brand-sub {
  font-size: 11px;
  color: var(--muted);
  display: none;
}
@media (min-width: 1220px) {
  .brand-sub { display: inline; }
}

.preset-pills {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}
.preset-pills::-webkit-scrollbar { display: none; }

.top-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

button, select, input[type="text"] {
  font-family: inherit;
  color: var(--text);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}

.btn:hover {
  background: #1e263b;
  border-color: #3b4968;
}

.btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.btn-pill {
  padding: 4px 9px;
  font-size: 11.5px;
  border-radius: 999px;
}

.btn-pill.active, .btn.active {
  background: rgba(255, 75, 36, 0.18);
  border-color: var(--neon);
  color: #fff;
  box-shadow: 0 0 10px rgba(255, 75, 36, 0.28);
}

.btn-accent {
  background: rgba(56, 182, 255, 0.16);
  border-color: rgba(56, 182, 255, 0.65);
  color: #e8f7ff;
}
.btn-accent:hover {
  background: rgba(56, 182, 255, 0.26);
  box-shadow: 0 0 12px rgba(56, 182, 255, 0.35);
}

.btn-danger {
  background: rgba(255, 58, 58, 0.14);
  border-color: rgba(255, 75, 75, 0.45);
  color: #ffd4d4;
}
.btn-danger:hover {
  background: rgba(255, 58, 58, 0.28);
}

.btn-torch {
  background: rgba(255, 170, 40, 0.14);
  border-color: rgba(255, 175, 45, 0.55);
  color: #ffebc2;
}
.btn-torch:hover {
  background: rgba(255, 170, 40, 0.26);
  box-shadow: 0 0 12px rgba(255, 160, 30, 0.35);
}

/* Sidebar */
.sidebar {
  grid-area: sidebar;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 12px 13px 16px;
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding-bottom: 11px;
  border-bottom: 1px solid rgba(37, 46, 66, 0.72);
}
.panel-section:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.tool-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.tool-btn {
  padding: 7px 8px;
  font-size: 12px;
  justify-content: flex-start;
}

.text-stamp-row {
  display: none;
  gap: 6px;
  margin-top: 2px;
}
.text-stamp-row.visible {
  display: flex;
}

.text-input {
  flex: 1;
  min-width: 0;
  background: #0a0d14;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 12px;
  font-family: var(--font-mono);
  text-transform: uppercase;
}
.text-input:focus {
  outline: none;
  border-color: var(--argon);
}

/* Gas Swatches */
.gas-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}

.gas-swatch {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 6px 7px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: #0c1019;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.15s, box-shadow 0.15s;
}
.gas-swatch:hover {
  border-color: #46577d;
}
.gas-swatch.active {
  border-color: var(--swatch-color, #ff4b24);
  background: #141a29;
  box-shadow: 0 0 12px var(--swatch-glow, rgba(255, 75, 36, 0.35));
}

.gas-swatch-top {
  display: flex;
  align-items: center;
  gap: 5px;
  width: 100%;
}

.gas-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--swatch-color);
  box-shadow: 0 0 8px var(--swatch-color);
  flex-shrink: 0;
}

.gas-sym {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  color: #dce6ff;
}

.gas-name {
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* Properties Row */
.prop-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.seg-group {
  display: flex;
  gap: 4px;
  flex: 1;
}
.seg-group .btn {
  flex: 1;
  padding: 4px 5px;
  font-size: 11px;
}

.select-box {
  width: 100%;
  background: #0a0d14;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 12px;
}

/* Transformer & Paschen Bench */
.slider-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.slider-head {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
}
.slider-val {
  font-family: var(--font-mono);
  color: #bfe8ff;
  font-weight: 600;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: #1f273a;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--neon);
  box-shadow: 0 0 8px rgba(255, 75, 36, 0.75);
  cursor: pointer;
  border: 2px solid #fff3eb;
}

.power-row {
  display: flex;
  gap: 6px;
}

.btn-power {
  flex: 1;
  font-family: var(--font-mono);
  font-weight: 700;
  letter-spacing: 0.04em;
}
.btn-power.on {
  background: rgba(46, 255, 139, 0.16);
  border-color: var(--emerald);
  color: #dcffe9;
  box-shadow: 0 0 12px rgba(46, 255, 139, 0.28);
}

.telemetry-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}

.tele-card {
  background: #0a0d14;
  border: 1px solid rgba(37, 46, 66, 0.85);
  border-radius: 6px;
  padding: 5px 7px;
}
.tele-label {
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.tele-val {
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 700;
  color: #eef4ff;
  margin-top: 1px;
}

/* Main Stage */
.stage-wrap {
  grid-area: stage;
  position: relative;
  background: #05070b;
  overflow: hidden;
}

#signCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

.stage-hud {
  position: absolute;
  top: 10px;
  left: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
  gap: 10px;
}

.hud-pill {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(11, 15, 24, 0.82);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(56, 70, 102, 0.6);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 11.5px;
  color: #d6e2ff;
}

.snap-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}

.toast {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: rgba(14, 19, 32, 0.94);
  border: 1px solid var(--argon);
  box-shadow: 0 0 18px rgba(56, 182, 255, 0.35);
  color: #eef8ff;
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: 88%;
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Bottom Spectrometer */
.spectro-bar {
  grid-area: spectro;
  background: #0b0e16;
  border-top: 1px solid var(--border);
  padding: 6px 12px 8px;
  display: grid;
  grid-template-columns: 1fr 258px;
  gap: 10px;
  align-items: stretch;
}

.spectro-left {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.spectro-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.spectro-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.spectro-hover {
  font-family: var(--font-mono);
  font-size: 11px;
  color: #bfe8ff;
}

.spectro-canvas-box {
  position: relative;
  flex: 1;
  min-height: 82px;
  border-radius: 7px;
  border: 1px solid #222b3e;
  overflow: hidden;
  background: #05070b;
}

#spectroCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.spectro-info {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 4px;
  background: #0f1421;
  overflow: hidden;
  border: 1px solid #20283b;
  border-radius: 8px;
  padding: 8px 10px;
}

.spectro-gas-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.spectro-gas-name {
  font-size: 12.5px;
  font-weight: 700;
  color: #f3f7ff;
}

.spectro-vb {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--amber);
}

.spectro-note {
  font-size: 11px;
  line-height: 1.42;
  color: #b4c2e0;
  margin: 4px 0 0;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 235px 1fr;
  }
  .spectro-bar {
    grid-template-columns: 1fr 210px;
  }
}

/* Polished preset selector & single-line spectrometer header */
.preset-picker {
  display: flex;
  align-items: center;
}
.preset-select {
  background: rgba(255, 75, 36, 0.14);
  border: 1px solid rgba(255, 75, 36, 0.65);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  color: #fff4ee;
  cursor: pointer;
  outline: none;
  box-shadow: 0 0 10px rgba(255, 75, 36, 0.22);
}
.preset-select option {
  background: #10141f;
  color: #e8eefc;
}
.spectro-head {
  flex-wrap: nowrap;
  white-space: nowrap;
}
.spectro-hover {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  text-align: center;
}
.spectro-modes {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.spectro-modes .btn-pill {
  padding: 2px 8px;
  font-size: 11px;
}
.spectro-note {
  font-size: 10.8px;
  line-height: 1.38;
  margin: 2px 0 0;
}

/* Fit all topbar controls cleanly at 1024px */
.topbar { padding: 0 10px; gap: 8px; }
.brand { gap: 7px; }
.brand-title { font-size: 14.5px; }
.preset-select { max-width: 192px; padding: 4px 10px; font-size: 11.5px; }
.top-actions { gap: 4px; }
.top-actions .btn { padding: 4px 7px; font-size: 11.5px; }

/* WCAG 2.1 AA keyboard focus visibility (Charter Art. 2 §9) */
button:focus-visible,
select:focus-visible,
input:focus-visible,
a:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid #00e5ff;
  outline-offset: 2px;
}
