:root {
  --purple-900: #2e1a47;
  --purple-700: #5b2a86;
  --purple-500: #7c3aed;
  --purple-300: #c4b5fd;
  --purple-100: #f3effc;
  --bg: #faf9fc;
  --card: #ffffff;
  --text: #241934;
  --text-muted: #6b6178;
  --border: #e6e0f0;
  --green: #1c9d5c;
  --amber: #b9770e;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(46, 26, 71, 0.08), 0 1px 2px rgba(46, 26, 71, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17111f;
    --card: #241a30;
    --text: #f1ecf9;
    --text-muted: #b3a6c4;
    --border: #392a4a;
    --purple-100: #2c2038;
  }
}
:root[data-theme="dark"] {
  --bg: #17111f;
  --card: #241a30;
  --text: #f1ecf9;
  --text-muted: #b3a6c4;
  --border: #392a4a;
  --purple-100: #2c2038;
}
:root[data-theme="light"] {
  --bg: #faf9fc;
  --card: #ffffff;
  --text: #241934;
  --text-muted: #6b6178;
  --border: #e6e0f0;
  --purple-100: #f3effc;
}

* { box-sizing: border-box; }
html, body { max-width: 100%; overflow-x: hidden; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 3rem;
}

.app { max-width: 640px; margin: 0 auto; padding: 0 16px; }

header.top {
  background: linear-gradient(135deg, var(--purple-700), var(--purple-500));
  color: white;
  padding: 20px 16px 24px;
  border-radius: 0 0 20px 20px;
  margin-bottom: 16px;
}
header.top .row { display: flex; justify-content: space-between; align-items: center; }
header.top h1 { margin: 0; font-size: 1.3rem; letter-spacing: 0.02em; }
header.top .sub { opacity: 0.85; font-size: 0.85rem; margin-top: 2px; }

.icon-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: white;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.85rem;
  cursor: pointer;
}
.icon-btn:hover { background: rgba(255,255,255,0.25); }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin-bottom: 14px;
}

.setup-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 140px; }
.field label { font-size: 0.78rem; color: var(--text-muted); font-weight: 600; }
input[type="date"], input[type="text"], select {
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}
button.primary {
  background: var(--purple-500);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.9rem;
}
button.primary:hover { background: var(--purple-700); }
button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 0.85rem;
  cursor: pointer;
}
button.ghost:hover { background: var(--purple-100); }

.day-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.day-banner .big { font-size: 1.6rem; font-weight: 700; }
.progress-ring-wrap { display: flex; align-items: center; gap: 8px; }
.mini-progress {
  width: 100%;
  height: 8px;
  background: var(--purple-100);
  border-radius: 6px;
  overflow: hidden;
  margin-top: 8px;
}
.mini-progress > div { height: 100%; background: var(--purple-500); transition: width 0.25s; }

.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 4px 2px 10px;
  -webkit-overflow-scrolling: touch;
}
.tab {
  flex: 0 0 auto;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  position: relative;
  white-space: nowrap;
}
.tab.active { background: var(--purple-500); color: white; border-color: var(--purple-500); }
.tab .dot {
  display: inline-block;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--green);
  margin-left: 6px;
}

.section-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 700;
  margin: 4px 0 8px;
}

.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 4px;
  border-bottom: 1px solid var(--border);
}
.checklist li:last-child { border-bottom: none; }
.checklist input[type="checkbox"] {
  width: 20px; height: 20px;
  margin-top: 1px;
  accent-color: var(--purple-500);
  flex: 0 0 auto;
}
.item-text { flex: 1; font-size: 0.93rem; line-height: 1.35; }
.item-text.checked { text-decoration: line-through; color: var(--text-muted); }
.edit-btn {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 0.85rem; padding: 2px 6px; flex: 0 0 auto;
}
.edit-btn:hover { color: var(--purple-500); }
.item-edit-input {
  flex: 1; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--purple-500);
  font-size: 0.9rem; background: var(--bg); color: var(--text);
}

.swap-toggle {
  display: flex; gap: 4px; background: var(--purple-100); border-radius: 10px; padding: 3px;
}
.swap-toggle button {
  border: none; background: transparent; padding: 5px 10px; border-radius: 8px;
  font-size: 0.75rem; font-weight: 600; cursor: pointer; color: var(--text-muted);
}
.swap-toggle button.active { background: var(--purple-500); color: white; }

.section-block { margin-bottom: 14px; }
.section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 6px 4px;
  border-radius: 10px;
  user-select: none;
}
.section-header:hover { background: var(--purple-100); }
.section-header .chevron {
  display: inline-block;
  transition: transform 0.15s;
  color: var(--text-muted);
  font-size: 0.8rem;
  flex: 0 0 auto;
}
.section-header .chevron.collapsed { transform: rotate(-90deg); }
.section-header .section-head-title {
  font-weight: 700;
  font-size: 1rem;
  flex: 1;
}
.progress-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--purple-100);
  color: var(--purple-700);
  flex: 0 0 auto;
  white-space: nowrap;
}
.progress-badge.complete { background: var(--green); color: white; }

.wait-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--purple-100); border-radius: 10px; padding: 8px 10px; margin: 2px 0 2px 30px;
}
.wait-row .txt { font-size: 0.85rem; color: var(--text); flex: 1; }
.timer-display { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--purple-700); font-size: 0.95rem; }
.timer-display.ready { color: var(--green); }
.wait-row:has(.timer-display.ready) { background: color-mix(in srgb, var(--green) 16%, var(--purple-100)); }
.small-btn {
  border: 1px solid var(--purple-500); color: var(--purple-500); background: transparent;
  border-radius: 8px; padding: 5px 10px; font-size: 0.78rem; cursor: pointer; font-weight: 600;
}
.small-btn:hover { background: var(--purple-500); color: white; }

.note-box {
  font-size: 0.82rem; color: var(--text-muted); background: var(--purple-100);
  border-radius: 10px; padding: 8px 10px; margin: 4px 0 10px;
}

textarea.notes {
  width: 100%; min-height: 70px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); padding: 8px; font-size: 0.9rem; font-family: inherit;
  resize: vertical;
}

.history-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 4px; border-bottom: 1px solid var(--border);
}
.history-item:last-child { border-bottom: none; }
.history-item .meta { font-size: 0.8rem; color: var(--text-muted); }
.badge {
  font-size: 0.72rem; font-weight: 700; padding: 3px 8px; border-radius: 999px;
  background: var(--purple-100); color: var(--purple-700);
}

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50;
}
.modal {
  background: var(--card); border-radius: 16px; padding: 20px; max-width: 420px; width: 100%;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}
.modal h2 { margin-top: 0; font-size: 1.1rem; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.hidden { display: none !important; }

footer.foot {
  text-align: center; color: var(--text-muted); font-size: 0.75rem; margin-top: 24px; padding: 0 16px;
}
