:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #1b1f2a;
  --muted: #667085;
  --border: #e4e7ec;
  --primary: #4f46e5;
  --primary-text: #ffffff;
  --success: #15803d;
  --success-bg: #dcfce7;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1220;
    --card: #181c2e;
    --text: #e8eaf3;
    --muted: #9aa3b8;
    --border: #2a3050;
    --primary: #8b85ff;
    --primary-text: #0f1220;
    --success: #4ade80;
    --success-bg: #12301d;
    --warn: #fbbf24;
    --warn-bg: #3a2c0b;
    --danger: #f87171;
    --danger-bg: #3b1515;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.05rem; }
h3 { font-size: 0.95rem; color: var(--muted); font-weight: 600; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }

.page { max-width: 640px; margin: 0 auto; padding: 16px; padding-top: calc(16px + env(safe-area-inset-top)); }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card > h2 + * { margin-top: 10px; }

/* Countdown hero */
.hero { text-align: center; }
.countdown { font-size: 2.4rem; font-weight: 700; letter-spacing: 0.02em; font-variant-numeric: tabular-nums; }
.countdown.low { color: var(--warn); }
.countdown.critical { color: var(--danger); }
.label { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

progress { width: 100%; height: 10px; appearance: none; border: 0; border-radius: 99px; overflow: hidden; background: var(--border); display: block; }
progress::-webkit-progress-bar { background: var(--border); }
progress::-webkit-progress-value { background: var(--primary); border-radius: 99px; }
progress::-moz-progress-bar { background: var(--primary); border-radius: 99px; }
progress.good::-webkit-progress-value { background: var(--success); }
progress.good::-moz-progress-bar { background: var(--success); }

.chip {
  display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 0.78rem; font-weight: 600;
  background: var(--border); color: var(--muted);
}
.chip.done { background: var(--success-bg); color: var(--success); }
.chip.missed { background: var(--danger-bg); color: var(--danger); }
.chip.paused, .chip.open { background: var(--warn-bg); color: var(--warn); }

/* Tasks */
.task { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-top: 1px solid var(--border); }
.task:first-of-type { border-top: 0; padding-top: 0; }
.check {
  flex: none; width: 32px; height: 32px; border-radius: 50%; border: 2px solid var(--primary);
  background: transparent; display: grid; place-items: center; cursor: pointer; padding: 0;
}
.check[aria-pressed="true"] { background: var(--success); border-color: var(--success); color: #fff; }
.check svg { width: 18px; height: 18px; }
.task.done .title { text-decoration: line-through; color: var(--muted); }
.title { font-weight: 600; }
.meta { font-size: 0.82rem; color: var(--muted); margin-top: 2px; }

/* Buttons and forms */
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--card); color: var(--text);
  border-radius: 12px; padding: 10px 16px; cursor: pointer; font-weight: 600; min-height: 44px;
}
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 0.9rem; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn:focus-visible, .check:focus-visible, .tab:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid var(--primary); outline-offset: 2px;
}
label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 4px; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg);
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 420px) { .form-grid { grid-template-columns: 1fr; } }
.full { grid-column: 1 / -1; }

.grid-buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.grid-buttons .btn { min-height: 56px; }
.grid-buttons .btn[aria-pressed="true"] { background: var(--primary); color: var(--primary-text); }

.notice { padding: 12px 14px; border-radius: 12px; background: var(--warn-bg); color: var(--warn); font-weight: 500; }
.notice.error { background: var(--danger-bg); color: var(--danger); }
.notice.ok { background: var(--success-bg); color: var(--success); }

.crew { display: grid; gap: 8px; }
.crew .msg { display: flex; gap: 10px; align-items: baseline; }
.crew .who { font-weight: 700; flex: none; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; text-align: center; }
.stat .num { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.list-row { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-top: 1px solid var(--border); align-items: center; }
.list-row:first-child { border-top: 0; }

/* Bottom navigation */
nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--border);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
nav.tabs .inner { display: flex; width: 100%; max-width: 640px; gap: 4px; }
.tab {
  flex: 1; border: 0; background: transparent; color: var(--muted); padding: 8px 4px; border-radius: 10px;
  display: grid; justify-items: center; gap: 2px; font-size: 0.72rem; font-weight: 600; cursor: pointer; min-height: 52px;
}
.tab svg { width: 22px; height: 22px; }
.tab[aria-current="page"] { color: var(--primary); background: color-mix(in srgb, var(--primary) 12%, transparent); }

.center { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 360px; }
.toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; z-index: 10; max-width: 90vw;
}
@media (prefers-reduced-motion: no-preference) {
  .card { transition: opacity 0.15s; }
}

.mt10 { margin-top: 10px; }
.mt12 { margin-top: 12px; }

.hint { margin-top: 6px; font-size: 0.85rem; color: var(--success); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
pre.code { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 10px; overflow-x: auto; font-size: 0.78rem; white-space: pre-wrap; word-break: break-all; margin: 8px 0; color: var(--text); }
.segmented { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; background: var(--border); border-radius: 12px; padding: 4px; }
.seg { border: 0; background: transparent; padding: 8px 4px; border-radius: 9px; font-weight: 600; color: var(--muted); cursor: pointer; min-height: 40px; }
.seg[aria-selected="true"] { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.seg:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
:root {
  --cat-Productive: #16a34a; --cat-Neutral: #94a3b8; --cat-Waste: #dc2626; --cat-Gaming: #9333ea;
  --cat-Leisure: #2563eb; --cat-Unlabeled: #d97706; --cat-Away: #cbd5e1;
}
@media (prefers-color-scheme: dark) {
  :root { --cat-Productive: #4ade80; --cat-Neutral: #94a3b8; --cat-Waste: #f87171; --cat-Gaming: #c084fc; --cat-Leisure: #60a5fa; --cat-Unlabeled: #fbbf24; --cat-Away: #475569; }
}
svg rect.c-Productive, .dot.c-Productive { fill: var(--cat-Productive); background: var(--cat-Productive); }
svg rect.c-Neutral, .dot.c-Neutral { fill: var(--cat-Neutral); background: var(--cat-Neutral); }
svg rect.c-Waste, .dot.c-Waste { fill: var(--cat-Waste); background: var(--cat-Waste); }
svg rect.c-Gaming, .dot.c-Gaming { fill: var(--cat-Gaming); background: var(--cat-Gaming); }
svg rect.c-Leisure, .dot.c-Leisure { fill: var(--cat-Leisure); background: var(--cat-Leisure); }
svg rect.c-Unlabeled, .dot.c-Unlabeled { fill: var(--cat-Unlabeled); background: var(--cat-Unlabeled); }
.dot.c-Away { background: var(--cat-Away); }
.dot { width: 12px; height: 12px; border-radius: 4px; flex: none; display: inline-block; }
svg { width: 100%; height: auto; display: block; }
svg .axis { font-size: 9px; fill: var(--muted); }
svg .baseline { stroke: var(--border); stroke-width: 1; }
.legend { display: grid; gap: 6px; }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 0.92rem; }
.chip.cat-Productive { background: var(--success-bg); color: var(--success); }
.chip.cat-Waste { background: var(--danger-bg); color: var(--danger); }
.chip.cat-Gaming, .chip.cat-Leisure { background: var(--border); color: var(--text); }
.label-select { width: auto; min-width: 120px; min-height: 40px; padding: 4px 8px; }
