:root {
  --bg: #f5f6f4;
  --card: #ffffff;
  --text: #1c1f1d;
  --muted: #6b726e;
  --line: #e2e5e1;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --danger: #b42318;
  --field: #f0f2ef;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151816;
    --card: #1f2321;
    --text: #e9ece9;
    --muted: #9aa29d;
    --line: #2e3430;
    --accent: #2dd4bf;
    --accent-ink: #0b2420;
    --danger: #f97066;
    --field: #282d2a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.top, main { max-width: 640px; margin: 0 auto; padding: 0 16px; }
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding-top: 18px; padding-bottom: 10px;
}
h1 { margin: 0; font-size: 28px; letter-spacing: -0.02em; }

.menu-btn {
  position: relative; width: 44px; height: 44px; margin-right: -8px;
  border: 0; border-radius: 50%; background: none; font-size: 26px; line-height: 1; color: var(--muted);
}
.menu-btn[aria-expanded="true"] { background: var(--card); }
.menu-btn.due::after {
  content: ""; position: absolute; top: 9px; right: 8px;
  width: 9px; height: 9px; border-radius: 50%; background: var(--danger);
}

.menu {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 4px 14px 14px; margin-bottom: 14px; font-size: 14px;
}
.menu p { margin: 10px 0; }
.menu-note, .backup-info { color: var(--muted); }
.backup-due { color: var(--danger); font-weight: 600; }
.menu-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; height: 42px; padding: 0 16px; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--field); font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.add { display: flex; gap: 8px; margin: 4px 0 16px; }
.add input {
  flex: 1; min-width: 0; height: 48px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); outline: none;
}
.add input:focus { border-color: var(--accent); }
.add button, .log-form button {
  border: 0; border-radius: var(--radius); background: var(--accent); color: var(--accent-ink);
  font-weight: 600; padding: 0 18px;
}
.add button { height: 48px; }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.empty { color: var(--muted); text-align: center; padding: 24px 0; margin: 0; }

.task { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.row { display: flex; align-items: stretch; }

.check { display: flex; align-items: center; padding: 0 6px 0 14px; position: relative; }
.check input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.check .box {
  width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--muted);
  display: grid; place-items: center; transition: background .15s, border-color .15s;
}
.check input:checked + .box { background: var(--accent); border-color: var(--accent); }
.check input:checked + .box::after {
  content: ""; width: 7px; height: 13px; margin-top: -3px;
  border: solid var(--accent-ink); border-width: 0 3px 3px 0; transform: rotate(45deg);
}
.check input:focus-visible + .box { outline: 2px solid var(--accent); outline-offset: 2px; }

.toggle {
  flex: 1; min-width: 0; display: grid; grid-template-columns: 1fr auto; column-gap: 8px;
  text-align: left; border: 0; background: none; padding: 12px 14px 12px 8px; min-height: 56px;
}
.toggle .title { grid-column: 1; overflow-wrap: anywhere; }
.toggle .meta { grid-column: 1; font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 0 10px; }
.toggle .chev {
  grid-column: 2; grid-row: 1 / span 2; align-self: center;
  width: 10px; height: 10px; border: solid var(--muted); border-width: 0 2px 2px 0;
  transform: rotate(45deg); margin: -4px 4px 0; transition: transform .15s;
}
.task.open .toggle .chev { transform: rotate(-135deg); margin-top: 4px; }
.toggle .badges { display: contents; }
.badge::before { content: "· "; }

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

.details { padding: 4px 14px 14px; border-top: 1px solid var(--line); display: grid; gap: 12px; }
[hidden] { display: none !important; }
.log > .lbl { display: block; }
.lbl { display: grid; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); margin-top: 8px; }
.log-hint { font-weight: 400; }
.details input[type="text"], .details textarea {
  width: 100%; border: 1px solid transparent; border-radius: 10px; background: var(--field);
  padding: 10px 12px; font-size: 16px; font-weight: 400; color: var(--text); outline: none;
}
.details input[type="text"]:focus, .details textarea:focus { border-color: var(--accent); }
.details textarea { resize: none; min-height: 64px; overflow: hidden; }

.log { display: grid; gap: 6px; }
.log-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.log-list:empty { display: none; }
.log-list li {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 8px;
  padding: 8px 4px 8px 12px; border-left: 3px solid var(--accent); background: var(--field); border-radius: 0 10px 10px 0;
}
.log-list time { font-size: 12px; color: var(--muted); }
.log-list .text { grid-column: 1; overflow-wrap: anywhere; white-space: pre-wrap; }
.log-list .rm {
  grid-column: 2; grid-row: 1 / span 2; align-self: center; border: 0; background: none;
  color: var(--muted); font-size: 20px; width: 36px; height: 36px; border-radius: 50%;
}
.log-form { display: flex; gap: 8px; }
.log-form input { flex: 1; min-width: 0; }
.log-form button { height: 42px; }

.foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.stamps { font-size: 12px; color: var(--muted); }
.delete { border: 0; background: none; color: var(--danger); font-weight: 600; padding: 8px 0; }

.done-section { margin: 20px 0 40px; }
.done-section summary {
  color: var(--muted); font-weight: 600; padding: 10px 2px; list-style: none; cursor: pointer;
}
.done-section summary::-webkit-details-marker { display: none; }
.done-section summary::before { content: "▸ "; }
.done-section[open] summary::before { content: "▾ "; }
