:root {
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #222221;
  --border: rgba(255, 255, 255, 0.10);
  --ink: #ffffff;
  --ink-secondary: #c3c2b7;
  --ink-muted: #898781;
  --accent: #3987e5;
  --accent-dark: #2a6fc4;
  --pill: #9085e9;
  --good: #0ca30c;
  --warn: #fab219;
  --danger: #d03b3b;

  color-scheme: dark;
  --radius: 14px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

button {
  transition: transform 0.08s ease;
  font-family: inherit;
}
button:active { transform: scale(0.95); }
button:disabled { opacity: 0.55; cursor: default; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
  padding-bottom: calc(32px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top)) 18px 14px;
  background: rgba(13, 13, 13, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 1.3rem; font-weight: 700; margin: 0; }

.icon-btn {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--surface-2);
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.icon-btn:active { background: var(--border); }

.page {
  max-width: 560px;
  margin: 0 auto;
  padding: 14px 14px 8px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 14px;
}

/* --- Date --- */
.date-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.date-field {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.date-caption {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-secondary);
  min-height: 1.2em;
}
.date-caption.today { color: var(--good); }
.date-field input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 600;
  font-family: inherit;
  text-align: center;
  color-scheme: dark;
}
.date-field input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* --- Checklist --- */
.checklist {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 54px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink);
  font-size: 1.05rem;
  text-align: left;
  cursor: pointer;
}
.check-row:active { transform: scale(0.98); }
.check-row.on {
  border-color: var(--pill);
  background: rgba(144, 133, 233, 0.16);
}
.check-box {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 2px solid var(--ink-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  color: transparent;
}
.check-row.on .check-box {
  background: var(--pill);
  border-color: var(--pill);
  color: #fff;
}
.check-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.check-note { color: var(--ink-muted); font-size: 0.8rem; }

.empty-pills {
  text-align: center;
  color: var(--ink-muted);
  padding: 18px 8px;
  line-height: 1.5;
}

.save-state {
  min-height: 1.3em;
  margin: 12px 0 8px;
  font-size: 0.85rem;
  text-align: center;
  color: var(--ink-muted);
}
.save-state.saved { color: var(--good); }
.save-state.dirty { color: var(--warn); }

.btn-primary {
  width: 100%;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 700;
  padding: 15px;
  cursor: pointer;
}
.btn-primary:active { background: var(--accent-dark); }

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 8px 4px;
  cursor: pointer;
}

/* --- History --- */
.history { margin-top: 22px; }
.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.history-head h2 { font-size: 1.1rem; margin: 0; }
.filter-select {
  min-width: 0;
  max-width: 60%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  color: var(--ink);
  font-size: 0.9rem;
  font-family: inherit;
  color-scheme: dark;
}
.history-summary {
  color: var(--ink-secondary);
  font-size: 0.88rem;
  margin-bottom: 10px;
}
.history-summary:empty { display: none; }

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.month-label {
  margin: 10px 2px 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.day-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.day-card:active { background: var(--surface-2); transform: scale(0.99); }
.day-card.current { border-color: var(--accent); }
.day-date {
  flex: none;
  width: 64px;
  line-height: 1.25;
}
.day-date b { display: block; font-size: 1.15rem; }
.day-date span { font-size: 0.78rem; color: var(--ink-muted); }
.day-pills {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(144, 133, 233, 0.18);
  color: #d6d1ff;
  font-size: 0.85rem;
  line-height: 1.3;
}
.chip.deleted { background: var(--surface-2); color: var(--ink-muted); }
.chip.hl { background: var(--pill); color: #fff; }

.history-empty {
  text-align: center;
  color: var(--ink-muted);
  padding: 30px 16px;
  line-height: 1.5;
  font-size: 0.92rem;
}

/* --- Sheet (pills management) --- */
.sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--page);
}
.sheet {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 560px;
  margin: 0 auto;
}
.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top)) 16px 14px;
  border-bottom: 1px solid var(--border);
  flex: none;
}
.sheet-header h2 { font-size: 1.15rem; margin: 0; }
.sheet-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch;
}

.add-form {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.text-input {
  flex: 1;
  min-width: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  color: var(--ink);
  font-size: 1rem;
  font-family: inherit;
}
.text-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.btn-add {
  flex: none;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 0.95rem;
  padding: 0 16px;
  cursor: pointer;
}
.btn-add:active { background: var(--accent-dark); }

.manage-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.manage-row {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px 6px 6px 12px;
  min-height: 54px;
}
.manage-name {
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  color: var(--ink);
  font-size: 1rem;
  text-align: left;
  padding: 8px 0;
  cursor: pointer;
  overflow-wrap: anywhere;
}
.manage-name:active { transform: none; color: var(--accent); }
.manage-row .text-input { padding: 9px 10px; }
.row-btn {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--ink-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.row-btn:active { background: var(--surface-2); color: var(--ink); }
.row-btn.danger:active { color: var(--danger); }
.row-btn.ok { color: var(--good); }
.row-btn[disabled] { visibility: hidden; }

.hint {
  color: var(--ink-muted);
  font-size: 0.82rem;
  line-height: 1.45;
  margin: 16px 2px 0;
}

/* --- Toast --- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(16px);
  max-width: calc(100vw - 48px);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--ink);
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.35;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 60;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.toast-error { background: #4a1712; border-color: rgba(208, 59, 59, 0.4); }
.toast.toast-success { background: #0f3a13; border-color: rgba(12, 163, 12, 0.4); }
