:root {
  color-scheme: light dark;
  --bg: #f4f4f6;
  --surface: #ffffff;
  --text: #16181d;
  --muted: #62666f;
  --line: #dcdde2;
  --accent: #c8102e;
  --accent-text: #ffffff;
  --chip: #e8e9ee;
  --warn: #b3261e;
  --few: #8a5300;
  --few-bg: #ffe9c2;
  --new-bg: #d6f2dc;
  --new: #0f5d25;
  --tap: 44px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101216;
    --surface: #1a1d23;
    --text: #eceef2;
    --muted: #9aa0ab;
    --line: #2b2f37;
    --accent: #e0344f;
    --accent-text: #ffffff;
    --chip: #272b33;
    --warn: #ff7b72;
    --few: #ffcf7a;
    --few-bg: #4a3512;
    --new-bg: #14401f;
    --new: #8be0a0;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tap) + 24px + env(safe-area-inset-bottom));
}

.app-header {
  background: var(--accent);
  color: var(--accent-text);
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
}

.app-header h1 { margin: 0; font-size: 1.35rem; }
.updated { margin: 2px 0 0; font-size: 0.85rem; opacity: 0.9; }

main { max-width: 760px; margin: 0 auto; }

.view[hidden] { display: none; }

.filters { padding: 12px 12px 4px; }

.search {
  width: 100%;
  min-height: var(--tap);
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chips-scroll { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
.chips-scroll .chip { flex: 0 0 auto; }

.chip {
  min-height: var(--tap);
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--chip);
  color: var(--text);
  font: inherit;
  font-size: 0.92rem;
  cursor: pointer;
  white-space: nowrap;
}

.chip[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-text);
}

.chip .n { opacity: 0.7; margin-left: 4px; font-size: 0.8rem; }

.filter-row { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }
.count { color: var(--muted); font-size: 0.85rem; }

.list { padding: 4px 0 0; }

.day {
  position: sticky;
  top: 0;
  z-index: 2;
  margin: 0;
  padding: 8px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  font-size: 0.95rem;
  font-weight: 700;
}

.day .rel { color: var(--accent); font-weight: 600; margin-left: 6px; }

.card {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  min-height: var(--tap);
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  color: inherit;
  text-decoration: none;
}

.card:active { background: var(--chip); }

.time {
  flex: 0 0 3.4rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
  padding-top: 1px;
}

.time.allday { font-weight: 600; font-size: 0.8rem; color: var(--muted); }

.body { flex: 1 1 auto; min-width: 0; }
.title { font-weight: 600; overflow-wrap: anywhere; }
.meta { color: var(--muted); font-size: 0.88rem; overflow-wrap: anywhere; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }

.tag {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--chip);
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.4;
}

.tag.few { background: var(--few-bg); color: var(--few); font-weight: 600; }
.tag.new { background: var(--new-bg); color: var(--new); font-weight: 600; }
.tag.until { color: var(--text); }

.empty, .intro, .error-box { padding: 16px; color: var(--muted); }
.error-box { color: var(--warn); }

.link-list, .source-list { list-style: none; margin: 0; padding: 0; }

.link-list a {
  display: block;
  min-height: var(--tap);
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  color: inherit;
  text-decoration: none;
}

.link-list .name { font-weight: 600; }
.link-list .kinds { color: var(--muted); font-size: 0.88rem; }

.source-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.source-list .name { font-weight: 600; }
.source-list .detail { color: var(--muted); font-size: 0.85rem; overflow-wrap: anywhere; }
.source-list .num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.source-list .bad { color: var(--warn); font-weight: 700; }

.add-site { padding: 12px 12px 0; }
.add-form { margin-top: 12px; }
.add-form label { display: block; margin: 10px 0 4px; font-size: 0.88rem; color: var(--muted); }
.add-form[hidden], .add-msg[hidden] { display: none; }
.add-actions { display: flex; gap: 8px; margin-top: 12px; }
.chip.primary { background: var(--accent); color: var(--accent-text); }
.chip:disabled { opacity: 0.6; cursor: default; }
.add-msg { margin: 10px 0 0; padding: 0; color: var(--text); }
.add-msg.bad { color: var(--warn); }
.section-title { margin: 16px 16px 6px; font-size: 0.95rem; font-weight: 700; }
.source-list .state { text-align: right; max-width: 55%; }
.source-list .state .detail { text-align: right; }
.source-list a.name { color: inherit; text-decoration: underline; }

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}

.tab {
  flex: 1 1 0;
  min-height: calc(var(--tap) + 8px);
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

.tab[aria-selected="true"] { color: var(--accent); font-weight: 700; }

@media (min-width: 800px) {
  main { margin-top: 8px; }
  .card:first-of-type { border-top: 1px solid var(--line); }
}
