*, *::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: 680px;
  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-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);
}

.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 0 14px;
}
.gpu-status-text strong {
  color: #e6edf3;
}
.gpu-detail-card {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(48, 54, 61, 0.6);
  border-radius: 8px;
  padding: 16px;
}
.gpu-detail-title {
  font-size: 14px;
  font-weight: 600;
  color: #e6edf3;
  margin-bottom: 8px;
}
.gpu-detail-text {
  font-size: 13px;
  line-height: 1.6;
  color: #8b949e;
  margin: 0;
}
.gpu-detail-text strong {
  color: #c9d1d9;
  font-weight: 600;
}
.gpu-detail-text em {
  color: #a5d6ff;
  font-style: italic;
}

#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;
  letter-spacing: 0.2px;
}
#start-sim-btn:hover {
  background: #2ea043;
  box-shadow: 0 0 16px rgba(35, 134, 54, 0.3);
}

@media (max-width: 640px) {
  #welcome-modal {
    padding: 32px 24px 28px;
  }
  .welcome-title-row h1 {
    font-size: 22px;
  }
}

#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;
}

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

.title-spacer {
  flex: 1;
}

.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;
}

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

.author-link:hover {
  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;
}

#colorbar {
  position: absolute;
  right: 20px;
  top: 20px;
  bottom: 20px;
  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, #fde725, #35b779, #31688e, #440154);
}

#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;
}

#flow-info {
  position: absolute;
  left: 12px;
  top: 68px;
  background: rgba(0, 0, 0, 0.7);
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 11px;
  color: #c9d1d9;
  z-index: 5;
}

.hint {
  color: #8b949e;
  cursor: help;
  font-size: 10px;
}

#canvas-hint {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 14px;
  color: white;
  background: rgba(0, 0, 0, 0.7);
  padding: 8px 16px;
  border-radius: 8px;
  pointer-events: none;
  animation: fadeOut 3s 2s forwards;
  z-index: 5;
}

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

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

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

.toolbar-group label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: #c9d1d9;
  cursor: pointer;
}

.toolbar-group input[type="checkbox"] {
  accent-color: #1f6feb;
}

.toolbar-divider {
  width: 1px;
  height: 18px;
  background: #30363d;
}

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

.shape-btn.active, .mode-btn.active {
  background: #1f6feb;
  border-color: #1f6feb;
  color: white;
}

.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;
}

.btn-advanced {
  background: #da3633;
  border-color: #da3633;
  color: white;
}

#advanced-panel {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 280px;
  background: #161b22;
  border-left: 1px solid #30363d;
  padding: 16px;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  z-index: 10;
  overflow-y: auto;
}

#advanced-panel.visible {
  transform: translateX(0);
}

.panel-header {
  font-weight: 600;
  font-size: 14px;
  color: #f0f6fc;
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
}

.panel-header button {
  background: none;
  border: none;
  color: #8b949e;
  cursor: pointer;
  font-size: 14px;
  padding: 0;
}

.panel-section {
  margin-bottom: 16px;
}

.section-title {
  font-size: 11px;
  color: #8b949e;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.slider-row {
  margin-bottom: 10px;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 3px;
}

.slider-name {
  font-size: 12px;
  color: #c9d1d9;
}

.slider-value {
  font-size: 12px;
  color: #7ee787;
  font-family: monospace;
}

input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  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;
}

.slider-hint {
  font-size: 10px;
  color: #6e7681;
  margin-top: 2px;
}

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

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

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

.tier-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 24px;
    font-family: monospace;
    color: #7ee787;
    background: rgba(0,0,0,0.7);
    padding: 8px 16px;
    border-radius: 8px;
    pointer-events: none;
    animation: fadeOut 1.5s forwards;
}
@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* 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-illustration {
  margin: 12px 0;
  display: flex;
  justify-content: center;
}
.guide-shapes-row {
  display: flex;
  gap: 24px;
  justify-content: center;
  align-items: flex-end;
  margin: 12px 0;
}
.guide-shape-item {
  text-align: center;
  font-size: 11px;
  color: #8b949e;
}
.guide-viz-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 10px;
}
.guide-viz-item strong {
  color: #e6edf3;
  min-width: 100px;
}
.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;
}
.guide-preset-block {
  margin-bottom: 16px;
}
.guide-preset-block h4 {
  font-size: 14px;
  color: #e6edf3;
  margin: 0 0 4px;
}

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