/**
 * Project: Compare My Commute (CMC)
 * File:    CMC-style.css
 * Version: 1.02.003
 */

/* ======================================================================
   1. THEME TOKENS
   Three themes, selected by <html data-theme="green|light|dark">.
   Green is the default: a darker green with soft gradients, chosen to look
   at home on a web page rather than loud. Every colour used elsewhere in
   this file comes from these variables, so a theme is only ever defined here.
   The heat colours (--heat-0 .. --heat-10, best to worst) are written by
   CMC-script.js from the theme and the user's colour-scale choice.
   ====================================================================== */

:root,
html[data-theme="green"] {
  color-scheme: dark;
  --bg-1: #08170f;
  --bg-2: #123524;
  --surface-1: #143a2a;
  --surface-2: #184532;
  --surface-solid: #143a2a;
  --text: #e9f6ee;
  --muted: #a9c8b6;
  --accent: #6ee7a0;
  --accent-2: #7cc4ff;
  --on-accent: #06210f;
  --border: #2b5c43;
  --border-strong: #46805f;
  --input-bg: #0e281c;
  --focus: #ffe27a;
  --danger: #ff9a90;
  --track: rgba(255, 255, 255, 0.14);
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}

html[data-theme="light"] {
  color-scheme: light;
  --bg-1: #f7faf8;
  --bg-2: #e6efe9;
  --surface-1: #ffffff;
  --surface-2: #f6faf7;
  --surface-solid: #ffffff;
  --text: #16261d;
  --muted: #4f655a;
  --accent: #1b7a4b;
  --accent-2: #2a6fb0;
  --on-accent: #ffffff;
  --border: #cddbd2;
  --border-strong: #8fa89a;
  --input-bg: #ffffff;
  --focus: #a15c00;
  --danger: #b3261e;
  --track: rgba(0, 0, 0, 0.1);
  --shadow: 0 4px 14px rgba(20, 50, 35, 0.12);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg-1: #0d1012;
  --bg-2: #171c20;
  --surface-1: #1c2125;
  --surface-2: #21272c;
  --surface-solid: #1c2125;
  --text: #e7eaec;
  --muted: #9ba6ac;
  --accent: #5fcf92;
  --accent-2: #7cb7ff;
  --on-accent: #06210f;
  --border: #2e363c;
  --border-strong: #4a555c;
  --input-bg: #14181b;
  --focus: #ffe27a;
  --danger: #ff9a90;
  --track: rgba(255, 255, 255, 0.14);
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
}

/* Heat colours: fallbacks until the script sets the real ones. */
:root {
  --heat-0: #4ade80; --heat-1: #7ade6c; --heat-2: #a6dd5c; --heat-3: #cfd85a; --heat-4: #f0d25e;
  --heat-5: #f4d35e; --heat-6: #f5be5e; --heat-7: #f6a760; --heat-8: #f68e64; --heat-9: #f77a68; --heat-10: #f87171;
}

/* One class per heat step: components read --heat. */
.h0 { --heat: var(--heat-0); }   .h1 { --heat: var(--heat-1); }   .h2 { --heat: var(--heat-2); }
.h3 { --heat: var(--heat-3); }   .h4 { --heat: var(--heat-4); }   .h5 { --heat: var(--heat-5); }
.h6 { --heat: var(--heat-6); }   .h7 { --heat: var(--heat-7); }   .h8 { --heat: var(--heat-8); }
.h9 { --heat: var(--heat-9); }   .h10 { --heat: var(--heat-10); }

/* ======================================================================
   2. BASE
   ====================================================================== */

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

html { -webkit-text-size-adjust: 100%; background-color: var(--bg-1); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background-color: var(--bg-1);
  background-image: linear-gradient(165deg, var(--bg-1) 0%, var(--bg-2) 55%, var(--bg-1) 100%);
  background-attachment: fixed;
  font: 1rem/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

[hidden] { display: none !important; }

h1, h2, h3, h4, h5 { line-height: 1.25; margin: 0 0 0.5rem; }
h1 { font-size: clamp(1.5rem, 1.1rem + 1.6vw, 2.2rem); }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.15rem; }
h4 { font-size: 1rem; }
p { margin: 0 0 0.75rem; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9em; background: var(--track); padding: 0.1em 0.35em; border-radius: 0.3em; }
small { display: block; color: var(--muted); font-weight: 400; }

.wrap { width: min(100% - 2rem, 74rem); margin-inline: auto; }
.muted, .hint { color: var(--muted); }
.hint { font-size: 0.85rem; margin: 0.3rem 0 0; }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip { position: absolute; left: -999px; top: 0; background: var(--accent); color: var(--on-accent); padding: 0.6rem 1rem; z-index: 10; }
.skip:focus { left: 0.5rem; top: 0.5rem; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ======================================================================
   3. HEADER AND CONTROLS
   ====================================================================== */

.site-head {
  background: linear-gradient(120deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0));
  border-bottom: 1px solid var(--border);
  padding: 1.25rem 0;
}
.head-inner { display: flex; flex-wrap: wrap; gap: 1rem 2rem; align-items: center; justify-content: space-between; }
.brand { display: flex; gap: 1rem; align-items: center; flex: 1 1 24rem; }
.brand img { flex: none; width: 138px; height: 138px; }
.brand p { margin: 0.25rem 0 0; color: var(--muted); max-width: 46rem; }
.controls { display: flex; flex-wrap: wrap; gap: 1rem; }
.control { display: flex; flex-direction: column; gap: 0.3rem; }
.control-label { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

/* Segmented control: used for the theme buttons and the cost basis choice. */
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 0.6rem; overflow: hidden; background: var(--input-bg); }
.seg-btn, .seg-opt span {
  display: block; padding: 0.5rem 0.9rem; font: inherit; color: var(--text);
  background: transparent; border: 0; cursor: pointer;
}
.seg-btn + .seg-btn, .seg-opt + .seg-opt { border-left: 1px solid var(--border-strong); }
.seg-btn[aria-pressed="true"], .seg-opt input:checked + span { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.seg-opt { position: relative; display: block; }
.seg-opt input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg-opt input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: -3px; }

/* ======================================================================
   4. CARDS, SECTIONS, BUTTONS
   ====================================================================== */

.app { padding-block: 1.5rem 3rem; display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.5rem; }

/* Grid children may shrink below their content width; wide tables then scroll
   inside their own .table-wrap instead of stretching the whole page. */
.app > *, .cats > *, .summary-grid > *, .plans > *, .insights > *, #cmc-compare-body > *, .ranking > *, .bars > * { min-width: 0; }

.card {
  background: linear-gradient(160deg, var(--surface-1), var(--surface-2));
  border: 1px solid var(--border);
  border-radius: 0.9rem;
  padding: 1.25rem;
  box-shadow: var(--shadow);
}
.section-head { margin-bottom: 0.75rem; }
.lead { color: var(--muted); margin-bottom: 1rem; }
.section-head .lead { margin-bottom: 0; }

.notice { padding: 0.7rem 0.9rem; border: 1px solid var(--border-strong); border-radius: 0.6rem; background: var(--track); margin: 0.5rem 0; }
.notice.is-warn { border-color: var(--focus); }

.btn {
  font: inherit; font-weight: 600; cursor: pointer; color: var(--text);
  background: var(--surface-solid); border: 1px solid var(--border-strong);
  padding: 0.55rem 1rem; border-radius: 0.6rem;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.btn-danger { color: var(--danger); }
.btn-small { padding: 0.3rem 0.65rem; font-size: 0.85rem; }

.why-line { margin: 0; font-size: 1.05rem; line-height: 1.45; text-wrap: balance; }
.why-line a { color: var(--accent); font-weight: 600; white-space: nowrap; }
.toolbar { display: flex; flex-wrap: wrap; gap: 0.75rem 1.5rem; align-items: center; }
.toolbar-text { margin: 0; flex: 1 1 18rem; }
.toolbar-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.status { flex: 1 1 100%; margin: 0; min-height: 1.4em; color: var(--muted); font-size: 0.9rem; }
.status.is-error { color: var(--danger); }

/* ======================================================================
   5. FORMS
   ====================================================================== */

.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(13.5rem, 1fr)); gap: 0.9rem 1.1rem; }
.fields-3 { grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); }
.fields-4 { grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); }
.field { display: flex; flex-direction: column; min-width: 0; }
.field[hidden], .ebike-note[hidden] { display: none; }
.ebike-note { grid-column: 1 / -1; margin: 0.25rem 0 0; }
.field label { font-weight: 600; font-size: 0.92rem; margin-bottom: 0.3rem; }
.unit { font-weight: 400; color: var(--muted); }

input[type="number"], input[type="text"], select {
  width: 100%; font: inherit; color: var(--text);
  background: var(--input-bg); border: 1px solid var(--border-strong);
  border-radius: 0.5rem; padding: 0.5rem 0.65rem; min-height: 2.5rem;
}
input[type="color"] { width: 100%; height: 2.5rem; padding: 0.15rem; background: var(--input-bg); border: 1px solid var(--border-strong); border-radius: 0.5rem; }
input:disabled, select:disabled { opacity: 0.6; }

.pair { display: flex; align-items: center; gap: 0.4rem; }
.pair input { width: 5.5rem; }
.pair span { color: var(--muted); }

.field-check { justify-content: flex-start; }
.check, .switch { display: inline-flex; gap: 0.55rem; align-items: center; cursor: pointer; font-weight: 600; }
.field-check .check { margin-bottom: 0; }
input[type="checkbox"] { width: 1.25rem; height: 1.25rem; accent-color: var(--accent); flex: none; }

.calc-line { margin-top: 1rem; padding: 0.75rem 1rem; border-radius: 0.6rem; background: var(--track); }
.calc-formula { margin: 0.15rem 0; }

/* ======================================================================
   6. CATEGORY CARDS
   ====================================================================== */

/* Eight collapsed option cards sit in rows of four, so all of them show above the fold.
   A card that is opened takes the full row, so its fields have room. */
.cats { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr)); gap: 1rem; align-items: start; }
.cat:has(.cat-details[open]) { grid-column: 1 / -1; }
.cat {
  background: linear-gradient(160deg, var(--surface-1), var(--surface-2));
  border: 1px solid var(--border); border-radius: 0.9rem; box-shadow: var(--shadow); overflow: hidden;
}
.cat-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.8rem; padding: 0.8rem 1rem; border-bottom: 1px solid var(--border); }
.cat-icon { flex: none; width: 115px; height: 115px; }
.cat-title { flex: 1 1 7rem; min-width: 0; }
.cat-title h3 { margin: 0; line-height: 1.2; }
.cat-title p { margin: 0; color: var(--muted); font-size: 0.9rem; }
.cat-body { border: 0; margin: 0; padding: 1rem 1.25rem 1.25rem; min-width: 0; }
.group + .group { margin-top: 1.1rem; }
.group h4 { color: var(--accent); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.6rem; }
/* Fold-away details: closed cards stay short, so eight options remain easy to scan. */
.cat-details > summary {
  cursor: pointer; font-weight: 600; padding: 0.5rem 1rem; color: var(--accent);
  list-style: none;
}
.cat-details[open] > summary { border-bottom: 1px solid var(--border); }
.cat-details > summary::-webkit-details-marker { display: none; }
.cat-details > summary::before { content: "▸ "; }
.cat-details[open] > summary::before { content: "▾ "; }
.cat-details .when-open { display: none; }
.cat-details[open] .when-open { display: inline; }
.cat-details[open] .when-closed { display: none; }
.cat-details:not([open]) > .cat-body { display: none; }
.cat-details > summary:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }
.field.is-included { opacity: 0.5; }
.cat.is-off .cat-body { opacity: 0.45; }
.cat.is-off .cat-icon { filter: grayscale(1); opacity: 0.6; }
.cat:not(.is-off) { border-color: var(--accent); }

/* ======================================================================
   7. COST AND TIME BY OPTION
   ====================================================================== */

.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 34rem), 1fr)); gap: 1rem; align-items: start; }
.sum-head { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.75rem; }
.sum-head img { width: 86px; height: 86px; }
.sum-head h3 { margin: 0; }

/* position: relative makes the wrapper the containing block for the absolutely
   positioned .sr-only captions inside it, so they scroll with the table instead of
   escaping it and widening the page. */
.table-wrap { position: relative; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 0.5rem 0.65rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
thead th { font-size: 0.85rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
th[scope="row"] { font-weight: 600; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.facts { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.3rem 1rem; margin: 1rem 0 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

.breakdown-wrap { margin-top: 1rem; }
.breakdown-wrap summary { cursor: pointer; font-weight: 600; }
.breakdown { list-style: none; margin: 0.6rem 0 0; padding: 0; display: grid; gap: 0.4rem; }
.breakdown li { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(4rem, 1fr) 5.5rem; gap: 0.6rem; align-items: center; font-size: 0.9rem; }
.bd-amount { text-align: right; font-variant-numeric: tabular-nums; }
.bd-variable { --heat: var(--accent); }
.bd-fixed { --heat: var(--accent-2); }

.ranking { margin-top: 1rem; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 24rem), 1fr)); gap: 1.5rem; }

/* ======================================================================
   8. PROGRESS BARS (used for every bar chart: no inline styles needed)
   The bar colour comes from --heat, set by an h0..h10 class.
   ====================================================================== */

progress.bar {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 0.8rem; border: 0; border-radius: 999px; overflow: hidden;
  background: var(--track); color: var(--heat, var(--accent));
}
progress.bar::-webkit-progress-bar { background: var(--track); border-radius: 999px; }
progress.bar::-webkit-progress-value { background: currentColor; border-radius: 999px; }
progress.bar::-moz-progress-bar { background: currentColor; border-radius: 999px; }

.rank-group h3, .rank-group h4 { margin-bottom: 0.6rem; }
.rank-row { display: grid; grid-template-columns: minmax(6rem, 0.9fr) minmax(5rem, 2fr) minmax(5rem, auto); gap: 0.6rem; align-items: center; margin-bottom: 0.45rem; }
.rank-label { display: flex; align-items: center; gap: 0.4rem; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.rank-value { text-align: right; font-variant-numeric: tabular-nums; }

/* ======================================================================
   9. SCENARIO BUILDER (week grid)
   ====================================================================== */

#cmc-compare-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem; margin-bottom: 1rem; }
/* Scenario cards: one column on phones and tablets, exactly two on desktop (the baseline
   always first, then one scenario beside it, further ones filling the rows below). */
.plans { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem; align-items: start; }
@media (min-width: 60rem) {
  .plans { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.plan-base { border-color: var(--accent); }
.plan-head { display: flex; gap: 0.6rem; align-items: center; justify-content: space-between; margin-bottom: 0.6rem; }
.plan-head h3 { margin: 0; }
.plan-name { font-weight: 700; }

.matrix th, .matrix td { text-align: center; padding: 0.4rem 0.5rem; }
.matrix tbody th { text-align: left; white-space: nowrap; }
.matrix img { vertical-align: middle; }

/* The week grid uses real radio buttons, restyled as large round targets. */
input.pick {
  -webkit-appearance: none; appearance: none; display: inline-grid; place-content: center;
  width: 1.7rem; height: 1.7rem; min-height: 0; padding: 0; margin: 0; cursor: pointer;
  border: 2px solid var(--border-strong); border-radius: 50%; background: var(--input-bg);
}
input.pick::before { content: ""; width: 0.8rem; height: 0.8rem; border-radius: 50%; background: var(--on-accent); transform: scale(0); transition: transform 0.12s ease-in-out; }
input.pick:checked { background: var(--accent); border-color: var(--accent); }
input.pick:checked::before { transform: scale(1); }

.plan-counts { margin: 0.6rem 0 0; font-size: 0.9rem; color: var(--muted); }
.plan-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-top: 0.75rem; font-size: 0.9rem; }
.plan-tools select { width: auto; min-height: 2.1rem; padding: 0.25rem 0.5rem; }
.tools-label { font-weight: 600; }
.plans-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; }
.plans-actions .hint { margin: 0; }

/* ======================================================================
   10. RESULTS
   ====================================================================== */

.results-head { display: flex; flex-wrap: wrap; gap: 0.75rem 1.5rem; align-items: center; justify-content: space-between; }
.results-head h3 { margin: 0; }
.sub { margin: 1.5rem 0 0.6rem; color: var(--accent); }

.results-table .name-col { min-width: 9rem; }
.results-table th.grp { text-align: center; color: var(--text); border-bottom: 2px solid var(--border-strong); }
.results-table .row-base th, .results-table .row-base td { border-bottom: 2px solid var(--border-strong); }

/* Each result cell is tinted and edged with its heat colour (best to worst). */
td.heat {
  background: color-mix(in srgb, var(--heat) 20%, transparent);
  box-shadow: inset 4px 0 0 var(--heat);
  font-weight: 600;
}

.diff .arrow { margin-right: 0.35rem; }
.arrow.good { color: var(--heat-0); }
.arrow.bad { color: var(--heat-10); }

.bars { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 24rem), 1fr)); gap: 1.5rem; }

.insights { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr)); gap: 1rem; }
.insight { box-shadow: none; background: color-mix(in srgb, var(--accent) 9%, var(--surface-solid)); }
.insight h5 { font-size: 1.05rem; margin-bottom: 0.1rem; }
.insight-counts { color: var(--muted); font-size: 0.9rem; }
.insight-list { margin: 0; padding-left: 1.2rem; display: grid; gap: 0.4rem; }
.insight-list .be { font-weight: 600; }

/* ======================================================================
   11. COLOUR SCALE LEGEND, PRIVACY, FOOTER
   ====================================================================== */

.legend { display: flex; align-items: center; gap: 0; margin-top: 1rem; }
.legend .swatch { flex: 1 1 0; height: 1rem; background: var(--heat); }
.legend .swatch:first-of-type { border-radius: 999px 0 0 999px; }
.legend .swatch:last-of-type { border-radius: 0 999px 999px 0; }
.legend-end { font-size: 0.8rem; color: var(--muted); padding: 0 0.6rem; }

.privacy p { max-width: 62rem; }

.site-foot { border-top: 1px solid var(--border); padding: 1.25rem 0 2rem; color: var(--muted); font-size: 0.9rem; }
.site-foot p { margin: 0 0 0.3rem; }
.site-foot a { color: var(--accent); }

/* ======================================================================
   12. SMALL SCREENS AND PREFERENCES
   ====================================================================== */

@media (max-width: 40rem) {
  /* Keep the whole week visible in the scenario grid: let option names wrap and tighten the columns. */
  .matrix th, .matrix td { padding: 0.35rem 0.15rem; }
  .matrix tbody th { white-space: normal; width: 6rem; font-size: 0.85rem; line-height: 1.2; }
  .matrix tbody th img { width: 26px; height: 26px; }
  input.pick { width: 1.6rem; height: 1.6rem; }
  .card, .cat-head, .cat-body { padding-left: 0.9rem; padding-right: 0.9rem; }
  .brand img { width: 100px; height: 100px; }
  .cat-icon { width: 96px; height: 96px; }
  .rank-row { grid-template-columns: 1fr; gap: 0.2rem; }
  .rank-value { text-align: left; }
  .breakdown li { grid-template-columns: 1fr auto; }
  .breakdown li progress { grid-column: 1 / -1; order: 3; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

@media print {
  body { background: #fff; color: #000; }
  .site-head .controls, .toolbar, #cmc-settings, .plan-tools, .plans-actions { display: none !important; }
  .card, .cat { box-shadow: none; }
}

/* The difference table has many columns now; tighten it so it fits a desktop without scrolling. */
.diff-table th, .diff-table td { padding-inline: 0.4rem; }
.status:empty { display: none; }

/* ---- Share your result ---- */
.share textarea {
  width: 100%; margin-top: 0.3rem; padding: 0.7rem 0.8rem; font: inherit; line-height: 1.45;
  color: var(--text); background: var(--input-bg); border: 1px solid var(--border-strong);
  border-radius: 0.5rem; resize: vertical;
}
.share h2 { margin: 0 0 0.6rem; }
.btn-share-make { font-size: 1.05rem; padding: 0.6rem 1.1rem; border-color: var(--accent); }
.share-buttons { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; margin-top: 0.4rem; }
.share-btn {
  display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.35rem 0.8rem 0.35rem 0.4rem;
  font: inherit; font-weight: 600; color: var(--text); text-decoration: none; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 0.6rem;
}
.share-btn:hover, .share-btn:focus-visible { border-color: var(--accent); }
.share-btn img { display: block; }
