:root {
  color-scheme: dark;
  --bg: #0b0e14;
  --panel: rgba(18, 22, 30, 0.85);
  --border: rgba(255, 255, 255, 0.08);
  --text: #e8ebf0;
  --muted: #8a91a0;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
}

#app {
  position: relative;
  width: 100%;
  height: 100vh;
}

canvas {
  display: block;
  touch-action: none;
}

#loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  background: var(--bg);
  z-index: 20;
  transition: opacity 0.4s ease;
}

#loading .spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.15);
  border-top-color: #6cc4ff;
  animation: spin 0.8s linear infinite;
}

#loading span {
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.02em;
}

@keyframes spin { to { transform: rotate(360deg); } }

.hidden { opacity: 0; pointer-events: none; }

#panel {
  z-index: 10;
  position: absolute;
  top: 12px;
  left: 12px;
  max-width: 240px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  backdrop-filter: blur(8px);
  font-size: 12.5px;
  max-height: calc(100vh - 24px);
  overflow-y: auto;
}

#panel h1 {
  font-size: 13px;
  margin: 0 0 8px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

#panel .section {
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
#panel .section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }

#panel label.row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 3px 0;
  cursor: pointer;
  user-select: none;
}

#panel .swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex: none;
}

#panel .slider-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 6px 0;
}

#panel .slider-row .top {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
}

#panel input[type="range"] {
  width: 100%;
}

#panel .actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

#panel button {
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 5px 9px;
  font-size: 11.5px;
  cursor: pointer;
}
#panel button:hover { background: rgba(255,255,255,0.12); }

#panel .lines-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 8px;
}

#tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(10, 12, 18, 0.92);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 11.5px;
  color: var(--text);
  transform: translate(-50%, -130%);
  white-space: nowrap;
  display: none;
  z-index: 10;
}

.stop-label {
  pointer-events: none;
}

.stop-label-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  transform: translateY(-100%);
  white-space: nowrap;
}

.stop-label .stop-name {
  background: rgba(10, 12, 18, 0.82);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 2px 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
}

.stop-label .stop-steps {
  background: rgba(10, 12, 18, 0.7);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 9.5px;
  color: var(--muted);
}

#toggle-panel {
  z-index: 10;
  position: absolute;
  top: 12px;
  right: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  width: 32px;
  height: 32px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

#panel {
  transition: transform 0.25s ease, opacity 0.25s ease;
}
#panel.collapsed {
  transform: translateX(-120%);
  opacity: 0;
  pointer-events: none;
}

.muted-note {
  color: var(--muted);
  font-size: 11px;
  cursor: default;
}

#stats-panel {
  z-index: 5;
  position: absolute;
  top: 12px;
  right: 12px;
  width: 210px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  backdrop-filter: blur(8px);
}

.stats-lines {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}

.stat-row {
  display: grid;
  grid-template-columns: 10px 44px 1fr 32px;
  align-items: center;
  gap: 6px;
  font-size: 10.5px;
  color: var(--muted);
}

.stat-row .swatch {
  width: 8px;
  height: 8px;
  border-radius: 2px;
}

.stat-row .stat-pct {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.bar-track {
  height: 5px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.09);
  overflow: hidden;
}
.bar-track.big {
  height: 9px;
  border-radius: 5px;
  margin-top: 6px;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: #6cc4ff;
  width: 0%;
  transition: width 0.3s ease;
}

.stats-overall {
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.stats-overall-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 15px;
  font-weight: 600;
}

#overall-pct {
  font-variant-numeric: tabular-nums;
}

@media (max-width: 640px) {
  #panel { font-size: 11.5px; max-width: 200px; }
  #toggle-panel { display: flex; }
  #stats-panel { top: 56px; width: 150px; padding: 8px 10px; }
  .stats-overall-top { font-size: 12px; }
}

#cta-banner {
  z-index: 8;
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(108, 196, 255, 0.14);
  border: 1px solid rgba(108, 196, 255, 0.45);
  color: #d6eeff;
  border-radius: 999px;
  padding: 7px 16px;
  font-size: 12.5px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  backdrop-filter: blur(8px);
  transition: background 0.15s ease, transform 0.15s ease;
}
#cta-banner:hover {
  background: rgba(108, 196, 255, 0.24);
  transform: translateX(-50%) translateY(-1px);
}

#thanks-widget {
  z-index: 5;
  position: absolute;
  bottom: 14px;
  right: 14px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

#thanks-toggle {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 12px;
  cursor: pointer;
  backdrop-filter: blur(8px);
}
#thanks-toggle:hover {
  background: rgba(255, 255, 255, 0.1);
}

#thanks-list {
  list-style: none;
  margin: 0;
  padding: 10px 14px;
  max-width: 280px;
  max-height: 220px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  backdrop-filter: blur(8px);
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
}
#thanks-list li {
  margin: 4px 0;
}
#thanks-list li::before {
  content: "— ";
  color: var(--text);
}

@media (max-width: 640px) {
  #cta-banner { font-size: 11px; padding: 6px 12px; max-width: 78vw; white-space: normal; text-align: center; }
  #thanks-list { max-width: 60vw; }
}
