/* Emerald theme: mint-tinted paper, deep emerald brand, warm gold for deadlines and progress. */
:root {
  --bg: #eef6f1;
  --bg-glow: #c9ecd9;
  --surface: #fbfefc;
  --surface-2: #dcefe5;
  --ink: #0b2a20;
  --ink-soft: #4b6a5e;
  --line: #cde3d7;
  --brand: #047857;
  --brand-ink: #ffffff;
  --hero-bg: linear-gradient(135deg, #064e3b 0%, #047857 55%, #10b981 130%);
  --hero-ink: #ecfdf5;
  --accent: #e3a83a;
  --accent-soft: #fbefd2;
  --danger: #b4483c;
  --ok: #059669;
  --ok-soft: #d1fae5;
  --shadow: 0 1px 2px rgb(6 78 59 / 6%), 0 8px 22px rgb(6 78 59 / 8%);
  --radius: 18px;
  --font-body: "Atkinson Hyperlegible", system-ui, sans-serif;
  --font-display: "Fraunces", Georgia, serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #06140f;
    --bg-glow: #0b3a2a;
    --surface: #0e211a;
    --surface-2: #163428;
    --ink: #e4f4ec;
    --ink-soft: #8fb4a4;
    --line: #1d3b30;
    --brand: #34d399;
    --brand-ink: #032b1f;
    --hero-bg: linear-gradient(135deg, #064e3b 0%, #065f46 60%, #047857 130%);
    --hero-ink: #ecfdf5;
    --accent: #f0c063;
    --accent-soft: #3a2e12;
    --danger: #e0877c;
    --ok: #34d399;
    --ok-soft: #0f3326;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
/* Soft emerald glow at the top of the screen. */
body { background: radial-gradient(120% 340px at 50% -80px, var(--bg-glow), transparent 70%) no-repeat, var(--bg); }
body {
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

#app { max-width: 640px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }

/* --- Top bar --- */
.topbar {
  display: flex; justify-content: space-between; align-items: flex-end;
  padding: calc(env(safe-area-inset-top, 0px) + 20px) 20px 8px;
}
.eyebrow { margin: 0; color: var(--ink-soft); font-size: 14px; text-transform: capitalize; }
h1 { margin: 2px 0 0; font-family: var(--font-display); font-weight: 650; font-size: 34px; letter-spacing: -0.02em; }
h2 {
  font-family: var(--font-display); font-weight: 500; font-size: 21px;
  margin: 28px 0 10px; display: flex; align-items: baseline; gap: 8px;
}
h2 .count { font-family: var(--font-body); font-size: 14px; color: var(--ink-soft); }
.icon-btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  width: 44px; height: 44px; display: grid; place-items: center;
}
.icon-btn.spinning svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

main { flex: 1; padding: 0 16px calc(96px + var(--safe-bottom)); }

/* --- Hero summary --- */
.hero {
  background: var(--hero-bg); color: var(--hero-ink); border-radius: var(--radius);
  padding: 18px 20px; margin-top: 10px; box-shadow: var(--shadow);
}
.hero p { margin: 0; }
.hero .big { font-family: var(--font-display); font-size: 24px; line-height: 1.2; }
.hero .small { opacity: 0.85; margin-top: 6px; font-size: 15px; }

/* --- Progress (finite list) --- */
.progress { margin-top: 14px; display: flex; gap: 6px; }
.progress span { flex: 1; height: 6px; border-radius: 99px; background: color-mix(in srgb, var(--hero-ink) 25%, transparent); }
.progress span.done { background: var(--accent); }

/* --- Cards --- */
.list { display: flex; flex-direction: column; gap: 10px; }
.card-wrap { position: relative; border-radius: var(--radius); overflow: hidden; }
.swipe-bg {
  position: absolute; inset: 0; display: flex; justify-content: space-between; align-items: center;
  padding: 0 22px; font-weight: 700; font-size: 15px;
}
.swipe-bg .left { color: var(--ok); }
.swipe-bg .right { color: var(--accent); }
.card-wrap[data-dir="right"] .swipe-bg { background: var(--ok-soft); }
.card-wrap[data-dir="left"] .swipe-bg { background: var(--accent-soft); }
.card {
  position: relative; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
  touch-action: pan-y; user-select: none; transition: transform 0.2s ease;
  display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: start; width: 100%; text-align: left;
}
.card.dragging { transition: none; }
.card .check {
  width: 28px; height: 28px; border-radius: 99px; border: 2px solid var(--line); background: transparent;
  display: grid; place-items: center; margin-top: 1px; padding: 0;
}
.card .check svg { width: 16px; height: 16px; opacity: 0; }
.card .check:hover svg, .card .check:focus-visible svg { opacity: 0.4; }
.card.is-done .check { background: var(--ok); border-color: var(--ok); color: white; }
.card.is-done .check svg { opacity: 1; }
.card.is-done .title { text-decoration: line-through; color: var(--ink-soft); }
.card .title { font-weight: 700; margin: 0; }
.card .meta { margin: 4px 0 0; font-size: 14px; color: var(--ink-soft); display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
.card .summary { margin: 4px 0 0; color: var(--ink-soft); font-size: 15px; }
.card.compact { grid-template-columns: 1fr; padding: 12px 16px; }

.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 99px;
  font-size: 13px; background: var(--surface-2); color: var(--ink); font-weight: 700;
}
.chip.due { background: var(--accent-soft); color: var(--ink); }
.chip.overdue { background: var(--danger); color: white; }
.chip.high { background: var(--accent); color: #2b1608; }

.more-btn {
  border: 1px dashed var(--line); background: transparent; border-radius: var(--radius);
  padding: 12px; color: var(--ink-soft); width: 100%;
}

/* --- Collapsible info groups --- */
details.group { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px; }
details.group summary {
  list-style: none; padding: 14px 16px; display: flex; justify-content: space-between; align-items: center;
  font-weight: 700; cursor: pointer;
}
details.group summary::-webkit-details-marker { display: none; }
details.group summary .count { color: var(--ink-soft); font-weight: 400; }
details.group[open] summary { border-bottom: 1px solid var(--line); }
details.group .row {
  padding: 12px 16px; border-bottom: 1px solid var(--line); display: block; width: 100%;
  background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left;
}
details.group .row:last-child { border-bottom: 0; }
details.group .row p { margin: 0; }
details.group .row .from { font-size: 13px; color: var(--ink-soft); }

/* --- Empty / calm states --- */
.calm {
  text-align: center; padding: 48px 20px; color: var(--ink-soft);
}
.calm .emoji { font-size: 44px; }
.calm p.big { font-family: var(--font-display); font-size: 24px; color: var(--ink); margin: 10px 0 4px; }

/* --- Topic chips row --- */
/* Wraps instead of scrolling: a hidden horizontal scroll looked "cut" and was unreachable with a mouse. */
.topic-row { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 0 16px; }
.topic-row button {
  border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 7px 8px 7px 14px;
  display: inline-flex; align-items: center; gap: 8px; min-height: 40px;
}
.topic-row button .n {
  font-size: 13px; font-weight: 700; min-width: 24px; height: 24px; padding: 0 7px; border-radius: 99px;
  display: inline-grid; place-items: center; background: var(--surface-2); color: var(--ink-soft);
}
.topic-row button.active { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.topic-row button.active .n { background: color-mix(in srgb, var(--brand-ink) 22%, transparent); color: var(--brand-ink); }

/* --- Forms / settings --- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.panel h3 { margin: 0 0 6px; font-size: 17px; }
.panel p.help { margin: 0 0 12px; color: var(--ink-soft); font-size: 15px; }
label.field { display: block; margin-bottom: 12px; font-size: 14px; color: var(--ink-soft); }
label.field input, label.field select {
  display: block; width: 100%; margin-top: 4px; padding: 12px 14px; font-size: 16px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--ink);
}
.btn {
  border: 0; border-radius: 14px; padding: 13px 18px; font-weight: 700; background: var(--brand); color: var(--brand-ink);
  min-height: 48px;
}
.btn.secondary { background: var(--surface-2); color: var(--ink); }
.btn.ghost { background: transparent; color: var(--ink-soft); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.btn.wide { width: 100%; }
.btn[disabled] { opacity: 0.55; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; }
.account { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.account:last-child { border-bottom: 0; }
.account .sub { font-size: 13px; color: var(--ink-soft); }
.account .err { font-size: 13px; color: var(--danger); }
.notice { background: var(--accent-soft); border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-bottom: 12px; }

/* --- Login --- */
.login { padding-top: 12vh; }
.login .panel { padding: 22px; }

/* --- Tab bar --- */
.tabbar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; width: 100%; max-width: 640px;
  display: flex; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); padding: 6px 8px calc(6px + var(--safe-bottom));
}
.tab {
  flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 12px; color: var(--ink-soft); padding: 6px 0; border-radius: 12px; min-height: 52px;
}
.tab.active { color: var(--brand); font-weight: 700; }

/* --- Bottom sheet --- */
.sheet-backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / 35%); z-index: 20; }
.sheet {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; width: 100%; max-width: 640px; z-index: 21;
  background: var(--surface); border-radius: 22px 22px 0 0; padding: 10px 20px calc(20px + var(--safe-bottom));
  max-height: 88dvh; overflow-y: auto; animation: rise 0.22s ease;
}
@keyframes rise { from { transform: translate(-50%, 30px); opacity: 0; } }
.sheet .grabber { width: 40px; height: 5px; border-radius: 99px; background: var(--line); margin: 0 auto 14px; }
.sheet h3 { font-family: var(--font-display); font-weight: 500; font-size: 23px; margin: 0 0 6px; line-height: 1.25; }
.sheet .from { color: var(--ink-soft); font-size: 14px; margin: 0 0 14px; }
.sheet .block { background: var(--bg); border-radius: 14px; padding: 12px 14px; margin-bottom: 12px; }
.sheet .block .label { font-size: 13px; color: var(--ink-soft); margin: 0 0 2px; }
.sheet .block p { margin: 0; }
.sheet .section-label { font-size: 13px; color: var(--ink-soft); margin: 16px 0 8px; }
.sheet .stack { display: flex; flex-direction: column; gap: 8px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { border: 1px solid var(--line); background: var(--bg); border-radius: 99px; padding: 8px 12px; font-size: 14px; }
.seg button.active { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

/* --- Toast --- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + var(--safe-bottom)); z-index: 30;
  background: var(--ink); color: var(--bg); border-radius: 14px; padding: 12px 16px; font-size: 15px;
  display: flex; gap: 14px; align-items: center; box-shadow: var(--shadow); max-width: calc(100% - 32px);
}
.toast button { background: none; border: 0; color: var(--accent); font-weight: 700; padding: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* --- History --- */
.history .intro { color: var(--ink-soft); font-size: 15px; margin: 6px 0 0; }
.hist-row {
  display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 12px 10px 16px;
}
.hist-main { flex: 1; min-width: 0; background: none; border: 0; padding: 2px 0; text-align: left; }
.hist-main .title { margin: 0; font-weight: 700; color: var(--ink-soft); }
.hist-main .meta { margin: 4px 0 0; font-size: 13px; color: var(--ink-soft); display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; }
.btn.small { min-height: 38px; padding: 8px 12px; font-size: 14px; border-radius: 12px; flex: none; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.calm.small { padding: 24px 12px; }
details.group .help-row { margin: 0; padding: 10px 16px; font-size: 14px; color: var(--ink-soft); border-bottom: 1px solid var(--line); }
details.group .filtered-row { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
details.group .filtered-row > div { min-width: 0; }
details.group .filtered-row p:first-child { overflow-wrap: anywhere; }
