/* Apple-style, readability first: system font, large type, high-contrast secondary text. */

:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #000000;
  --text-2: #5c5c62;          /* darker than iOS default gray, for readability */
  --separator: rgba(60, 60, 67, 0.18);
  --fill: rgba(118, 118, 128, 0.12);
  --blue: #007aff;
  --red: #e5372b;
  --green: #28a745;
  --orange: #f08a00;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
  --radius: 14px;
  --safe-bottom: max(env(safe-area-inset-bottom), var(--tg-safe-area-inset-bottom, 0px));
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #000000;
  --card: #1c1c1e;
  --text: #ffffff;
  --text-2: #b4b4ba;
  --separator: rgba(84, 84, 88, 0.6);
  --fill: rgba(118, 118, 128, 0.24);
  --blue: #0a84ff;
  --red: #ff453a;
  --green: #30d158;
  --orange: #ff9f0a;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 17px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

button, input, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 16px calc(120px + var(--safe-bottom));
}

/* --- header --- */

.hero { display: flex; align-items: center; gap: 16px; margin: 4px 4px 18px; }
.hero-text { flex: 1; min-width: 0; }
.eyebrow { margin: 0; color: var(--text-2); font-size: 15px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em; }
h1 { margin: 2px 0 2px; font-size: 32px; line-height: 1.15; font-weight: 700; letter-spacing: -0.02em; }
.summary { margin: 0; color: var(--text-2); font-size: 17px; }

.ring { width: 68px; height: 68px; flex: none; }
.ring circle { fill: none; stroke-width: 7; }
.ring-track { stroke: var(--fill); }
.ring-fill {
  stroke: var(--green); stroke-linecap: round;
  transform: rotate(-90deg); transform-origin: 50% 50%;
  stroke-dasharray: 169.65; stroke-dashoffset: 169.65;
  transition: stroke-dashoffset 0.6s cubic-bezier(.2, .8, .2, 1);
}
.ring-label { fill: var(--text); font-size: 15px; font-weight: 700; text-anchor: middle; dominant-baseline: central; }

/* --- quote --- */

.quote {
  margin: 0 0 26px; padding: 16px 18px; border-radius: var(--radius);
  background: var(--card); cursor: pointer; user-select: none;
}
.quote blockquote { margin: 0; font-size: 18px; line-height: 1.4; font-weight: 500; }
.quote figcaption { margin-top: 6px; color: var(--text-2); font-size: 15px; }
.quote figcaption:empty { display: none; }

/* --- lists --- */

.section { margin-bottom: 26px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin: 0 4px 8px; }
.section-head h2 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.section-head .count { color: var(--text-2); font-size: 17px; font-weight: 600; }
.section.overdue h2 { color: var(--red); }

.card { background: var(--card); border-radius: var(--radius); overflow: hidden; }

.row-wrap { position: relative; overflow: hidden; }
.row-wrap + .row-wrap .row::before {
  content: ""; position: absolute; top: 0; left: 54px; right: 0; height: 0.5px; background: var(--separator);
}
.swipe-bg {
  position: absolute; inset: 0; display: flex; align-items: center; padding: 0 22px;
  color: #fff; font-weight: 600; font-size: 16px; opacity: 0;
}
.swipe-bg.complete { background: var(--green); justify-content: flex-start; }
.swipe-bg.snooze { background: var(--orange); justify-content: flex-end; }

.row {
  position: relative; display: flex; align-items: flex-start; gap: 12px;
  min-height: 56px; padding: 12px 16px 12px 14px; background: var(--card);
  touch-action: pan-y; user-select: none; -webkit-user-select: none;
}
.row.animating { transition: transform 0.25s cubic-bezier(.2, .8, .2, 1); }
.row-wrap.leaving { transition: opacity 0.3s ease, max-height 0.35s ease 0.15s; max-height: 0 !important; opacity: 0; }

.check {
  flex: none; width: 28px; height: 28px; margin-top: -1px; border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--text-2) 70%, transparent);
  display: grid; place-items: center; transition: background 0.2s, border-color 0.2s;
}
.check svg { width: 16px; height: 16px; stroke: #fff; stroke-width: 3; fill: none; opacity: 0; }
.check.on { background: var(--green); border-color: var(--green); }
.check.on svg { opacity: 1; }
.important .check { border-color: var(--orange); }

.row-body { flex: 1; min-width: 0; padding-top: 1px; cursor: pointer; }
.row-title { font-size: 17px; line-height: 1.3; overflow-wrap: anywhere; }
.row-title .bang { color: var(--orange); font-weight: 700; margin-right: 4px; }
.row-meta { margin-top: 2px; color: var(--text-2); font-size: 15px; }
.row-meta.late { color: var(--red); }
.done .row-title { color: var(--text-2); text-decoration: line-through; }

.recurring-row .row-icon {
  flex: none; width: 28px; height: 28px; border-radius: 8px; background: var(--fill);
  display: grid; place-items: center; color: var(--blue); font-size: 16px; font-weight: 700;
}

.collapsible-toggle { color: var(--blue); font-size: 17px; font-weight: 600; }

.empty { text-align: center; padding: 40px 20px 20px; }
.empty-icon {
  width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 50%;
  background: var(--fill); color: var(--green); font-size: 32px; display: grid; place-items: center;
}
.empty-title { margin: 0; font-size: 20px; font-weight: 600; }
.empty-sub { margin: 4px 0 0; color: var(--text-2); }

.link-button { display: block; margin: 6px auto; color: var(--blue); font-size: 17px; padding: 10px; }
.swipe-tip { text-align: center; color: var(--text-2); font-size: 14px; margin: 4px 0 0; }

/* --- composer --- */

.composer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; gap: 10px; align-items: center;
  padding: 10px 16px calc(10px + var(--safe-bottom));
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--separator);
}
.composer input {
  flex: 1; min-width: 0; height: 44px; padding: 0 16px; border-radius: 22px;
  border: 0; outline: none; background: var(--card); font-size: 17px;
}
.composer input::placeholder { color: var(--text-2); opacity: 0.85; }
.composer button {
  flex: none; width: 44px; height: 44px; border-radius: 50%; background: var(--blue);
  display: grid; place-items: center; transition: opacity 0.2s, transform 0.1s;
}
.composer button:active { transform: scale(0.94); }
.composer button:disabled { opacity: 0.4; }
.composer button svg { width: 22px; height: 22px; stroke: #fff; stroke-width: 2.6; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.composer.busy button svg { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }

/* --- sheets --- */

.backdrop {
  position: fixed; inset: 0; z-index: 10; background: rgba(0, 0, 0, 0.35);
  animation: fade 0.2s ease;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11;
  max-width: 640px; margin: 0 auto; max-height: 92vh; overflow-y: auto;
  padding: 6px 16px calc(16px + var(--safe-bottom));
  background: var(--bg); border-radius: 16px 16px 0 0; box-shadow: var(--shadow);
  animation: rise 0.28s cubic-bezier(.2, .8, .2, 1);
}
@keyframes rise { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

.grabber { width: 38px; height: 5px; border-radius: 3px; background: var(--fill); margin: 4px auto 6px; }
.sheet-bar { display: flex; align-items: center; justify-content: space-between; margin: 0 0 12px; min-height: 44px; }
.sheet-title { font-weight: 600; }
.bar-button { color: var(--blue); font-size: 17px; padding: 10px 4px; }
.strong { font-weight: 600; }
.sheet-heading { text-align: center; color: var(--text-2); font-size: 15px; margin: 8px 12px 14px; }

.group { background: var(--card); border-radius: var(--radius); margin-bottom: 18px; overflow: hidden; }
.group > * + * { border-top: 0.5px solid var(--separator); }

.group textarea {
  display: block; width: 100%; resize: none; border: 0; outline: none; background: transparent;
  padding: 14px 16px; font-size: 19px; font-weight: 500; line-height: 1.35; overflow: hidden;
}

.cell {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; min-height: 52px; padding: 10px 16px; text-align: left; font-size: 17px;
}
.cell small { display: block; color: var(--text-2); font-size: 14px; margin-top: 1px; }
.cell.action { justify-content: center; color: var(--blue); }
.cell.action:active { background: var(--fill); }
.cell.danger { color: var(--red); }

.cell input[type="datetime-local"] {
  border: 0; outline: none; background: var(--fill); border-radius: 8px;
  padding: 6px 10px; font-size: 16px; color: var(--text); min-width: 0; flex: 1; max-width: 220px;
}
.cell > span { flex: none; }
.cell input[type="datetime-local"]:invalid, .cell input[type="datetime-local"].empty { color: var(--text-2); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 16px; }
.chips button {
  padding: 7px 13px; border-radius: 18px; background: var(--fill); font-size: 15px; font-weight: 500;
}
.chips button:active { background: color-mix(in srgb, var(--blue) 25%, transparent); }

.switch {
  appearance: none; -webkit-appearance: none; flex: none; position: relative;
  width: 51px; height: 31px; border-radius: 16px; background: var(--fill); transition: background 0.2s; cursor: pointer;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2); transition: transform 0.2s;
}
.switch:checked { background: var(--green); }
.switch:checked::after { transform: translateX(20px); }

/* --- toast --- */

.toast {
  position: fixed; left: 16px; right: 16px; z-index: 20;
  bottom: calc(76px + var(--safe-bottom)); max-width: 560px; margin: 0 auto;
  display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-radius: 14px;
  background: #2c2c2e; color: #fff; box-shadow: var(--shadow); font-size: 16px;
  animation: rise-small 0.25s cubic-bezier(.2, .8, .2, 1);
}
.toast span { flex: 1; }
.toast button { color: #64b5ff; font-weight: 600; font-size: 16px; }
@keyframes rise-small { from { transform: translateY(20px); opacity: 0; } }

[hidden] { display: none !important; }

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