:root {
  color-scheme: light dark;
  --bg: #fafafa;
  --fg: #1a1a1a;
  --muted: #6b6b6b;
  --card-bg: #ffffff;
  --border: #e2e2e2;
  --accent: #2563eb;
  --accent-fg: #ffffff;
  --emergency: #d32f2f;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --fg: #f2f2f2;
    --muted: #a0a0a0;
    --card-bg: #1e1e1e;
    --border: #333333;
    --accent: #3b82f6;
    --accent-fg: #0b0b0b;
  }
}

* { box-sizing: border-box; }

/* Author styles always beat the browser's default [hidden]{display:none}
   rule regardless of selector specificity, once an element also matches
   an author rule that sets its own `display` (e.g. .task-row's
   display:flex below) - so `hidden` alone silently does nothing on those
   elements without this. Toggle visibility with the `hidden` attribute
   everywhere in this app; this one rule is what makes that reliable. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.page {
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 16px 96px;
}

.today-header h1 {
  margin: 0;
  font-size: 1.6rem;
}

.today-date {
  margin: 4px 0 20px;
  color: var(--muted);
}

.zone { margin-bottom: 28px; }

.zone-title {
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 0 0 10px;
}

.task-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.task-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-left-width: 5px;
  border-radius: 10px;
  padding: 10px 12px;
}

/* Full Calendar day cell: a visible break where the timed group starts,
   marking the same untimed-then-timed grouping the Today view shows as
   two headed sections - scaled down to a divider line rather than a
   second heading, since a compact per-day cell has no room for one. */
.timed-zone-start {
  margin-top: 8px;
  padding-top: 18px;
  border-top: 1px dashed var(--border);
  position: relative;
}
.timed-zone-start::before {
  content: "Timed";
  position: absolute;
  top: -1px;
  left: 0;
  transform: translateY(-50%);
  background: var(--bg);
  padding: 0 6px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.complete-form { margin: 0; }

.complete-check {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
}

.complete-check:active { background: var(--accent); color: var(--accent-fg); }

.task-info {
  flex: 1;
  min-width: 0;
  color: inherit;
  text-decoration: none;
  display: block;
}

.task-name-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.task-name { font-weight: 600; }
.task-time { font-weight: 600; color: var(--accent); }

.badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 6px;
  text-transform: uppercase;
}

.badge-daylock { background: var(--border); color: var(--fg); }
.badge-notes { background: transparent; border: 1px solid var(--border); color: var(--muted); }
.badge-quota { background: var(--accent); color: var(--accent-fg); }

.quota-actions { display: flex; flex-direction: column; gap: 16px; margin-bottom: 24px; }
.quota-actions .delete-form { margin-top: 0; }
.quota-actions .nav-button:not(.nav-primary) { width: 100%; }

.detail-list { margin: 0 0 24px; }

.detail-row {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.detail-row dt {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.detail-row dd {
  margin: 4px 0 0;
  white-space: pre-wrap;
}

.task-meta {
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

.category-chip {
  color: #fff;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}

.empty-state { color: var(--muted); font-style: italic; }

.delete-form { margin-top: 24px; }
.nav-danger {
  background: transparent;
  color: var(--emergency);
  border-color: var(--emergency);
  width: 100%;
  cursor: pointer;
  font-size: 1rem;
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--border);
}

.nav-button {
  flex: 1;
  text-align: center;
  padding: 14px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--fg);
  text-decoration: none;
  font-weight: 600;
}

.nav-primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }

.task-form { display: flex; flex-direction: column; gap: 16px; }

.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }

.field input, .field select, .field textarea {
  font-size: 1rem;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--fg);
  font-weight: normal;
}

fieldset.field {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
}

.radio-inline { font-weight: normal; margin-right: 12px; display: inline-flex; gap: 4px; align-items: center; }

fieldset select, fieldset input[type="date"], fieldset input[type="number"] { margin-top: 8px; width: 100%; }

.radio-inline-group { display: flex; flex-wrap: wrap; margin-top: 8px; }
.recurrence-day-of-month-fields, .recurrence-nth-weekday-fields { margin-top: 8px; }
.recurrence-nth-weekday-fields { display: flex; gap: 8px; }
.recurrence-nth-weekday-fields select { margin-top: 0; }

.field-note {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-weight: normal;
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 10px;
}

.form-actions { display: flex; gap: 10px; }

.error-list {
  background: #fdecea;
  color: #611a15;
  border: 1px solid #f5c6cb;
  border-radius: 8px;
  padding: 10px 16px;
  margin-bottom: 16px;
}

.more-list { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.more-list li { display: flex; align-items: center; gap: 8px; }
.more-list form { flex: 1; margin: 0; }
.more-list form .nav-button { width: 100%; cursor: pointer; }
.coming-soon { color: var(--muted); font-size: 0.85rem; }

.category-nav-button { text-align: left; border-left-width: 5px; }

.category-manage-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }

.category-manage-row {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-left-width: 5px;
  border-radius: 10px;
  padding: 12px;
}

.category-manage-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
}

.category-rank { color: var(--muted); font-size: 0.85rem; }

.task-row-manage { flex-direction: column; align-items: stretch; gap: 10px; }

.row-actions { display: flex; gap: 8px; }
.row-actions .nav-button { flex: 1; padding: 10px 12px; font-size: 0.9rem; cursor: pointer; }
.row-actions form { flex: 1; margin: 0; }

.rules-section { margin-bottom: 24px; }
.rules-section h2 { font-size: 1.05rem; margin: 0 0 8px; }
.rules-section p { margin: 0 0 10px; line-height: 1.5; }

.rules-section.disclaimer {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  background: var(--card-bg);
}

.calendar-nav { display: flex; gap: 10px; margin-bottom: 20px; }
.nav-disabled { opacity: 0.4; pointer-events: none; }

.calendar-jump {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin-bottom: 20px;
}
.calendar-jump .field-note { flex: 1; margin-top: 0; }
.calendar-jump input[type="date"] {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--fg);
}
.calendar-jump button { flex: 0 0 auto; padding: 10px 16px; }

.calendar-days { display: flex; flex-direction: column; gap: 18px; margin-bottom: 24px; }

.calendar-day {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  background: var(--card-bg);
}

.calendar-today { border-color: var(--accent); border-width: 2px; }

.calendar-day-title {
  margin: 0 0 10px;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.calendar-closed { color: var(--muted); margin: 0; }

.quota-marker-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.quota-marker {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px dashed var(--border);
  border-left-width: 5px;
  border-radius: 10px;
  padding: 8px 12px;
}

.quota-marker-label { font-size: 0.85rem; color: var(--muted); font-style: italic; }
