/* ---------- tokens ---------- */
:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #efede8;
  --text: #1c1b18;
  --text-dim: #66635b;
  --accent: #1f6a72;        /* library teal */
  --accent-soft: #dcecec;
  --line: #e3e0d9;
  --danger: #b5432a;
  --ok: #3a7d44;
  --shadow: 0 1px 2px rgba(28, 27, 24, .06), 0 4px 16px rgba(28, 27, 24, .06);
  --radius: 14px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --topbar-h: 58px; /* measured in JS; used by sticky day labels */
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171614;
    --surface: #201f1c;
    --surface-2: #2a2925;
    --text: #ece9e2;
    --text-dim: #9b978d;
    --accent: #6cbcc4;
    --accent-soft: #1d3436;
    --danger: #e07a5f;
    --line: #33312c;
    --ok: #6fbf7b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { height: 100%; }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}
html.is-locked, html.is-locked body { overflow: hidden; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; touch-action: manipulation; }
ul { list-style: none; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--sat)) max(16px, calc((100vw - 704px) / 2)) 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 1.15rem; font-weight: 700; letter-spacing: -.01em; }
.topbar__title { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.topbar__status {
  font-size: .78rem; color: var(--text-dim);
  display: flex; align-items: baseline; gap: 8px; min-height: 1.2em;
  white-space: nowrap;
}
.topbar__status > span { overflow: hidden; text-overflow: ellipsis; }
.topbar__status.is-error { color: var(--danger); }
.topbar__actions { display: flex; gap: 4px; align-items: center; }

.linkbtn {
  flex: none;
  font-size: .78rem; font-weight: 700; color: var(--accent);
  text-decoration: underline; text-underline-offset: 2px;
  padding: 2px 0;
}

.iconbtn {
  display: grid; place-items: center;
  width: 44px; height: 44px; border-radius: 50%;
  color: var(--text-dim);
  transition: background .15s, color .15s;
}
.iconbtn:hover { background: var(--surface-2); color: var(--text); }
.iconbtn.is-spinning svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- controls: search, pills ---------- */
.controls { max-width: 720px; margin: 0 auto; padding: 10px 16px 6px; }


.search { position: relative; }
.settings__tools .search { margin-top: 10px; }
.search__icon {
  position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  color: var(--text-dim); pointer-events: none;
}
.search__input {
  width: 100%; height: 42px;
  padding: 0 14px 0 38px;
  font: inherit; font-size: 1rem; /* 16px+: stops iOS zooming on focus */
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  appearance: none; -webkit-appearance: none;
}
.search__input::placeholder { color: var(--text-dim); }
.search__input:focus-visible { outline-offset: 0; border-color: var(--accent); }
.search__input::-webkit-search-cancel-button { cursor: pointer; }

.pills { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 10px; }
.pill {
  flex: none;
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 34px; padding: 0 13px; border-radius: 999px;
  font-size: .82rem; font-weight: 600; color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--line);
  transition: background .15s, color .15s, opacity .15s;
}
.pill:hover { color: var(--text); }
.pill.is-active { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.pill__n { font-weight: 500; font-variant-numeric: tabular-nums; opacity: .75; }

/* ---------- list ---------- */
.list { max-width: 720px; margin: 0 auto; padding: 4px 16px calc(88px + var(--sab)); }
.list:focus { outline: none; }

.daylabel {
  position: sticky; top: calc(var(--topbar-h) - 1px); z-index: 5;
  font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-dim);
  margin: 10px -16px 4px; padding: 14px 20px 6px;
  background: linear-gradient(var(--bg) 78%, transparent);
}
.daylabel em { font-style: normal; color: var(--accent); }

.hint {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin: 8px 0 4px; padding: 10px 12px 10px 16px;
  font-size: .86rem; color: var(--text-dim);
  background: var(--surface-2); border-radius: var(--radius);
}
.hint .btn { flex: none; }

.cardwrap { position: relative; margin-bottom: 10px; border-radius: var(--radius); }
.cardwrap__action {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: flex-end;
  padding-right: 22px;
  border-radius: var(--radius);
  background: var(--danger); color: #fff;
  font-weight: 700; font-size: .9rem;
  opacity: 0;
}
.cardwrap--restore .cardwrap__action {
  background: var(--ok);
  justify-content: flex-start; padding-left: 22px;
}

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  touch-action: pan-y;
  will-change: transform;
}
.card.is-swiping { transition: none; user-select: none; -webkit-user-select: none; }
.card.is-settling { transition: transform .22s ease; }
.card:has(.card__main:active) { background: var(--surface-2); }
.card:has(.card__main:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.card__main:focus-visible { outline: none; }

.card__main {
  display: flex; flex-direction: column; gap: 6px;
  width: 100%; padding: 14px 16px;
  text-align: left; border-radius: var(--radius);
}
.card__top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.card__heading { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.eyebrow {
  display: flex; align-items: center; gap: 6px;
  font-size: .7rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: var(--text-dim);
}
.badge {
  padding: 1px 7px; border-radius: 999px;
  font-size: .68rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  background: var(--surface-2); color: var(--text-dim);
}
.badge--cancelled { background: var(--danger); color: #fff; }
.badge--full { background: var(--text); color: var(--bg); }
.badge--live { background: var(--accent-soft); color: var(--accent); }
.card__title { font-size: 1rem; font-weight: 650; letter-spacing: -.01em; overflow-wrap: anywhere; }
.card--cancelled .card__title { text-decoration: line-through; text-decoration-thickness: 1px; }
.card--cancelled .card__main, .card--cancelled .card__time { opacity: .6; }
.card__time { font-size: .86rem; font-weight: 600; color: var(--accent); white-space: nowrap; padding-top: 1px; font-variant-numeric: tabular-nums; }
.card__meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding-right: 36px; }
.chip {
  font-size: .78rem; font-weight: 600;
  color: var(--text-dim);
  background: var(--surface-2);
  border-radius: 999px; padding: 3px 10px;
}
.chip--more { background: none; border: 1px dashed var(--line); }
.card__dates { font-size: .8rem; color: var(--text-dim); }

/* Archive button: pointer devices only (touch uses the swipe). */
.card__archive {
  position: absolute; right: 8px; bottom: 6px;
  width: 36px; height: 36px;
  opacity: 0;
}
@media (hover: hover) {
  .card:hover .card__archive, .card__archive:focus-visible { opacity: 1; }
}
@media (hover: none) {
  .card__archive { display: none; }
}

/* skeletons */
.skel {
  height: 88px; border-radius: var(--radius); margin-bottom: 10px;
  background: linear-gradient(100deg, var(--surface) 40%, var(--surface-2) 50%, var(--surface) 60%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite;
  border: 1px solid var(--line);
}
@keyframes shimmer { to { background-position: -200% 0; } }

.empty {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  text-align: center; color: var(--text-dim);
  padding: 56px 24px; font-size: .95rem;
}
.empty__title { color: var(--text); font-weight: 650; font-size: 1.05rem; }
.empty__icon { font-size: 2rem; line-height: 1; margin-bottom: 6px; }
.empty .btn { margin-top: 12px; }

/* ---------- buttons ---------- */
.btn {
  border-radius: 999px; padding: 10px 18px; min-height: 40px;
  font-weight: 650; font-size: .9rem;
  transition: filter .15s, background .15s;
}
.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover { filter: brightness(1.08); }
.btn--ghost { background: var(--surface-2); }
.btn--ghost:hover { filter: brightness(.97); }
.btn--sm { padding: 6px 14px; min-height: 36px; font-size: .84rem; }

/* ---------- bottom sheet ---------- */
.sheet { position: fixed; inset: 0; z-index: 40; }
.sheet__backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, .42);
  opacity: 0; transition: opacity .22s;
}
.sheet.is-open .sheet__backdrop { opacity: 1; }
.sheet__panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-width: 720px; margin: 0 auto;
  max-height: 86dvh;
  display: flex; flex-direction: column;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, .25);
  transform: translateY(100%);
  transition: transform .26s cubic-bezier(.32, .72, .28, 1);
  padding-bottom: var(--sab);
}
.sheet__panel:focus { outline: none; }
.sheet.is-open .sheet__panel { transform: translateY(0); }
.sheet__grip { flex: none; touch-action: none; cursor: grab; }
.sheet__handle {
  width: 38px; height: 4px; border-radius: 2px;
  background: var(--line);
  margin: 10px auto 2px;
}
.sheet__head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 8px 12px 4px 20px;
}
.sheet__heading { padding-top: 6px; min-width: 0; }
.sheet__eyebrow { display: flex; gap: 6px; align-items: center; margin-bottom: 2px; }
.sheet__head h2 { font-size: 1.2rem; line-height: 1.25; letter-spacing: -.01em; overflow-wrap: anywhere; }
.sheet__body { overflow-y: auto; overscroll-behavior: contain; padding: 4px 20px 8px; }
.sheet__desc { color: var(--text-dim); font-size: .94rem; white-space: pre-line; margin-bottom: 18px; }
.sheet__desc .btn { margin-top: 8px; white-space: normal; }
.sheet__skel { display: flex; flex-direction: column; gap: 8px; padding-top: 4px; }
.sheet__skel i {
  display: block; height: 12px; border-radius: 6px;
  background: linear-gradient(100deg, var(--surface-2) 40%, var(--line) 50%, var(--surface-2) 60%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite;
}
.sheet__skel i:nth-child(2) { width: 92%; }
.sheet__skel i:nth-child(3) { width: 64%; }
.sheet__sub {
  font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-dim); margin-bottom: 2px;
}

.sheet__instances { display: flex; flex-direction: column; }
.inst {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 0 8px;
  border-top: 1px solid var(--line);
}
.inst:first-child { border-top: 0; }
.inst__when { font-size: .94rem; font-weight: 600; }
.inst__when em { font-style: normal; color: var(--accent); }
.inst__where { font-size: .82rem; color: var(--text-dim); }
.inst__actions { display: flex; gap: 2px; flex: none; }

.sheet__foot {
  flex: none; padding: 12px 20px calc(14px + var(--sab));
  border-top: 1px solid var(--line);
  display: flex; justify-content: center;
}

/* ---------- libraries picker ---------- */
.settings {
  position: fixed; inset: 0; z-index: 50;
  background: var(--bg);
  overflow-y: auto; overscroll-behavior: contain;
  animation: fadein .18s ease;
}
.settings:focus { outline: none; }
@keyframes fadein { from { opacity: 0; } }
.settings__tools { max-width: 720px; margin: 0 auto; padding: 4px 16px 0; }
.settings__quick { display: flex; gap: 8px; padding-top: 10px; }
.settings__list { max-width: 720px; margin: 0 auto; padding: 10px 16px calc(24px + var(--sab)); }
.settings__empty { max-width: 720px; margin: 0 auto; padding: 32px 16px; text-align: center; color: var(--text-dim); }
.setrow {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 8px;
  cursor: pointer;
}
.setrow:has(input:focus-visible) { border-color: var(--accent); }
.setrow__name { font-size: .95rem; }

.switch { position: relative; flex: none; width: 46px; height: 28px; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.switch__track {
  position: absolute; inset: 0; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line);
  transition: background .18s, border-color .18s;
}
.switch__track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 22px; height: 22px; border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  transition: transform .18s ease;
}
.switch input:checked + .switch__track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch__track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch__track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- snackbar ---------- */
.snackhost {
  position: fixed; left: 0; right: 0; bottom: calc(20px + var(--sab)); z-index: 60;
  display: flex; justify-content: center; pointer-events: none;
}
.snackbar {
  pointer-events: auto;
  display: flex; align-items: center; gap: 16px;
  background: var(--text); color: var(--bg);
  border-radius: 12px;
  padding: 6px 6px 6px 18px;
  font-size: .9rem;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .3);
  animation: snackin .2s ease;
  max-width: calc(100vw - 32px);
}
.snackbar #snackbarText { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@keyframes snackin { from { opacity: 0; transform: translateY(8px); } }
.snackbar__action {
  flex: none; min-height: 40px; padding: 0 12px; border-radius: 8px;
  font-weight: 700; color: var(--accent);
  text-transform: uppercase; font-size: .82rem; letter-spacing: .04em;
}
.snackbar__action:focus-visible { outline-color: var(--bg); }
@media (prefers-color-scheme: dark) {
  .snackbar__action { color: #ffb59f; }
}

@media (min-width: 720px) {
  .card__title { font-size: 1.05rem; }
  .sheet__panel { border-radius: 20px; bottom: 24px; left: 24px; right: 24px; }
}

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

/* ---------- library-events additions ---------- */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; gap: 2px; }
.seg__btn {
  border: 0; background: none; color: var(--text-dim); font: inherit; font-size: .84rem; font-weight: 600;
  padding: 6px 12px; min-height: 34px; border-radius: 999px; cursor: pointer;
}
.seg__btn:hover { color: var(--text); }
.seg__btn.is-active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }

.searchinfo { font-size: .86rem; color: var(--text-dim); padding: 4px 2px 10px; }
.searchinfo .linkbtn { font-size: inherit; }

.card__snippet {
  font-size: .86rem; color: var(--text-dim); margin: 2px 0 8px; padding-right: 36px;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
mark { background: color-mix(in srgb, var(--accent) 22%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }

.more { display: block; margin: 12px auto 24px; }

.sheet__descblock + .sheet__descblock { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.inst--cancelled .inst__when { text-decoration: line-through; text-decoration-color: color-mix(in srgb, currentColor 50%, transparent); }
.inst__when .badge { vertical-align: 1px; }

.sys { list-style: none; margin-bottom: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.sys__head { display: flex; align-items: center; gap: 8px; padding: 6px 12px 6px 4px; }
.sys__toggle {
  flex: 1; display: flex; align-items: center; gap: 6px; min-width: 0; text-align: left;
  border: 0; background: none; color: inherit; font: inherit; padding: 8px 4px; cursor: pointer; border-radius: 10px;
}
.sys__toggle svg { flex: none; color: var(--text-dim); transform: rotate(-90deg); transition: transform .15s ease; }
.sys__toggle.is-open svg { transform: none; }
.sys__label { display: flex; flex-direction: column; min-width: 0; }
.sys__name { font-weight: 650; font-size: .98rem; }
.sys__sub { font-size: .8rem; color: var(--text-dim); }
.sys__branches { list-style: none; border-top: 1px solid var(--line); padding: 4px 12px 8px 36px; }
.sys__branches .setrow { border: 0; background: none; padding: 8px 0; margin: 0; border-radius: 0; box-shadow: none; }
.sys__branches li + li .setrow { border-top: 1px solid var(--line); }
.setrow__n { margin-left: auto; margin-right: 12px; font-size: .8rem; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.switch input:indeterminate + .switch__track { background: color-mix(in srgb, var(--accent) 45%, var(--surface-2)); border-color: transparent; }
.switch input:indeterminate + .switch__track::after { transform: translateX(9px); }
.settings__note { max-width: 720px; margin: 0 auto; padding: 0 16px calc(24px + var(--sab)); font-size: .8rem; color: var(--text-dim); }

/* ---------- Nearby ---------- */
.scope { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; padding-top: 10px; }
.scope__origin { font-size: .88rem; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.near { padding-top: 2px; }
.pills--reach { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.pills--reach::-webkit-scrollbar { display: none; }
.pills--reach .pill { flex: none; }
.origin { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 12px; margin-top: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.origin__or { color: var(--text-dim); font-size: .86rem; }
.origin__zip {
  width: 7.5em; min-height: 36px; padding: 6px 12px; font: inherit; font-size: .95rem; color: var(--text);
  background: var(--surface-2); border: 1px solid transparent; border-radius: 999px; letter-spacing: .04em;
}
.origin__zip:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.origin__msg { flex-basis: 100%; margin: 0; font-size: .84rem; color: var(--text-dim); }
.origin__msg:empty { display: none; }
.origin__msg.is-error { color: var(--danger); }
.chip--dist { background: var(--accent-soft); color: var(--accent); border-color: transparent; font-weight: 600; }
.inst__dist { color: var(--accent); font-weight: 600; }
.settings__note a { color: inherit; }
.settings__note + .settings__note { margin-top: -16px; }

/* ---------- filter chips + picker ---------- */
.fbar {
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
  margin: 0 -16px; padding: 10px 16px 4px;
}
.fbar::-webkit-scrollbar { display: none; }
.fchip {
  flex: none; display: inline-flex; align-items: center; gap: 5px;
  min-height: 36px; padding: 0 10px 0 13px; border-radius: 999px;
  font-size: .86rem; font-weight: 600; color: var(--text-dim);
  background: var(--surface); border: 1px solid var(--line);
  transition: background .15s, color .15s, border-color .15s;
}
.fchip:hover { color: var(--text); border-color: var(--text-dim); }
.fchip > svg:last-child { opacity: .7; }
.fchip[aria-pressed] { padding-right: 13px; }
.fchip.is-set { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.fchip__label { max-width: 15em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.picker__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 20px 6px; }
.picker__head h2 { font-size: 1.2rem; letter-spacing: -.01em; }
.picker__clear { font-size: .9rem; padding: 8px 0; }
.picker .sheet__body { padding-bottom: 12px; }
.picker .scope { padding-top: 2px; }
.picker__sub { margin: 18px 0 8px; }
.picker .pills--reach { flex-wrap: wrap; overflow: visible; padding-top: 0; }
.picker .pills--reach .pill { min-height: 40px; font-size: .88rem; }
.picker__done { width: 100%; max-width: 420px; }
.mine { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; padding-top: 14px; }
.mine__list { font-size: .94rem; color: var(--text-dim); }

.optlist { border: 0; display: flex; flex-direction: column; }
.opt {
  display: flex; align-items: center; gap: 14px;
  min-height: 50px; padding: 4px 2px;
  border-top: 1px solid var(--line);
  font-size: 1rem; cursor: pointer;
}
.optlist legend + .opt { border-top: 0; }
.opt input { flex: none; width: 20px; height: 20px; margin: 0; accent-color: var(--accent); }
.opt__label { flex: 1; }
.opt__n { color: var(--text-dim); font-size: .86rem; font-variant-numeric: tabular-nums; }
