:root {
  --bg: #fff7f2;
  --card: #ffffff;
  --ink: #2a2230;
  --muted: #7d7285;
  --line: #efe4de;
  --a: #f0645a;       /* person A */
  --a-soft: #fde4e1;
  --b: #2aa198;       /* person B */
  --b-soft: #d9f2ef;
  --accent: #7c5cff;
  --ok: #33a36b;
  --shadow: 0 1px 2px rgba(42,34,48,.06), 0 6px 20px rgba(42,34,48,.06);
  --r: 18px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16131a; --card: #221e27; --ink: #f3eef6; --muted: #a79daf; --line: #332d3a;
    --a-soft: #43272a; --b-soft: #193a37; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #16131a; --card: #221e27; --ink: #f3eef6; --muted: #a79daf; --line: #332d3a;
  --a-soft: #43272a; --b-soft: #193a37; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  min-height: 100dvh;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; width: 100%; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.err { color: var(--a); min-height: 1.2em; }

.btn { border: 0; border-radius: 14px; padding: 12px 16px; font-weight: 600; background: var(--line); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.small { padding: 8px 12px; font-size: 14px; border-radius: 12px; }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; padding: 8px; }

/* setup */
.setup { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.setup-card { width: 100%; max-width: 360px; text-align: center; display: grid; gap: 14px; }
.setup-card h1 { margin: 0; font-size: 34px; letter-spacing: -.02em; }
.logo { font-size: 56px; }
.who { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.who .btn { padding: 22px 10px; font-size: 18px; }
.who-a { background: var(--a-soft); color: var(--a); }
.who-b { background: var(--b-soft); color: var(--b); }
#pinBox { text-align: left; display: grid; gap: 6px; }

/* header */
.top { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: calc(12px + env(safe-area-inset-top)) 16px 10px; }
.duo-head { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.person { background: var(--card); border-radius: var(--r); padding: 12px; display: flex; gap: 10px; align-items: center; box-shadow: var(--shadow); border: 2px solid transparent; }
.person.me { border-color: currentColor; }
.person.pa { color: var(--a); } .person.pb { color: var(--b); }
.person .meta { color: var(--ink); min-width: 0; }
.person .nm { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person .sub { font-size: 12px; color: var(--muted); }
.ring { width: 46px; height: 46px; flex: none; }
.ring text { font-size: 11px; font-weight: 700; fill: var(--ink); }

.view { padding: 4px 16px 16px; max-width: 560px; margin: 0 auto; }
.top .duo-head { max-width: 528px; margin: 0 auto; }
h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 4px 8px; }

/* habit cards */
.list { display: grid; gap: 10px; }
.habit { background: var(--card); border-radius: var(--r); padding: 12px 14px; box-shadow: var(--shadow); display: grid; grid-template-columns: 36px 1fr auto; gap: 10px; align-items: center; position: relative; overflow: hidden; }
.habit .em { font-size: 26px; text-align: center; }
.habit .t { font-weight: 650; }
.habit .p { font-size: 13px; color: var(--muted); }
.habit .bar { grid-column: 1 / -1; height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; }
.habit .bar i { display: block; height: 100%; background: var(--c, var(--accent)); border-radius: 99px; transition: width .3s; }
.habit.done { outline: 2px solid color-mix(in srgb, var(--ok) 50%, transparent); }
.habit.done .t::after { content: " ✓"; color: var(--ok); }
.ctrl { display: flex; gap: 6px; align-items: center; }
.round { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--line); font-size: 20px; font-weight: 700; display: grid; place-items: center; }
.round.go { background: var(--c, var(--accent)); color: #fff; }
.check { width: 44px; height: 44px; border-radius: 14px; border: 2px solid var(--line); background: transparent; font-size: 22px; }
.check.on { background: var(--ok); border-color: var(--ok); color: #fff; }

/* partner */
.nudge-btn { border: 0; border-radius: 12px; padding: 8px 12px; font-weight: 600; background: var(--accent); color: #fff; font-size: 14px; }
.nudge-btn.sent { background: var(--line); color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 99px; padding: 8px 12px; font-size: 14px; }
.card { background: var(--card); border-radius: var(--r); padding: 14px; box-shadow: var(--shadow); }

/* week chart */
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; align-items: end; height: 110px; }
.week .d { display: grid; grid-template-rows: 1fr auto; gap: 4px; height: 100%; text-align: center; font-size: 11px; color: var(--muted); }
.week .bars { display: flex; gap: 3px; align-items: end; justify-content: center; }
.week .bars i { width: 9px; border-radius: 4px 4px 2px 2px; min-height: 3px; }
.legend { display: flex; gap: 14px; font-size: 13px; margin-top: 8px; color: var(--muted); }
.legend b { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* notes */
.thread { display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 82%; padding: 10px 12px; border-radius: 16px; background: var(--card); box-shadow: var(--shadow); }
.msg.mine { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 6px; }
.msg.theirs { align-self: flex-start; border-bottom-left-radius: 6px; }
.msg small { display: block; font-size: 11px; opacity: .7; margin-top: 4px; }
.msg.nudge::before { content: "👉 "; }
.compose { position: sticky; bottom: calc(76px + env(safe-area-inset-bottom)); background: var(--bg); padding: 10px 0 4px; display: grid; gap: 8px; }
.compose .row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

/* fast */
.fast { text-align: center; display: grid; gap: 12px; justify-items: center; }
.fast .big { font-size: 40px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.fast-ring { width: 190px; height: 190px; }
.goals { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.goals button { border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 8px 12px; font-weight: 600; }
.goals button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.hist { font-size: 14px; color: var(--muted); display: grid; gap: 4px; }

/* settings */
.form { display: grid; gap: 10px; }
.form .row { display: grid; grid-template-columns: 70px 1fr; gap: 8px; }
.form .row3 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.srow { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.srow:last-child { border-bottom: 0; }
.del { background: none; border: 0; color: var(--a); font-weight: 600; }

/* tabs */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: var(--card); border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(5, 1fr); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
.tabs button { border: 0; background: none; display: grid; justify-items: center; gap: 1px; font-size: 11px; color: var(--muted); padding: 4px 0; position: relative; }
.tabs button em { font-style: normal; max-width: 70px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs button span { font-size: 21px; filter: grayscale(1); opacity: .7; }
.tabs button.on { color: var(--ink); font-weight: 700; }
.tabs button.on span { filter: none; opacity: 1; }
.tabs b { position: absolute; top: 0; right: calc(50% - 22px); background: var(--a); color: #fff; font-size: 11px; border-radius: 99px; padding: 1px 6px; }

/* timer */
.timer { position: fixed; inset: 0; z-index: 50; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(6px); display: grid; place-items: center; padding: 16px; }
.timer-card { text-align: center; display: grid; gap: 18px; justify-items: center; width: 100%; max-width: 360px; }
.timer-label { font-size: 20px; font-weight: 700; }
.timer-clock { font-size: 72px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.03em; }
.timer-actions { display: grid; grid-template-columns: 1fr 1.5fr; gap: 10px; width: 100%; }
.breath { position: relative; width: 150px; height: 150px; display: grid; place-items: center; }
.breath div { position: absolute; inset: 0; border-radius: 50%; background: var(--b-soft); animation: breathe 8s ease-in-out infinite; }
.breath span { position: relative; font-weight: 600; color: var(--b); }
@keyframes breathe { 0%,100% { transform: scale(.55); } 50% { transform: scale(1); } }

/* toast & offline */
.toast { position: fixed; left: 16px; right: 16px; top: calc(12px + env(safe-area-inset-top)); z-index: 60; background: var(--ink); color: var(--bg); padding: 14px 16px; border-radius: 16px; font-weight: 600; box-shadow: 0 10px 30px rgba(0,0,0,.25); max-width: 528px; margin: 0 auto; animation: drop .25s ease-out; }
@keyframes drop { from { transform: translateY(-20px); opacity: 0; } }
.offline { background: var(--a); color: #fff; text-align: center; font-size: 13px; padding: 6px; }
@keyframes shake { 0%,100%{transform:none} 25%{transform:translateX(-4px)} 75%{transform:translateX(4px)} }
.shake { animation: shake .3s 2; }
