:root {
  --olive: #3b4a2a;
  --olive-2: #556b2f;
  --olive-soft: #e7ecdc;
  --bg: #f4f5ef;
  --card: #ffffff;
  --text: #1d2116;
  --muted: #6b7262;
  --line: #d9ddd0;
  --p1: #b3261e;
  --p2: #556b2f;
  --p3: #8a8f80;
  --danger: #b3261e;
  --radius: 12px;
  --tap: 48px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15180f;
    --card: #1f2418;
    --text: #e8ebe0;
    --muted: #9aa190;
    --line: #333a29;
    --olive-soft: #2b3420;
    --p3: #7d8373;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  max-width: 720px;
  margin: 0 auto;
  padding: 0 12px calc(24px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.spacer { flex: 1; }
.muted { color: var(--muted); font-size: 14px; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  margin: 0 -12px; padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  background: var(--olive); color: #fff;
}
.icon-btn {
  min-width: var(--tap); height: var(--tap);
  border: 0; border-radius: var(--radius);
  background: rgba(255,255,255,.12); color: #fff;
  font-size: 30px; line-height: 1; cursor: pointer;
}
.icon-btn.small { min-width: 40px; height: 40px; font-size: 24px; background: var(--olive-soft); color: var(--text); }
.date-title {
  flex: 1; min-height: var(--tap);
  border: 0; background: none; color: #fff; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
#dateMain { font-size: 20px; font-weight: 700; }
#dateSub { opacity: .8; font-size: 14px; }

.toolbar { display: flex; gap: 8px; align-items: center; margin: 10px 0; }
.chip {
  min-height: 40px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--card); cursor: pointer;
  display: inline-flex; align-items: center; text-decoration: none; color: var(--text);
}
.chip[aria-expanded="true"] { background: var(--olive-soft); border-color: var(--olive-2); }
.chip-ghost { border-color: transparent; background: none; color: var(--muted); }

/* calendar */
.calendar { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; margin-bottom: 10px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-weekdays span { text-align: center; font-size: 13px; color: var(--muted); }
.cal-day {
  position: relative; height: 44px; border: 0; border-radius: 10px;
  background: none; cursor: pointer; font-size: 16px;
}
.cal-day.other { color: var(--muted); opacity: .5; }
.cal-day.today { font-weight: 700; color: var(--olive-2); box-shadow: inset 0 0 0 2px var(--olive-2); }
.cal-day.selected { background: var(--olive); color: #fff; }
.cal-day .dot {
  position: absolute; left: 50%; bottom: 5px; width: 6px; height: 6px; margin-left: -3px;
  border-radius: 50%; background: var(--olive-2);
}
.cal-day .dot.done { background: var(--p3); }
.cal-day.selected .dot { background: #fff; }

.banner { background: #fff3cd; color: #5c4400; border-radius: var(--radius); padding: 10px 12px; margin-bottom: 10px; }

/* quick add */
.quick-add { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; margin-bottom: 14px; }
.quick-add input {
  width: 100%; min-height: var(--tap); padding: 0 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
}
.quick-row { display: flex; gap: 8px; margin-top: 8px; align-items: center; flex-wrap: wrap; }
.prio-pick { display: flex; gap: 6px; flex: 1; }
.prio-opt {
  flex: 1; min-height: 44px; border: 1px solid var(--line); border-radius: 10px;
  background: none; cursor: pointer; font-size: 15px;
}
.prio-opt.active.p1 { background: var(--p1); border-color: var(--p1); color: #fff; }
.prio-opt.active.p2 { background: var(--p2); border-color: var(--p2); color: #fff; }
.prio-opt.active.p3 { background: var(--p3); border-color: var(--p3); color: #fff; }

.btn {
  min-height: var(--tap); padding: 0 18px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); cursor: pointer;
}
.btn-primary { background: var(--olive); border-color: var(--olive); color: #fff; font-weight: 600; }
.btn-danger { color: var(--danger); border-color: var(--danger); background: none; }
.btn:disabled { opacity: .5; }

/* task list */
.group { margin-bottom: 16px; }
.group h3 {
  margin: 0 0 6px; font-size: 14px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); display: flex; align-items: center; gap: 8px;
}
.group h3::before { content: ""; width: 10px; height: 10px; border-radius: 3px; background: var(--pc); }
.group.p1 { --pc: var(--p1); }
.group.p2 { --pc: var(--p2); }
.group.p3 { --pc: var(--p3); }
.task {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--pc);
  border-radius: var(--radius); padding: 8px 10px; margin-bottom: 8px;
}
.task.done { opacity: .55; }
.task.done .t-title { text-decoration: line-through; }
.t-check {
  flex: none; width: var(--tap); height: var(--tap); margin: -4px 0 -4px -6px;
  display: flex; align-items: center; justify-content: center;
  border: 0; background: none; cursor: pointer;
}
.t-check span {
  width: 28px; height: 28px; border: 2px solid var(--pc); border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
}
.task.done .t-check span { background: var(--pc); }
.task.done .t-check span::after {
  content: ""; width: 7px; height: 13px; margin-top: -3px;
  border: solid #fff; border-width: 0 3px 3px 0; transform: rotate(45deg);
}
.t-body { flex: 1; min-width: 0; cursor: pointer; padding-top: 4px; }
.t-title { word-wrap: break-word; }
.t-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; font-size: 13px; color: var(--muted); }
.t-time { font-weight: 700; color: var(--text); }
.t-carry { background: #fdeccc; color: #6b4a00; border-radius: 6px; padding: 0 6px; }
.t-note { white-space: pre-wrap; margin-top: 4px; font-size: 14px; color: var(--muted);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.empty { text-align: center; color: var(--muted); padding: 24px 0; }

/* dialog */
dialog {
  width: min(560px, calc(100vw - 16px)); border: 0; border-radius: 16px;
  padding: 16px; background: var(--card); color: var(--text);
}
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h2 { margin: 0 0 10px; font-size: 20px; }
dialog label { display: block; margin-bottom: 10px; font-size: 14px; color: var(--muted); }
dialog input:not([type=checkbox]), dialog select, dialog textarea {
  display: block; width: 100%; margin-top: 4px; min-height: 44px; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text);
}
dialog textarea { resize: vertical; }
.row2 { display: flex; gap: 10px; }
.row2 label { flex: 1; }
.check-line { display: flex !important; align-items: center; gap: 10px; color: var(--text) !important; font-size: 17px !important; }
.check-line input { width: 24px; height: 24px; }
.dlg-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }

/* login */
.login-body { display: flex; min-height: 100vh; align-items: center; justify-content: center; }
.login-card {
  width: min(380px, 100%); background: var(--card); border: 1px solid var(--line);
  border-radius: 16px; padding: 24px; display: flex; flex-direction: column; gap: 10px; text-align: center;
}
.login-card img { align-self: center; border-radius: 16px; }
.login-card h1 { margin: 0 0 6px; font-size: 22px; }
.login-card label { text-align: left; color: var(--muted); font-size: 14px; }
.login-card input { min-height: var(--tap); padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.login-error { color: var(--danger); margin: 0; }

@media (min-width: 700px) {
  body { padding-left: 20px; padding-right: 20px; }
  .topbar { margin: 0 -20px; padding-left: 20px; padding-right: 20px; }
}
