:root {
  --bg: #fafaf9;
  --surface: #ffffff;
  --border: #e7e5e4;
  --text: #1c1917;
  --text-muted: #78716c;
  --urgent: #dc2626;
  --urgent-bg: #fef2f2;
  --urgent-border: #fecaca;
  --calm: #2563eb;
  --calm-bg: #eff6ff;
  --calm-border: #bfdbfe;
  --accent: #171717;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #18181b;
    --surface: #232326;
    --border: #333336;
    --text: #f4f4f5;
    --text-muted: #a1a1aa;
    --urgent: #f87171;
    --urgent-bg: #3f1d1d;
    --urgent-border: #5b2323;
    --calm: #60a5fa;
    --calm-bg: #1c2b47;
    --calm-border: #24365a;
    --accent: #f4f4f5;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.app {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 0 16px 40px;
}

.topbar {
  position: sticky;
  top: 0;
  background: var(--bg);
  padding: env(safe-area-inset-top, 0) 0 8px;
  z-index: 10;
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 16px 0 12px;
}

.topbar h1 {
  font-size: 22px;
  margin: 0;
}

.settings-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-panel.hidden { display: none; }

.settings-panel h2 {
  font-size: 15px;
  margin: 0;
}

.settings-hint {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.4;
}

.settings-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.settings-field input {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  padding: 8px 10px;
}

.settings-actions {
  display: flex;
  gap: 8px;
}

.settings-save {
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: var(--bg);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  cursor: pointer;
}

.settings-clear {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  cursor: pointer;
}

.settings-status {
  font-size: 12px;
  color: var(--calm);
  margin: 0;
  min-height: 14px;
}

.tabs {
  display: flex;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
}

.tab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 999px;
  cursor: pointer;
}

.tab.active {
  background: var(--accent);
  color: var(--bg);
}

.view.hidden { display: none; }

.day-nav, .cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 12px 0;
}

.day-label, .cal-label {
  font-size: 15px;
  font-weight: 600;
  text-transform: capitalize;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
}

.add-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  margin-bottom: 20px;
}

#task-input {
  flex: 1 1 100%;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  padding: 6px 4px;
  outline: none;
  min-width: 0;
}

.toggle-time-btn {
  flex: 0 0 auto;
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
}

.toggle-time-btn.active {
  border-style: solid;
  border-color: var(--calm-border);
  background: var(--calm-bg);
  color: var(--calm);
}

.time-fields {
  flex: 1 1 100%;
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.time-fields.hidden { display: none; }

.time-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.time-field input[type="time"] {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  padding: 6px 8px;
}

.clear-time-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 6px 8px;
}

.urgency-toggle {
  display: flex;
  gap: 6px;
  flex: 1;
}

.urgency-btn {
  flex: 1;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 6px;
  border-radius: 10px;
  cursor: pointer;
}

.urgency-btn.urgent.active {
  background: var(--urgent-bg);
  border-color: var(--urgent-border);
  color: var(--urgent);
}

.urgency-btn.calm.active {
  background: var(--calm-bg);
  border-color: var(--calm-border);
  color: var(--calm);
}

.add-btn {
  width: 40px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: var(--bg);
  font-size: 20px;
  cursor: pointer;
}

.task-groups {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.group-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 8px;
}

.urgent-title { color: var(--urgent); }
.calm-title { color: var(--calm); }

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

.empty-hint {
  color: var(--text-muted);
  font-size: 14px;
  margin: 4px 0 0;
}

.task-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border-color, var(--border));
  border-radius: 10px;
  padding: 10px 12px;
}

.task-item.urgent { --border-color: var(--urgent); }
.task-item.calm { --border-color: var(--calm); }

.task-check {
  position: relative;
  display: inline-flex;
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
}

.task-check input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}

.checkmark {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  border: 2px solid var(--text-muted);
  display: block;
}

.task-check input:checked + .checkmark {
  background: var(--accent);
  border-color: var(--accent);
  position: relative;
}

.task-check input:checked + .checkmark::after {
  content: "";
  position: absolute;
  left: 6px;
  top: 2px;
  width: 6px;
  height: 11px;
  border: solid var(--bg);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.task-body {
  flex: 1;
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.task-time {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 6px;
  white-space: nowrap;
}

.task-text {
  flex: 1;
  font-size: 15px;
  word-break: break-word;
}

.task-item.done .task-text {
  text-decoration: line-through;
  color: var(--text-muted);
}

.task-item.done .task-time {
  text-decoration: line-through;
}

.task-delete {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 4px;
}

/* Calendar */
.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 6px;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.cal-day {
  aspect-ratio: 1;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
}

.cal-day.other-month {
  opacity: 0.35;
}

.cal-day.today {
  border-color: var(--accent);
  border-width: 2px;
  font-weight: 700;
}

.cal-day .dots {
  display: flex;
  gap: 3px;
}

.cal-day .dot {
  width: 5px;
  height: 5px;
  border-radius: 999px;
}

.dot.urgent { background: var(--urgent); }
.dot.calm { background: var(--calm); }
