/* ---------- tokens ---------- */
:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #efede8;
  --text: #1c1b18;
  --text-dim: #6f6c64;
  --accent: #b5432a;        /* SFPL-ish brick red */
  --accent-soft: #f6e3de;
  --line: #e3e0d9;
  --danger: #b5432a;
  --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);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171614;
    --surface: #201f1c;
    --surface-2: #2a2925;
    --text: #ece9e2;
    --text-dim: #9b978d;
    --accent: #e07a5f;
    --accent-soft: #3a2721;
    --line: #33312c;
    --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; }
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;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
ul { list-style: none; }

/* ---------- 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: .74rem; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar__status.is-error { color: var(--danger); }
.topbar__actions { display: flex; gap: 4px; align-items: center; }

.iconbtn {
  display: grid; place-items: center;
  width: 40px; height: 40px; 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); } }

/* ---------- tabs ---------- */
.tabs {
  display: flex; gap: 4px;
  padding: 10px 16px 2px;
  max-width: 720px; margin: 0 auto; width: 100%;
}
.tab {
  padding: 7px 14px; border-radius: 999px;
  font-size: .9rem; font-weight: 600; color: var(--text-dim);
  transition: background .15s, color .15s;
}
.tab:hover { color: var(--text); }
.tab.is-active { background: var(--text); color: var(--bg); }
.tab__count { font-weight: 400; opacity: .7; }

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

.daylabel {
  font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-dim);
  margin: 22px 4px 8px;
}
.daylabel:first-child { margin-top: 12px; }
.daylabel em { font-style: normal; color: var(--accent); }

.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: #3a7d44;
  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);
  padding: 14px 16px;
  display: flex; flex-direction: column; gap: 6px;
  touch-action: pan-y;
  will-change: transform;
  cursor: pointer;
}
.card:active { background: var(--surface-2); }
.card.is-swiping { transition: none; }
.card.is-settling { transition: transform .22s ease; }

.card__top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.card__title { font-size: 1rem; font-weight: 650; letter-spacing: -.01em; }
.card__time { font-size: .86rem; font-weight: 600; color: var(--accent); white-space: nowrap; }
.card__meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip {
  font-size: .74rem; font-weight: 600;
  color: var(--text-dim);
  background: var(--surface-2);
  border-radius: 999px; padding: 3px 9px;
}
.chip--more { background: none; border: 1px dashed var(--line); }
.card__dates { font-size: .8rem; color: var(--text-dim); }

/* skeletons */
.skel {
  height: 76px; 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 {
  text-align: center; color: var(--text-dim);
  padding: 64px 24px; font-size: .95rem;
}
.empty .btn { margin-top: 14px; }

/* ---------- buttons ---------- */
.btn {
  border-radius: 999px; padding: 9px 18px;
  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 13px; font-size: .82rem; }

/* ---------- 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.is-open .sheet__panel { transform: translateY(0); }
.sheet__handle {
  width: 38px; height: 4px; border-radius: 2px;
  background: var(--line);
  margin: 10px auto 2px;
  flex: none;
}
.sheet__head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 8px 20px 4px;
  flex: none;
}
.sheet__head h2 { font-size: 1.15rem; letter-spacing: -.01em; padding-top: 6px; }
.sheet__body { overflow-y: auto; padding: 4px 20px 8px; }
.sheet__desc { color: var(--text-dim); font-size: .92rem; white-space: pre-line; margin-bottom: 14px; }
.sheet__desc.is-loading { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }

.sheet__instances { display: flex; flex-direction: column; }
.inst {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 0;
  border-top: 1px solid var(--line);
}
.inst__when { font-size: .92rem; font-weight: 600; }
.inst__where { font-size: .8rem; color: var(--text-dim); }
.inst__past { opacity: .45; }
.inst__actions { display: flex; gap: 2px; flex: none; }
.inst__actions .iconbtn { width: 36px; height: 36px; }

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

/* ---------- settings ---------- */
.settings {
  position: fixed; inset: 0; z-index: 50;
  background: var(--bg);
  overflow-y: auto;
  animation: fadein .18s ease;
}
@keyframes fadein { from { opacity: 0; } }
.settings__quick {
  display: flex; gap: 8px;
  max-width: 720px; margin: 0 auto; padding: 12px 16px 4px;
}
.settings__list { max-width: 720px; margin: 0 auto; padding: 8px 16px calc(24px + var(--sab)); }
.setrow {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom-width: 0;
  cursor: pointer;
}
.setrow:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.setrow:last-child { border-radius: 0 0 var(--radius) var(--radius); border-bottom-width: 1px; }
.setrow:only-child { border-radius: var(--radius); }
.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); }

/* ---------- snackbar ---------- */
.snackbar {
  position: fixed; left: 50%; bottom: calc(20px + var(--sab)); z-index: 60;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 16px;
  background: var(--text); color: var(--bg);
  border-radius: 12px;
  padding: 12px 18px;
  font-size: .9rem;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .3);
  animation: snackin .2s ease;
  max-width: calc(100vw - 32px);
}
@keyframes snackin { from { opacity: 0; transform: translate(-50%, 8px); } }
.snackbar__action {
  font-weight: 700; color: var(--accent);
  text-transform: uppercase; font-size: .82rem; letter-spacing: .04em;
  flex: none;
}
@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; }
}
