/* Advanced E-Bike Simulator — premium engineering dashboard */

:root {
  --bg: #f4f6f9;
  --bg-elevated: #ffffff;
  --text: #0c1118;
  --text-muted: #5c6678;
  --border: rgba(12, 17, 24, 0.08);
  --border-strong: rgba(12, 17, 24, 0.12);
  --accent: #3d7cff;
  --accent-soft: rgba(61, 124, 255, 0.12);
  --accent-glow: rgba(61, 124, 255, 0.22);
  --teal: #12b4a7;
  --amber: #e8a23c;
  --danger: #e5484d;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(12, 17, 24, 0.04);
  --shadow-md: 0 8px 24px rgba(12, 17, 24, 0.08);
  --shadow-lg: 0 20px 50px rgba(12, 17, 24, 0.12);
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sidebar-width: min(380px, 100%);
  --header-h: auto;
}

body.dark {
  --bg: #070a0f;
  --bg-elevated: #0f141c;
  --text: #e8ecf2;
  --text-muted: #94a3b8;
  --border: rgba(255, 255, 255, 0.06);
  --border-strong: rgba(255, 255, 255, 0.1);
  --accent: #6ea8ff;
  --accent-soft: rgba(110, 168, 255, 0.14);
  --accent-glow: rgba(110, 168, 255, 0.25);
  --teal: #2ee6d6;
  --amber: #f5c15c;
  --danger: #ff6b6b;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.55);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  transition: background 0.25s ease, color 0.2s ease;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.hidden {
  display: none !important;
}

.wrapper {
  min-height: 100dvh;
  overflow-x: hidden;
}

.sim-wrapper {
  padding: clamp(12px, 2.5vw, 24px);
  max-width: 1280px;
  margin: 0 auto;
}

.sim-app {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius-lg) + 4px);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.sim-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px 24px;
  padding: clamp(16px, 3vw, 28px) clamp(16px, 3vw, 28px) 12px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--bg-elevated), var(--bg));
}

body.dark .sim-header {
  background: linear-gradient(180deg, #121826, var(--bg-elevated));
}

.sim-kicker {
  margin: 0 0 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.sim-title {
  margin: 0 0 6px;
  font-size: clamp(1.35rem, 2.2vw, 1.75rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.sim-sub {
  margin: 0;
  max-width: 52ch;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.sim-header__actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.theme-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.theme-pill__track {
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: #dfe5ee;
  border: 1px solid var(--border-strong);
  position: relative;
  transition: background 0.2s ease;
}

.theme-pill__track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s ease;
}

body.dark .theme-pill__track {
  background: #243044;
  border-color: rgba(255, 255, 255, 0.12);
}

body.dark .theme-pill__track::after {
  transform: translateX(18px);
  background: #e8ecf2;
}

.theme-pill__label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}

.sim-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  gap: 0;
  align-items: stretch;
  min-height: 0;
}

.sim-sidebar {
  border-right: 1px solid var(--border);
  background: var(--bg);
  min-width: 0;
}

.sidebar-sticky {
  position: sticky;
  top: 0;
  max-height: 100dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: clamp(12px, 2vw, 18px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}

.sim-main {
  min-width: 0;
  padding: clamp(12px, 2vw, 20px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}

.panel--accent {
  border-color: rgba(61, 124, 255, 0.22);
  box-shadow: 0 0 0 1px var(--accent-soft), var(--shadow-sm);
}

.panel--challenge {
  border-color: rgba(232, 162, 60, 0.35);
  background: linear-gradient(180deg, rgba(232, 162, 60, 0.06), var(--bg-elevated));
}

body.dark .panel--challenge {
  background: linear-gradient(180deg, rgba(232, 162, 60, 0.08), var(--bg-elevated));
}

.panel--compare {
  border-style: dashed;
}

.panel__head {
  margin-bottom: 10px;
}

.panel__title {
  margin: 0 0 4px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.panel__hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.speed-cluster__row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 12px;
}

.speed-readout {
  min-width: 7rem;
  text-align: center;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--bg);
  border: 1px solid var(--border);
}

.speed-readout__value {
  font-size: 1.75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}

.speed-readout__unit {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.slider-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

.slider-field__label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}

.toolbar-row {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn--primary {
  background: linear-gradient(135deg, var(--accent), #5ab0ff);
  color: #fff;
  box-shadow: 0 6px 18px var(--accent-glow);
}

.btn--secondary {
  background: var(--bg);
  color: var(--text);
  border-color: var(--border-strong);
}

.btn--ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border-strong);
  min-width: 44px;
  padding: 0 12px;
}

.btn--ghost:hover,
.btn--secondary:hover {
  border-color: var(--accent);
  color: var(--text);
}

.btn--challenge {
  background: linear-gradient(135deg, #f0b429, #e8942a);
  color: #1a1206;
  box-shadow: 0 6px 18px rgba(232, 162, 60, 0.35);
}

.btn--export {
  background: linear-gradient(135deg, #12b4a7, #0d9f93);
  color: #041312;
  box-shadow: 0 6px 18px rgba(18, 180, 167, 0.28);
}

body.dark .btn--export {
  color: #e8fffc;
}

.btn--sm {
  min-height: 38px;
  padding: 0 12px;
  font-size: 0.82rem;
}

.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.preset-btn {
  flex: 1 1 30%;
  min-height: 44px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg);
  font: inherit;
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.preset-btn:hover {
  border-color: var(--accent);
}

.preset-btn.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.challenge-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.challenge-live {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.challenge-phase {
  margin: 8px 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.challenge-results {
  margin-top: 12px;
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg);
}

.challenge-results__lead {
  margin-top: 0;
}

.challenge-score-hint {
  font-size: 0.85em;
  color: var(--text-muted);
}

.params {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.param-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.param-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
}

.field-help {
  margin: 4px 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.terrain-select {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font: inherit;
  font-weight: 600;
}

.param-slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.range,
.param-slider-row input[type="range"] {
  flex: 1;
  min-width: 0;
  height: 6px;
  border-radius: 999px;
  -webkit-appearance: none;
  appearance: none;
  background: linear-gradient(90deg, var(--accent-soft), rgba(18, 180, 167, 0.15));
  border: 1px solid var(--border);
}

.range::-webkit-slider-thumb,
.param-slider-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 2px solid var(--accent);
  box-shadow: 0 2px 8px var(--accent-glow);
  cursor: pointer;
}

.range::-moz-range-thumb,
.param-slider-row input[type="range"]::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 2px solid var(--accent);
  box-shadow: 0 2px 8px var(--accent-glow);
  cursor: pointer;
}

.range:focus-visible,
.param-slider-row input[type="range"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.param-value {
  flex-shrink: 0;
  min-width: 4.75rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--accent);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  font-family: var(--font-mono);
}

.compare-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.compare-hint {
  margin: 0 0 10px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.compare-grid[hidden] {
  display: none !important;
}

.compare-grid {
  display: grid;
  grid-template-columns: minmax(5rem, auto) 1fr 1fr;
  gap: 8px 10px;
  align-items: center;
  font-size: 0.88rem;
}

.compare-head {
  font-weight: 700;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.compare-label {
  font-weight: 600;
  color: var(--text);
}

.compare-val {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  text-align: center;
  background: var(--bg);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.compare-val.compare-better {
  border-color: #22c55e;
  background: rgba(34, 197, 94, 0.1);
}

.compare-val.compare-muted {
  opacity: 0.5;
}

.scene-card {
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.scene-card__inner {
  padding: 12px;
}

.canvas-wrap {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg);
}

#simCanvas {
  display: block;
  width: 100%;
  height: auto;
  vertical-align: middle;
}

#bike {
  position: absolute;
  left: 50%;
  top: 0;
  width: clamp(72px, 18vw, 96px);
  height: auto;
  aspect-ratio: 88 / 50;
  transform: translate(-50%, 0);
  pointer-events: none;
  z-index: 3;
  will-change: transform, filter;
}

#bike svg {
  width: 100%;
  height: auto;
  display: block;
}

#bike .wheel {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.4;
}

#bike .frame {
  fill: none;
  stroke: var(--text-muted);
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.hud-stack {
  position: absolute;
  left: 12px;
  top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 4;
  pointer-events: none;
}

.hud-pill {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(7, 10, 15, 0.55);
  color: #e8ecf2;
  backdrop-filter: blur(8px);
  font-size: 0.78rem;
}

body:not(.dark) .hud-pill {
  background: rgba(255, 255, 255, 0.82);
  color: var(--text);
  border: 1px solid var(--border);
}

.hud-pill__k {
  font-weight: 600;
  opacity: 0.75;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.65rem;
}

.hud-pill__v {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
}

.battery-hud {
  margin-top: 12px;
}

.battery-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.battery-meta__val {
  font-family: var(--font-mono);
  color: var(--text);
}

.battery-bar-track {
  height: 12px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  overflow: hidden;
}

.battery-bar-fill {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  transform-origin: left center;
  transition: width 0.28s ease-out, background 0.35s ease, box-shadow 0.35s ease;
}

.battery-tier-high {
  background: linear-gradient(90deg, #16a34a, #4ade80);
  box-shadow: 0 0 14px rgba(74, 222, 128, 0.35);
}

.battery-tier-mid {
  background: linear-gradient(90deg, #ea580c, #fb923c);
}

.battery-tier-low {
  background: linear-gradient(90deg, #b91c1c, #f87171);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.stat-card {
  padding: 14px 16px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-sm);
}

.stat-card--wide {
  grid-column: 1 / -1;
}

.stat-card__label {
  margin: 0 0 6px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.stat-card__value {
  margin: 0;
  font-size: 1.45rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.stat-card__unit {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-left: 4px;
}

.stat-card__note {
  margin: 8px 0 0;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.insight-card {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px dashed var(--border-strong);
  background: var(--bg);
  font-size: 0.88rem;
  color: var(--text-muted);
}

.insight-card--empty::before {
  content: "Insight";
  display: block;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.actions-row {
  display: flex;
  justify-content: flex-end;
}

.chart-card {
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  padding: 14px 16px 8px;
  box-shadow: var(--shadow-sm);
}

.chart-card__head {
  margin-bottom: 8px;
}

.chart-card__title {
  margin: 0 0 4px;
  font-size: 0.85rem;
  font-weight: 700;
}

.chart-card__hint {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.sim-chart-wrap {
  position: relative;
  width: 100%;
  min-height: 200px;
}

.sim-chart-wrap canvas {
  display: block;
  width: 100% !important;
  height: auto !important;
}

/* Floating install */
.chip-btn {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  color: var(--text);
}

.chip-btn.install-btn {
  position: fixed;
  left: max(12px, env(safe-area-inset-left));
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 9998;
  border-radius: 999px;
  padding: 12px 18px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-lg);
  font-weight: 700;
  cursor: pointer;
}

.chip-btn.secondary-btn {
  display: none;
}

@media (max-width: 960px) {
  .sim-layout {
    grid-template-columns: 1fr;
  }

  .sim-sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    order: 2;
  }

  .sim-main {
    order: 1;
  }

  .sidebar-sticky {
    position: relative;
    max-height: none;
    overflow: visible;
  }
}

@media (max-width: 600px) {
  .chip-btn.install-btn {
    width: 52px;
    height: 52px;
    padding: 0;
    border-radius: 50%;
  }

  .chip-btn.install-btn .btn-label {
    display: none;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  .stat-card--wide {
    grid-column: 1 / -1;
  }
}

/* Popups & legal — compact */
.tool-extra-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 16px auto;
  max-width: 1280px;
  padding: 0 clamp(12px, 2.5vw, 24px);
}

.tool-toggle-btn {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.popup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 99999;
  padding: 20px;
  min-height: 100vh;
}

.popup-overlay.active {
  display: flex;
  animation: fadeIn 0.25s ease;
}

.popup-box {
  width: 100%;
  max-width: 720px;
  max-height: calc(100vh - 40px);
  overflow: auto;
  background: var(--bg-elevated);
  color: var(--text);
  border-radius: 20px;
  padding: 24px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  position: relative;
}

.popup-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--bg);
  cursor: pointer;
  font-size: 16px;
}

textarea#embedCode {
  width: 100%;
  min-height: 160px;
  margin-top: 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  background: var(--bg);
  color: var(--text);
}

.copy-btn {
  margin-top: 12px;
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--teal);
  color: #041312;
  font-weight: 700;
  cursor: pointer;
}

.legal-popup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99999;
  padding: 20px;
}

.legal-popup-box {
  width: 100%;
  max-width: 480px;
  background: var(--bg-elevated);
  color: var(--text);
  border-radius: 20px;
  padding: 24px;
  text-align: center;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
}

.legal-popup-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

.legal-popup-box button {
  margin-top: 12px;
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

#similarToolsList {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
}

#similarToolsList li {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  background: var(--bg);
}
