:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --green: #238636;
  --green-hover: #2ea043;
  --blue: #2f81f7;
  --red: #f85149;
  --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body { padding: env(safe-area-inset-top) 16px calc(env(safe-area-inset-bottom) + 24px); }

main, .auth { max-width: 640px; margin: 0 auto; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }

.brand { font-size: 20px; font-weight: 600; margin: 0; }
h2 { font-size: 16px; margin: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.row { display: flex; gap: 8px; align-items: center; }
.between { justify-content: space-between; }
.grow { flex: 1; }
.full { width: 100%; }

input[type="text"], input[inputmode], input[type="email"], input[type="password"], input[type="time"] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 9px 12px;
  font: inherit;
  width: 100%;
  color-scheme: dark;
}
input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(47,129,247,.3); }

.btn {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 14px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  color: var(--text);
  background: var(--surface-2);
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--green); border-color: rgba(240,246,252,.1); color: #fff; }
.btn-primary:hover { background: var(--green-hover); }
.btn-secondary { background: var(--surface-2); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }
.btn-link { background: none; border: none; color: var(--blue); padding: 4px 0; display: block; margin: 0 auto 8px; }
.icon { font-size: 24px; line-height: 1; padding: 4px 14px; }

/* Header */
.top { display: flex; justify-content: space-between; align-items: center; padding: 16px 0 8px; }
.top-actions { display: flex; gap: 4px; }

/* Day nav */
.daynav { display: flex; align-items: center; justify-content: space-between; margin: 8px 0; }
.day-label { position: relative; display: flex; flex-direction: column; align-items: center; cursor: pointer; }
#day-title { font-size: 22px; font-weight: 600; }
#day-sub::first-letter { text-transform: uppercase; }
#day-sub { display: block; }
#day-picker { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }

/* Progress */
.progress-wrap { display: flex; align-items: center; gap: 10px; margin: 8px 0 16px; }
.progress { flex: 1; height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
#progress-bar { height: 100%; width: 0; background: var(--green-hover); transition: width .25s; }

/* Add form */
.add { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.times { flex-wrap: wrap; }
.tfield { display: flex; align-items: center; gap: 4px; }
.tfield input.t { width: 76px; text-align: center; font-variant-numeric: tabular-nums; }
.ampm { padding: 8px 10px; font-size: 13px; font-weight: 600; min-width: 46px; }
.ampm.pm { color: var(--blue); border-color: var(--blue); }
.ampm.off { opacity: .35; pointer-events: none; }
.repeat { display: flex; align-items: center; gap: 8px; cursor: pointer; color: var(--muted); user-select: none; }
.repeat input { width: 18px; height: 18px; accent-color: var(--green-hover); margin: 0; color-scheme: dark; }
.hint { margin: 0; }
.err { color: var(--red); }

/* Tasks */
.tasks { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.tasks:empty { display: none; }
.task { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--surface); border-top: 1px solid var(--border); }
.task:first-child { border-top: none; }
.task input[type="checkbox"] {
  appearance: none; -webkit-appearance: none;
  width: 22px; height: 22px; flex: none;
  border: 2px solid var(--muted); border-radius: 6px; cursor: pointer;
  display: grid; place-content: center; margin: 0;
}
.task input[type="checkbox"]:checked { background: var(--green-hover); border-color: var(--green-hover); }
.task input[type="checkbox"]:checked::after { content: ""; width: 6px; height: 11px; border: solid #fff; border-width: 0 2.5px 2.5px 0; transform: rotate(45deg) translate(-1px, -1px); }
.task .body { flex: 1; min-width: 0; cursor: pointer; display: flex; align-items: center; gap: 12px; }
.task .title { word-break: break-word; flex: 1; }
.task .pin { font-size: 12px; margin-left: 6px; opacity: .8; }
.task.done .title { text-decoration: line-through; color: var(--muted); }
.task .time { font-size: 14px; color: var(--blue); font-variant-numeric: tabular-nums; white-space: nowrap; margin-left: auto; }
.task.done .time { color: var(--muted); }
.task .del { color: var(--muted); background: none; border: none; font-size: 20px; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.task .del:hover { color: var(--red); background: var(--surface-2); }

/* Inline edit */
.task.editing { flex-wrap: wrap; }
.task.editing .edit { display: flex; flex-direction: column; gap: 8px; width: 100%; }

/* History */
#history { margin-top: 16px; }
.history { list-style: none; margin: 12px 0 0; padding: 0; }
.history li { display: flex; justify-content: space-between; align-items: center; padding: 10px 4px; border-top: 1px solid var(--border); cursor: pointer; }
.history li:hover { background: var(--surface-2); }
.history .count { font-variant-numeric: tabular-nums; }
.history .count.full { color: var(--green-hover); }

/* Auth */
.auth { margin-top: 15vh; display: flex; flex-direction: column; gap: 12px; max-width: 380px; }
.auth form { display: flex; flex-direction: column; gap: 10px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

#mode-note { margin-top: 24px; }
