/* ============================================================
   Home — ride card (status strip) · paper ticket (primary action)
   · diary rows (recent list)
   ============================================================ */

@keyframes live-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.5; transform: scale(0.85); }
}

@keyframes dot-pulse {
  0%, 100% { opacity: 0.4; }
  50%      { opacity: 1; }
}

/* These decorative loops use literal durations, so the --motion-* token
   zeroing in tokens.css doesn't reach them — disable them explicitly. */
@media (prefers-reduced-motion: reduce) {
  .status-strip[data-state="tracking"] .row:first-child::before,
  .status-strip .pred-pending::after,
  .primary-action .loading-dots { animation: none; }
}

/* ---------- Status strip → live ride card (torn carbon copy) ---------- */
.status-strip {
  --r-edge: var(--ink-line);
  position: relative;
  background: var(--paper-light);
  background-image: var(--ticket-texture);
  border: 1px solid var(--r-edge);
  border-radius: var(--r-sm);
  padding: var(--sp-4);
  margin-bottom: var(--sp-6);
  box-shadow: var(--shadow-1);
  min-height: 92px;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.status-strip .row {
  display: flex;
  align-items: baseline;
  gap: var(--sp-2);
  flex-wrap: wrap;
}

.status-strip .time {
  font-family: var(--font-mono);
  font-size: var(--fs-2xl);
  font-weight: 500;
  font-feature-settings: "tnum" 1;
  letter-spacing: -0.01em;
  line-height: 1;
  color: var(--ink);
}

.status-strip .label {
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  letter-spacing: 0.01em;
  color: var(--ink);
}

.status-strip .eta {
  font-family: var(--font-mono);
  font-size: var(--fs-lg);
  font-weight: 500;
  font-feature-settings: "tnum" 1;
  color: var(--ink);
}

.status-strip .eta .small {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--ink-muted);
  font-weight: 400;
  letter-spacing: 0.04em;
}

.status-strip .pred-pending {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-muted);
  border: 1px solid var(--ink-line);
  border-radius: var(--r-full);
  padding: 3px 10px;
}
.status-strip .pred-pending::after {
  content: "···";
  margin-left: 2px;
  animation: dot-pulse 1.6s ease-in-out infinite;
}

.status-strip .weather {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  color: var(--ink-muted);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
}

.status-strip .weather .temp {
  font-family: var(--font-mono);
  font-size: var(--fs-base);
  color: var(--ink);
  font-feature-settings: "tnum" 1;
}

.status-strip .weather.unavailable .icon { opacity: 0.5; color: var(--ink-faint); }

.status-strip .weather .reason {
  font-size: var(--fs-sm);
  color: var(--ink-muted);
  font-family: var(--font-body);
}

.status-strip .retry-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  border: 1px solid var(--ink-line);
  border-radius: var(--r-full);
  padding: 4px 12px;
  min-height: 30px;
  background: var(--paper);
  color: var(--ink);
  transition: opacity var(--motion-base) var(--ease-out), background var(--motion-fast) var(--ease-out);
  margin-left: auto;
  white-space: nowrap;
  flex-shrink: 0;
}
.status-strip .retry-pill[disabled] { opacity: 0.5; pointer-events: none; }
.status-strip .retry-pill:active { background: var(--surface-press); }
.status-strip .retry-pill .icon-sm { display: inline-flex; align-items: center; }

.status-strip[data-state="empty"] {
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--ink-muted);
  font-family: var(--font-body);
  font-size: var(--fs-base);
  background-image: none;
}

.status-strip[data-state="locating"] .row,
.status-strip[data-state="locating"] .weather { opacity: 0.6; }

/* Tracking = LIVE on the road. Leaf accent + sawtooth tear + pulsing dot. */
.status-strip[data-state="tracking"] {
  --r-edge: var(--leaf-deep);
  border-color: var(--leaf-deep);
  background: var(--leaf-soft);
}
.status-strip[data-state="tracking"]::before {
  content: "";
  position: absolute;
  left: -1px; right: -1px; top: -3px;
  height: 5px;
  background-image: radial-gradient(circle at 5px 50%, var(--bg) 2.2px, transparent 2.5px);
  background-size: 10px 5px;
  background-repeat: repeat-x;
}
.status-strip[data-state="tracking"]::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -5px;
  height: 6px;
  background:
    linear-gradient(135deg, transparent 50%, var(--leaf-deep) 50%) repeat-x left top / 8px 6px,
    linear-gradient(225deg, transparent 50%, var(--leaf-deep) 50%) repeat-x left top / 8px 6px;
}
.status-strip[data-state="tracking"] .time { color: var(--ink); }
.status-strip[data-state="tracking"] .label { color: var(--leaf-deep); }
/* LIVE pulse dot ahead of the first row */
.status-strip[data-state="tracking"] .row:first-child::before {
  content: "";
  width: 8px; height: 8px;
  align-self: center;
  background: var(--leaf);
  border-radius: var(--r-full);
  box-shadow: 0 0 0 3px rgba(92, 140, 74, 0.22);
  animation: live-pulse 1.6s ease-in-out infinite;
  flex-shrink: 0;
}
.status-strip .undo-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  margin-left: auto;
  padding: 0 12px;
  border-radius: var(--r-full);
  border: 1px solid var(--leaf-deep);
  background: var(--paper);
  color: var(--leaf-deep);
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  font-weight: 600;
  transition: background var(--motion-fast) var(--ease-out);
}
.status-strip .undo-pill .count { color: var(--ink-muted); font-feature-settings: "tnum" 1; }
.status-strip .undo-pill:active { background: var(--surface-press); }

.status-strip[data-state="error"] {
  border-color: var(--danger);
}

/* ---------- Primary action → paper commute ticket (left body / right punch) ---------- */
.entry-buttons {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--sp-2);
  margin-bottom: var(--sp-8);
}

.primary-action {
  /* Ticket-warm local theme — stays amber even in dark mode (see overrides) */
  --t-paper: var(--am-soft);
  --t-edge:  var(--am-deep);
  --t-stamp: var(--am-deep);
  --t-ink:   var(--ink);
  --punch:   var(--paper-light);

  position: relative;
  width: 100%;
  max-width: 380px;
  margin: 0 auto;
  min-height: 132px;
  display: grid;
  grid-template-columns: 1fr 60px;
  align-items: stretch;
  background: var(--t-paper);
  background-image: var(--ticket-texture);
  color: var(--t-ink);
  border: 1px solid var(--t-edge);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-1);
  padding: 0;
  text-align: left;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  transition:
    transform var(--motion-fast) var(--ease-out),
    box-shadow var(--motion-fast) var(--ease-out),
    border-color var(--motion-base) var(--ease-out);
}

/* Perforated top + bottom edges (punched dots) */
.primary-action::before,
.primary-action::after {
  content: "";
  position: absolute;
  left: -1px; right: -1px;
  height: 5px;
  background-image: radial-gradient(circle at 5px 50%, var(--bg) 2.2px, transparent 2.5px);
  background-size: 10px 5px;
  background-repeat: repeat-x;
  pointer-events: none;
  z-index: 2;
}
.primary-action::before { top: -3px; }
.primary-action::after  { bottom: -3px; }

.primary-action[data-color="cool"] {
  --t-paper: var(--pm-soft);
  --t-edge:  var(--pm-deep);
  --t-stamp: var(--pm-deep);
}

/* ----- Body (left) ----- */
.pas-body {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4) var(--sp-4);
  min-width: 0;
}
.pas-meta {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--sp-3);
}
.pas-date {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--t-ink);
  padding-top: 3px;
}
.pas-verb {
  font-family: var(--font-hand);
  font-size: 26px;
  line-height: 1;
  color: var(--t-stamp);
  transform: rotate(-3deg);
  white-space: nowrap;
}
.pas-stations {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  min-width: 0;
}
.pas-stn { display: flex; flex-direction: column; line-height: 1; min-width: 0; }
.pas-cn {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 400;
  letter-spacing: 0.02em;
  color: var(--t-ink);
  white-space: nowrap;
}
.pas-en {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.14em;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-top: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pas-arrow {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 300;
  line-height: 1;
  color: var(--t-stamp);
  margin-top: 4px;
}

/* ----- Punch column (right, 60px) ----- */
.pas-punch {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  color: var(--t-stamp);
}
.pas-punch::before {
  content: "";
  position: absolute;
  top: 12px; bottom: 12px; left: 0;
  width: 1px;
  background-image: linear-gradient(to bottom, var(--t-stamp) 0 3px, transparent 3px 7px);
  background-size: 1px 7px;
}
.pas-hole {
  width: 11px; height: 11px;
  border-radius: var(--r-full);
  background: var(--punch);
  box-shadow: inset 0 1px 1.5px rgba(43, 36, 23, 0.4);
  border: 1px solid rgba(43, 36, 23, 0.24);
}
.pas-glyph {
  font-family: var(--font-mono);
  font-size: 32px;
  font-weight: 500;
  line-height: 1;
}
.pas-glyph .loading-dots {
  font-size: 22px;
  letter-spacing: 0.04em;
  animation: dot-pulse 1.6s ease-in-out infinite;
}
.pas-ticks {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.18em;
  font-weight: 700;
}

/* ----- Saving stamp (bouncy, on success) ----- */
.pas-stamp {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 4;
  pointer-events: none;
  font-family: var(--font-hand);
  font-size: 40px;
  color: var(--t-stamp);
}
.primary-action[data-state="success"] .pas-stamp {
  display: flex;
  animation: stamp-impact 360ms cubic-bezier(.34, 1.56, .64, 1);
}
@keyframes stamp-impact {
  0%   { opacity: 0; transform: scale(1.4) rotate(-8deg); }
  40%  { opacity: 0.55; transform: scale(1.12) rotate(-5deg); }
  70%  { opacity: 1; transform: scale(1.02) rotate(-3deg); }
  100% { opacity: 1; transform: scale(1) rotate(-3deg); }
}

.primary-action:active {
  transform: scale(0.985) rotate(-0.3deg);
  box-shadow: 0 1px 0 rgba(70, 50, 20, 0.05);
}
.primary-action[data-state="loading"] { opacity: 0.8; pointer-events: none; }
.primary-action[data-state="success"] { border-color: var(--leaf-deep); }
.primary-action[data-state="error"] { border-color: var(--danger); }
.primary-action[disabled] { opacity: 0.45; pointer-events: none; }

.primary-action__hint {
  margin: var(--sp-2) 0 0;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: 0.04em;
  color: var(--ink-faint);
  min-height: 1.2em;
  line-height: 1.1;
}

.primary-action.shake { animation: shake 0.24s ease-in-out; }

/* Tickets stay warm-amber at night — only chrome flips */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .primary-action {
    --t-paper: #E0A040; --t-edge: #8E5F1A; --t-stamp: #2B2417; --t-ink: #2B2417; --punch: #C98A2E;
  }
  :root:not([data-theme="light"]) .primary-action[data-color="cool"] {
    --t-paper: #B85432; --t-edge: #5C2814; --t-stamp: #2B2417; --punch: #9E4628;
  }
}
:root[data-theme="dark"] .primary-action {
  --t-paper: #E0A040; --t-edge: #8E5F1A; --t-stamp: #2B2417; --t-ink: #2B2417; --punch: #C98A2E;
}
:root[data-theme="dark"] .primary-action[data-color="cool"] {
  --t-paper: #B85432; --t-edge: #5C2814; --t-stamp: #2B2417; --punch: #9E4628;
}

/* ---------- Recent list → diary leg rows ---------- */
.recent-section h2 {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  margin: 0 0 var(--sp-2) 0;
  padding-bottom: var(--sp-2);
  border-bottom: 1px dashed var(--ink-line);
}

.recent-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.recent-list .pair-row {
  display: grid;
  grid-template-columns: 52px 32px 24px 36px 1fr 44px 24px 36px 28px;
  gap: var(--sp-2);
  align-items: center;
  min-height: 44px;
  padding: var(--sp-2) var(--sp-1);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  position: relative;
}
.recent-list .pair-row:not(:last-child)::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 1px;
  background-image: repeating-linear-gradient(to right, var(--ink-line) 0 4px, transparent 4px 8px);
}

/* open = boarded, not yet alighted = live/on-road → leaf accent (not sun) */
.recent-list .pair-row.open {
  background: rgba(92, 140, 74, 0.12);
  box-shadow: inset 3px 0 0 var(--leaf);
}

.recent-list .mono { font-feature-settings: "tnum" 1; }
.recent-list .date { color: var(--ink); font-weight: 500; }
.recent-list .wkday { color: var(--ink-muted); letter-spacing: 0.06em; }
.recent-list .dir {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  border-radius: var(--r-full);
  font-weight: 700;
  background: var(--am-soft);
  color: var(--am-deep);
}
.recent-list .pair-row[data-direction="from_work"] .dir { background: var(--pm-soft); color: var(--pm-deep); }
.recent-list .dir-label { font-family: var(--font-body); font-weight: 500; color: var(--ink); }
.recent-list .trip { font-family: var(--font-mono); color: var(--ink); letter-spacing: 0.02em; }
.recent-list .duration { font-size: var(--fs-xs); color: var(--ink-muted); text-align: right; }
.recent-list .duration.active {
  color: var(--leaf-deep);
  font-weight: 600;
  font-family: var(--font-hand);
  font-size: var(--fs-hand);
}
.recent-list .wx { color: var(--ink-muted); display: inline-flex; align-items: center; justify-content: center; }
.recent-list .wx.unavailable { color: var(--ink-faint); opacity: 0.5; }
.recent-list .temp { font-family: var(--font-mono); font-feature-settings: "tnum" 1; text-align: right; color: var(--ink); }
.recent-list .delete-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border: 1px solid var(--ink-line);
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-muted);
  transition: background var(--motion-fast) var(--ease-out), border-color var(--motion-fast) var(--ease-out);
}
.recent-list .delete-btn:active { background: var(--surface-press); }
.recent-list .delete-btn.confirm {
  background: var(--danger-bg);
  border-color: var(--danger);
  color: var(--danger);
  width: auto;
  padding: 0 var(--sp-2);
  font-family: var(--font-body);
  font-size: var(--fs-xs);
  font-weight: 600;
}
.recent-list .delete-btn[disabled] { opacity: 0.5; pointer-events: none; }
.recent-list .empty {
  color: var(--ink-muted);
  padding: var(--sp-4);
  text-align: center;
  list-style: none;
  font-family: var(--font-body);
}

@media (max-width: 480px) {
  .recent-list .pair-row {
    grid-template-columns: auto auto 24px auto 1fr auto;
    grid-template-areas:
      "date wkday dir label duration delete"
      "trip trip trip wx temp delete";
    column-gap: var(--sp-2);
    row-gap: 3px;
    padding: var(--sp-3) 0;
  }
  .recent-list .pair-row > .date { grid-area: date; }
  .recent-list .pair-row > .wkday { grid-area: wkday; }
  .recent-list .pair-row > .dir { grid-area: dir; }
  .recent-list .pair-row > .dir-label { grid-area: label; }
  .recent-list .pair-row > .trip { grid-area: trip; }
  .recent-list .pair-row > .duration { grid-area: duration; text-align: right; }
  .recent-list .pair-row > .wx { grid-area: wx; justify-self: end; }
  .recent-list .pair-row > .temp { grid-area: temp; text-align: right; }
  .recent-list .pair-row > .delete-btn { grid-area: delete; align-self: center; }
}

@media (min-width: 720px) {
  .primary-action { min-height: 200px; }
}

/* ---------- First-launch splash (loading is waiting) ---------- */
.splash {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-4);
  background: var(--bg);
  background-image: var(--paper-texture);
  transition: opacity 380ms ease, visibility 380ms ease;
}
.splash.hide { opacity: 0; visibility: hidden; pointer-events: none; }
.splash-sign {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-1);
  padding: var(--sp-6) var(--sp-10);
  border: 1px solid var(--ink-line);
  border-radius: var(--r-sm);
  background: var(--paper-light);
  box-shadow: var(--shadow-1);
}
.splash-stop {
  width: 14px; height: 14px;
  border-radius: var(--r-full);
  background: var(--am);
  box-shadow: 0 0 0 5px rgba(217, 164, 65, 0.26);
  margin-bottom: var(--sp-2);
}
.splash-name { font-family: var(--font-display); font-size: var(--fs-3xl); line-height: 1; color: var(--ink); letter-spacing: -0.02em; }
.splash-cn { font-family: var(--font-body); font-size: var(--fs-base); color: var(--ink-muted); letter-spacing: 0.12em; margin-top: var(--sp-1); }
.splash-hand { font-family: var(--font-hand); font-size: var(--fs-hand); color: var(--leaf-deep); }
@media (prefers-reduced-motion: reduce) { .splash { transition: none; } }

/* ---------- Pull-to-refresh (bus rolls in from above) ---------- */
.pull-indicator {
  position: fixed;
  top: -60px; left: 0; right: 0;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  z-index: 40;
  pointer-events: none;
}
.pull-indicator img { width: 50px; height: auto; filter: drop-shadow(0 2px 2px rgba(80, 55, 20, 0.25)); }
.pull-indicator .pull-dots {
  font-family: var(--font-mono);
  font-size: var(--fs-base);
  color: var(--ink-muted);
  opacity: 0;
}
.pull-indicator.ready .pull-dots { opacity: 1; }
.pull-indicator.refreshing .pull-dots { opacity: 1; animation: dot-pulse 1.2s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) { .pull-indicator.refreshing .pull-dots { animation: none; } }
