:root {
  --bg: #0b1220;
  --surface: #131d33;
  --surface-2: #1b2745;
  --line: #27355a;
  --ink: #eef2fb;
  --ink-dim: #9aa8c7;
  --accent: #e8c98c;
  --accent-ink: #2a1e06;
  --new: #6fd3a0;
  --updated: #7fb6f5;
  --removed: #f2907f;
  --radius: 14px;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* Respect the iPhone notch and home indicator in standalone mode. */
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

main { max-width: 640px; margin: 0 auto; padding: 0 16px 32px; }

/* ------------------------------------------------------------------ topbar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(11, 18, 32, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar h1 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: 0.01em;
}

.title { min-width: 0; }

.freshness {
  display: block;
  font-size: 0.72rem;
  color: var(--ink-dim);
  margin-top: 1px;
  min-height: 1em;   /* reserve the line so the header never jumps */
}

/* Pull-to-refresh indicator, parked above the viewport until dragged down. */
.pull {
  position: fixed;
  top: 6px;
  left: 50%;
  transform: translate(-50%, -64px);
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--ink-dim);
  z-index: 20;
  pointer-events: none;
  opacity: 0;
}

/* The element ships with the hidden attribute, so this rule is what lets JS
   reveal it. Without it, `display: grid` above would beat the browser's own
   [hidden] rule and the indicator would sit on the page permanently. */
.pull[hidden] { display: none; }

.pull svg { width: 19px; height: 19px; }
.pull.is-pulling { opacity: 1; }
.pull.is-armed { color: var(--accent); border-color: var(--accent); }

@media (prefers-reduced-motion: no-preference) {
  .pull:not(.is-pulling) { transition: transform 220ms ease, opacity 220ms ease; }
  .pull.is-armed svg { transform: rotate(180deg); transition: transform 160ms ease; }
}

.bell {
  position: relative;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

.bell svg { width: 22px; height: 22px; }

.bell-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
}

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

.card {
  margin: 16px 0;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.card.accent { border-color: var(--accent); }
.card h2 { margin: 0 0 6px; font-size: 1.02rem; }
.card p { margin: 0 0 12px; color: var(--ink-dim); font-size: 0.94rem; }

.row { display: flex; flex-wrap: wrap; gap: 8px; }

button.primary, button.ghost {
  font: inherit;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  /* Comfortably above the 44px touch-target floor once padding is counted. */
  min-height: 44px;
}

button.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border: 1px solid var(--accent);
}

button.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

button.primary:disabled, button.ghost:disabled { opacity: 0.5; cursor: default; }

.steps { margin: 4px 0 0; padding-left: 22px; color: var(--ink-dim); font-size: 0.94rem; }
.steps li { margin: 4px 0; }
.steps strong { color: var(--ink); }

/* -------------------------------------------------------- tabs and filters */

.tabs {
  display: flex;
  gap: 4px;
  margin: 18px 0 12px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.tab {
  flex: 1;
  font: inherit;
  font-weight: 600;
  padding: 9px 8px;
  min-height: 42px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--ink-dim);
  cursor: pointer;
}

.tab.is-active { background: var(--surface-2); color: var(--ink); }

.chips { display: flex; flex-wrap: wrap; gap: 7px; }

.chip {
  font: inherit;
  font-size: 0.87rem;
  padding: 7px 13px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-dim);
  cursor: pointer;
}

.chip.is-on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.filters { margin-bottom: 8px; }
.filters .small { margin: 8px 0 0; }

/* ------------------------------------------------------------------- lists */

.list { display: flex; flex-direction: column; gap: 10px; }

.event {
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 14px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.datebox {
  text-align: center;
  padding: 7px 0;
  background: var(--surface-2);
  border-radius: 10px;
  height: fit-content;
}

.datebox .dow { font-size: 0.66rem; text-transform: uppercase; color: var(--ink-dim); letter-spacing: 0.06em; }
.datebox .day { font-size: 1.4rem; font-weight: 700; line-height: 1.1; }
.datebox .mon { font-size: 0.72rem; text-transform: uppercase; color: var(--ink-dim); }

.event h3 { margin: 0 0 4px; font-size: 1rem; line-height: 1.3; }

.event h3 a { color: var(--ink); text-decoration: none; }
.event h3 a:hover, .event h3 a:focus { text-decoration: underline; }

.meta { margin: 0; color: var(--ink-dim); font-size: 0.88rem; }

.pills { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }

.pill {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink-dim);
  border: 1px solid var(--line);
}

/* change entries */

.change { border-left: 3px solid var(--line); }
.change.kind-new { border-left-color: var(--new); }
.change.kind-updated { border-left-color: var(--updated); }
.change.kind-removed { border-left-color: var(--removed); }

.badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 8px;
  border-radius: 999px;
  margin-bottom: 6px;
}

.kind-new .badge { background: var(--new); color: #06281a; }
.kind-updated .badge { background: var(--updated); color: #08203c; }
.kind-removed .badge { background: var(--removed); color: #3d0f06; }

.difflist { margin: 8px 0 0; padding: 0; list-style: none; font-size: 0.85rem; color: var(--ink-dim); }
.difflist li { margin: 3px 0; }
.difflist .was { text-decoration: line-through; opacity: 0.75; }
.difflist .now { color: var(--ink); }

/* ------------------------------------------------------------- misc + util */

.muted { color: var(--ink-dim); }
.small { font-size: 0.84rem; }

.footer { max-width: 640px; margin: 0 auto; padding: 8px 16px 40px; }
.footer a { color: var(--accent); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(92vw, 420px);
  padding: 11px 16px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  font-size: 0.9rem;
  z-index: 50;
}

@media (prefers-reduced-motion: no-preference) {
  .toast { animation: rise 180ms ease-out; }
  @keyframes rise {
    from { opacity: 0; transform: translate(-50%, 8px); }
    to { opacity: 1; transform: translate(-50%, 0); }
  }
}

/* The app is dark by design, but honour a light preference for readability. */
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #eaeefa;
    --line: #d3dbee;
    --ink: #16203a;
    --ink-dim: #566180;
    --accent: #8a6a20;
    --accent-ink: #ffffff;
  }
  .topbar { background: rgba(244, 246, 251, 0.92); }
}
