/* The crash map's own rules on top of the Proactive Health AIO kit (kit/css, the 1.3.0 export from when it was called dayring).
   The shell (menu, head, About dialog) follows the Ready to Train? web version. Data colours were checked with the dataviz
   validator: the hex ramp is one hue, lighter to darker on the light map (more crashes = darker) and the other way
   round on the dark map, each step clearly apart and the faintest step at least 2:1 against its basemap; the two
   "higher / lower than Victoria" colours pass the colour-vision checks in both modes. */

:root {
  --hex-0: #e18f4b; --hex-1: #db702c; --hex-2: #cf521b; --hex-3: #bc3718; --hex-4: #a3231e; --hex-5: #871823;
  --crash: #a3231e;
  --sensor: #52607a;
  --diff-up: #048e7a;
  --diff-down: #6a53bd;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-mode="light"]) {
    --hex-0: #b9402c; --hex-1: #d45624; --hex-2: #e97125; --hex-3: #f98f38; --hex-4: #ffb164; --hex-5: #fed2a0;
    --crash: #f98f38;
    --sensor: #a3b0c8;
    --diff-up: #02a99b;
    --diff-down: #927fe7;
  }
}
:root[data-mode="dark"] {
  --hex-0: #b9402c; --hex-1: #d45624; --hex-2: #e97125; --hex-3: #f98f38; --hex-4: #ffb164; --hex-5: #fed2a0;
  --crash: #f98f38;
  --sensor: #a3b0c8;
  --diff-up: #02a99b;
  --diff-down: #927fe7;
}

/* ---- the menu (kit .side): the logo a little larger, as in Ready to Train? ---- */
.side .brand span { font-weight: 700; letter-spacing: -.01em; }
.side .brand svg { width: 28px; height: 28px; flex: none; }

/* between phone and laptop widths (a half-screen window, a tablet) the kit would move the menu to a bottom tab bar;
   here it stays on the left as a narrow column, each page an icon with its name under it. Phones keep the tab bar. */
@media (min-width: 641px) and (max-width: 899px) {
  body:has(> .side) { padding-left: 76px; padding-bottom: 0; }
  body > .side {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 20; width: 76px; overflow-y: auto; overscroll-behavior: contain;
    flex-direction: column; align-items: center; justify-content: flex-start; gap: var(--s-4);
    padding: var(--s-5) var(--s-1) 14px; background: var(--surface); border-right: 1px solid var(--line); border-bottom: 0;
  }
  body > .side .brand span { display: none; }
  body > .side .side-nav {
    position: static; display: flex; flex-direction: column; gap: var(--s-1); width: 100%; padding: 0;
    background: none; border-top: 0; backdrop-filter: none; -webkit-backdrop-filter: none;
  }
  body > .side .side-nav a { flex-direction: column; justify-content: center; gap: 3px; min-height: 56px; padding: var(--s-1) 2px;
    font-size: 10.5px; font-weight: 600; white-space: normal; text-align: center; line-height: 1.2; }
  body > .side .side-nav a svg { width: 20px; height: 20px; }
  body > .side .side-nav a[aria-current="page"] { background: var(--accent-soft); }
  body > .side .side-tools { margin-top: auto; flex-direction: column; flex-wrap: nowrap; padding: 6px 0; }
  body > .side .demo-badge { writing-mode: vertical-rl; padding: var(--s-2) 3px; }
}

/* ---- the head: both names on one line, three lines for a first-time reader, then the data line ---- */
.head { margin-bottom: var(--s-4); }
.head h1 .h1-alt { margin-left: var(--s-2); font-size: var(--t-lg); font-weight: 600; color: var(--ink-2); letter-spacing: 0; }
@media (min-width: 900px) { .head h1 .h1-alt { white-space: nowrap; } }
@media (max-width: 899px) { .head h1 .h1-alt { display: block; margin: var(--s-1) 0 0; font-size: var(--t-md); } }
.head .brief { margin: var(--s-2) 0; display: grid; grid-template-columns: max-content minmax(0, 1fr); column-gap: var(--s-3); row-gap: 5px; max-width: 128ch; font-size: var(--t-sm); line-height: 1.55; }
.brief-row { display: contents; }
.brief-row dt { font-weight: 700; color: var(--ink); white-space: nowrap; }
.brief-row dd { margin: 0; color: var(--ink-2); }
@media (max-width: 640px) { .head .brief { grid-template-columns: 1fr; row-gap: 2px; } .brief-row dd { margin-bottom: var(--s-2); } }
.head .data-line { margin: var(--s-1) 0 0; display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-1) var(--s-4); font-size: var(--t-xs); color: var(--ink-3); }
.solves-link { display: inline-flex; align-items: center; gap: 5px; font-weight: 650; }
.link-button { display: inline-flex; align-items: center; gap: 5px; padding: 0; border: 0; background: none; color: var(--accent); font-size: var(--t-xs); font-weight: 600; cursor: pointer; }
.link-button:hover { text-decoration: underline; text-underline-offset: 3px; }
.solves-link .metric-icon, .link-button .metric-icon { width: 15px; height: 15px; flex: none; }

/* ---- a numbered step marker (the tip bar, the guide, the project cards) ---- */
.step-n { display: inline-grid; place-items: center; flex: none; width: 22px; height: 22px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 700; line-height: 1; }

/* ---- the three-step tip above the map; "Got it" hides it for good, the menu keeps the full guide ---- */
.tips { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2) var(--s-3); margin: 0 0 var(--s-4); padding: var(--s-3) var(--s-4);
  border: 1px dashed var(--line-2); border-radius: var(--r-lg); background: var(--surface); font-size: var(--t-sm); }
.tips[hidden] { display: none; }
.tips > .metric-icon { flex: none; width: 20px; height: 20px; color: var(--accent); }
.tips-lead { font-weight: 700; }
.tips-steps { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--s-1) var(--s-4); flex: 1 1 520px; min-width: 0; counter-reset: tip; }
.tips-steps li { counter-increment: tip; display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); }
.tips-steps li::before { content: counter(tip); display: inline-grid; place-items: center; flex: none; width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-size: 11.5px; font-weight: 700; }
.tips-end { display: inline-flex; align-items: center; gap: var(--s-3); margin-left: auto; white-space: nowrap; }
.tips-end a { font-weight: 600; }

/* ---- a page's title block and the heading of a later part ---- */
.page-intro { margin: var(--s-2) 0 var(--s-4); }
.page-intro h2 { margin: 0; font-size: var(--t-xl); font-weight: 700; letter-spacing: -.015em; }
.page-intro p { margin: var(--s-1) 0 0; color: var(--ink-2); font-size: var(--t-sm); max-width: 82ch; }
.page-lede { margin: 0 0 var(--s-4); color: var(--ink-2); font-size: var(--t-sm); max-width: 82ch; }
.section-head { margin: var(--s-6) 0 var(--s-1); padding-top: var(--s-4); border-top: 1px solid var(--line); font-size: var(--t-xl); font-weight: 700; letter-spacing: -.015em; }

/* ---- How to use: five steps and a note in two columns, each with what it looks like on the map page ---- */
.guide-steps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-4); align-items: start; }
@media (max-width: 1080px) { .guide-steps { grid-template-columns: 1fr; } }
.guide-step { margin: 0; display: flex; flex-direction: column; gap: var(--s-3); min-width: 0; }
.guide-step h3, .brief-card h3, .ai-note h3 { margin: 0; display: flex; align-items: center; gap: var(--s-2); font-size: var(--t-md); font-weight: 680; }
.guide-step ul, .brief-card ul { margin: 0; padding-left: 1.1em; display: grid; gap: var(--s-2); font-size: var(--t-sm); line-height: 1.6; color: var(--ink); }
.guide-step li::marker, .brief-card li::marker { color: var(--ink-3); }
.guide-step.care .step-n { background: var(--watch-soft); color: var(--watch-ink); }
.guide-key { padding: var(--s-3); border-radius: var(--r-md); background: var(--surface-2); gap: var(--s-2) var(--s-3); }
.guide-key .tool { cursor: default; pointer-events: none; background: var(--surface); }
.seg.demo > span { padding: var(--s-1) var(--s-3); border-radius: var(--r-pill); font-size: var(--t-xs); font-weight: 600; color: var(--ink-2); }
.seg.demo > span.on { background: var(--seg-on); color: var(--ink); box-shadow: var(--seg-on-edge); }
.cmp-demos { display: flex; flex-direction: column; }
.cmp-demo { display: grid; align-items: center; gap: 2px var(--s-3); padding: 6px 0;
  grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "factor vals" "cond d" "bar bar"; }
.cmp-demo + .cmp-demo { border-top: 1px solid var(--line); }
.cmp-demo > .dbar { grid-area: bar; margin-top: 4px; }
.cmp-demo .cmp-factor::before { content: none; }

.try-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s-4); }
@media (max-width: 1280px) { .try-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .try-grid { grid-template-columns: 1fr; } }
.try-card { margin: 0; display: flex; flex-direction: column; gap: var(--s-2); min-width: 0; }
.try-q { margin: 0; font-size: var(--t-sm); font-weight: 650; line-height: 1.5; }
.try-how { margin: 0 0 var(--s-1); font-size: var(--t-xs); color: var(--ink-3); }
.try-card .btn { margin-top: auto; align-self: flex-start; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 34px; padding: 0 var(--s-4); border-radius: var(--r-pill);
  border: 1px solid transparent; font-size: var(--t-sm); font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn.soft { background: var(--accent-soft); color: var(--accent); }
.btn.soft:hover { filter: brightness(.97); }

/* ---- The project: three cards (the assignment, the problem, what came out), then the Tableau dashboard ---- */
.brief-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-4); align-items: stretch; margin-bottom: var(--s-3); }
@media (max-width: 1180px) { .brief-grid { grid-template-columns: 1fr; } }
.brief-card { margin: 0; display: flex; flex-direction: column; gap: var(--s-3); min-width: 0; }
.brief-try { margin: auto 0 0; display: flex; flex-wrap: wrap; gap: var(--s-1) var(--s-3); align-items: baseline; font-size: var(--t-sm); }
.brief-try span { color: var(--ink-3); }
.brief-try a { font-weight: 600; }
.shots { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-4); }
@media (max-width: 900px) { .shots { grid-template-columns: 1fr; } }
.shot { margin: 0; min-width: 0; }
.shot img { display: block; width: 100%; height: auto; border-radius: var(--r-md); border: 1px solid var(--line); background: var(--surface-2); }
.shot figcaption { margin-top: var(--s-2); font-size: var(--t-xs); color: var(--ink-2); }
.ai-note { margin-top: var(--s-5); display: flex; flex-direction: column; gap: var(--s-2); }
.ai-note p { margin: 0; font-size: var(--t-sm); color: var(--ink-2); line-height: 1.6; max-width: 110ch; }

/* ---- About the data & methods (the dialog of Ready to Train?) ---- */
dialog.about { width: min(780px, calc(100vw - 24px)); max-height: calc(100vh - 48px); padding: 0; border: 1px solid var(--line); border-radius: var(--r-lg);
  background: var(--surface); color: var(--ink); box-shadow: 0 24px 60px rgba(0, 0, 0, .25); }
dialog.about::backdrop { background: rgba(10, 12, 18, .45); }
.about-in { padding: var(--s-5) var(--s-6) var(--s-6); font-size: var(--t-sm); line-height: 1.6; }
.about-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); margin-bottom: var(--s-2); }
.about-head h2 { margin: 0; font-size: var(--t-xl); }
.about-in h3 { margin: var(--s-5) 0 var(--s-2); font-size: var(--t-md); }
.about-in p, .about-in li { color: var(--ink-2); }
.about-in ul { padding-left: 1.2em; display: grid; gap: var(--s-2); }
@media (max-width: 640px) { .about-in { padding: var(--s-4); } }

.foot { flex-direction: column; gap: var(--s-1); padding-top: var(--s-4); border-top: 1px solid var(--line); }

/* ---- the map beside a fixed column for the filters and the comparison, so the menu takes its width from the map ---- */
.map-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(340px, 380px); gap: var(--s-4); align-items: stretch; margin-bottom: var(--s-4); }
@media (max-width: 1080px) { .map-row { grid-template-columns: minmax(0, 1fr); } }

/* ---- the map card ---- */
.map-card { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.map-bar { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); flex-wrap: wrap; padding: var(--s-4) var(--s-5) var(--s-3); }
#map { position: relative; flex: 1 1 auto; min-height: 640px; background: var(--surface-2); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.map-foot { padding: var(--s-3) var(--s-5) var(--s-4); display: flex; flex-direction: column; gap: var(--s-2); }
.map-foot .legend { gap: var(--s-2) var(--s-4); align-items: center; }
.map-tools { gap: var(--s-2); }
.map-tools .tool[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.map-tools .tool[hidden] { display: none; }
.map-hint { margin: 0; }
@media (max-width: 640px) {
  .map-bar { padding: var(--s-3) var(--s-4) var(--s-2); }
  .map-foot { padding: var(--s-3) var(--s-4); }
  #map { flex: none; height: 62vh; min-height: 360px; }
}

.map-canvas { position: absolute; left: 0; top: 0; z-index: 1; pointer-events: none; transition: opacity .12s var(--ease); }
.map-box { position: absolute; display: none; z-index: 1; pointer-events: none; border: 1.5px dashed var(--accent); background: var(--accent-soft); border-radius: 4px; }
#map.boxing, #map.boxing canvas { cursor: crosshair !important; }

/* MapLibre's controls in the kit's look */
.maplibregl-map { font-family: var(--font); }
.maplibregl-ctrl-group { background: var(--surface) !important; border: 1px solid var(--line-2); border-radius: var(--r-md) !important; box-shadow: var(--shadow) !important; overflow: hidden; }
.maplibregl-ctrl-group button + button { border-top: 1px solid var(--line) !important; }
.maplibregl-ctrl-group button:not(:disabled):hover { background: var(--surface-2) !important; }
:root[data-mode="dark"] .maplibregl-ctrl-icon { filter: invert(1); }
@media (prefers-color-scheme: dark) { :root:not([data-mode="light"]) .maplibregl-ctrl-icon { filter: invert(1); } }
.maplibregl-ctrl-attrib { background: var(--header) !important; color: var(--ink-3); font-size: 10.5px; }
.maplibregl-ctrl-attrib a { color: var(--ink-2); }
.maplibregl-ctrl-attrib-button { background-color: var(--surface) !important; }

/* legend keys: a hex for the ramp, dots for crashes and sensors */
.key i.hexkey { width: 13px; height: 12px; border-radius: 0; clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%); }
.key i.hexkey.ring { background: var(--accent); position: relative; }
.key i.hexkey.ring::after { content: ""; position: absolute; inset: 2.5px; background: var(--surface); clip-path: inherit; }
.key i.dotkey { width: 10px; height: 10px; border-radius: 50%; }
.key i.dotkey.sel { background: var(--accent); box-shadow: 0 0 0 1.5px var(--surface), 0 0 0 2.5px var(--line-2); }
.key i.dotkey.sensor { width: 14px; height: 14px; border: 1.2px solid var(--sensor); background: color-mix(in srgb, var(--sensor) 28%, transparent); }

.tip.map-tip { white-space: pre-line; max-width: 300px; }

/* ---- filters ---- */
/* one grid for all four rows: the label column is as wide as the longest label, so the age switch stays on one line */
.filters { display: grid; grid-template-columns: max-content minmax(0, 1fr); align-items: center; gap: var(--s-3) var(--s-4); font-size: var(--t-sm); color: var(--ink-2); }
.filter { display: contents; }
.filter select {
  font: inherit; color: var(--ink); background: var(--surface-2); border: 1px solid var(--line-2); border-radius: var(--r-sm);
  height: 32px; padding: 0 var(--s-2); min-width: 0; width: 100%;
}
.filter .seg { justify-self: start; flex-wrap: wrap; }
.filter .seg button { padding-left: 10px; padding-right: 10px; }
@media (max-width: 360px) { .filters { grid-template-columns: minmax(0, 1fr); gap: var(--s-1); } }

/* ---- selection vs Victoria ---- */
.cmp-status { margin: 0 0 var(--s-2); }
.cmp-status .chip { white-space: normal; height: auto; min-height: 24px; padding: 3px 10px; }
.cmp-list { display: flex; flex-direction: column; margin-top: var(--s-3); }
details.cmp { border-top: 1px solid var(--line); }
details.cmp summary {
  list-style: none; cursor: pointer; padding: 10px 0; display: grid; align-items: center; gap: 2px var(--s-3);
  grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "factor vals" "cond d" "bar bar";
}
details.cmp summary::-webkit-details-marker { display: none; }
.cmp-factor { grid-area: factor; font-size: var(--t-xs); font-weight: 650; color: var(--ink-3); letter-spacing: .04em; text-transform: uppercase; }
.cmp-factor::before { content: "›"; display: inline-block; width: 12px; color: var(--ink-3); transition: transform .12s var(--ease); }
details.cmp[open] .cmp-factor::before { transform: rotate(90deg); }
.cmp-cond { grid-area: cond; font-weight: 600; font-size: var(--t-md); min-width: 0; }
.cmp-vals { grid-area: vals; font-size: var(--t-xs); color: var(--ink-2); text-align: right; }
.cmp-d { grid-area: d; font-weight: 650; text-align: right; }
.cmp-d small { font-weight: 550; color: var(--ink-3); font-size: var(--t-xs); }
details.cmp summary > .dbar { grid-area: bar; margin-top: 4px; }
.dbar { position: relative; display: block; height: 8px; border-radius: 4px; background: var(--c-band); overflow: hidden; min-width: 60px; }
.dbar::before { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--c-axis); }
.dbar > span { position: absolute; top: 0; bottom: 0; min-width: 2px; }
.cmp-axis { display: flex; justify-content: space-between; padding-top: var(--s-1); border-top: 1px solid var(--line); }
.cmp-table { margin: 0 0 var(--s-3); }
.cmp-table th, .cmp-table td { font-size: var(--t-xs); padding-top: 6px; padding-bottom: 6px; }
.cmp-table .r { text-align: right; white-space: nowrap; }
.cmp-table tr.top th[scope="row"] { font-weight: 700; }
.cmp-table td.gap { width: 38%; }
.cmp-table td.gap .dbar { display: inline-block; vertical-align: middle; width: calc(100% - 46px); }
.cmp-table td.gap .num { display: inline-block; width: 42px; text-align: right; }

/* ---- overview and limits ---- */
.facts.overview { margin-top: 0; }
.facts.overview div { align-items: baseline; }
.facts.overview dt { flex: none; width: 92px; }
.facts.overview dd { font-weight: 500; text-align: left; flex: 1; }
.limits { margin: var(--s-2) 0 0; padding-left: 1.2em; color: var(--ink-2); line-height: 1.55; }
.limits li { margin: 2px 0; }
.lim-more { margin: var(--s-3) 0 0; }
