/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-weight: 600;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  background: #d0d0d0;
}

/* === Loading screen === */
#loading-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: #1a1a1a;
  transition: opacity 0.3s ease;
}

#loading-screen::before {
  content: 'Loading';
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: #666;
}

#loading-bar-track {
  width: 340px;
  height: 3px;
  background: #2a2a2a;
  border-radius: 2px;
  overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.4);
}

#loading-bar-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #0a8a5e, #10B981, #0a8a5e);
  background-size: 200% 100%;
  border-radius: 2px;
  transition: width 0.2s ease;
  animation: shimmer 1.5s ease-in-out infinite;
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.3);
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

body:not(.loading) #loading-screen {
  opacity: 0;
  pointer-events: none;
}

/* Hide everything until initialization is complete to prevent flash */
body.loading > canvas,
body.loading #three-container,
body.loading #side-panel,
body.loading #panel-toggle,
body.loading #camera-presets,
body.loading #ss-display {
  opacity: 0 !important;
}

/* Hide p5.js-generated UI elements immediately to prevent flash */
body > input,
body > select,
body > button:not(#panel-toggle):not(#refresh-btn),
body > div > input,
body > .select,
body > img,
body > label,
#ssdiv {
  display: none !important;
}

/* === Preserve original p5 checkbox styling === */
label {
  color: #333;
  font-size: 10px;
  display: block;
  font-weight: bold;
  text-align: center;
}

input[type="checkbox"] { display: none; }
input[type="checkbox"] + *::before {
  content: "";
  display: block;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 3px solid #333;
}
input[type="checkbox"]:checked + *::before {
  font-size: 16px;
  content: "\2713";
  color: white;
  text-align: center;
  background: #333;
  border-color: #333;
}
input[type="checkbox"]:checked + * { color: #333; }

.select { background-color: black; color: white; }

/* === Popup === */
#popup {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  background: rgba(30, 30, 30, 0.92);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  padding: 8px 20px;
  border-radius: 4px;
  letter-spacing: 0.3px;
  display: none;
  backdrop-filter: blur(8px);
}

:root {
  --panel-width: 320px;
}

/* === Left Panel === */
#side-panel {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--panel-width);
  height: 100vh;
  overflow: visible;
  background: #fff;
  color: #333;
  z-index: 500;
  transform: translateX(calc(-1 * var(--panel-width)));
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  border-right: 1px solid #ccc;
}

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

/* Resize handle on right edge */
#panel-resize-handle {
  position: absolute;
  top: 0;
  right: -4px;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  z-index: 510;
}
#panel-resize-handle::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 32px;
  border-radius: 4px;
  background: transparent;
  transition: background 0.2s;
}
#panel-resize-handle:hover::after,
#panel-resize-handle.active::after {
  background: rgba(0,0,0,0.2);
}
body.dark #panel-resize-handle:hover::after,
body.dark #panel-resize-handle.active::after {
  background: rgba(255,255,255,0.25);
}
body.panel-resizing {
  cursor: col-resize !important;
  user-select: none !important;
}
body.panel-resizing * {
  cursor: col-resize !important;
}
body.panel-resizing canvas,
body.panel-resizing #three-container,
body.panel-resizing #ss-display,
body.panel-resizing #side-panel {
  transition: none !important;
}

/* Push page content when panel is open */
body.panel-open canvas {
  position: fixed !important;
  left: var(--panel-width) !important;
  width: calc(100% - var(--panel-width)) !important;
  transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1), width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
canvas {
  transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1), width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
body.panel-open #three-container {
  left: var(--panel-width);
  width: calc(100% - var(--panel-width));
  transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1), width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
#three-container {
  transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1), width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
body.panel-open #ss-display {
  left: calc(var(--panel-width) + 12px);
}
#ss-display {
  transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Icon rail — hidden in this layout */
#icon-rail {
  display: none;
}

/* Panel toggle — fixed top-left */
#panel-toggle {
  position: fixed;
  left: 12px;
  top: 12px;
  width: 32px;
  height: 32px;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  color: #555;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s, background 0.2s, box-shadow 0.2s;
  z-index: 600;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

#panel-toggle:hover {
  color: #333;
  background: #f5f5f5;
  box-shadow: 0 2px 12px rgba(0,0,0,0.12);
}

body.panel-open #panel-toggle {
  z-index: 400;
}

/* Panel close button (inside panel, top-right) */
#panel-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 28px;
  height: 28px;
  background: none;
  border: none;
  color: #999;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
  z-index: 1;
}
#panel-close:hover {
  color: #333;
  background: rgba(0,0,0,0.05);
}

/* Panel header */
#panel-header {
  position: relative;
  padding: 24px 48px 16px 24px;
  border-bottom: 1px solid #f0f0f0;
}

#panel-header h1 {
  font-size: 17px;
  font-weight: 700;
  color: #1a1a1a;
  letter-spacing: 0.3px;
}

#panel-header p {
  font-size: 13px;
  color: #999;
  margin-top: 4px;
}

/* Panel sections */
#panel-content {
  flex: 1;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 24px 0;
}

.panel-section {
  padding: 0;
  border-bottom: 1px solid #f0f0f0;
}

.panel-section-header {
  display: flex;
  align-items: center;
  padding: 12px 24px;
  cursor: pointer;
  user-select: none;
  gap: 8px;
  transition: background 0.15s;
}
.panel-section-header:hover { background: rgba(0,0,0,0.03); }

.panel-section-title {
  font-size: 13px;
  font-weight: 700;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin: 0;
  flex-shrink: 0;
}

.panel-section-summary {
  flex: 1;
  text-align: right;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
  color: #999;
  display: none;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.panel-section-chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  color: #999;
  transition: transform 0.2s;
  flex-shrink: 0;
  margin-left: auto;
}
.panel-section-chevron svg {
  width: 18px;
  height: 18px;
}

.panel-section.collapsed .panel-section-summary { display: flex; }
.panel-section.collapsed .panel-section-chevron { transform: rotate(0deg); }
.panel-section:not(.collapsed) .panel-section-chevron { transform: rotate(180deg); }
.panel-section.collapsed .panel-section-body { display: none; }

.panel-section-body {
  padding: 0 24px 16px;
}

/* Status dot */
.status-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #10B981;
  flex-shrink: 0;
}
.status-dot.paused { background: #888; }

/* === Terminal Block === */
.terminal-block {
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  overflow: hidden;
}
.terminal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 24px;
  padding: 0 12px;
  background: #f0f0f0;
}
.terminal-comment {
  font-family: 'IBM Plex Mono', 'SF Mono', monospace;
  font-size: 12px;
  color: #999;
}
.terminal-status {
  display: flex;
  align-items: center;
  gap: 6px;
}
#status-text {
  font-family: 'IBM Plex Mono', 'SF Mono', monospace;
  font-size: 12px;
  color: #10B981;
}
#status-text.paused { color: #ccc; }
.terminal-input-row {
  display: flex;
  align-items: center;
  height: 40px;
  padding: 0 12px;
  gap: 8px;
  background: #f5f5f5;
  border-top: 1px solid #e0e0e0;
  border-bottom: 1px solid #e0e0e0;
}
.terminal-prompt {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 16px;
  font-weight: 700;
  color: #10B981;
  flex-shrink: 0;
}
.terminal-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 16px;
  font-weight: 600;
  color: #1a1a1a;
  letter-spacing: 1px;
  min-width: 0;
}
.terminal-input::placeholder { color: #bbb; }
.terminal-buttons {
  display: flex;
  height: 32px;
}
.terminal-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f0f0f0;
  border: none;
  border-right: 1px solid #e0e0e0;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 13px;
  font-weight: 600;
  color: #777;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  padding: 0;
}
.terminal-btn:last-child { border-right: none; }
.terminal-btn:hover { background: #e8e8e8; color: #333; }
.terminal-btn:first-child { color: #10B981; }
.terminal-btn:first-child:hover { background: rgba(16,185,129,0.08); }

.terminal-history {
  padding: 8px 12px;
  background: #fafafa;
}

/* Radio group */
.radio-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.radio-option {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  color: #999;
}

.radio-option input[type="radio"] {
  display: none;
}

.radio-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid #ccc;
  position: relative;
  flex-shrink: 0;
  transition: border-color 0.15s;
}

.radio-option input[type="radio"]:checked ~ .radio-dot {
  border-color: #10B981;
}

.radio-option input[type="radio"]:checked ~ .radio-dot::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #10B981;
}

.radio-option input[type="radio"]:checked ~ .radio-text {
  color: #333;
}

.radio-text {
  text-transform: uppercase;
  letter-spacing: 0.2px;
  transition: color 0.15s;
}

.radio-group-inline {
  flex-direction: row;
  gap: 16px;
}

/* Settings card — matches terminal-block dark style */
.settings-card {
  background: #f5f5f5;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  padding: 16px;
}
.terminal-history .terminal-comment { margin-bottom: 4px; }
.history-item {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
  color: #999;
  cursor: pointer;
  padding: 3px 0;
  transition: color 0.15s;
}
.history-item:hover { color: #10B981; }
.history-item.active { color: #10B981; font-weight: 600; }

/* === Mobile Quick Actions Tray === */
#mobile-tray {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 52px;
  background: #fff;
  border-top: 1px solid #e0e0e0;
  z-index: 600;
  align-items: center;
}
.tray-zone {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 2px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px 0;
  -webkit-tap-highlight-color: transparent;
}
.tray-center { border-left: 1px solid #e0e0e0; border-right: 1px solid #e0e0e0; }
.tray-icon { font-size: 18px; font-weight: 700; color: #10B981; line-height: 1; }
.tray-pattern { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 16px; font-weight: 500; color: #333; }
.tray-text { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 13px; color: #777; }
.tray-label { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 10px; color: #aaa; }

/* Panel controls */
.panel-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.panel-label {
  font-size: 12px;
  color: #777;
  font-weight: 600;
}

.panel-slider-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-slider {
  --progress: 0%;
  -webkit-appearance: none;
  appearance: none;
  width: 110px;
  height: 3px;
  background: linear-gradient(to right, #10B981 var(--progress), #e0e0e0 var(--progress));
  border-radius: 3px;
  outline: none;
  cursor: pointer;
  transition: background 0.1s;
}

.panel-number {
  width: 40px;
  background: #f5f5f5;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  padding: 4px 4px;
  font-size: 13px;
  font-weight: 600;
  color: #555;
  text-align: center;
  outline: none;
  -moz-appearance: textfield;
  transition: border-color 0.15s;
}

.panel-number::-webkit-inner-spin-button,
.panel-number::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.panel-number:focus {
  border-color: #999;
}

.panel-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid #10B981;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

.panel-slider::-webkit-slider-thumb:hover {
  transform: scale(1.15);
  border-color: #34D399;
  box-shadow: 0 1px 6px rgba(0,0,0,0.2);
}

.panel-slider::-webkit-slider-thumb:active {
  transform: scale(1.05);
  border-color: #333;
}

.panel-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid #10B981;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

/* Earth Gravity pill */
.earth-gravity-row {
  display: flex;
  justify-content: flex-end;
  margin-top: 2px;
  margin-bottom: 4px;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.25s ease, opacity 0.2s ease, margin 0.25s ease;
}

.earth-gravity-row.visible {
  max-height: 32px;
  opacity: 1;
  margin-top: 4px;
  margin-bottom: 6px;
}

.earth-gravity-pill {
  display: inline-flex;
  align-items: center;
  background: none;
  border: 1px solid #ccc;
  border-radius: 12px;
  padding: 3px 10px 3px 8px;
  font-size: 12px;
  font-weight: 600;
  color: #888;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  letter-spacing: 0.2px;
}

.earth-gravity-pill:hover {
  color: #555;
  border-color: #999;
  background: rgba(0,0,0,0.03);
}

/* Reset to Default pill */
.reset-defaults-row {
  display: flex;
  justify-content: flex-end;
  margin-top: 2px;
  margin-bottom: 4px;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.25s ease, opacity 0.2s ease, margin 0.25s ease;
}

.reset-defaults-row.visible {
  max-height: 32px;
  opacity: 1;
  margin-top: 4px;
  margin-bottom: 6px;
}

.reset-defaults-pill {
  display: inline-flex;
  align-items: center;
  background: none;
  border: 1px solid #ccc;
  border-radius: 12px;
  padding: 3px 10px 3px 8px;
  font-size: 12px;
  font-weight: 600;
  color: #888;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  letter-spacing: 0.2px;
}

.reset-defaults-pill:hover {
  color: #555;
  border-color: #999;
  background: rgba(0,0,0,0.03);
}

.panel-input {
  width: 100%;
  background: #f5f5f5;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  padding: 10px 14px;
  color: #1a1a1a;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 1px;
  outline: none;
  transition: border-color 0.2s;
}

.panel-input:focus {
  border-color: #bbb;
}

.panel-color-picker {
  -webkit-appearance: none;
  appearance: none;
  width: 42px;
  height: 28px;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  padding: 2px;
  cursor: pointer;
  background: #f5f5f5;
}
.panel-color-picker::-webkit-color-swatch-wrapper { padding: 2px; }
.panel-color-picker::-webkit-color-swatch { border: none; border-radius: 4px; }
.panel-color-picker::-moz-color-swatch { border: none; border-radius: 4px; }

.color-swatch {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
  box-sizing: border-box;
}
.color-swatch:hover {
  transform: scale(1.15);
  border-color: #999;
}
.color-swatch.active {
  border-color: #333;
  transform: scale(1.15);
}

.panel-select {
  width: 100%;
  background: #f5f5f5;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  padding: 8px 12px;
  color: #555;
  font-size: 14px;
  font-weight: 600;
  outline: none;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.panel-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: #f5f5f5;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  padding: 10px 14px;
  color: #555;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.panel-btn:hover {
  background: #eee;
}

.panel-btn.active {
  background: #1a1a1a;
  color: #fff;
  border-color: #1a1a1a;
}

/* Grid Editor */
.ge-row {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 6px 0;
  border-bottom: 1px solid #f0f0f0;
}
.ge-row:last-child { border-bottom: none; }
.ge-height {
  width: 32px;
  padding: 3px 2px;
  border: 1px solid #ddd;
  border-radius: 4px;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  background: #fff;
  flex-shrink: 0;
  margin-top: 4px;
  -moz-appearance: textfield;
}
.ge-height::-webkit-inner-spin-button,
.ge-height::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.ge-positions {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.ge-pos-row {
  display: flex;
  align-items: center;
  gap: 0;
  height: 18px;
}
.ge-pos-slots {
  display: flex;
  flex: 1;
  justify-content: space-around;
  align-items: center;
  position: relative;
}
.ge-pos-slots::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 10%;
  right: 10%;
  height: 1px;
  background: #ddd;
}
.ge-slot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid #ddd;
  background: #fff;
  cursor: pointer;
  position: relative;
  z-index: 1;
  transition: all 0.1s;
  box-sizing: border-box;
}
.ge-slot:hover {
  border-color: #bbb;
}
.ge-slot.ge-slot-throw,
.ge-slot.ge-slot-catch {
  background: #bbb;
  border-color: #aaa;
}
.ge-slot[data-label]::before {
  content: attr(data-label);
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 7px;
  color: #bbb;
  pointer-events: none;
}
.ge-positions { position: relative; }
.ge-arc-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
  z-index: 2;
}
.ge-arc-path {
  fill: none;
  stroke: #337cff;
  stroke-width: 2;
  stroke-linecap: round;
}
body.dark .ge-arc-path { stroke: #5a9bff; }
.ge-del-btn {
  background: none;
  border: none;
  color: #ccc;
  cursor: pointer;
  font-size: 14px;
  padding: 0 2px;
  flex-shrink: 0;
  margin-top: 6px;
}
.ge-del-btn:hover { color: #e55; }

/* Dark mode */
body.dark .ge-row { border-color: #333; }
body.dark .ge-height { background: #2a2a2a; border-color: #444; color: #eee; }
body.dark .ge-pos-slots::before { background: #444; }
body.dark .ge-slot { background: #2a2a2a; border-color: #555; }
body.dark .ge-slot:hover { border-color: #777; }
body.dark .ge-slot.ge-slot-throw,
body.dark .ge-slot.ge-slot-catch { background: #666; border-color: #777; }
body.dark .ge-slot[data-label]::before { color: #555; }
body.dark .ge-del-btn { color: #555; }
body.dark .ge-del-btn:hover { color: #e55; }

.panel-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #f5f5f5;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  padding: 8px 14px;
  color: #777;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.panel-toggle-btn.active {
  background: #1a1a1a;
  color: #fff;
  border-color: #1a1a1a;
}

.panel-toggle-btn:hover {
  border-color: #ccc;
}

/* Mode toggle group */
.toggle-group {
  display: flex;
  gap: 8px;
}

/* Toggle switch */
.toggle-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  margin-bottom: 12px;
}

.toggle-row:last-child {
  margin-bottom: 0;
}

.toggle-label {
  font-size: 12px;
  color: #555;
  font-weight: 600;
}

.toggle-switch-group {
  display: flex;
  flex-wrap: wrap;
  background: #f0f0f0;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid #e0e0e0;
}

.toggle-option {
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 700;
  color: #999;
  cursor: pointer;
  border: none;
  background: transparent;
  transition: all 0.15s;
  text-transform: uppercase;
  letter-spacing: 0.2px;
  flex: 1 1 auto;
  min-width: 0;
  text-align: center;
  white-space: nowrap;
}

.toggle-option.active {
  background: #1a1a1a;
  color: #fff;
}

.toggle-option:hover:not(.active) {
  color: #555;
}

/* Credits */
#panel-footer {
  padding: 8px 24px;
  border-top: 1px solid #f0f0f0;
}

/* 3D container */
#three-container {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: none;
  z-index: 0;
}

#three-container.active {
  display: block;
  z-index: 1;
}

body.mode-3d > canvas { display: none !important; }
#camera-presets { display: none !important; }
body.mode-3d #camera-presets { display: flex !important; }

/* Siteswap display overlay */
#ss-display {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 400;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: #333;
  background: rgba(240, 240, 240, 0.85);
  backdrop-filter: blur(8px);
  padding: 6px 14px;
  border-radius: 4px;
  border: 1px solid rgba(0,0,0,0.08);
  max-width: calc(100vw - 120px);
  overflow: hidden;
  white-space: nowrap;
}

.cam-btn {
  padding: 6px 12px;
  background: rgba(255,255,255,0.9);
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  color: #555;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: background 0.15s, color 0.15s;
}

.cam-btn:hover {
  border-color: #10B981;
  color: #333;
}

.cam-btn.active {
  border-color: #10B981;
  color: #10B981;
  background: rgba(255,255,255,0.9);
}

/* === Dark Mode === */
body.dark { background: #1a1a1a; }
body.dark #side-panel { background: rgba(26, 26, 26, 0.85); backdrop-filter: blur(8px); color: #ccc; border-right-color: #444; }
body.dark .panel-section-header:hover { background: rgba(255,255,255,0.03); }
body.dark .panel-section-summary { color: #666; }
body.dark .panel-section-chevron { color: #555; }
/* Dark terminal block */
body.dark .terminal-block { border-color: #2a2a2a; }
body.dark .terminal-header { background: #080808; }
body.dark .terminal-comment { color: #444; }
body.dark .terminal-input-row { background: #111; border-color: #2a2a2a; }
body.dark .terminal-input { color: #eee; }
body.dark .terminal-input::placeholder { color: #444; }
body.dark .terminal-buttons { border-top-color: #2a2a2a; }
body.dark .terminal-btn { background: #0F0F0F; border-right-color: #2a2a2a; color: #6B7280; }
body.dark .terminal-btn:hover { background: #1a1a1a; color: #ccc; }
body.dark .terminal-btn:first-child { color: #10B981; }
body.dark .terminal-btn:first-child:hover { background: rgba(16,185,129,0.1); }
body.dark .terminal-history { background: #080808; }
body.dark .history-item { color: #6B7280; }
body.dark .history-item:hover { color: #10B981; }
/* Dark settings card */
body.dark .settings-card { background: #0a0a0a; border-color: #2a2a2a; }
body.dark .settings-card .toggle-switch-group { background: #111; border-color: #2a2a2a; }
body.dark .settings-card .toggle-option { color: #6B7280; }
body.dark .settings-card .toggle-option.active { background: #10B981; color: #fff; }
body.dark .settings-card .toggle-option:hover:not(.active) { color: #aaa; }
body.dark .settings-card .toggle-label { color: #999; }
body.dark .settings-card .radio-option { color: #6B7280; }
body.dark .settings-card .radio-dot { border-color: #444; }
body.dark .settings-card .radio-option input[type="radio"]:checked ~ .radio-text { color: #eee; }
body.dark .settings-card .panel-label { color: #999; }
body.dark .settings-card .panel-number { background: #111; border-color: #2a2a2a; color: #ccc; }
body.dark .settings-card .panel-select { background: #111; border-color: #2a2a2a; color: #ccc; }
body.dark .settings-card .panel-slider { background: linear-gradient(to right, #10B981 var(--progress), #333 var(--progress)); }
body.dark .settings-card .panel-slider::-webkit-slider-thumb { background: #111; border-color: #10B981; }
body.dark .settings-card .panel-slider::-webkit-slider-thumb:hover { border-color: #34D399; }
body.dark .settings-card .panel-slider::-moz-range-thumb { background: #111; border-color: #10B981; }
body.dark .settings-card .earth-gravity-pill { border-color: #2a2a2a; color: #10B981; }
body.dark .settings-card .earth-gravity-pill:hover { border-color: #10B981; background: rgba(16,185,129,0.08); }
body.dark .settings-card .reset-defaults-pill { border-color: #2a2a2a; color: #6B7280; }
body.dark .settings-card .reset-defaults-pill:hover { border-color: #444; color: #aaa; background: rgba(255,255,255,0.03); }
/* Dark mobile tray */
body.dark #mobile-tray { background: #0A0A0A; border-top-color: #2a2a2a; }
body.dark .tray-center { border-color: #2a2a2a; }
body.dark .tray-pattern { color: #e0e0e0; }
body.dark .tray-text { color: #6B7280; }
body.dark .tray-label { color: #444; }
body.dark #panel-header { border-bottom-color: #333; }
body.dark #panel-header h1 { color: #eee; }
body.dark #panel-header p { color: #666; }
body.dark .panel-section { border-bottom-color: #333; }
body.dark .panel-section-title { color: #666; }
body.dark .panel-label { color: #999; }
body.dark .panel-input { background: #2a2a2a; border-color: #444; color: #eee; }
body.dark .panel-input:focus { border-color: #666; }
body.dark .panel-select { background: #2a2a2a; border-color: #444; color: #ccc; }
body.dark .panel-number { background: #2a2a2a; border-color: #444; color: #ccc; }
body.dark .panel-number:focus { border-color: #666; }
body.dark .panel-btn { background: #2a2a2a; border-color: #444; color: #ccc; }
body.dark .panel-btn:hover { background: #333; }
body.dark .panel-btn.active { background: #eee; color: #1a1a1a; border-color: #eee; }
body.dark .panel-toggle-btn { background: #2a2a2a; border-color: #444; color: #888; }
body.dark .panel-toggle-btn.active { background: #eee; color: #1a1a1a; border-color: #eee; }
body.dark .panel-toggle-btn:hover { border-color: #555; }
body.dark .toggle-switch-group { background: #2a2a2a; border-color: #444; }
body.dark .toggle-option { color: #666; }
body.dark .toggle-option.active { background: #eee; color: #1a1a1a; }
body.dark .toggle-option:hover:not(.active) { color: #aaa; }
body.dark .toggle-label { color: #ccc; }
body.dark .panel-slider { background: linear-gradient(to right, #aaa var(--progress), #444 var(--progress)); }
body.dark .panel-slider::-webkit-slider-thumb { background: #2a2a2a; border-color: #aaa; box-shadow: 0 1px 3px rgba(0,0,0,0.3); }
body.dark .panel-slider::-webkit-slider-thumb:hover { border-color: #ccc; box-shadow: 0 1px 6px rgba(0,0,0,0.4); }
body.dark .panel-slider::-moz-range-thumb { background: #2a2a2a; border-color: #aaa; box-shadow: 0 1px 3px rgba(0,0,0,0.3); }
body.dark .earth-gravity-pill { border-color: #555; color: #777; }
body.dark .earth-gravity-pill:hover { color: #bbb; border-color: #777; background: rgba(255,255,255,0.05); }
body.dark .reset-defaults-pill { border-color: #555; color: #777; }
body.dark .reset-defaults-pill:hover { color: #bbb; border-color: #777; background: rgba(255,255,255,0.05); }
body.dark #panel-toggle { background: #222; border-color: #444; color: #aaa; box-shadow: 0 2px 8px rgba(0,0,0,0.3); }
body.dark #panel-toggle:hover { background: #333; color: #eee; }
body.dark #panel-close { color: #666; }
body.dark #panel-close:hover { color: #eee; background: rgba(255,255,255,0.08); }
body.dark #panel-footer { border-top-color: #333; }
body.dark .panel-color-picker { background: #2a2a2a; border-color: #444; }

/* === Language grid === */
.lang-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.lang-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 4px;
  border: 1px solid #e0e0e0;
  background: #f5f5f5;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.lang-option:hover {
  border-color: #10B981;
  background: rgba(16,185,129,0.04);
}

.lang-option.active {
  border-color: #10B981;
  background: rgba(16,185,129,0.08);
}

.lang-code {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: #999;
  text-transform: uppercase;
  min-width: 20px;
}

.lang-option.active .lang-code {
  color: #10B981;
}

.lang-name {
  font-size: 14px;
  font-weight: 600;
  color: #555;
}

.lang-option.active .lang-name {
  color: #333;
}

/* Dark mode */
body.dark .lang-option {
  background: #111;
  border-color: #2a2a2a;
}

body.dark .lang-option:hover {
  border-color: #10B981;
  background: rgba(16,185,129,0.06);
}

body.dark .lang-option.active {
  border-color: #10B981;
  background: rgba(16,185,129,0.1);
}

body.dark .lang-code {
  color: #555;
}

body.dark .lang-option.active .lang-code {
  color: #10B981;
}

body.dark .lang-name {
  color: #888;
}

body.dark .lang-option.active .lang-name {
  color: #eee;
}

/* Info modal */
#info-modal,
#gen-modal {
  background: #fff;
  border-radius: 4px;
  padding: 28px 24px 24px;
  max-width: 480px;
  width: 90%;
  max-height: calc(100vh - 300px);
  overflow-y: auto;
  position: relative;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
#info-modal-overlay,
#gen-modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.5);
  z-index: 10000;
  align-items: center;
  justify-content: center;
}
.info-close {
  position: absolute;
  top: 10px; right: 14px;
  background: none;
  border: none;
  font-size: 18px;
  color: #999;
  cursor: pointer;
  padding: 4px;
}
.info-close:hover { color: #333; }
.info-title { margin: 0 0 20px; font-size: 18px; font-weight: 700; color: #222; }
.info-body { font-size: 14px; color: #555; line-height: 1.7; }
.info-section { margin-bottom: 16px; }
.info-section:last-child { margin-bottom: 0; }
.info-section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #10B981;
  margin-bottom: 6px;
}
.info-body b { color: #222; }
.code-snip {
  display: inline-block;
  background: #f0f0f0;
  border-radius: 4px;
  padding: 1px 8px;
  margin: 1px 0;
  font-family: monospace;
  font-size: 13px;
  color: #333;
}
.info-row { display: flex; gap: 6px; align-items: center; margin: 2px 0; }
.info-kbd {
  display: inline-block;
  background: #f0f0f0;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 0 6px;
  font-family: monospace;
  font-size: 13px;
  color: #333;
  line-height: 1.8;
}
.info-divider { border: none; border-top: 1px solid #eee; margin: 12px 0; }

body.dark #info-modal,
body.dark #gen-modal { background: #2a2a2a; box-shadow: 0 8px 32px rgba(0,0,0,0.5); }
body.dark .info-close { color: #666; }
body.dark .info-close:hover { color: #eee; }
body.dark .info-title { color: #eee; }
body.dark .info-body { color: #999; }
body.dark .info-body b { color: #ddd; }
body.dark .info-section-title { color: #10B981; }
body.dark .code-snip { background: #383838; color: #ddd; }
body.dark .info-kbd { background: #383838; border-color: #555; color: #ddd; }
body.dark .info-divider { border-top-color: #3a3a3a; }

body.dark #ss-display { color: #ccc; background: rgba(30,30,30,0.85); border-color: rgba(255,255,255,0.08); }
body.dark .cam-btn { background: rgba(30,30,30,0.9); border-color: #444; color: #aaa; }
body.dark .cam-btn:hover { border-color: #10B981; color: #aaa; background: rgba(30,30,30,0.9); }
body.dark .cam-btn.active { border-color: #10B981; color: #10B981; background: rgba(30,30,30,0.9); }
body.dark label { color: #ccc; }
body.dark input[type="checkbox"] + *::before { border-color: #ccc; }
body.dark input[type="checkbox"]:checked + *::before { background: #ccc; border-color: #ccc; color: #1a1a1a; }

/* === Camera preset layout === */
.cam-desktop { display: flex; gap: 12px; }
.cam-mobile { display: none; position: relative; }

.cam-mobile-toggle {
  width: 32px;
  height: 32px;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.cam-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  flex-direction: column;
  gap: 6px;
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(12px);
  padding: 8px;
  border-radius: 8px;
  border: 1px solid #ddd;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  min-width: 100px;
}
.cam-dropdown.open { display: flex; }
.cam-dropdown .cam-btn {
  width: 100%;
  text-align: center;
  justify-content: center;
  min-height: 34px;
}
body.dark .cam-dropdown {
  background: rgba(34,34,34,0.95);
  border-color: #444;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

/* === Mobile === */
@media (max-width: 768px) {
  :root { --panel-width: 280px; }

  /* Panel starts closed — handled by JS, but ensure no push by default */
  body:not(.panel-open) canvas {
    left: 0 !important;
    width: 100% !important;
  }
  body:not(.panel-open) #three-container {
    left: 0;
    width: 100%;
  }
  body:not(.panel-open) #ss-display {
    left: 12px;
  }

  /* When panel is open on mobile, overlay instead of push */
  body.panel-open canvas {
    left: 0 !important;
    width: 100% !important;
  }
  body.panel-open #three-container {
    left: 0;
    width: 100%;
  }
  body.panel-open #ss-display {
    left: 12px;
  }
  #side-panel {
    box-shadow: 4px 0 24px rgba(0,0,0,0.3);
  }

  /* Camera presets: hide desktop, show mobile toggle */
  .cam-desktop { display: none; }
  .cam-mobile { display: block; }
  #camera-presets {
    top: 8px !important;
    right: 12px !important;
  }

  /* Siteswap display — smaller on mobile */
  #ss-display {
    font-size: 15px;
    padding: 4px 10px;
    max-width: calc(100vw - 100px);
  }

  /* Panel toggle — match eye button size & vertical alignment */
  #panel-toggle {
    top: 8px;
    left: 10px;
  }

  /* Compact panel header on mobile */
  #panel-header {
    padding: 14px 40px 10px 16px;
  }
  #panel-header h1 { font-size: 16px; }
  #panel-header p { font-size: 12px; margin-top: 2px; }
  #panel-close { top: 8px; right: 8px; }

  /* Disable panel resize on mobile */
  #panel-resize-handle { display: none; }

  /* Mobile quick-actions tray */
  #mobile-tray { display: flex; }
  body { padding-bottom: 52px; }
}
