:root {
  --bar-w: 320px;
  --bar-bg: rgba(10, 12, 18, 0.78);
  --bar-border: rgba(255, 255, 255, 0.14);
  --txt: #e8e8ef;
  --muted: #a9adc1;
  --accent: #7aa2ff;
  --tab-bg: #0f172a;         /* slate-900 */
  --tab-fg: #ffffff;
  --tab-bg-hover: #1e293b;   /* slate-800 */
  --tab-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  --tab-radius: 12px;
}

body {
  background-color: #000000;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  font-family: 'Roboto', system-ui, -apple-system, sans-serif;
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 0;
}

main {
  background-color: transparent;
  flex: 1;
  overflow: hidden;
  margin: 0;
  position: relative;
}

canvas.gl-background {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  background: #000000;
}

/* --- Background Click Circuit Graphics --- */
@keyframes fadeOut {
  from {
    opacity: 0.2;
  }
  to {
    opacity: 0;
  }
}

.segment {
  position: absolute;
  height: 4px;
  width: 0;
  background-color: #ffffff;
  transform-origin: 0 50%;
  pointer-events: none;
  transition: width 0.3s ease;
  animation: fadeOut 3.5s forwards;
  z-index: 0;
}

.circle {
  position: absolute;
  width: 6px;
  height: 6px;
  background-color: #ffffff;
  border-radius: 50%;
  pointer-events: none;
  animation: fadeOut 3.5s forwards;
  z-index: 0;
}

/* --- Buttons & Shared Controls --- */
button {
  background: rgba(255, 255, 255, 0.06);
  color: var(--txt);
  border: 1px solid var(--bar-border);
  padding: 10px 12px;
  border-radius: 12px;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.2px;
  cursor: pointer;
  transition: transform 0.06s ease, background 0.2s ease, box-shadow 0.2s ease;
}

button:hover {
  background: rgba(255, 255, 255, 0.12);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
}

button:active {
  transform: translateY(1px) scale(0.99);
}

/* --- Settings Side Panel (Desktop: Right-Docked) --- */
.side-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--bar-w);
  max-width: 90vw;
  z-index: 1000;

  display: flex;
  flex-direction: column;
  box-sizing: border-box;

  background: var(--bar-bg);
  border-left: 1px solid var(--bar-border);
  box-shadow: -12px 0 32px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(12px) saturate(1.15);
  -webkit-backdrop-filter: blur(12px) saturate(1.15);
  color: var(--txt);

  transform: translateX(100%);
  visibility: hidden;
  pointer-events: none;
  transition: transform 0.26s cubic-bezier(0.22, 1, 0.36, 1), visibility 0.26s;
}

.side-panel.open {
  transform: translateX(0);
  visibility: visible;
  pointer-events: auto;
}

.side-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--bar-border);
  flex-shrink: 0;
}

.side-panel-title-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.side-panel-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.side-panel .title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--txt);
}

.badge {
  background: rgba(122, 162, 255, 0.14);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(122, 162, 255, 0.28);
  font-size: 0.6875rem;
  font-weight: 600;
}

.sub {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 400;
}

.panel-close {
  background: rgba(255, 255, 255, 0.06);
  color: var(--txt);
  border: 1px solid var(--bar-border);
  width: 34px;
  height: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  font-size: 1.25rem;
  line-height: 1;
  font-weight: 600;
  flex-shrink: 0;
}

.side-panel-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 12px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 7px 0;
}

.row label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.row input[type="range"] {
  width: 100%;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
  touch-action: pan-y;
}

.num {
  color: var(--txt);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.row-toggle label {
  cursor: pointer;
}

.toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}

.toggle input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}

.toggle-track {
  width: 100%;
  height: 100%;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid var(--bar-border);
  transition: background 0.2s ease, border-color 0.2s ease;
  box-sizing: border-box;
  position: relative;
}

.toggle-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--txt);
  transition: transform 0.2s ease;
}

.toggle input:checked + .toggle-track {
  background: rgba(122, 162, 255, 0.45);
  border-color: var(--accent);
}

.toggle input:checked + .toggle-track::after {
  transform: translateX(18px);
}

.toggle input:focus-visible + .toggle-track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
  padding-top: 6px;
}

.btn-full {
  grid-column: 1 / -1;
}

/* --- Toggle Tab (Desktop: Right Vertical Tab) --- */
.panel-toggle {
  position: fixed;
  top: 50%;
  right: 0;
  z-index: 1001;

  background: var(--tab-bg);
  color: var(--tab-fg);
  border: 1px solid var(--bar-border);
  border-right: none;
  border-top-left-radius: var(--tab-radius);
  border-bottom-left-radius: var(--tab-radius);
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  box-shadow: var(--tab-shadow);

  padding: 0.75rem 0.85rem;
  min-height: 3rem;
  font: 600 0.9rem/1 system-ui, -apple-system, sans-serif;
  letter-spacing: 0.2px;

  writing-mode: vertical-rl;
  text-orientation: mixed;

  transform: translate(0, -50%);
  transition: transform 0.26s cubic-bezier(0.22, 1, 0.36, 1), background 0.2s ease, opacity 0.2s ease;
}

/* Dock tab to the outer edge of the open side panel on desktop */
.panel-toggle.open {
  transform: translate(calc(-1 * var(--bar-w)), -50%);
}

.panel-toggle:hover,
.panel-toggle:focus-visible {
  background: var(--tab-bg-hover);
  outline: none;
}

.panel-toggle:active {
  transform: translate(0, -50%) scale(0.98);
}

.panel-toggle.open:active {
  transform: translate(calc(-1 * var(--bar-w)), -50%) scale(0.98);
}

/* --- Mobile Layout (Bottom-Docked Sheet) --- */
@media (max-width: 640px) {
  .side-panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    max-height: 44vh;
    max-height: 44dvh;

    border-left: none;
    border-top: 1px solid var(--bar-border);
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -10px 32px rgba(0, 0, 0, 0.55);

    transform: translateY(100%);
  }

  .side-panel.open {
    transform: translateY(0);
  }

  .side-panel-header {
    padding: 12px 16px 10px;
    position: relative;
  }

  /* Subtle sheet handle visual cue on mobile */
  .side-panel-header::before {
    content: "";
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 4px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.22);
  }

  .side-panel-body {
    padding: 10px 16px calc(18px + env(safe-area-inset-bottom, 0px));
  }

  .row {
    padding: 8px 0;
    gap: 8px;
  }

  .row input[type="range"] {
    height: 24px;
  }

  /* Horizontal pill button anchored near bottom-right on mobile */
  .panel-toggle {
    top: auto;
    right: 16px;
    bottom: calc(136px + env(safe-area-inset-bottom, 0px));
    writing-mode: horizontal-tb;
    border-right: 1px solid var(--bar-border);
    border-radius: 999px;
    min-height: 2.5rem;
    padding: 0.6rem 1rem;
    font-size: 0.85rem;
    transform: translateY(0);
  }

  /* Tuck toggle away cleanly while bottom sheet is open */
  .panel-toggle.open {
    opacity: 0;
    pointer-events: none;
    transform: translateY(12px);
  }

  .panel-toggle:active {
    transform: scale(0.97);
  }
}

/* --- Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
  .side-panel,
  .panel-toggle,
  .toggle-track,
  .toggle-track::after {
    transition: none;
  }
}
