:root {
  --bg: #12161d;
  --surface: #1b2129;
  --surface-2: #232b35;
  --text: #eef1f5;
  --muted: #9aa5b4;
  --border: #2e3846;
  --accent: #f2b134;
  --accent-text: #1a1305;
  --danger: #ff6b6b;
  --danger-bg: #3a1d20;
  --ok: #4cc38a;
  --focus: #7cb7ff;
  --radius: 12px;
  font-size: 18px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #eef1f5;
    --text: #141a22;
    --muted: #5b6676;
    --border: #d7dde5;
    --accent: #b97700;
    --accent-text: #ffffff;
    --danger: #c62828;
    --danger-bg: #fdecec;
    --ok: #1d7f4f;
    --focus: #1d5fd1;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

#app { max-width: 760px; margin: 0 auto; padding: 16px 16px 48px; }
h1 { font-size: 1.6rem; margin: 0 0 4px; font-weight: 700; }
h2 { font-size: 1.05rem; margin: 0; font-weight: 700; display: inline; }
.muted { color: var(--muted); font-size: 0.85rem; }
.error { color: var(--danger); min-height: 1.4em; }

button, input { font: inherit; color: inherit; }
button {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  min-height: 44px;
  cursor: pointer;
}
button:hover { border-color: var(--muted); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 700; }
button.link { background: none; border: none; color: var(--muted); text-decoration: underline; padding: 8px 0; min-height: 0; }
button.big { font-size: 1.15rem; padding: 14px 20px; min-height: 56px; flex: 1 1 0; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

input[type="text"], input[type="password"] {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  min-height: 48px;
}

.row-form { display: flex; gap: 8px; }
.row-form input { flex: 1 1 auto; min-width: 0; }
.row-form button { flex: 0 0 auto; }

.top { margin: 4px 0 14px; }
.summary { margin: 0; font-size: 1.1rem; color: var(--muted); }
.summary.has-overdue { color: var(--danger); font-weight: 600; }

.capture { position: sticky; top: 0; z-index: 2; background: var(--bg); padding: 8px 0; }
.capture input { font-size: 1.1rem; }
.capture-result { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--ok); border-radius: var(--radius); padding: 10px 14px; margin: 4px 0 12px; }
.capture-result.kind-error { border-left-color: var(--danger); }
.capture-result.kind-queued, .capture-result.kind-fallback, .capture-result.kind-confirm { border-left-color: var(--accent); }
.capture-result p { margin: 0; }
.capture-options { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.capture-options:empty { display: none; }

.section { margin: 18px 0 0; }
.section > h2, .section summary { display: block; margin-bottom: 8px; }
.section summary { cursor: pointer; padding: 6px 0; list-style-position: inside; }
.count { color: var(--muted); font-weight: 400; }
.overdue > h2 { color: var(--danger); }
.empty { color: var(--muted); margin: 4px 0; }
.day-head { margin: 12px 0 6px; color: var(--muted); font-size: 0.9rem; text-transform: capitalize; }

.tasks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.task {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  transition: opacity 0.35s ease, transform 0.35s ease;
}
.overdue .task { border-left: 4px solid var(--danger); }
.task.next { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.task.next .title { font-size: 1.2rem; }
.task.gone { opacity: 0; transform: translateX(24px); }
.task .info { flex: 1 1 220px; min-width: 0; }
.task .line1 { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.task .when { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--accent); white-space: nowrap; }
.overdue .task .when { color: var(--danger); }
.task .title { font-weight: 600; word-break: break-word; }
.task .meta { color: var(--muted); font-size: 0.8rem; margin-top: 2px; }
.badge { background: var(--danger); color: #fff; font-size: 0.7rem; font-weight: 800; letter-spacing: 0.04em; padding: 2px 6px; border-radius: 6px; }
.task .actions { display: flex; gap: 8px; flex: 0 0 auto; }
.task .actions .done { background: var(--ok); border-color: var(--ok); color: #06140d; font-weight: 700; }
.postpone-menu { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 8px; padding-top: 4px; }
.postpone-menu form { display: flex; gap: 8px; flex-basis: 100%; }
.postpone-menu input { flex: 1 1 auto; min-width: 0; }

.foot { margin-top: 32px; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

.screen#token-screen { padding-top: 15vh; }
.screen#token-screen p { color: var(--muted); }

.screen#alert-screen { padding-top: 6vh; text-align: center; }
.alert-card { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 24px 18px; }
.alert-card.urgent { border: 2px solid var(--danger); background: linear-gradient(var(--danger-bg), var(--surface)); }
.alert-kind { color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.8rem; margin: 0 0 8px; }
.alert-card.urgent .alert-kind { color: var(--danger); font-weight: 800; }
.alert-card h1 { font-size: 1.9rem; word-break: break-word; }
.alert-body { white-space: pre-line; font-size: 1.1rem; }
.alert-actions { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.alert-msg { margin: 14px 0 0; font-weight: 600; min-height: 1.4em; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 16px; max-width: calc(100vw - 32px); z-index: 10; box-shadow: 0 6px 24px rgba(0,0,0,0.35);
}
.toast.error { border-color: var(--danger); }

@media (max-width: 480px) {
  :root { font-size: 17px; }
  #app { padding: 10px 12px 40px; }
  .task .actions { flex: 1 1 100%; }
  .task .actions button { flex: 1 1 0; }
}

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