/* Layout concept: one column, native-sheet feel. The pick is a big card with a
   proportional trip strip; alternatives are compact rows; live boards are chip rails.
   Surfaces come from Telegram's theme (--tg-theme-*), so light/dark follow the app. */
:root {
  --bg:       var(--tg-theme-secondary-bg-color, #f2f2f7);
  --surface:  var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text:     var(--tg-theme-text-color, #0b0b0f);
  --hint:     var(--tg-theme-hint-color, #8a8a90);
  --accent:   var(--tg-theme-button-color, #2f7cf6);
  --on-accent:var(--tg-theme-button-text-color, #ffffff);
  --line:     color-mix(in srgb, var(--text) 10%, transparent);
  --skel:     color-mix(in srgb, var(--text) 7%, transparent);

  /* CTA line colors (official) and the two non-rail modes */
  --blue:    #00A1DE;
  --brown:   #62361B;
  --purple:  #522398;
  --bus:     #4B5563;
  --shuttle: #0E7C74;
  --metra:   #1F3D7A;   /* Metra navy */
  --walk:    color-mix(in srgb, var(--text) 22%, transparent);

  /* Semantic state, separate from the accent */
  --ok:    #1F9D55;
  --tight: #D98A00;
  --miss:  #E0452B;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  --display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, system-ui, sans-serif;
  --r-lg: 22px; --r-md: 16px; --r-sm: 10px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --top: calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px));
  --bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
  color-scheme: light;
}
/* Outside Telegram (or before its theme lands), follow the OS. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: var(--tg-theme-secondary-bg-color, #000000);
    --surface: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #1c1c1e));
    --text: var(--tg-theme-text-color, #f5f5f7);
    --hint: var(--tg-theme-hint-color, #8e8e93);
    --accent: var(--tg-theme-button-color, #3e88f7);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: var(--tg-theme-secondary-bg-color, #000000);
  --surface: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #1c1c1e));
  --text: var(--tg-theme-text-color, #f5f5f7);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --accent: var(--tg-theme-button-color, #3e88f7);
  color-scheme: dark;
}
/* Telegram tells us its scheme; the deep CTA brown/purple need lifting on dark. */
.tg-dark { --brown: #8A5634; --purple: #7B52C9; --bus: #6B7280; --metra: #4A6FB5; color-scheme: dark; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.35 var(--font); font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:focus-visible, .card:focus-visible, .tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.view {
  height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding-top: calc(var(--top) + 12px);
  padding-bottom: calc(var(--bottom) + 28px);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: flex; flex-direction: column; gap: 18px;
  will-change: transform;
}
.view > * { flex-shrink: 0; }

/* ---------- Header ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.eyebrow { font-size: 13px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--hint); }
h1 { font: 700 28px/1.1 var(--display); letter-spacing: -.02em; margin: 2px 0 0; text-wrap: balance; }
.fresh { font-size: 12px; color: var(--hint); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.fresh .pulse { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 50%, transparent); animation: pulse 2s infinite; }
.fresh.stale .pulse { background: var(--tight); animation: none; }
.fresh.stale { color: var(--tight); }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

/* Segmented control: To work / Home */
.seg {
  position: relative; display: grid; grid-template-columns: 1fr 1fr;
  background: var(--skel); border-radius: 12px; padding: 3px;
}
.seg button { position: relative; z-index: 1; padding: 8px 0; font-size: 14px; font-weight: 600; color: var(--hint); transition: color .2s; }
.seg button[aria-selected="true"] { color: var(--text); }
.seg .thumb {
  position: absolute; top: 3px; bottom: 3px; left: 3px; width: calc(50% - 3px);
  background: var(--surface); border-radius: 9px; box-shadow: 0 1px 3px rgba(0,0,0,.12);
  transition: transform .32s var(--ease);
}
.seg[data-leg="pm"] .thumb { transform: translateX(100%); }

/* ---------- Hero (the pick) ---------- */
.hero {
  background: var(--surface); border-radius: var(--r-lg); padding: 18px 18px 16px;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 1px 0 var(--line), 0 8px 24px -12px rgba(0,0,0,.18);
  transition: transform .18s var(--ease);
}
.hero:active { transform: scale(.985); }
.hero .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700;
  letter-spacing: .03em; text-transform: uppercase; padding: 4px 9px; border-radius: 999px;
  background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok);
}
.badge.tight { background: color-mix(in srgb, var(--tight) 16%, transparent); color: var(--tight); }
.badge.miss  { background: color-mix(in srgb, var(--miss) 14%, transparent); color: var(--miss); }
.call { font-size: 13px; font-weight: 600; color: var(--hint); text-align: right; }

.count { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.count .lbl { font-size: 17px; font-weight: 600; color: var(--hint); }
.count .big { font: 800 52px/1 var(--display); letter-spacing: -.03em; }
.count .big.go { color: var(--tight); }
.count .big.gone { color: var(--miss); }
.meta { display: flex; gap: 16px; font-size: 15px; color: var(--hint); }
.meta b { color: var(--text); font-weight: 600; }
.reason { font-size: 15px; line-height: 1.35; }

/* ---------- Trip strip: one bar, each leg proportional to its minutes ---------- */
.strip { position: relative; display: flex; height: 30px; border-radius: 9px; overflow: hidden; gap: 2px; background: var(--surface); }
.strip.mini { height: 8px; border-radius: 4px; gap: 1px; }
.s { position: relative; min-width: 6px; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 12px; font-weight: 700; white-space: nowrap; overflow: hidden; }
.s.blue { background: var(--blue); } .s.brown { background: var(--brown); } .s.purple { background: var(--purple); }
.s.bus { background: var(--bus); } .s.shuttle { background: var(--shuttle); } .s.metra { background: var(--metra); }
.s.walk { background: repeating-linear-gradient(90deg, var(--walk) 0 4px, transparent 4px 7px); color: var(--hint); }
.s.wait { background: color-mix(in srgb, var(--text) 7%, transparent); color: var(--hint); }
.s.est { background-image: linear-gradient(135deg, rgba(255,255,255,.18) 25%, transparent 25% 50%, rgba(255,255,255,.18) 50% 75%, transparent 75%); background-size: 8px 8px; }
.strip .past { position: absolute; inset: 0 auto 0 0; background: color-mix(in srgb, var(--surface) 55%, transparent); pointer-events: none; transition: width 1s linear; }
.strip .now { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--text); border-radius: 2px; transition: left 1s linear; }
.ticks { position: relative; height: 16px; font-size: 12px; color: var(--hint); }
.ticks span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.ticks span:first-child { transform: none; }
.ticks span:last-child { transform: translateX(-100%); }

/* Expandable steps */
.steps { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .3s var(--ease); }
.steps > div { overflow: hidden; }
.open .steps { grid-template-rows: 1fr; }
.step { display: grid; grid-template-columns: 14px 1fr auto; gap: 12px; align-items: start; padding: 8px 0; font-size: 15px; position: relative; }
/* Connectors turn the steps into a small line map: solid in the line's color for rides, dotted for walks/changes. */
.step::before { content: ""; position: absolute; left: 6px; top: 28px; bottom: -6px; width: 2px;
  background: repeating-linear-gradient(var(--walk) 0 3px, transparent 3px 6px); }
.step.ride::before { left: 5px; width: 4px; border-radius: 2px; background: var(--lc); }
.step:last-child::before { display: none; }
.step .dot { width: 14px; height: 14px; border-radius: 50%; margin-top: 2px; border: 3px solid var(--walk); background: var(--surface); }
.step .dot.blue { border-color: var(--blue); } .step .dot.brown { border-color: var(--brown); } .step .dot.purple { border-color: var(--purple); }
.step .dot.bus { border-color: var(--bus); } .step .dot.shuttle { border-color: var(--shuttle); } .step .dot.metra { border-color: var(--metra); }
.step small { display: block; color: var(--hint); font-size: 13px; }
.step .t { font-weight: 600; }
.hint-line { font-size: 12px; color: var(--hint); text-align: center; }

/* ---------- Alternatives ---------- */
.section-h { font-size: 13px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--hint); margin: 4px 4px -8px; }
.list { background: var(--surface); border-radius: var(--r-md); overflow: hidden; }
.card { display: grid; grid-template-columns: 64px 1fr auto; gap: 14px; align-items: center; padding: 14px 16px; position: relative; transition: background .15s; }
.card + .card::before { content: ""; position: absolute; left: 16px; right: 0; top: 0; height: 1px; background: var(--line); }
.card:active { background: var(--skel); }
.card .dep { font: 700 20px/1 var(--display); }
.card .dep small { display: block; font: 500 12px/1.3 var(--font); color: var(--hint); margin-top: 3px; }
.card .arr { text-align: right; font-weight: 600; }
.card .arr small { display: block; font-size: 12px; font-weight: 600; }
.card .arr small.ok { color: var(--hint); } .card .arr small.tight { color: var(--tight); } .card .arr small.miss { color: var(--miss); }
.card .mid { min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.card .via { font-size: 13px; color: var(--hint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card.missed { opacity: .5; }

/* ---------- Live boards: chip rails ---------- */
.board { background: var(--surface); border-radius: var(--r-md); padding: 14px 0 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.board h3 { margin: 0; font-size: 15px; font-weight: 600; padding-right: 16px; }
.board h3 small { color: var(--hint); font-weight: 500; }
.rail { display: flex; gap: 8px; overflow-x: auto; padding-right: 16px; scrollbar-width: none; }
.rail::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: flex; flex-direction: column; gap: 2px; padding: 8px 12px; border-radius: 12px;
  background: color-mix(in srgb, var(--c) 14%, transparent); min-width: 66px;
  animation: chip-in .38s var(--ease) both; animation-delay: calc(var(--i) * 45ms);
}
.chip b { font: 700 17px/1 var(--display); color: var(--text); }
.chip span { font-size: 11px; color: var(--hint); white-space: nowrap; }
.chip .bar { height: 3px; border-radius: 2px; background: var(--c); margin-bottom: 4px; }
.chip.blue { --c: var(--blue); } .chip.brown { --c: var(--brown); } .chip.purple { --c: var(--purple); } .chip.bus { --c: var(--bus); }
@keyframes chip-in { from { transform: translateX(12px); opacity: .0; } to { transform: none; opacity: 1; } }
.note { font-size: 13px; color: var(--hint); text-align: center; padding: 0 12px; }

/* ---------- States ---------- */
.banner { display: flex; gap: 10px; align-items: center; padding: 12px 14px; border-radius: var(--r-md); font-size: 14px;
  background: color-mix(in srgb, var(--tight) 14%, var(--surface)); }
.banner.err { background: color-mix(in srgb, var(--miss) 12%, var(--surface)); }
.sk { background: var(--skel); border-radius: 8px; position: relative; overflow: hidden; }
.sk::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface) 60%, transparent), transparent);
  animation: shimmer 1.3s infinite; }
@keyframes shimmer { to { transform: translateX(100%); } }

/* Pull to refresh */
#ptr { position: fixed; left: 0; right: 0; top: calc(var(--top) + 6px); display: flex; justify-content: center; pointer-events: none; z-index: 5; }
.ptr-dot { width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--skel); border-top-color: var(--accent);
  opacity: 0; transform: scale(.6); transition: opacity .15s, transform .15s; background: var(--surface); }
#ptr.pulling .ptr-dot { opacity: 1; transform: scale(1) rotate(var(--rot, 0deg)); }
#ptr.loading .ptr-dot { opacity: 1; transform: scale(1); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Bottom sheet (long-press) ---------- */
.sheet { position: fixed; inset: 0; z-index: 10; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.35); animation: fade .2s both; }
.sheet-panel { position: absolute; left: 0; right: 0; bottom: 0; background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 8px max(16px, env(safe-area-inset-right, 0px)) calc(var(--bottom) + 20px) max(16px, env(safe-area-inset-left, 0px));
  animation: rise .32s var(--ease) both; max-height: 75%; overflow-y: auto; }
.sheet-grip { width: 36px; height: 5px; border-radius: 3px; background: var(--skel); margin: 0 auto 12px; }
.sheet h2 { font: 700 20px/1.2 var(--display); margin: 0 0 8px; }
.alt { padding: 12px 0; border-top: 1px solid var(--line); }
.alt:first-child { border-top: 0; }
.alt b { display: block; font-weight: 600; }
.alt small { color: var(--hint); font-size: 14px; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(100%); } }

/* ---------- Hub ---------- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile {
  background: var(--surface); border-radius: var(--r-lg); padding: 16px; min-height: 150px; text-align: left;
  display: flex; flex-direction: column; justify-content: space-between; gap: 12px;
  transition: transform .18s var(--ease); position: relative; overflow: hidden;
}
.tile:active { transform: scale(.97); }
.tile.wide { grid-column: span 2; min-height: 132px; }
.tile .icon { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--blue); }
.tile .icon svg { width: 22px; height: 22px; }
.tile .name { font: 700 20px/1.1 var(--display); }
.tile .peek { font-size: 14px; color: var(--hint); }
.tile .peek b { color: var(--text); }
.tile .lines { position: absolute; right: -10px; top: 18px; display: flex; flex-direction: column; gap: 6px; transform: rotate(-12deg); opacity: .9; }
.tile .lines i { display: block; height: 8px; border-radius: 4px; }
.tile.ghost { background: transparent; border: 1.5px dashed var(--line); color: var(--hint); justify-content: center; align-items: center; text-align: center; font-size: 14px; }

/* View transitions between legs */
.slide-l { animation: slide-l .28s var(--ease); } .slide-r { animation: slide-r .28s var(--ease); }
@keyframes slide-l { from { transform: translateX(28px); opacity: .4; } }
@keyframes slide-r { from { transform: translateX(-28px); opacity: .4; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

/* ======================= To-Do =======================
   Same language as Commute: grouped lists on the Telegram background, one accent,
   the check is the hero interaction. */
.ring-sm { width: 44px; height: 44px; position: relative; flex: none; }
.ring-sm svg { transform: rotate(-90deg); }
.ring-sm b { position: absolute; inset: 0; display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.todo-list { background: var(--surface); border-radius: var(--r-md); overflow: hidden; }
.row { position: relative; touch-action: pan-y; }
.row + .row::before { content: ""; position: absolute; left: 52px; right: 0; top: 0; height: 1px; background: var(--line); z-index: 2; }
.row .under { position: absolute; inset: 0; display: flex; justify-content: flex-end; align-items: center; padding-right: 20px;
  background: var(--tight); color: #fff; font-weight: 700; font-size: 14px; gap: 6px; }
.row .face { position: relative; z-index: 1; background: var(--surface); display: grid; grid-template-columns: 26px 1fr 22px;
  gap: 12px; align-items: start; padding: 13px 14px 13px 14px; transition: transform .25s var(--ease), background .15s; }
.row .face:active { background: color-mix(in srgb, var(--text) 4%, var(--surface)); }
.row.dragging { z-index: 6; }
.row.dragging .face { box-shadow: 0 12px 28px -8px rgba(0,0,0,.35); transform: scale(1.02); transition: none; border-radius: 12px; }
.chk { width: 24px; height: 24px; margin-top: 1px; border-radius: 50%; border: 2px solid color-mix(in srgb, var(--text) 28%, transparent);
  display: grid; place-items: center; transition: background .2s, border-color .2s, transform .2s var(--ease); }
.chk svg { width: 14px; height: 14px; stroke: #fff; stroke-width: 3; fill: none; stroke-dasharray: 20; stroke-dashoffset: 20; transition: stroke-dashoffset .25s .05s var(--ease); }
.row.done .chk { background: var(--ok); border-color: var(--ok); }
.row.done .chk svg { stroke-dashoffset: 0; }
.row.pop .chk { transform: scale(1.18); }
.txt { min-width: 0; font-size: 15px; line-height: 1.38; overflow-wrap: anywhere; }
.txt b { font-weight: 600; }
.txt .ctx { display: block; color: var(--hint); font-size: 13px; margin-top: 3px; }
.txt .wl { color: var(--accent); }
.txt a { color: var(--accent); text-decoration: none; }
.txt .stamp { display: block; color: var(--ok); font-size: 12px; font-weight: 600; margin-top: 4px; }
.row.done .txt .body { text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--text) 45%, transparent); color: var(--hint); }
.row.done .txt .body .wl, .row.done .txt .body b { color: var(--hint); }
.grip { width: 22px; height: 28px; display: grid; place-items: center; color: color-mix(in srgb, var(--text) 30%, transparent); touch-action: none; cursor: grab; }
.grip svg { width: 16px; height: 16px; }
.zz .face { grid-template-columns: 1fr auto; }
.zz .when { font-size: 12px; font-weight: 600; color: var(--tight); white-space: nowrap; padding-top: 2px; }
.toast { position: fixed; left: 50%; bottom: calc(var(--bottom) + 18px); transform: translateX(-50%); z-index: 9;
  background: var(--text); color: var(--bg); border-radius: 14px; padding: 10px 10px 10px 16px; display: flex; gap: 14px; align-items: center;
  font-size: 14px; box-shadow: 0 10px 30px -10px rgba(0,0,0,.4); animation: rise .28s var(--ease) both; max-width: calc(100% - 32px); }
.toast button { color: var(--accent); font-weight: 700; padding: 4px 8px; background: color-mix(in srgb, var(--bg) 12%, transparent); border-radius: 8px; }
.opts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 6px; }
.opt.wide { grid-column: 1 / -1; }
.opt { background: var(--skel); border-radius: 14px; padding: 12px; text-align: left; display: flex; flex-direction: column; gap: 2px; }
.opt b { font-size: 16px; } .opt span { font-size: 13px; color: var(--hint); }
.opt:active { transform: scale(.97); }
.datepick { grid-column: 1 / -1; display: flex; gap: 10px; align-items: center; }
.datepick input { flex: 1; font: inherit; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--text); }
.datepick button { background: var(--accent); color: var(--on-accent); padding: 12px 16px; border-radius: 12px; font-weight: 600; }
.tile .icon.todo { background: var(--ok); }

/* Live vs scheduled marker on Metra cards */
.lv { display: inline-flex; align-items: center; gap: 4px; margin-right: 6px; padding: 1px 6px; border-radius: 999px;
  font-size: 11px; font-weight: 700; color: var(--hint); background: var(--skel); vertical-align: 1px; }
.lv i { width: 6px; height: 6px; border-radius: 50%; background: var(--hint); }
.lv.on { color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.lv.on i { background: var(--ok); animation: pulse 2s infinite; }
.card .alert { font-size: 12px; color: var(--tight); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
