/* Calm, legible, follows the iPhone's light/dark setting. */
:root {
  --bg: #f7f6f3;
  --surface: #ffffff;
  --text: #1c1b1a;
  --muted: #6f6b66;
  --line: #e2dfda;
  --accent: #2f5d8a;
  --done: #2e7d4f;
  --overdue: #b3261e;
  --overdue-bg: #fbe9e7;
  --today: #8a5a00;
  --today-bg: #fdf3dc;
  /* Title colours: "black" is the normal text colour, so it stays readable in dark mode. */
  --c-black: var(--text);
  --c-red: #c0392b;
  --c-green: #2e7d32;
  --c-blue: #1f5fbf;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161515;
    --surface: #211f1f;
    --text: #ece8e1;
    --muted: #9c968e;
    --line: #34312f;
    --accent: #7fb0e6;
    --done: #5cc48a;
    --overdue: #ff8a80;
    --overdue-bg: #3a1d1b;
    --today: #f2c46d;
    --today-bg: #3a2f17;
    --c-red: #ff7b72;
    --c-green: #6fcf87;
    --c-blue: #79b2ff;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  min-height: 100vh;
}
[hidden] { display: none !important; }
h1 { font-size: 22px; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 28px 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
a { color: var(--accent); text-decoration: none; }

/* --- bars --------------------------------------------------------------- */
.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 16px 10px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.bar nav { display: flex; gap: 4px; }
.bar .back { min-width: 70px; font-size: 17px; }
.bar-spacer { min-width: 70px; }
.icon-btn { display: inline-flex; width: 40px; height: 40px; align-items: center; justify-content: center; color: var(--text); border-radius: 10px; }
.icon-btn svg, .fab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* --- sections & items ------------------------------------------------------ */
.sections { padding: 4px 0 110px; }
.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 22px 16px 0; padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
  font-size: 13px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em;
}
.section-head .count { font-weight: 500; }
.todo-list { list-style: none; margin: 0; padding: 6px 12px 0; min-height: 44px; }
.todo-list:empty { min-height: 42px; }
/* Sits over the empty list (which stays a drop target underneath). */
.empty-hint { margin: -42px 0 0; height: 42px; padding: 12px 18px 0; color: var(--muted); font-size: 14px; pointer-events: none; }
.todo-list:not(:empty) + .empty-hint { display: none; }

.todo-item {
  position: relative;
  margin: 6px 0;
  border-radius: var(--radius);
  background: var(--done);
  overflow: hidden;
  /* Vertical panning stays native scrolling; horizontal moves come to us (swipe). */
  touch-action: pan-y;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}
.todo-item .swipe-label {
  position: absolute; inset: 0 auto 0 0; display: flex; align-items: center; padding-left: 18px;
  color: #fff; font-weight: 600; font-size: 15px;
}
.todo-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 14px;
  box-shadow: var(--shadow);
  will-change: transform;
}
.todo-item.overdue .todo-card { border-left: 4px solid var(--overdue); padding-left: 11px; }
.todo-title { font-size: 17px; font-weight: 550; overflow-wrap: anywhere; }
.color-black { color: var(--c-black); }
.color-red { color: var(--c-red); }
.color-green { color: var(--c-green); }
.color-blue { color: var(--c-blue); }
.todo-meta { margin-top: 3px; font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; }
.pill { display: inline-block; padding: 0 7px; border-radius: 999px; font-weight: 600; }
.pill-overdue { color: var(--overdue); background: var(--overdue-bg); }
.pill-today { color: var(--today); background: var(--today-bg); }
.todo-desc { margin-top: 3px; font-size: 14px; color: var(--muted); white-space: pre-line; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* drag states (SortableJS) */
.drag-ghost .todo-card { opacity: 0.35; }
.drag-chosen .todo-card { box-shadow: 0 8px 24px rgb(0 0 0 / 22%); transform: scale(1.02); }
.drag-fallback { opacity: 0.95 !important; }
body.dragging { touch-action: none; }
body.dragging .todo-list { min-height: 56px; }

/* --- floating button ---------------------------------------------------------- */
.fab {
  position: fixed; right: calc(20px + env(safe-area-inset-right)); bottom: calc(24px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%;
  border: 0; background: var(--text); color: var(--bg);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 18px rgb(0 0 0 / 25%);
}
.fab svg { width: 26px; height: 26px; stroke-width: 2.2; }

/* --- forms & buttons -------------------------------------------------------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 12px; padding: 12px 16px; font: inherit; font-weight: 600;
}
.btn-primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn-wide { display: block; width: 100%; margin: 10px 0; }
.btn-danger-outline { color: var(--overdue); }
.btn:disabled { opacity: 0.5; }
.link-btn { appearance: none; border: 0; background: none; color: var(--accent); font: inherit; padding: 8px 4px; }
.link-btn.strong { font-weight: 650; }
.link-btn.danger { color: var(--overdue); }
.stack { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
input, textarea {
  font: inherit; font-size: 17px; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%;
}
textarea { resize: vertical; min-height: 80px; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.msg { min-height: 1.2em; color: var(--overdue); font-size: 14px; margin: 4px 0; }
.msg.ok { color: var(--done); }
.hint { color: var(--muted); font-size: 14px; margin: 4px 0; }

.seg { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.seg legend { font-size: 14px; color: var(--muted); margin-bottom: 6px; padding: 0; }
.seg label { flex-direction: row; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg span {
  display: inline-block; min-width: 54px; text-align: center; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
  color: var(--text); font-size: 15px; font-weight: 600;
}
.seg input:checked + span { border-color: var(--text); box-shadow: inset 0 0 0 1px var(--text); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }
.swatch-black span { color: var(--c-black); }
.swatch-red span { color: var(--c-red); }
.swatch-green span { color: var(--c-green); }
.swatch-blue span { color: var(--c-blue); }
.field-row { display: flex; align-items: flex-end; gap: 8px; }
.field-row label { flex: 1; min-width: 0; }
.field-row input { min-width: 0; }
.field-row .link-btn { flex: none; }

/* --- editor dialog (full-screen sheet) ------------------------------------------- */
.editor {
  border: 0; padding: 0; margin: 0; width: 100%; max-width: 100%; height: 100%; max-height: 100%;
  background: var(--bg); color: var(--text);
}
.editor form { padding: calc(env(safe-area-inset-top) + 4px) 16px calc(env(safe-area-inset-bottom) + 24px); height: 100%; overflow-y: auto; }
.editor-bar { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: var(--bg); padding: 8px 0; z-index: 1; }
.editor-bar h2 { margin: 0; text-transform: none; letter-spacing: 0; color: var(--text); font-size: 17px; }
.editor-actions { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }

/* --- archive ------------------------------------------------------------------------- */
.archive { padding: 8px 12px 40px; }
.archive-item { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 11px 14px; margin: 8px 0; }
.archive-item .todo-title { opacity: 0.85; }
.archive-actions { display: flex; gap: 16px; margin-top: 6px; }
.archive-actions .danger { color: var(--overdue); }

/* --- settings / login ---------------------------------------------------------------------- */
.settings { padding: 0 16px 40px; }
.plain-list { list-style: none; padding: 0; margin: 0; }
.plain-list li { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.plain-list small { color: var(--muted); display: block; font-size: 13px; }
.login { max-width: 420px; margin: 0 auto; padding: 12vh 24px 40px; text-align: center; }
.login-logo { border-radius: 16px; }
.login h1 { margin: 14px 0 28px; }
.login details { margin-top: 18px; text-align: left; }
.login summary { color: var(--accent); cursor: pointer; text-align: center; padding: 8px; }
.login form { margin-top: 12px; }

/* --- toast ------------------------------------------------------------------------------------- */
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(92px + env(safe-area-inset-bottom)); z-index: 20;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  background: var(--text); color: var(--bg); border-radius: 12px; padding: 12px 16px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 25%);
}
.toast button { appearance: none; border: 0; background: none; color: var(--bg); font: inherit; font-weight: 700; text-decoration: underline; padding: 4px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
