/* ============================================================
   Ride Analyzer — design tokens (light / dark)
   ============================================================ */
:root {
  --bg-page: #eef1f6;
  --bg-surface: #ffffff;
  --bg-elevated: #f4f6fa;
  --bg-input: #ffffff;
  --text-primary: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;
  --border: rgba(15, 23, 42, 0.09);
  --border-strong: rgba(15, 23, 42, 0.14);
  --accent: #0d9488;
  --accent-hover: #0f766e;
  --accent-soft: rgba(13, 148, 136, 0.14);
  --accent-glow: rgba(13, 148, 136, 0.35);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.07);
  --shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.1);
  --radius: 14px;
  --radius-sm: 10px;
  --radius-xs: 8px;
  --transition: 0.2s ease;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --good: #059669;
  --bad: #dc2626;
}

body.dark {
  --bg-page: #0c1017;
  --bg-surface: #161d27;
  --bg-elevated: #1e2733;
  --bg-input: #1a222d;
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --border: rgba(241, 245, 249, 0.08);
  --border-strong: rgba(241, 245, 249, 0.14);
  --accent: #2dd4bf;
  --accent-hover: #5eead4;
  --accent-soft: rgba(45, 212, 191, 0.12);
  --accent-glow: rgba(45, 212, 191, 0.25);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 48px rgba(0, 0, 0, 0.45);
  --good: #34d399;
  --bad: #f87171;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  background: var(--bg-page);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  transition: background-color var(--transition), color var(--transition);
}

/* ----- Shell / marketing sections (readability) ----- */
.wrapper {
  min-height: 100%;
}

.tool-header {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: background-color var(--transition), border-color var(--transition);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem 1.25rem;
}

.tool-header-wrapper {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
}

.brand-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.brand-title .highlight-w {
  color: var(--accent);
}

.tool-title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text-primary);
}

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* Toggle switch (header) */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  transition: var(--transition);
}

.slider::before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 2px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
}

.switch input:checked + .slider {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.switch input:checked + .slider::before {
  transform: translateX(20px);
  background: var(--accent);
}

.slider.round {
  border-radius: 24px;
}

.slider.round::before {
  border-radius: 50%;
}

/* ----- 3-column layout (unchanged columns) ----- */
.layout {
  display: grid;
  grid-template-columns: 220px 1fr 260px;
  height: 100vh;
  padding: 20px;
  gap: 0;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
}

.sidebar {
  padding: 18px 16px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  box-shadow: var(--shadow-sm);
  transition: background-color var(--transition), border-color var(--transition), box-shadow var(--transition);
}

.sidebar h2 {
  margin: 0 0 1rem;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.right {
  border-right: none;
  border-left: 1px solid var(--border);
}

.center {
  padding: 20px 22px;
  overflow-y: auto;
  min-height: 0;
  background: transparent;
}

.center > h1 {
  margin: 0 0 1.25rem;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

h1 {
  text-align: center;
}

/* ----- Forms (sidebar) ----- */
.sidebar input[type="text"],
.sidebar input[type="file"] {
  width: 100%;
  margin-top: 0;
  font-family: inherit;
  font-size: 0.875rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.sidebar input[type="text"] {
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs);
  background: var(--bg-input);
  color: var(--text-primary);
}

.sidebar input[type="text"]::placeholder {
  color: var(--text-muted);
}

.sidebar input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.sidebar input[type="file"] {
  padding: 8px 0;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.sidebar input[type="file"]::file-selector-button {
  margin-right: 10px;
  padding: 8px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), transform 0.15s ease;
}

.sidebar input[type="file"]::file-selector-button:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

/* ----- Buttons ----- */
.sidebar button {
  width: 100%;
  margin-top: 10px;
  padding: 10px 14px;
  border: none;
  border-radius: var(--radius-xs);
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-hover) 100%);
  color: #fff;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: var(--shadow-sm), 0 0 0 1px rgba(0, 0, 0, 0.04) inset;
  transition:
    transform 0.15s ease,
    box-shadow var(--transition),
    filter var(--transition);
}

.sidebar button:hover {
  filter: brightness(1.06);
  box-shadow: var(--shadow-md), 0 0 20px var(--accent-glow);
  transform: translateY(-1px);
}

.sidebar button:active {
  transform: translateY(0);
  filter: brightness(0.98);
}

.sidebar button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#themeToggle {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-sm);
}

#themeToggle:hover {
  filter: none;
  background: var(--accent-soft);
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
}

/* ----- Compare ----- */
.compare-panel {
  margin-top: 20px;
  padding: 18px;
  background: var(--bg-surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  transition: background-color var(--transition), border-color var(--transition);
}

.compare-card {
  padding: 14px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  text-align: center;
  transition: border-color var(--transition), box-shadow var(--transition), transform 0.15s ease;
}

.compare-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}

.compare-card h3 {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.compare-card .value {
  font-size: 1.25rem;
  font-weight: 700;
  margin-top: 8px;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.good {
  color: var(--good) !important;
}

.bad {
  color: var(--bad) !important;
}

.hidden {
  display: none;
}

/* ----- Charts ----- */
.charts {
  display: grid;
  gap: 18px;
}

#compareChart,
.center > canvas#effortChart {
  display: block;
  width: 100% !important;
  max-width: 100%;
  margin-top: 18px;
}

canvas {
  background: var(--bg-surface) !important;
  border-radius: var(--radius);
  padding: 14px 16px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  transition: background-color var(--transition), border-color var(--transition), box-shadow var(--transition);
}

/* ----- Map ----- */
#map {
  height: 350px;
  margin-top: 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  z-index: 0;
}

/* ----- Tips ----- */
.tips {
  margin-top: 20px;
  padding: 18px 20px;
  background: var(--bg-surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  transition: background-color var(--transition), border-color var(--transition);
}

.tips h3 {
  margin: 0 0 12px;
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.tip {
  padding: 10px 14px;
  margin-bottom: 8px;
  border-radius: var(--radius-xs);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.9rem;
  cursor: default;
  transition: border-color var(--transition), background var(--transition), transform 0.15s ease;
}

.tip:last-child {
  margin-bottom: 0;
}

.tip:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: translateX(2px);
}

/* ----- History list (JS uses .history-item) ----- */
#history .history-item {
  font-size: 0;
  padding: 14px 12px;
  margin-bottom: 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  transition:
    border-color var(--transition),
    box-shadow var(--transition),
    background var(--transition);
}

#history .history-item:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
  background: var(--bg-surface);
}

body.dark #history .history-item:hover {
  background: rgba(45, 212, 191, 0.06);
}

#history .history-item strong {
  display: block;
  font-size: 0.95rem;
  color: var(--text-primary);
  margin-bottom: 4px;
}

#history .history-item small {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

/* Two buttons per row; overrides global button { width:100% } */
#history .history-item button {
  width: calc(50% - 3px);
  display: inline-block;
  vertical-align: top;
  box-sizing: border-box;
  margin-top: 6px;
  margin-right: 3px;
  padding: 7px 6px;
  font-size: 0.72rem;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

#history .history-item button:nth-child(6),
#history .history-item button:nth-child(8) {
  margin-right: 0;
}

#history .history-item button:hover {
  transform: translateY(-1px);
}

/* Legacy selector if any static items used .item */
#history .item {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  border-radius: var(--radius-xs);
  transition: background var(--transition);
}

#history .item:hover {
  background: var(--accent-soft);
}

/* ----- Ride score ----- */
.score-box {
  background: linear-gradient(145deg, var(--bg-elevated) 0%, var(--bg-surface) 100%);
  color: var(--text-primary);
  padding: 20px;
  border-radius: var(--radius);
  text-align: center;
  margin-top: 16px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  transition: background-color var(--transition), border-color var(--transition);
}

body:not(.dark) .score-box {
  background: linear-gradient(145deg, #0f766e 0%, #0d9488 55%, #115e59 100%);
  color: #f0fdfa;
  border-color: rgba(255, 255, 255, 0.15);
}

body.dark .score-box {
  background: linear-gradient(145deg, #1e3a3a 0%, #134e4a 100%);
  color: #ecfdf5;
  border-color: rgba(45, 212, 191, 0.2);
}

.score-box h3 {
  margin: 0 0 8px;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.9;
}

.big-score {
  font-size: 2.75rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1.1;
  text-shadow: 0 2px 24px rgba(0, 0, 0, 0.15);
}

/* ----- Embed / SEO / FAQ (consistency, no structure change) ----- */
.embed-box {
  max-width: 900px;
  margin: 2rem auto;
  padding: 1.5rem 1.75rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}

.embed-box h3 {
  margin-top: 0;
  color: var(--text-primary);
  font-size: 1.1rem;
}

.embed-box p {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.embed-code textarea {
  width: 100%;
  min-height: 120px;
  padding: 12px;
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-strong);
  background: var(--bg-input);
  color: var(--text-primary);
  resize: vertical;
}

.copy-btn {
  width: auto;
  margin-top: 10px;
  padding: 8px 20px;
}

.seo-faq-container {
  padding: 0 20px 2rem;
  max-width: 900px;
  margin: 0 auto;
}

.seo-box {
  padding: 1.75rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  color: var(--text-secondary);
}

.seo-box h2 {
  color: var(--text-primary);
  margin-top: 0;
}

.seo-box ul {
  padding-left: 1.25rem;
}

.seo-box li {
  margin-bottom: 0.5rem;
}

.faq-box {
  max-width: 900px;
  margin: 0 auto 2rem;
  padding: 0 20px;
}

.faq-box > h2 {
  color: var(--text-primary);
  font-size: 1.25rem;
}

.faq-item {
  padding: 1rem 1.25rem;
  margin-bottom: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition), border-color var(--transition);
}

.faq-item:hover {
  box-shadow: var(--shadow-md);
}

.faq-item h4 {
  margin: 0 0 0.5rem;
  color: var(--text-primary);
  font-size: 1rem;
}

.faq-item p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.similar-tools {
  max-width: 900px;
  margin: 0 auto 2rem;
  padding: 1.25rem 1.5rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.similar-tools h3 {
  margin-top: 0;
  color: var(--text-primary);
}

.scroll-btn-wrapper {
  text-align: center;
  padding: 1rem;
}

#scrollTopBtn {
  width: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 999px;
}

.tool-legal {
  max-width: 900px;
  margin: 0 auto;
  padding: 1.5rem 20px 2.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
}

.tool-disclaimer {
  max-width: 900px;
  margin: 1rem auto;
  padding: 0 20px;
}

/* ----- Fullscreen (behavior unchanged) ----- */
body:fullscreen {
  background: var(--bg-page);
  height: 100vh;
  overflow: hidden;
}

body:fullscreen .layout {
  grid-template-columns: 1fr;
  height: 100%;
  width: 100vw;
}

body:fullscreen .sidebar {
  display: none;
}

body:fullscreen .center {
  height: 100vh;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  min-height: 0;
}

body:fullscreen .charts {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

body:fullscreen #map {
  flex: 2;
  height: auto;
  min-height: 45vh;
  border-radius: var(--radius);
}

body:fullscreen canvas {
  height: 180px !important;
}

body:fullscreen .tips {
  flex: 1;
  overflow: auto;
}

/* ----- Dark mode surfaces (charts / tips / sidebars) ----- */
body.dark .sidebar,
body.dark .tips,
body.dark canvas {
  background: var(--bg-surface);
  color: var(--text-primary);
}

body.dark .compare-panel,
body.dark .embed-box,
body.dark .seo-box,
body.dark .faq-item,
body.dark .similar-tools {
  background: var(--bg-surface);
}

body.dark .tool-header {
  background: var(--bg-surface);
}

body.dark #history .item:hover {
  background: var(--accent-soft);
}
