:root {
  --fb-bg: #ffffff;
  --fb-secondary: #f1f2f6;
  --fb-section: #ffffff;
  --fb-text: #111317;
  --fb-hint: #8a8f98;
  --fb-button: #2f7de1;
  --fb-button-text: #ffffff;
  --fb-danger: #e0493e;
  --fb-ok: #2fa65a;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fb-bg: #17191d;
    --fb-secondary: #0f1013;
    --fb-section: #1f2227;
    --fb-text: #eef0f3;
    --fb-hint: #8d939c;
    --fb-button: #4a90e8;
    --fb-danger: #ff6b5e;
    --fb-ok: #4cc27a;
  }
}

:root {
  --bg: var(--tg-theme-secondary-bg-color, var(--fb-secondary));
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, var(--fb-section)));
  --text: var(--tg-theme-text-color, var(--fb-text));
  --hint: var(--tg-theme-hint-color, var(--fb-hint));
  --accent: var(--tg-theme-button-color, var(--fb-button));
  --accent-text: var(--tg-theme-button-text-color, var(--fb-button-text));
  --danger: var(--tg-theme-destructive-text-color, var(--fb-danger));
  --ok: var(--fb-ok);
  --line: color-mix(in srgb, var(--hint) 22%, transparent);
  --soft: color-mix(in srgb, var(--accent) 12%, transparent);
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: 10px 16px 8px;
}
.tabs, .seg {
  display: flex; gap: 4px;
  background: var(--card);
  border-radius: 12px; padding: 4px;
  overflow-x: auto; scrollbar-width: none;
}
.tabs button, .seg button {
  flex: 1 0 auto;
  border: 0; background: transparent;
  padding: 7px 10px; border-radius: 9px;
  color: var(--hint); font-weight: 600; font-size: 14px;
  white-space: nowrap;
}
.tabs button[aria-selected="true"], .seg button[aria-selected="true"] {
  background: var(--accent); color: var(--accent-text);
}
.badge {
  display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px;
  border-radius: 9px; background: var(--danger); color: #fff; font-size: 12px; line-height: 18px;
}

main { max-width: 640px; margin: 0 auto; padding: 4px 16px 96px; }
.seg { margin: 4px 0 12px; }
.seg button { font-size: 13px; }

h2 {
  margin: 18px 4px 8px; font-size: 13px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em; color: var(--hint);
}
h2.alert { color: var(--danger); }
details > summary { list-style: none; cursor: pointer; }
details > summary::-webkit-details-marker { display: none; }
details > summary h2::after { content: " ▸"; }
details[open] > summary h2::after { content: " ▾"; }

.list { display: flex; flex-direction: column; gap: 8px; }
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 12px 14px; display: flex; gap: 12px; align-items: flex-start;
}
.card.tap { cursor: pointer; }
.card.dim { opacity: .62; }
.card .body { flex: 1; min-width: 0; }
.card .title { font-weight: 600; overflow-wrap: anywhere; }
.card .title.strike { text-decoration: line-through; }
.card .meta { color: var(--hint); font-size: 13px; margin-top: 2px; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.card .note { color: var(--hint); font-size: 13px; margin-top: 4px; white-space: pre-wrap; overflow-wrap: anywhere; }
.tag { font-size: 12px; font-weight: 600; padding: 1px 7px; border-radius: 7px; }
.tag.late { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.tag.fail { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.tag.done { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }

.check {
  flex: none; width: 26px; height: 26px; margin-top: 1px;
  border-radius: 50%; border: 2px solid var(--hint); background: transparent;
  display: grid; place-items: center; font-size: 14px; font-weight: 700; color: #fff; padding: 0;
}
.check.on { background: var(--ok); border-color: var(--ok); }
.check.fail { background: var(--danger); border-color: var(--danger); }
.check.static { cursor: default; }
.check.static:not(.on):not(.fail) { border-style: dashed; opacity: .45; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  border: 0; border-radius: 10px; padding: 6px 10px;
  background: var(--soft); color: var(--accent); font-size: 13px; font-weight: 600;
}
.chip.danger { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.link { border: 0; background: none; color: var(--accent); padding: 0; font-size: 13px; font-weight: 600; }

.when {
  flex: none; min-width: 58px; text-align: center;
  background: var(--soft); color: var(--accent);
  border-radius: 10px; padding: 6px 6px; font-size: 12px; font-weight: 700; line-height: 1.2;
}
.when.today { background: var(--accent); color: var(--accent-text); }
.when b { display: block; font-size: 18px; }

.empty { text-align: center; color: var(--hint); padding: 40px 12px; }
.screen { text-align: center; padding: 80px 24px; }
.screen .big { font-size: 48px; }

.toggle { display: flex; align-items: center; gap: 8px; margin: 6px 4px 10px; color: var(--hint); font-size: 14px; }
.history .card { display: block; }
.history .when-line { color: var(--hint); font-size: 12px; }
.history .changes { color: var(--hint); font-size: 13px; margin-top: 2px; }

.fab {
  position: fixed; right: max(16px, calc(50% - 304px)); bottom: calc(20px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%; border: 0;
  background: var(--accent); color: var(--accent-text); font-size: 30px; line-height: 1;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 40%, transparent);
}

.overlay {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(0, 0, 0, .45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--bg); width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
}
.sheet h3 { margin: 0 0 12px; font-size: 18px; }
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--hint); margin: 0 4px 4px; }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 11px;
  background: var(--card); padding: 10px 12px; outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field textarea { min-height: 72px; resize: vertical; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; min-width: 0; }
.btn {
  display: block; width: 100%; border: 0; border-radius: 12px; padding: 12px;
  background: var(--accent); color: var(--accent-text); font-weight: 700; margin-top: 8px;
}
.btn.ghost { background: var(--card); color: var(--accent); }
.btn.danger { background: var(--card); color: var(--danger); }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 30; max-width: calc(100% - 32px);
  background: color-mix(in srgb, var(--text) 88%, transparent); color: var(--bg);
  padding: 10px 16px; border-radius: 12px; font-size: 14px; text-align: center;
}
