*, *::before, *::after {
  box-sizing: border-box;
}

body {
  background: #0d1117;
  color: #e0e0e0;
  font-family: -apple-system, 'Segoe UI', sans-serif;
  margin: 0;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Welcome modal */
#welcome-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  transition: opacity 0.3s ease;
}
#welcome-overlay.welcome-hidden {
  opacity: 0;
  pointer-events: none;
}

#welcome-modal {
  position: relative;
  max-width: 600px;
  width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  background: rgba(13, 17, 23, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(48, 54, 61, 0.8);
  border-radius: 12px;
  padding: 48px 48px 40px;
  box-shadow: 0 19px 38px rgba(0,0,0,0.3), 0 15px 12px rgba(0,0,0,0.22);
}

.welcome-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.welcome-title-row h1 {
  font-size: 28px;
  font-weight: 700;
  color: #e6edf3;
  letter-spacing: -0.5px;
  margin: 0;
}
.welcome-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  font-family: 'SF Mono', 'Cascadia Code', monospace;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: rgba(31, 111, 235, 0.2);
  color: #58a6ff;
  border: 1px solid rgba(31, 111, 235, 0.3);
}

.welcome-desc {
  font-size: 15px;
  line-height: 1.65;
  color: #b1bac4;
  margin-bottom: 24px;
}
.welcome-desc strong { color: #e6edf3; font-weight: 600; }
.welcome-desc em { color: #a5d6ff; font-style: italic; }

#gpu-status-card {
  border-radius: 10px;
  border: 1px solid rgba(35, 134, 54, 0.5);
  background: rgba(35, 134, 54, 0.08);
  padding: 20px;
  margin-bottom: 28px;
}
.gpu-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px 4px 8px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  background: rgba(35, 134, 54, 0.5);
  color: #7ee787;
  border: 1px solid rgba(126, 231, 135, 0.25);
  margin-bottom: 12px;
}
.gpu-status-text {
  font-size: 14px;
  color: #b1bac4;
  margin: 0;
}
.gpu-status-text strong { color: #e6edf3; }

#start-sim-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 32px;
  font-size: 16px;
  font-weight: 600;
  color: #ffffff;
  background: #238636;
  border: 1px solid rgba(35, 134, 54, 0.6);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s;
}
#start-sim-btn:hover {
  background: #2ea043;
  box-shadow: 0 0 16px rgba(35, 134, 54, 0.3);
}

#no-webgpu {
  display: none;
  align-items: center;
  justify-content: center;
  height: 100vh;
  font-size: 18px;
  text-align: center;
  padding: 20px;
}

#device-lost-banner {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: #da3633;
  color: white;
  padding: 10px;
  text-align: center;
  z-index: 100;
}

#title-bar {
  background: #161b22;
  border-bottom: 1px solid #30363d;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

#app-name {
  font-weight: 700;
  font-size: 16px;
  color: #e6edf3;
}

.badge {
  color: #484f58;
  font-size: 12px;
}

.title-spacer {
  flex: 1;
}

.author-link {
  color: #b1bac4;
  text-decoration: none;
  font-size: 12px;
  transition: color 0.2s;
}

.author-link:hover {
  color: #ffffff;
}

.gh-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: #c9d1d9;
  text-decoration: none;
  font-size: 11px;
  padding: 3px 10px;
  border: 1px solid #30363d;
  border-radius: 12px;
  background: #21262d;
  transition: border-color 0.2s, color 0.2s;
}

.gh-pill:hover {
  border-color: #58a6ff;
  color: #ffffff;
}

#gh-stars:not(:empty)::before {
  content: "\2605 ";
}

#preset-bar {
  background: #161b22;
  border-bottom: 1px solid #30363d;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.preset-label {
  font-size: 11px;
  color: #8b949e;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.preset-btn {
  padding: 4px 10px;
  background: #21262d;
  border: 1px solid #30363d;
  border-radius: 4px;
  font-size: 12px;
  color: #c9d1d9;
  cursor: pointer;
}

.preset-btn.active {
  background: #1f6feb;
  border-color: #1f6feb;
  color: white;
}

#canvas-container {
  flex: 1;
  position: relative;
  background: #000;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#colorbar {
  position: absolute;
  right: 16px;
  top: 16px;
  bottom: 16px;
  width: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 10px;
  color: #8b949e;
  z-index: 5;
}

#colorbar-gradient {
  flex: 1;
  width: 14px;
  border-radius: 2px;
  background: linear-gradient(to bottom, #ffffff, #ff0000, #ffff00, #00ff00, #000000);
}

.colorbar-label {
  font-family: monospace;
  font-size: 10px;
}

.colorbar-unit {
  font-size: 9px;
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

#perf-hud {
  position: absolute;
  left: 12px;
  top: 12px;
  background: rgba(0, 0, 0, 0.7);
  padding: 6px 10px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 11px;
  color: #7ee787;
  line-height: 1.6;
  z-index: 5;
  white-space: pre;
}

.toolbar {
  background: #161b22;
  border-top: 1px solid #30363d;
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.toolbar-group {
  display: flex;
  gap: 12px;
  align-items: center;
}

.toolbar-label {
  font-size: 11px;
  color: #8b949e;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.slider-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #c9d1d9;
  cursor: pointer;
}

.slider-inline input[type="range"] {
  width: 80px;
}

.slider-inline span {
  font-family: monospace;
  font-size: 11px;
  color: #7ee787;
  min-width: 40px;
}

.btn {
  padding: 5px 14px;
  border: 1px solid #30363d;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  background: #21262d;
  color: #c9d1d9;
}

.btn-play {
  background: #238636;
  border-color: #238636;
  color: white;
  font-weight: 500;
}

input[type="range"] {
  -webkit-appearance: none;
  height: 4px;
  background: #21262d;
  border-radius: 2px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #1f6feb;
  cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #1f6feb;
  cursor: pointer;
  border: none;
}

.resolution-picker {
  display: flex;
  gap: 4px;
}

.res-btn {
  padding: 3px 8px;
  background: #21262d;
  border: 1px solid #30363d;
  border-radius: 4px;
  font-size: 11px;
  font-family: monospace;
  color: #c9d1d9;
  cursor: pointer;
}

.res-btn.active {
  background: #1f6feb;
  border-color: #1f6feb;
  color: white;
}

/* Close button (shared by welcome & guide modals) */
.welcome-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: none;
  border: none;
  color: #8b949e;
  font-size: 24px;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s, background 0.2s;
}
.welcome-close:hover {
  color: #c9d1d9;
  background: rgba(255, 255, 255, 0.06);
}

/* Guide button */
.guide-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #21262d;
  border: 1px solid #30363d;
  color: #c9d1d9;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.2s, color 0.2s;
}
.guide-btn:hover {
  border-color: #58a6ff;
  color: #ffffff;
}

/* Guide overlay */
#guide-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  transition: opacity 0.3s ease;
  opacity: 0;
  pointer-events: none;
}
#guide-overlay.guide-visible {
  opacity: 1;
  pointer-events: auto;
}

/* Guide modal */
#guide-modal {
  position: relative;
  max-width: 720px;
  width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  background: rgba(13, 17, 23, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(48, 54, 61, 0.8);
  border-radius: 12px;
  padding: 48px 48px 40px;
  box-shadow: 0 19px 38px rgba(0,0,0,0.3), 0 15px 12px rgba(0,0,0,0.22);
}

/* Welcome guide link */
.welcome-guide-link {
  text-align: center;
  margin-top: 12px;
  font-size: 14px;
  color: #8b949e;
}
.welcome-guide-link a {
  color: #58a6ff;
  text-decoration: none;
}
.welcome-guide-link a:hover {
  text-decoration: underline;
}

/* Accordion sections */
.guide-section {
  border-bottom: 1px solid rgba(48, 54, 61, 0.6);
}
.guide-section:last-child {
  border-bottom: none;
}
.guide-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  cursor: pointer;
  user-select: none;
}
.guide-section-header:hover .guide-section-title {
  color: #ffffff;
}
.guide-section-title {
  font-size: 15px;
  font-weight: 600;
  color: #e6edf3;
  transition: color 0.2s;
}
.guide-section-summary {
  display: block;
  font-size: 13px;
  color: #8b949e;
  margin-top: 2px;
}
.guide-chevron {
  color: #8b949e;
  font-size: 14px;
  transition: transform 0.2s;
  flex-shrink: 0;
}
.guide-section.guide-section-open .guide-chevron {
  transform: rotate(90deg);
}
.guide-section-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}
.guide-section.guide-section-open .guide-section-body {
  max-height: 2000px;
}
.guide-section-content {
  padding: 0 0 16px;
  font-size: 14px;
  line-height: 1.65;
  color: #b1bac4;
}
.guide-section-content strong {
  color: #e6edf3;
  font-weight: 600;
}
.guide-section-content em {
  color: #a5d6ff;
}

/* Learn more expanders */
.guide-learn-more {
  margin-top: 12px;
}
.guide-learn-more-toggle {
  color: #58a6ff;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}
.guide-learn-more-toggle:hover {
  text-decoration: underline;
}
.guide-learn-more-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}
.guide-learn-more.learn-more-open .guide-learn-more-body {
  max-height: 500px;
}
.guide-learn-more-body p {
  margin: 8px 0 0;
  font-size: 13px;
  line-height: 1.6;
  color: #8b949e;
}

/* Guide content helpers */
.guide-param-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  align-items: baseline;
}
.guide-param-name {
  font-weight: 600;
  color: #e6edf3;
  min-width: 120px;
  font-size: 13px;
}
.guide-param-desc {
  font-size: 13px;
  color: #b1bac4;
}
.guide-shortcut-row {
  display: flex;
  gap: 12px;
  margin-bottom: 6px;
  align-items: center;
}
.guide-shortcut-key {
  background: #21262d;
  border: 1px solid #30363d;
  border-radius: 4px;
  padding: 2px 8px;
  font-family: 'SF Mono', 'Cascadia Code', monospace;
  font-size: 13px;
  color: #e6edf3;
  min-width: 32px;
  text-align: center;
}
.guide-shortcut-desc {
  font-size: 13px;
  color: #b1bac4;
}

@media (max-width: 640px) {
  #guide-modal {
    padding: 32px 24px 28px;
  }
}
