/* ===========================================================================
   TdF Time — Tour de France 2026
   Light, minimal, mobile-first. TdF-yellow accent + jersey color coding.
   =========================================================================== */

:root {
  /* Brand / accent */
  --tdf-yellow: #ffd500;
  --tdf-yellow-deep: #f0c000;

  /* Jersey-derived stage-type colors */
  --type-flat: #16a34a;        /* green points jersey  */
  --type-hilly: #f59e0b;       /* amber                */
  --type-mountain: #e11d48;    /* polka-dot red (KOM)  */
  --type-tt: #2563eb;          /* against the clock    */
  --type-rest: #94a3b8;        /* rest day             */

  /* Climb category chips */
  --cat-hc: #7f1d1d;
  --cat-1: #dc2626;
  --cat-2: #ea580c;
  --cat-3: #ca8a04;
  --cat-4: #16a34a;

  /* Surface / ink */
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #fbfbf9;
  --ink: #1c1c1a;
  --ink-2: #55554f;
  --ink-3: #8a8a82;
  --line: #e7e7e1;
  --line-2: #efefe9;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 14px rgba(0,0,0,.05);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.06);

  --maxw: 720px;
  --pad: 16px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ------------------------------------------------------------------ header */

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}

.app-header__inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 10px var(--pad) 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.app-title { display: flex; align-items: center; gap: 10px; min-width: 0; }

.app-title__text { display: flex; flex-direction: column; line-height: 1.05; min-width: 0; }
.app-title__text strong { font-size: 17px; letter-spacing: -.01em; }
.app-title__text small { font-size: 11px; color: var(--ink-3); }

/* view tabs */
.viewtabs {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 var(--pad) 8px;
  display: flex;
  gap: 6px;
}
.viewtab {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink-2);
  font: inherit; font-size: 14px; font-weight: 600;
  padding: 7px 16px;
  border-radius: 999px;
  cursor: pointer;
}
.viewtab.is-active {
  background: var(--tdf-yellow);
  border-color: var(--tdf-yellow-deep);
  color: #2a2400;
}

/* --------------------------------------------------------------------- main */

#main { max-width: var(--maxw); margin: 0 auto; padding: 12px var(--pad) 60px; }

.view { display: none; }
.view.is-active { display: block; }

.status {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 24px var(--pad);
  color: var(--ink-3);
  text-align: center;
}
.status[hidden] { display: none; }
.status.is-error { color: var(--type-mountain); }

/* --------------------------------------------------------------- list intro */

.list-intro {
  display: flex; flex-wrap: wrap; gap: 8px 18px;
  padding: 4px 4px 14px;
  color: var(--ink-2); font-size: 13px;
}
.list-intro b { color: var(--ink); }

/* -------------------------------------------------------------- stage cards */

.stage {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin: 0 0 12px;
  overflow: hidden;
  scroll-margin-top: 132px;
}
.stage--past { opacity: .5; }
.stage--today {
  border-color: var(--tdf-yellow-deep);
  box-shadow: 0 0 0 2px var(--tdf-yellow), var(--shadow);
}

/* colored left rail by stage type */
.stage::before {
  content: "";
  position: absolute; left: 0; top: 0; bottom: 0; width: 5px;
  background: var(--type, var(--line));
}
[data-type="flat"]     { --type: var(--type-flat); }
[data-type="hilly"]    { --type: var(--type-hilly); }
[data-type="mountain"] { --type: var(--type-mountain); }
[data-type="tt"]       { --type: var(--type-tt); }

.stage__head {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas:
    "badge body"
    "time  time";
  gap: 2px 14px;
  align-items: start;
  width: 100%;
  text-align: left;
  background: none; border: 0; font: inherit; color: inherit;
  padding: 14px 16px;
  cursor: pointer;
}

/* left column: type icon stacked over the stage number */
.stage__badge {
  grid-area: badge;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  padding-top: 2px;
}
.stage__icon { color: var(--type, var(--ink-3)); display: flex; }
.stage__icon svg { width: 30px; height: 30px; display: block; }
.stage__num { display: flex; flex-direction: column; align-items: center; }
.stage__num b { font-size: 21px; line-height: 1; letter-spacing: -.02em; }
.stage__num small { font-size: 9px; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-3); }

/* right column: date/badges, route, metadata — full width */
.stage__body { grid-area: body; min-width: 0; display: flex; flex-direction: column; gap: 3px; }

.stage__meta {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px;
  font-size: 12px; color: var(--ink-2);
}
.stage__date { font-weight: 600; color: var(--ink); }

.stage__route {
  font-size: 16px; font-weight: 600; letter-spacing: -.01em;
}
.stage__route .arrow { color: var(--ink-3); font-weight: 400; }

.stage__info {
  display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px;
  font-size: 12px;
}
.stage__info .stage__type { color: var(--type, var(--ink-2)); font-weight: 700; font-size: 12.5px; }
.stage__info .dist { font-weight: 500; color: var(--ink-3); }
.stage__info > span + span::before {
  content: "·"; margin-right: 6px; color: var(--ink-3); font-weight: 400;
}

/* full-width time row below the text */
.stage__time {
  grid-area: time;
  margin-top: 9px; padding-top: 10px;
  border-top: 1px solid var(--line-2);
  display: flex; align-items: baseline; gap: 8px;
}
.stage__time .lab { font-size: 9px; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-3); }
.stage__time .time { font-size: 21px; font-weight: 700; letter-spacing: -.02em; line-height: 1; }
.stage__time .sub { font-size: 12px; color: var(--ink-3); }

.stage__time {
  grid-area: time;
  text-align: right;
  align-self: center;
  min-width: 86px;
}
.stage__time .lab { font-size: 9px; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-3); display: block; }
.stage__time .time { font-size: 20px; font-weight: 700; letter-spacing: -.02em; line-height: 1.05; }
.stage__time .sub { font-size: 11px; color: var(--ink-3); display: block; margin-top: 1px; }

/* badges */
.badge {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  padding: 2px 7px; border-radius: 999px;
  border: 1px solid transparent; white-space: nowrap;
}
.badge--type { color: #fff; }
.stage[data-type="flat"]     .badge--type { background: var(--type-flat); }
.stage[data-type="hilly"]    .badge--type { background: var(--type-hilly); }
.stage[data-type="mountain"] .badge--type { background: var(--type-mountain); }
.stage[data-type="tt"]       .badge--type { background: var(--type-tt); }
.badge--summit { background: #fff; color: var(--type-mountain); border-color: var(--type-mountain); }
.badge--uphill { background: #fff; color: var(--type-hilly); border-color: var(--type-hilly); }
.badge--rest   { background: #f1f5f9; color: var(--type-rest); border-color: #e2e8f0; }

.chev { color: var(--ink-3); transition: transform .18s ease; }

/* ------------------------------------------------------------ stage detail */

.stage__detail {
  display: none;
  border-top: 1px solid var(--line-2);
  padding: 4px 16px 16px;
}
.stage.is-open .stage__detail { display: block; }

.detail-block { margin-top: 14px; }
.detail-block > h3 {
  margin: 0 0 8px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .08em; color: var(--ink-3); font-weight: 700;
}

/* profile image slot (swappable for SVG later) */
.profile {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden; background: var(--surface-2);
}
.profile img { display: block; width: 100%; height: auto; }
.profile__cap { font-size: 11px; color: var(--ink-3); padding: 6px 10px; border-top: 1px solid var(--line-2); }

/* times row */
.times {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
}
.timecell {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 9px 10px; text-align: center;
}
.timecell .lab { font-size: 9px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); }
.timecell .big { font-size: 18px; font-weight: 700; letter-spacing: -.02em; }
.timecell .fr { font-size: 10px; color: var(--ink-3); }
.timecell--watch { background: #fffbea; border-color: var(--tdf-yellow-deep); }

.watch-note { font-size: 13px; color: var(--ink-2); margin-top: 8px; }
.watch-note b { color: var(--ink); }

/* climbs */
.climbs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.climb {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-2); font-size: 13px;
}
.climb__no {
  flex: none; width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--line);
  color: var(--ink-2); font-weight: 700; font-size: 12px;
}
.climb__cat {
  display: inline-block; color: #fff; font-weight: 800; font-size: 10px;
  padding: 1px 6px; border-radius: 999px; letter-spacing: .02em;
  vertical-align: middle; margin-right: 6px;
}
.climb__cat[data-cat="HC"] { background: var(--cat-hc); }
.climb__cat[data-cat="1"]  { background: var(--cat-1); }
.climb__cat[data-cat="2"]  { background: var(--cat-2); }
.climb__cat[data-cat="3"]  { background: var(--cat-3); }
.climb__cat[data-cat="4"]  { background: var(--cat-4); }
.climb__name { font-weight: 600; min-width: 0; }
.climb__name small { display: block; font-weight: 400; color: var(--ink-3); font-size: 11px; }
.climb__start { display: block; margin-top: 3px; font-size: 12px; font-weight: 700; color: var(--ink); letter-spacing: -.01em; }
.climb__start .lab { font-weight: 400; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; font-size: 9px; margin-right: 4px; }
.climb__stat { text-align: right; color: var(--ink-2); font-size: 12px; white-space: nowrap; }
.climb__stat b { color: var(--ink); }

.no-climbs { font-size: 13px; color: var(--ink-3); font-style: italic; }

/* timetable (collapsible) */
.tt-toggle {
  appearance: none; width: 100%; text-align: left;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  font: inherit; font-size: 13px; font-weight: 600; color: var(--ink-2);
  padding: 9px 12px; cursor: pointer;
  display: flex; align-items: center; justify-content: space-between;
}
.tt-wrap { display: none; margin-top: 8px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tt-wrap.is-open { display: block; }
table.tt { border-collapse: collapse; width: 100%; font-size: 12px; white-space: nowrap; }
table.tt th, table.tt td { padding: 5px 8px; border-bottom: 1px solid var(--line-2); text-align: right; }
table.tt th { position: sticky; top: 0; background: var(--surface); color: var(--ink-3); font-weight: 600; font-size: 10px; text-transform: uppercase; letter-spacing: .04em; }
table.tt td.loc, table.tt th.loc { text-align: left; font-weight: 600; color: var(--ink); }
table.tt tr.is-cp td { background: #fffdf2; }
.tt-picto {
  display: inline-block; min-width: 15px; height: 15px; line-height: 15px; text-align: center;
  border-radius: 4px; font-size: 9px; font-weight: 800; color: #fff; margin-left: 6px;
}
.tt-picto[data-p="n"] { background: var(--type-flat); }
.tt-picto[data-p="1"], .tt-picto[data-p="2"], .tt-picto[data-p="3"], .tt-picto[data-p="4"] { background: var(--type-mountain); }
.tt-picto[data-p="a"] { background: var(--tdf-yellow-deep); color: #2a2400; }
.tt-picto[data-p="r"] { background: var(--ink-3); }

/* ----------------------------------------------------------------- calendar */

.cal-caption { padding: 4px 2px 12px; color: var(--ink-2); font-size: 13px; }

.cal-scroll { padding-bottom: 4px; }
.cal-dow-row, .cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(80px, 1fr));
  gap: 6px;
  min-width: 596px;
}
.cal-dow-row { margin-bottom: 6px; }
.cal-dow {
  text-align: left; padding-left: 2px; font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3);
}
.cal-cell {
  min-height: 104px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); padding: 6px 8px 7px;
  display: flex; flex-direction: column;
  position: relative; min-width: 0;
}
.cal-cell--empty { background: transparent; border-color: transparent; }
.cal-cell--stage { cursor: pointer; border-top: 3px solid var(--type, var(--line)); }
.cal-cell--stage:hover { border-color: var(--type, var(--line)); }
.cal-cell--past { opacity: .5; }
.cal-cell--today { box-shadow: 0 0 0 2px var(--tdf-yellow); border-color: var(--tdf-yellow-deep); }
.cal-cell__dom { font-size: 10px; color: var(--ink-3); font-weight: 700; }
.cal-cell--stage .cal-cell__dom { color: var(--ink-2); }
.cal-cell__flag { display: none; }  /* summit/uphill marker — shown in the mobile icon grid */
.cal-cell__body { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 2px; min-height: 0; }
.cal-cell__stage {
  display: flex; align-items: center; gap: 5px;
  font-size: 13px; font-weight: 800; letter-spacing: -.01em;
  color: var(--type, var(--ink));
}
.cal-cell__stage svg { width: 18px; height: 18px; flex: none; }
.cal-cell__type { font-size: 10.5px; line-height: 1.2; color: var(--ink-2); }
.cal-cell__finish { margin-top: 3px; }
.cal-cell__finish .lab { display: block; font-size: 8px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); }
.cal-cell__finish .t { font-size: 14px; font-weight: 700; letter-spacing: -.02em; }
.cal-cell__rest {
  margin: auto 0; font-size: 11px; font-weight: 700; text-transform: uppercase;
  color: var(--type-rest); letter-spacing: .04em;
}

.cal-legend { margin-top: 18px; display: flex; flex-wrap: wrap; gap: 10px 16px; }
.cal-legend span { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); }
.cal-legend svg { width: 20px; height: 20px; color: var(--type, var(--ink-3)); }

/* narrow screens: keep a real 7-col month grid, but icon-only cells (no text) */
@media (max-width: 680px) {
  .cal-dow-row, .cal-grid { grid-template-columns: repeat(7, 1fr); min-width: 0; gap: 4px; }
  .cal-dow { font-size: 8px; text-align: center; padding-left: 0; letter-spacing: 0; }

  .cal-cell { min-height: 0; aspect-ratio: 1 / 1; padding: 3px; }
  .cal-cell--stage { border-top-width: 3px; }
  .cal-cell__dom { position: absolute; top: 3px; left: 4px; font-size: 9px; }

  /* show only the type icon; hide all text labels */
  .cal-cell__stage span, .cal-cell__type, .cal-cell__finish { display: none; }
  .cal-cell__body { justify-content: center; align-items: center; }
  .cal-cell__stage { justify-content: center; }
  .cal-cell__stage svg { width: 24px; height: 24px; }

  /* summit / uphill marker, top-right */
  .cal-cell__flag { display: block; position: absolute; top: 2px; right: 3px; font-size: 9px; line-height: 1; }
  .cal-cell__flag[data-finish="summit"] { color: var(--type-mountain); }
  .cal-cell__flag[data-finish="uphill"] { color: var(--type-hilly); }

  .cal-cell__rest { margin: 0; font-size: 8px; letter-spacing: 0; }
}

/* --------------------------------------------------------------- desktop up */

@media (min-width: 620px) {
  .stage__head {
    grid-template-columns: auto 1fr auto;
    grid-template-areas: "badge body time";
    align-items: center;
    padding: 15px 18px 15px 20px;
  }
  .stage__time {
    margin-top: 0; padding-top: 0; border-top: 0;
    flex-direction: column; align-items: flex-end; text-align: right; gap: 1px;
    min-width: 92px; padding-left: 8px;
  }
  .stage__time .time { font-size: 22px; }
}

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