/* RemindMe: mobile-first. Base styles target phones; @media (min-width) adds desktop layout. */
:root {
  --bg: #0d0d12;
  --bg-2: #14141b;
  --card: #1a1a23;
  --card-2: #22222d;
  --line: #2a2a36;
  --fg: #eeeef4;
  --muted: #9898a8;
  --faint: #66667a;
  --accent: #7c6cff;
  --accent-fg: #ffffff;
  --accent-soft: #7c6cff22;
  --red: #ff4d5e;
  --red-soft: #ff4d5e1a;
  --red-line: #ff4d5e55;
  --green: #22c55e;
  --shadow: 0 12px 40px #0008;
  --radius: 18px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f5fb;
    --bg-2: #eeedf6;
    --card: #ffffff;
    --card-2: #f3f2fa;
    --line: #e3e1ee;
    --fg: #17171f;
    --muted: #63637a;
    --faint: #9a9aae;
    --accent: #5b4cf0;
    --accent-soft: #5b4cf01a;
    --red: #e11d48;
    --red-soft: #e11d480f;
    --red-line: #e11d4840;
    --green: #16a34a;
    --shadow: 0 12px 40px #1b1a3a26;
    color-scheme: light;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.45 var(--font);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-t)) calc(16px + var(--safe-r)) 10px calc(16px + var(--safe-l));
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
}
.brand { display: flex; align-items: center; gap: 10px; font: 700 18px var(--font-display); letter-spacing: -0.01em; }
.brand img { border-radius: 8px; }
.icon-btn {
  position: relative; width: 44px; height: 44px; border-radius: 14px; border: 0;
  display: grid; place-items: center; background: var(--card); color: var(--muted);
}
.icon-btn svg { fill: currentColor; stroke: none; width: 22px; height: 22px; }
.icon-btn .dot { position: absolute; top: 9px; right: 10px; width: 9px; height: 9px; border-radius: 50%; background: var(--faint); border: 2px solid var(--card); }
.icon-btn[data-state="on"] { color: var(--accent); }
.icon-btn[data-state="on"] .dot { background: var(--green); }
.icon-btn[data-state="off"] .dot { background: var(--red); }

/* ---------- Layout ---------- */
main {
  padding: 4px calc(16px + var(--safe-r)) calc(120px + var(--safe-b)) calc(16px + var(--safe-l));
  max-width: 640px; margin: 0 auto;
}
.summary { padding: 8px 2px 18px; }
.greeting { margin: 0; color: var(--muted); font-size: 15px; }
.headline { margin: 2px 0 0; font: 800 28px/1.15 var(--font-display); letter-spacing: -0.02em; }
.headline .red { color: var(--red); }

.banner {
  display: flex; gap: 12px; align-items: center;
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-radius: 14px; padding: 12px 14px; margin: 6px 0 14px; font-size: 14px;
}
.banner p { margin: 0; flex: 1; }
.banner .btn { flex: none; }

.section { margin-bottom: 26px; }
.section h2 {
  display: flex; align-items: center; gap: 8px;
  margin: 0 0 10px 2px; font: 700 13px var(--font); text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted);
}
.count { color: var(--faint); font-weight: 600; }
.forgot h2 { color: var(--red); }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--red); box-shadow: 0 0 0 0 var(--red); animation: pulse 1.8s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 var(--red-line); } 70% { box-shadow: 0 0 0 10px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

.done summary { list-style: none; cursor: pointer; }
.done summary::-webkit-details-marker { display: none; }
.done summary h2::after { content: "›"; font-size: 18px; line-height: 1; transition: transform .2s; margin-left: 2px; }
.done details[open] summary h2::after { transform: rotate(90deg); }

.empty { text-align: center; padding: 28px 12px; border: 1.5px dashed var(--line); border-radius: var(--radius); color: var(--muted); }
.empty p { margin: 2px 0; }

/* ---------- Reminder items ---------- */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.item {
  display: grid; grid-template-columns: auto 1fr; align-items: start; gap: 4px 12px;
  background: var(--card); border-radius: var(--radius); padding: 12px 12px 12px 10px;
  border: 1px solid transparent; transition: transform .15s ease, opacity .2s ease;
}
.item.leaving { opacity: 0; transform: translateX(24px); }
.item.flash { animation: flash 1.2s ease; }
@keyframes flash { 30% { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); } }
.item .check {
  width: 44px; height: 44px; margin: -2px 0; border-radius: 50%; border: 0; display: grid; place-items: center;
  background: transparent; color: transparent; position: relative;
}
.item .check::before { content: ""; position: absolute; inset: 9px; border-radius: 50%; border: 2px solid var(--faint); transition: all .15s; }
.item .check svg { width: 16px; height: 16px; position: relative; stroke-width: 3; }
.item .check:active::before { transform: scale(.9); }
.item .body { text-align: left; border: 0; background: none; padding: 4px 0; min-width: 0; display: grid; gap: 2px; }
.item .title { font-weight: 600; font-size: 16.5px; overflow-wrap: anywhere; }
.item .note { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.item .note:empty { display: none; }
.item .meta { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; color: var(--muted); font-size: 13px; margin-top: 2px; }
.item .tags { display: inline-flex; gap: 4px; color: var(--faint); }
.item .snooze { grid-column: 2; display: none; gap: 8px; margin-top: 4px; }
.mini {
  min-height: 36px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card-2); font-size: 14px; font-weight: 600;
}

.forgot .item { background: linear-gradient(var(--red-soft), var(--red-soft)), var(--card); border-color: var(--red-line); }
.forgot .item .when { color: var(--red); font-weight: 600; }
.forgot .item .check::before { border-color: var(--red); }
.forgot .item .snooze { display: flex; }
.item.snoozed .when::after { content: " · snoozed"; color: var(--muted); font-weight: 400; }

.done .item { opacity: .72; }
.done .item .title { text-decoration: line-through; text-decoration-color: var(--faint); }
.done .item .check { color: #fff; }
.done .item .check::before { background: var(--green); border-color: var(--green); }

/* ---------- FAB (thumb zone) ---------- */
.fab {
  position: fixed; z-index: 20; right: calc(18px + var(--safe-r)); bottom: calc(18px + var(--safe-b));
  width: 62px; height: 62px; border-radius: 20px; border: 0; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-fg); box-shadow: 0 10px 30px color-mix(in srgb, var(--accent) 45%, transparent);
  transition: transform .12s;
}
.fab:active { transform: scale(.94); }
.fab svg { width: 28px; height: 28px; stroke-width: 2.6; }

/* ---------- Sheet (bottom sheet on mobile) ---------- */
.sheet {
  border: 0; padding: 0; margin: 0; color: var(--fg); background: var(--bg-2);
  width: 100%; max-width: 100%; max-height: calc(100dvh - 24px - var(--safe-t));
  inset: auto 0 0 0; position: fixed; border-radius: 24px 24px 0 0; box-shadow: var(--shadow);
  overflow: auto; overscroll-behavior: contain;
}
.sheet[open] { animation: up .24s cubic-bezier(.2, .9, .3, 1.05); }
@keyframes up { from { transform: translateY(40%); opacity: .4; } }
.sheet::backdrop { background: #0009; backdrop-filter: blur(2px); }
.grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 8px auto 0; }
.sheet-head {
  position: sticky; top: 0; z-index: 1; background: var(--bg-2);
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 4px 6px;
}
.sheet-head h2 { margin: 0; font: 700 16px var(--font-display); }
.sheet-head .text-btn:last-child { justify-self: end; }
.sheet-body { padding: 4px 16px calc(20px + var(--safe-b)); display: grid; gap: 14px; }
.sheet.small .sheet-body { padding-top: 20px; }
.sheet.small h2 { margin: 0; font: 700 20px var(--font-display); }
.sheet.small p { margin: 0; }

.text-btn { border: 0; background: none; color: var(--muted); padding: 0 12px; min-height: 44px; border-radius: 12px; font-size: 16px; }
.text-btn.strong { color: var(--accent); font-weight: 700; }

.field { display: block; }
input:not([type="radio"]):not([type="checkbox"]), textarea {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 14px;
  padding: 12px 14px; font-size: 16px; /* >=16px stops iOS zoom-on-focus */ outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 52px; }
.title-input { font-size: 19px !important; font-weight: 600; padding: 14px !important; }
.dt { min-height: 48px; }

.group { border: 0; margin: 0; padding: 0; display: grid; gap: 10px; }
.group legend { padding: 0; margin-bottom: 8px; font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.hint { margin: -2px 2px 0; font-size: 13px; color: var(--muted); min-height: 1em; }

.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 40px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); font-weight: 600; font-size: 15px; white-space: nowrap;
}
.chip:active { background: var(--accent-soft); border-color: var(--accent); }

.segmented { display: grid; grid-template-columns: repeat(6, 1fr); background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 4px; gap: 2px; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; }
.segmented span { display: grid; place-items: center; min-height: 40px; border-radius: 10px; font-size: 14px; font-weight: 600; color: var(--muted); }
.segmented input:checked + span { background: var(--accent); color: var(--accent-fg); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); }

.toggles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.toggle { position: relative; }
.toggle input { position: absolute; opacity: 0; inset: 0; margin: 0; }
.toggle span {
  display: grid; place-items: center; min-height: 48px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--card); font-size: 14px; font-weight: 600; color: var(--muted); text-align: center;
}
.toggle input:checked + span { border-color: var(--accent); color: var(--fg); background: var(--accent-soft); }
.toggle input:disabled + span { opacity: .4; }
.toggle input:focus-visible + span { outline: 2px solid var(--accent); }

.form-error { margin: 0; color: var(--red); font-size: 14px; }
.sheet-foot { display: flex; justify-content: center; padding-top: 4px; }

.btn { border: 0; min-height: 44px; padding: 0 18px; border-radius: 12px; font-weight: 700; background: var(--card-2); }
.btn.primary { background: var(--accent); color: var(--accent-fg); }
.btn.danger { background: transparent; color: var(--red); }
.btn.wide { width: 100%; min-height: 50px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; z-index: 30; left: calc(16px + var(--safe-l)); right: calc(96px + var(--safe-r)); bottom: calc(24px + var(--safe-b));
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--fg); color: var(--bg); border-radius: 14px; padding: 4px 6px 4px 16px; min-height: 52px;
  box-shadow: var(--shadow); font-size: 15px; animation: up .2s ease;
}
.toast .text-btn.strong { color: var(--accent); filter: brightness(1.3); }

/* ---------- Wider screens ---------- */
@media (min-width: 720px) {
  main { padding-top: 16px; }
  .headline { font-size: 34px; }
  .sheet {
    inset: 0; margin: auto; width: min(520px, calc(100% - 48px)); max-height: min(760px, calc(100dvh - 48px));
    border-radius: 24px; height: fit-content;
  }
  .grabber { display: none; }
  .sheet-head { padding-top: 10px; }
  .chips { margin: 0; padding: 0; flex-wrap: wrap; }
  .item .snooze { grid-column: auto; }
  .forgot .item { grid-template-columns: auto 1fr auto; align-items: center; }
  .forgot .item .snooze { margin: 0; }
  .toast { left: 50%; right: auto; transform: translateX(-50%); min-width: 320px; }
}

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