:root {
  --paper: #f7f4ed;
  --card: #fffdf8;
  --ink: #2f2b26;
  --muted: #7a7268;
  --faint: #a29a8e;
  --rule: #e4ddce;
  --late: #9a5f4a;
  --hover: #ece6d8;
  --tag-bg: #efe7d6;
  --tag-ink: #7a6444;
  --p1-bg: #f6e7e0;
  --p1-rule: #d8b9ab;
  --shadow: 47, 43, 38;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --serif: Iowan Old Style, Palatino, Georgia, serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* Dark palette. Warm-neutral rather than blue-black, so the earthy accents
   from the light theme still sit comfortably on it. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1c1a17;
    --card: #26231f;
    --ink: #ece6da;
    --muted: #9a9287;
    --faint: #7b756c;
    --rule: #3a352e;
    --late: #cf8b70;
    --hover: #322e28;
    --tag-bg: #35302a;
    --tag-ink: #c0ab8a;
    --p1-bg: #3d2e28;
    --p1-rule: #6b4a3c;
    --shadow: 0, 0, 0;
  }
}

:root[data-theme="dark"] {
  --paper: #1c1a17;
  --card: #26231f;
  --ink: #ece6da;
  --muted: #9a9287;
  --faint: #7b756c;
  --rule: #3a352e;
  --late: #cf8b70;
  --hover: #322e28;
  --tag-bg: #35302a;
  --tag-ink: #c0ab8a;
  --p1-bg: #3d2e28;
  --p1-rule: #6b4a3c;
  --shadow: 0, 0, 0;
}

* { box-sizing: border-box; }

/* The grid rules below set display, which would otherwise defeat [hidden]. */
[hidden] { display: none !important; }

body {
  transition: background-color 220ms ease, color 220ms ease;
  margin: 0;
  padding: 1.5rem 1.25rem 4rem;
  max-width: 900px;
  margin-inline: auto;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input {
  font: inherit;
  color: inherit;
}

.marker {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.09em;
  color: var(--faint);
  margin: 2rem 0 0.7rem;
}

.marker:first-of-type { margin-top: 1.5rem; }

/* Header */

.datestamp {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.09em;
  color: var(--faint);
}

.summary {
  font-family: var(--serif);
  font-size: 19px;
  line-height: 1.45;
  margin: 0.4rem 0 0;
  min-height: 1.45em;
}

.summary.stale { color: var(--late); }

/* Counts */

.counts {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 1.5rem;
}

.count {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
}

.count.alert {
  background: color-mix(in srgb, var(--late) 8%, var(--card));
  border-color: color-mix(in srgb, var(--late) 28%, var(--rule));
}

.count span {
  display: block;
  font-size: 12px;
  color: var(--muted);
}

.count strong {
  font-size: 22px;
  font-weight: 500;
}

.count.alert strong { color: var(--late); }

/* Links */

.links {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 1.2rem;
}

.links a {
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 4px 12px;
}

.links a:hover { border-color: var(--faint); color: var(--ink); }

/* Theme switch */

.topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.themebar {
  position: relative;
  display: inline-flex;
  flex: none;
  padding: 3px;
  background: color-mix(in srgb, var(--ink) 7%, var(--paper));
  border: 1px solid color-mix(in srgb, var(--ink) 9%, var(--rule));
  border-radius: 999px;
}

.themebar::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  bottom: 3px;
  width: calc(33.333% - 2px);
  background: var(--card);
  border: 1px solid color-mix(in srgb, var(--ink) 11%, var(--rule));
  border-radius: 999px;
  box-shadow: 0 1px 2px rgba(var(--shadow), 0.16);
  transition: transform 240ms cubic-bezier(0.32, 0.72, 0, 1);
}

.themebar[data-theme="light"]::before { transform: translateX(100%); }
.themebar[data-theme="dark"]::before { transform: translateX(200%); }

.tseg {
  position: relative;
  z-index: 1;
  flex: 1 1 0;
  min-width: 52px;
  padding: 4px 10px;
  background: none;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.07em;
  color: var(--faint);
  transition: color 180ms ease;
  -webkit-tap-highlight-color: transparent;
}

.tseg.on { color: var(--ink); }
.tseg:not(.on):hover { color: var(--muted); }
.tseg:focus-visible { outline: 2px solid var(--muted); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  .themebar::before { transition: none; }
}

@media (max-width: 480px) {
  .tseg { min-width: 44px; padding: 4px 7px; }
}

/* Banner */

.banner {
  height: 96px;
  margin: -0.5rem 0 1.2rem;
  border-radius: 10px;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, #000 55%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 55%, transparent 100%);
}

.banner svg { display: block; width: 100%; height: 100%; }

@media (max-width: 480px) {
  .banner { height: 64px; }
}

@media (prefers-reduced-motion: no-preference) {
  .banner { animation: settle 700ms ease-out both; }
}

@keyframes settle {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}

/* View toggle */

.viewbar {
  position: relative;
  display: inline-flex;
  padding: 4px;
  margin: 2rem 0 0.8rem;
  background: color-mix(in srgb, var(--ink) 7%, var(--paper));
  border: 1px solid color-mix(in srgb, var(--ink) 9%, var(--rule));
  border-radius: 999px;
  box-shadow: inset 0 1px 2px rgba(var(--shadow), 0.06);
}

/* The thumb. Segments are flex-equal, so it slides by exactly 100%. */
.viewbar::before {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  bottom: 4px;
  width: calc(50% - 4px);
  background: var(--card);
  border: 1px solid color-mix(in srgb, var(--ink) 11%, var(--rule));
  border-radius: 999px;
  box-shadow: 0 1px 2px rgba(var(--shadow), 0.16);
  transition: transform 240ms cubic-bezier(0.32, 0.72, 0, 1);
}

.viewbar[data-view="horizon"]::before { transform: translateX(100%); }

.seg {
  position: relative;
  z-index: 1;
  /* Equal basis keeps both segments the same width whatever the label says. */
  flex: 1 1 0;
  min-width: 100px;
  padding: 6px 18px;
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.09em;
  color: var(--faint);
  border-radius: 999px;
  transition: color 180ms ease;
  -webkit-tap-highlight-color: transparent;
}

.seg.on { color: var(--ink); }
.seg:not(.on):hover { color: var(--muted); }
.seg:focus-visible { outline: 2px solid var(--muted); outline-offset: 2px; }
.viewbar:active::before { transform: scale(0.97); }
.viewbar[data-view="horizon"]:active::before { transform: translateX(100%) scale(0.97); }

@media (prefers-reduced-motion: reduce) {
  .viewbar::before { transition: none; }
}

/* Horizon buckets */

.bucket-count {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--faint);
}

.more {
  font-size: 12px;
  color: var(--faint);
  padding-top: 0.45rem;
  border-top: 1px solid var(--rule);
}

.item-where {
  display: inline-block;
  margin-left: 8px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  color: color-mix(in srgb, var(--tint, var(--muted)) 60%, var(--ink));
  background: color-mix(in srgb, var(--tint, var(--muted)) 14%, var(--card));
  border: 1px solid color-mix(in srgb, var(--tint, var(--muted)) 30%, var(--rule));
  border-radius: 999px;
  padding: 1px 8px;
  white-space: nowrap;
}

.item-meta { line-height: 1.9; }

/* Scrolling panels */

.scroller {
  max-height: 300px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.triage-body {
  max-height: calc(var(--rows, 12) * 3.35rem);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.scroller::-webkit-scrollbar,
.triage-body::-webkit-scrollbar {
  width: 9px;
}

.scroller::-webkit-scrollbar-track,
.triage-body::-webkit-scrollbar-track {
  background: transparent;
}

.scroller::-webkit-scrollbar-thumb,
.triage-body::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--tint, var(--muted)) 45%, var(--rule));
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
  min-height: 32px;
}

.scroller::-webkit-scrollbar-thumb:hover,
.triage-body::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--tint, var(--muted)) 70%, var(--rule));
  background-clip: content-box;
}

.scroller,
.triage-body {
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--muted) 45%, var(--rule)) transparent;
}

/* Focus grid */

.focus {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px;
}

.group {
  --tint: var(--muted);
  background: color-mix(in srgb, var(--tint) 7%, var(--card));
  border: 1px solid color-mix(in srgb, var(--tint) 24%, var(--rule));
  border-top: 3px solid var(--tint);
  border-radius: 12px;
  padding: 0.85rem 0.7rem 0.95rem 1.05rem;
  display: flex;
  flex-direction: column;
}

.group .scroller { padding-right: 0.35rem; }

.group-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 0.6rem;
}

.chip {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
  background: var(--tint);
}

.group-name {
  font-size: 14px;
  font-weight: 600;
  color: color-mix(in srgb, var(--tint) 55%, var(--ink));
}

.group-parent {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--faint);
}

.group .item {
  padding: 0.45rem 0;
  border-top: 1px solid color-mix(in srgb, var(--tint) 20%, var(--rule));
}
.group .item:first-of-type { border-top: none; padding-top: 0; }
.item-meta { font-size: 12px; color: var(--muted); margin-top: 1px; }
.item-meta.late { color: var(--late); }

/* Triage */

.triage {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 12px;
  overflow: hidden;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0.6rem 0.9rem;
  border-top: 1px solid var(--rule);
}

.row:first-child { border-top: none; }
.row.going { opacity: 0.35; }

.tick {
  flex: none;
  width: 19px;
  height: 19px;
  border: 1.5px solid var(--faint);
  border-radius: 50%;
  background: none;
  cursor: pointer;
  padding: 0;
}

.tick:hover { border-color: var(--ink); background: var(--hover); }

.row-body { flex: 1; min-width: 0; }
.row-title { font-size: 14px; }
.row-meta { font-size: 12px; color: var(--muted); }
.row-meta .late { color: var(--late); }

.tag {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.05em;
  background: var(--tag-bg);
  color: var(--tag-ink);
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: 5px;
}

.pill {
  flex: none;
  font-family: var(--mono);
  font-size: 11px;
  border: 1px solid var(--rule);
  border-radius: 5px;
  background: none;
  padding: 2px 7px;
  cursor: pointer;
  color: var(--muted);
}

.pill.p1 { border-color: var(--p1-rule); background: var(--p1-bg); color: var(--late); }

.snooze {
  flex: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 4px;
}

.snooze:hover { color: var(--ink); }

/* Quick add */

.add { display: flex; gap: 8px; margin-top: 0.8rem; }

.add input {
  flex: 1;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
}

.add input:focus { outline: none; border-color: var(--faint); }

.add button {
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--card);
  padding: 0 1rem;
  cursor: pointer;
}

.add button:hover { border-color: var(--faint); }

/* Passcode gate */

.gate {
  position: fixed;
  inset: 0;
  background: var(--paper);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.gate form { display: flex; flex-direction: column; gap: 10px; width: 220px; }
.gate input { background: var(--card); border: 1px solid var(--rule); border-radius: 8px; padding: 0.55rem 0.75rem; }
.gate button { border: 1px solid var(--rule); border-radius: 8px; background: var(--card); padding: 0.5rem; cursor: pointer; }

.error { color: var(--late); font-size: 13px; min-height: 1.2em; }
.empty { color: var(--faint); font-size: 14px; padding: 0.8rem 0; }

@media (max-width: 480px) {
  .counts { grid-template-columns: repeat(2, 1fr); }
  .summary { font-size: 17px; }
}
