:root {
  --bg: #ffffff;
  --bg-soft: #f3f3f3;
  --raise: #ffffff;
  --text: #202020;
  --muted: #808080;
  --line: #ebebeb;
  --accent: #dc4c3e;
  --accent-soft: rgba(220, 76, 62, .12);
  --ok: #3a9a5b;
  --bar: rgba(250, 250, 250, .86);
  --shadow: 0 8px 28px rgba(0, 0, 0, .14);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1f1f1f;
    --bg-soft: #2a2a2a;
    --raise: #282828;
    --text: #f2f2f2;
    --muted: #8e8e8e;
    --line: #333333;
    --accent: #de5546;
    --accent-soft: rgba(222, 85, 70, .16);
    --ok: #5cb87a;
    --bar: rgba(36, 36, 36, .88);
    --shadow: 0 8px 28px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
#i-dots circle, .pill-btn svg { fill: currentColor; }

.center-msg { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* Login */
.login {
  max-width: 340px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 56px) 22px 22px;
  display: flex; flex-direction: column; gap: 14px;
}
.login h1 { margin: 0 0 6px; font-size: 30px; }
.login label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.login input {
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg-soft); font-size: 16px; color: var(--text);
}
.error { color: var(--accent); font-size: 13px; margin: 0; min-height: 1em; }
.primary {
  background: var(--accent); color: #fff; border: 0;
  border-radius: 12px; padding: 12px 14px; font-weight: 600;
}
.link { background: none; border: 0; color: var(--accent); padding: 8px; }
.link.small { font-size: 14px; padding: 6px 8px; }
.danger { color: var(--accent); }

/* App layout */
#app {
  max-width: 680px; margin: 0 auto;
  padding: env(safe-area-inset-top) calc(env(safe-area-inset-right) + 4px) 0 calc(env(safe-area-inset-left) + 4px);
}
.top {
  position: sticky; top: 0; z-index: 5;
  display: grid; grid-template-columns: 44px 1fr 44px; align-items: center;
  padding: 10px 14px 12px;
  background: var(--bg);
}
.top-title { grid-column: 2; text-align: center; }
.top h1 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -.2px; }
.sub { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.pill-btn {
  grid-column: 3; justify-self: end;
  width: 40px; height: 40px; border-radius: 20px; border: 1px solid var(--line);
  background: var(--bg-soft); color: var(--text); display: grid; place-items: center;
}

.note {
  margin: 4px 18px 10px; padding: 10px 12px; border-radius: 12px;
  background: var(--accent-soft); color: var(--accent); font-size: 14px;
}

.group h2 {
  margin: 14px 18px 2px; font-size: 16px; font-weight: 700;
}
.tasks { list-style: none; margin: 0; padding: 0; }
.task {
  display: flex; align-items: flex-start; gap: 14px;
  padding: 14px 18px 0;
  user-select: none; -webkit-user-select: none;
}
.task .body {
  flex: 1; min-width: 0; padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.task .title { font-size: 17px; word-wrap: break-word; }
.task .meta { display: flex; align-items: center; gap: 4px; margin-top: 5px; font-size: 14px; color: var(--muted); }
.task .meta svg { width: 15px; height: 15px; }
.meta.overdue { color: var(--accent); }
.meta.today { color: var(--ok); }
.check {
  flex: none; width: 24px; height: 24px; margin-top: 1px; border-radius: 50%;
  border: 1.6px solid var(--muted); background: none; padding: 0; position: relative;
}
.check::after {
  content: ""; position: absolute; left: 7px; top: 3px; width: 6px; height: 11px;
  border: solid var(--muted); border-width: 0 1.6px 1.6px 0; transform: rotate(45deg); opacity: 0;
  transition: opacity .15s;
}
@media (hover: hover) { .check:hover::after { opacity: .7; } }
.task.done-anim .check { background: var(--muted); border-color: var(--muted); }
.task.done-anim .check::after { opacity: 1; border-color: var(--bg); }
.task.done-anim .title { text-decoration: line-through; color: var(--muted); }
.task.done-anim { transition: opacity .25s .15s; opacity: .4; }

.empty { color: var(--muted); text-align: center; margin: 56px 30px; font-size: 15px; }
.spacer { height: calc(env(safe-area-inset-bottom) + 130px); }

/* Floating add button */
.fab {
  position: fixed; z-index: 6;
  right: max(20px, calc(50vw - 340px + 20px));
  bottom: calc(env(safe-area-inset-bottom) + 92px);
  width: 60px; height: 60px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; display: grid; place-items: center;
  box-shadow: var(--shadow);
}
.fab svg { width: 28px; height: 28px; stroke-width: 2.2; }
.fab:active { transform: scale(.94); }

/* Bottom tab bar */
.tabbar {
  position: fixed; z-index: 6; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 10px);
  width: min(calc(100% - 28px), 480px);
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px;
  padding: 6px; border-radius: 34px;
  background: var(--bar); border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}
.tabbar button {
  border: 0; background: none; border-radius: 26px; padding: 7px 0 6px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 12px; font-weight: 600; color: var(--text);
}
.tabbar button.active { background: var(--bg-soft); color: var(--accent); }
.tabbar .ic { position: relative; display: grid; }
.tabbar svg { width: 24px; height: 24px; }
.tabbar .count {
  position: absolute; top: -4px; right: -12px; min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 9px; background: var(--bg-soft); color: var(--muted);
  font-size: 10.5px; font-weight: 700; line-height: 17px; text-align: center;
}
.tabbar button.active .count { background: var(--accent-soft); color: var(--accent); }
.tabbar .count.over { background: var(--accent); color: #fff; }
.tabbar .count:empty { display: none; }

/* Sheets */
.sheet {
  position: fixed; inset: 0; z-index: 10; background: rgba(0, 0, 0, .4);
  display: flex; align-items: flex-end; justify-content: center;
  padding-bottom: var(--kb, 0px);
  animation: fade .15s ease-out;
}
.sheet-card {
  background: var(--raise); width: 100%; max-width: 520px;
  border-radius: 18px 18px 0 0; padding: 18px 16px calc(env(safe-area-inset-bottom) + 12px);
  display: flex; flex-direction: column; gap: 10px;
  animation: rise .2s ease-out;
}
@media (min-width: 600px) { .sheet { align-items: center; } .sheet-card { border-radius: 18px; } }
@keyframes rise { from { transform: translateY(24px); opacity: .6; } }
@keyframes fade { from { opacity: 0; } }
.sheet-title { margin: 0; font-weight: 600; word-wrap: break-word; }
.sheet-sync { margin: 0; display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
#sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
#sync-dot.pending { background: #e0a526; }
#sync-dot.offline { background: var(--muted); }
.row-btn { border: 0; background: var(--bg-soft); border-radius: 12px; padding: 12px; }

/* Editor */
.editor { gap: 14px; }
.ed-title {
  border: 0; background: none; outline: none; padding: 2px 2px;
  font-size: 19px; font-weight: 600; color: var(--text); width: 100%;
}
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button, .date-chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: none; border-radius: 10px;
  padding: 7px 11px; font-size: 14px; color: var(--muted);
}
.chips svg, .date-chip svg { width: 17px; height: 17px; }
.chips button.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.ed-row { display: flex; align-items: center; gap: 6px; padding-top: 10px; border-top: 1px solid var(--line); }
.grow { flex: 1; }
.date-chip { position: relative; cursor: pointer; }
.date-chip.set { color: var(--accent); border-color: var(--accent); }
.date-chip input { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; }
.send {
  width: 40px; height: 40px; border-radius: 50%; border: 0; flex: none;
  background: var(--accent); color: #fff; display: grid; place-items: center;
}
.send:disabled { opacity: .35; }
.send svg { stroke-width: 2.2; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 20;
  bottom: calc(env(safe-area-inset-bottom) + 96px);
  background: #333; color: #fff; border-radius: 12px;
  padding: 10px 8px 10px 16px; display: flex; gap: 14px; align-items: center;
  font-size: 15px; box-shadow: var(--shadow); white-space: nowrap;
}
.toast button { background: none; border: 0; color: #ff8a7d; font-weight: 700; padding: 4px 8px; }

/* Subtasks */
.meta-row { display: flex; justify-content: space-between; gap: 14px; }
.meta-left { display: flex; gap: 14px; flex-wrap: wrap; }
.subs-box { display: flex; flex-direction: column; max-height: 42vh; overflow-y: auto; }
.subs { list-style: none; margin: 0; padding: 0; }
.subrow { display: flex; align-items: center; gap: 12px; padding: 7px 2px; border-bottom: 1px solid var(--line); }
.subrow input, .sub-new input {
  flex: 1; min-width: 0; border: 0; background: none; outline: none;
  font-size: 16px; color: var(--text); padding: 2px 0;
}
.subrow.done input { text-decoration: line-through; color: var(--muted); }
.check.small { width: 20px; height: 20px; margin: 0; }
.check.small::after { left: 6px; top: 2px; width: 5px; height: 10px; }
.subrow.done .check { background: var(--muted); border-color: var(--muted); }
.subrow.done .check::after { opacity: 1; border-color: var(--raise); }
.check:disabled { opacity: .5; cursor: default; }
.sub-x { border: 0; background: none; color: var(--muted); padding: 4px; display: grid; }
.sub-x svg { width: 17px; height: 17px; }
.sub-new { display: flex; align-items: center; gap: 12px; padding: 7px 2px; }
.sub-plus { border: 0; background: none; color: var(--accent); padding: 0; width: 20px; display: grid; place-items: center; }
.sub-plus svg { width: 20px; height: 20px; }
.sub-new input::placeholder { color: var(--muted); }

/* Tags */
.tagbar { display: flex; gap: 8px; overflow-x: auto; padding: 0 18px 8px; scrollbar-width: none; }
.tagbar::-webkit-scrollbar { display: none; }
.tagbar button {
  flex: none; border: 1px solid var(--line); background: none; color: var(--muted);
  border-radius: 16px; padding: 5px 12px; font-size: 14px;
}
.tagbar button.on { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.meta.tag { color: var(--muted); }
.tag-chip input {
  position: static; opacity: 1; width: 70px; border: 0; background: none; outline: none;
  color: inherit; font-size: 14px; padding: 0; cursor: text;
}
.tag-chip input::placeholder { color: var(--muted); }
.date-chip select { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; font-size: 16px; }
.ed-row { flex-wrap: wrap; }
.ed-hint { margin: -8px 2px 0; font-size: 14px; color: var(--accent); }

/* Section header with action */
.row-head { display: flex; justify-content: space-between; align-items: center; }
.row-head .link { font-weight: 500; font-size: 15px; padding: 0; }

/* Swipe */
.task { position: relative; overflow: hidden; padding: 0; display: block; }
.task-inner {
  position: relative; z-index: 1; background: var(--bg);
  display: flex; align-items: flex-start; gap: 14px; padding: 14px 18px 0;
  touch-action: pan-y;
}
.swipe-bg {
  position: absolute; inset: 0; display: flex; align-items: center; padding: 0 24px;
  color: #fff; opacity: 0; transition: opacity .1s;
}
.swipe-bg svg { width: 24px; height: 24px; stroke-width: 2.2; }
.swipe-bg.left { background: var(--ok); justify-content: flex-start; }
.swipe-bg.right { background: #8a6fd6; justify-content: flex-end; }
.task.swiping-right .swipe-bg.left, .task.swiping-left .swipe-bg.right { opacity: .55; }
.task.armed .swipe-bg { opacity: 1 !important; }

/* Reschedule */
.rs-opts { display: flex; flex-direction: column; }
.rs-opt {
  display: flex; justify-content: space-between; align-items: center; position: relative;
  border: 0; border-bottom: 1px solid var(--line); background: none; padding: 13px 4px; font-size: 16px; text-align: left;
}
.rs-opt small { color: var(--muted); font-size: 14px; }
.rs-opt.pick { cursor: pointer; color: var(--accent); }
.rs-opt.pick input { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; }

/* Week plan */
.primary.small { padding: 7px 14px; font-size: 15px; border-radius: 10px; }
.plan-banner {
  margin: 0 18px 10px; padding: 10px 12px; border-radius: 12px; background: var(--accent-soft);
  display: flex; align-items: center; gap: 10px; font-size: 15px;
}
.plan-banner > div { flex: 1; }
.sheet.full .sheet-card { max-height: 92vh; }
.plan-card { gap: 6px; }
.plan-head { display: flex; justify-content: space-between; align-items: flex-start; }
.plan-head h2 { margin: 0; font-size: 20px; }
.dim { color: var(--muted); }
.small-text { font-size: 13px; margin: 0 0 6px; }
.plan-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.plan-row { padding: 10px 2px; border-bottom: 1px solid var(--line); }
.plan-title { font-size: 16px; }
.plan-sub { font-size: 13px; color: var(--muted); margin: 2px 0 8px; }
.plan-sub.overdue { color: var(--accent); }
.plan-btns { display: flex; gap: 6px; }
.plan-btns button {
  flex: 1; border: 1px solid var(--line); background: none; border-radius: 9px; padding: 6px 0; font-size: 14px; color: var(--muted);
}
.plan-btns button.on { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.plan-btns .plan-done { flex: 0 0 42px; display: grid; place-items: center; }
.plan-btns .plan-done svg { width: 18px; height: 18px; }

/* Guide */
.guide {
  position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center; padding: 16px;
  animation: fade .2s ease-out;
}
.guide-card {
  position: relative; background: var(--raise); width: 100%; max-width: 420px; max-height: 92vh; overflow-y: auto;
  border-radius: 22px; padding: 28px 22px 18px; display: flex; flex-direction: column; gap: 10px;
  box-shadow: var(--shadow); animation: rise .25s ease-out;
}
.guide-skip { position: absolute; top: 12px; right: 12px; color: var(--muted); }
.guide-icon {
  width: 56px; height: 56px; border-radius: 16px; background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center;
}
.guide-icon svg { width: 30px; height: 30px; }
.guide-card h2 { margin: 6px 0 0; font-size: 22px; letter-spacing: -.2px; }
.guide-body { font-size: 16px; line-height: 1.45; }
.guide-body p { margin: 0 0 10px; }
.guide-body .dim { font-size: 14px; }
.guide-body ul.ex { list-style: none; padding: 0; margin: 0 0 10px; }
.guide-body ul.ex li { padding: 8px 12px; margin-bottom: 6px; border-radius: 10px; background: var(--bg-soft); }
.guide-body ul.ex b { color: var(--accent); font-weight: 600; }
.guide-body ol.steps { padding-left: 20px; margin: 0 0 10px; }
.guide-body ol.steps li { margin-bottom: 6px; }
.guide-body code { font-size: 13px; background: var(--bg-soft); padding: 2px 5px; border-radius: 5px; word-break: break-all; }
.row-btn.accent { color: var(--accent); font-weight: 600; }
.guide-dots { display: flex; gap: 6px; justify-content: center; margin-top: 6px; }
.guide-dots span { width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.guide-dots span.on { background: var(--accent); width: 20px; border-radius: 4px; }
.guide-nav { display: flex; justify-content: space-between; align-items: center; }
.guide-nav .primary { min-width: 110px; }

/* Sharing */
.whobar { display: flex; gap: 4px; margin: 0 18px 10px; padding: 3px; border-radius: 12px; background: var(--bg-soft); }
.whobar button { flex: 1; border: 0; background: none; border-radius: 9px; padding: 7px 0; font-size: 14px; font-weight: 600; color: var(--muted); }
.whobar button.on { background: var(--raise); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.2); }
body.viewing-partner .fab, body.viewing-partner #resched-all { display: none; }
body.viewing-partner .check { opacity: .5; }
.share-box { display: flex; flex-direction: column; gap: 8px; padding: 8px 0 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.sheet-label { display: flex; align-items: center; gap: 10px; margin: 0; font-size: 14px; color: var(--muted); }
.name-input { flex: 1; border: 1px solid var(--line); background: var(--bg-soft); border-radius: 10px; padding: 8px 10px; font-size: 16px; color: var(--text); }
.share-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.share-list { list-style: none; margin: 0; padding: 0; }
.share-list li { display: flex; justify-content: space-between; align-items: center; padding: 6px 2px; font-size: 15px; }
.share-code-box { text-align: center; background: var(--bg-soft); border-radius: 12px; padding: 10px; }
.share-code-box p { margin: 0 0 6px; font-size: 14px; color: var(--muted); }
.share-code { font-size: 30px !important; font-weight: 700; letter-spacing: 4px; color: var(--text) !important; }
.sheet-title.big { font-size: 19px; }
.peek-sub { font-size: 16px; }
.subrow.done .peek-sub { text-decoration: line-through; color: var(--muted); }
.sheet-card { max-height: 90vh; overflow-y: auto; }
