:root {
  --bg: #F7F7F4;
  --surface: #FFFFFF;
  --surface-2: #EEEFEA;
  --line: #E4E5E0;
  --line-strong: #CFD0CA;
  --ink: #16181D;
  --ink-2: #3A3F47;
  --muted: #5F646C;
  --accent: #1F6F54;
  --accent-ink: #FFFFFF;
  --accent-soft: #E7F1EC;
  --accent-soft-ink: #1D4D3B;
  --warn: #9A4A12;
  --warn-soft: #FBEBDD;
  --danger: #A12C2C;
  --shadow: 0 10px 40px rgba(16, 24, 32, .18);
  /* portal tints: background / ink */
  --t-blue: #E3EEF8;   --i-blue: #1F4E7A;
  --t-purple: #ECE7F4; --i-purple: #4F3C78;
  --t-teal: #E1F1F2;   --i-teal: #1D5E63;
  --t-green: #E6F0E2;  --i-green: #35602A;
  --t-amber: #F8EEDB;  --i-amber: #7A5418;
  --t-rose: #F6E4E6;   --i-rose: #7E2F3B;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111315; --surface: #1A1D20; --surface-2: #23272B; --line: #2C3035; --line-strong: #3B4046;
    --ink: #ECEDEE; --ink-2: #C9CCD0; --muted: #9AA0A7; --accent: #3FA57F; --accent-ink: #08130E;
    --accent-soft: #15291F; --accent-soft-ink: #A9DCC4; --warn: #F0A56B; --warn-soft: #2D1F14; --danger: #F08A8A;
    --shadow: 0 10px 40px rgba(0, 0, 0, .5);
    --t-blue: #1A2A3A; --i-blue: #9CC3EA; --t-purple: #261F33; --i-purple: #C7B6EA;
    --t-teal: #15292B; --i-teal: #92D2D6; --t-green: #1B2818; --i-green: #A9D39A;
    --t-amber: #2E2414; --i-amber: #EBC27E; --t-rose: #2F1C1F; --i-rose: #EDA9B3;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111315; --surface: #1A1D20; --surface-2: #23272B; --line: #2C3035; --line-strong: #3B4046;
  --ink: #ECEDEE; --ink-2: #C9CCD0; --muted: #9AA0A7; --accent: #3FA57F; --accent-ink: #08130E;
  --accent-soft: #15291F; --accent-soft-ink: #A9DCC4; --warn: #F0A56B; --warn-soft: #2D1F14; --danger: #F08A8A;
  --shadow: 0 10px 40px rgba(0, 0, 0, .5);
  --t-blue: #1A2A3A; --i-blue: #9CC3EA; --t-purple: #261F33; --i-purple: #C7B6EA;
  --t-teal: #15292B; --i-teal: #92D2D6; --t-green: #1B2818; --i-green: #A9D39A;
  --t-amber: #2E2414; --i-amber: #EBC27E; --t-rose: #2F1C1F; --i-rose: #EDA9B3;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font-family: 'Geist', system-ui, -apple-system, sans-serif; font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
main { max-width: 720px; margin: 0 auto; padding: 24px 16px 56px; }
a { color: var(--accent); }
h1, h2, h3 { letter-spacing: -0.02em; margin: 0; }
p { margin: 0; }
.loading { color: var(--muted); padding: 40px 0; }
.mono { font-family: 'Geist Mono', ui-monospace, monospace; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* brand + top bar */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 18px; letter-spacing: -0.01em; }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.who { display: flex; align-items: center; gap: 8px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--t-purple); color: var(--i-purple);
  display: grid; place-items: center; font-size: 13px; font-weight: 600; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* buttons */
button, .btn { font: inherit; cursor: pointer; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-height: 48px;
  padding: 0 20px; border-radius: 14px; border: 1px solid transparent; font-weight: 500; text-decoration: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-dark { background: var(--ink); color: var(--bg); }
.btn-quiet { background: transparent; color: var(--ink-2); border-color: var(--line-strong); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--line-strong); }
.btn-block { width: 100%; }
.btn:disabled { opacity: .6; cursor: default; }
.link-btn { background: none; border: 0; padding: 0 4px; color: var(--muted); font-size: 14px; min-height: 44px; }
.link-btn:hover { color: var(--ink); text-decoration: underline; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; background: none; border: 0; color: var(--ink-2);
  border-radius: 10px; }
.icon-btn:hover { background: var(--surface-2); }

/* sign-in */
.signin { max-width: 420px; margin: 0 auto; min-height: calc(100dvh - 80px); display: flex; flex-direction: column;
  padding-top: 32px; }
.signin h1 { margin-top: 48px; font-size: 34px; line-height: 1.12; font-weight: 600; letter-spacing: -0.025em; }
.signin .lede { margin-top: 14px; font-size: 16px; color: var(--muted); }
.chips { margin-top: 28px; display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); font-size: 14px; font-weight: 500; }
.chip .badge { width: 26px; height: 26px; border-radius: 8px; font-size: 11px; }
.trust { margin-top: 28px; display: flex; flex-direction: column; gap: 14px; }
.trust div { display: flex; gap: 12px; align-items: flex-start; font-size: 15px; }
.trust svg { flex-shrink: 0; color: var(--accent); margin-top: 1px; }
.signin-cta { margin-top: auto; padding-top: 32px; display: flex; flex-direction: column; align-items: center; gap: 14px; }
#gsi-button { min-height: 44px; display: flex; justify-content: center; }
.fineprint { font-size: 13px; color: var(--muted); text-align: center; }
.alert { padding: 12px 14px; border-radius: 12px; background: var(--warn-soft); color: var(--warn); font-size: 14px; }
.dev { width: 100%; display: flex; gap: 8px; }
.dev input { flex: 1; }

/* forms */
label { font-size: 13px; font-weight: 500; color: var(--ink-2); }
input[type=text], input[type=email], input[type=password], input[type=url] {
  width: 100%; height: 48px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink); font: inherit; font-size: 16px; }
input:focus-visible, button:focus-visible, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.field { display: flex; flex-direction: column; gap: 6px; }

/* home */
.home-head { margin-top: 28px; display: flex; flex-direction: column; gap: 10px; }
.home-head h1 { font-size: 28px; line-height: 1.15; font-weight: 600; }
.count { font-size: 13px; font-weight: 500; color: var(--accent); }
.progress { height: 4px; border-radius: 4px; background: var(--line); overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); border-radius: 4px; transition: width .3s; }

.grid { margin-top: 20px; display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.card { text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px;
  color: var(--ink); display: flex; flex-direction: column; gap: 10px; min-height: 132px; transition: border-color .15s, transform .15s; }
button.card:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.card.add { background: transparent; border: 1.5px dashed var(--line-strong); }
.card-name { font-weight: 600; font-size: 15px; }
.card .grow { flex-grow: 1; }
.badge { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; font-weight: 700; font-size: 13px;
  background: var(--surface-2); color: var(--ink-2); flex-shrink: 0; }
.tint-blue { background: var(--t-blue); color: var(--i-blue); }
.tint-purple { background: var(--t-purple); color: var(--i-purple); }
.tint-teal { background: var(--t-teal); color: var(--i-teal); }
.tint-green { background: var(--t-green); color: var(--i-green); }
.tint-amber { background: var(--t-amber); color: var(--i-amber); }
.tint-rose { background: var(--t-rose); color: var(--i-rose); }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 500; color: var(--ink-2); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--line-strong); }
.status.connected { color: var(--accent); } .status.connected .dot { background: var(--accent); }
.status.reconnect { color: var(--warn); } .status.reconnect .dot { background: var(--warn); }
.status.syncing { color: var(--accent); }
.status.connecting .dot, .status.syncing .dot, .status.learning .dot { background: var(--accent); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.claude-row { margin-top: 28px; display: flex; align-items: center; gap: 14px; padding: 16px; border-radius: 16px;
  background: var(--t-amber); color: var(--ink); border: 0; width: 100%; text-align: left; }
.claude-row .badge { background: var(--surface); color: var(--i-amber); }
.claude-row .text { flex: 1; display: flex; flex-direction: column; }
.claude-row b { font-weight: 600; }
.claude-row .sub { font-size: 13px; color: var(--ink-2); }
.claude-row:hover { filter: brightness(.98); }

/* claude sheet */
.copy-row { display: flex; gap: 8px; align-items: stretch; }
.copy-row code { flex: 1; min-width: 0; overflow-x: auto; white-space: nowrap; padding: 12px 14px; border-radius: 10px;
  background: var(--surface-2); font-family: 'Geist Mono', ui-monospace, monospace; font-size: 13px; }
.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; color: var(--ink-2); }
.client { border-top: 1px solid var(--line); padding-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.client h3 { font-size: 15px; font-weight: 600; }

/* sheet */
dialog#sheet { width: min(980px, 100vw - 24px); max-height: calc(100dvh - 24px); border: 0; border-radius: 20px; padding: 0;
  background: var(--bg); color: var(--ink); box-shadow: var(--shadow); }
dialog#sheet.narrow { width: min(520px, 100vw - 24px); }
dialog#sheet::backdrop { background: rgba(10, 12, 14, .55); }
.sheet-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 12px 12px 20px; background: var(--bg); border-bottom: 1px solid var(--line); }
.sheet-head h2 { font-size: 18px; font-weight: 600; }
#sheet-body { padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.sheet-hero { display: flex; align-items: center; gap: 14px; }
.sheet-hero .badge { width: 48px; height: 48px; border-radius: 13px; font-size: 15px; }
.note { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; background: var(--accent-soft);
  color: var(--accent-soft-ink); font-size: 14px; }
.note svg { flex-shrink: 0; margin-top: 2px; }
.live { width: 100%; height: min(68dvh, 720px); border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.live-wrap { position: relative; }
.live-wrap .live { display: block; }
.tap-input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; padding: 0; border: 0;
  resize: none; overflow: hidden; touch-action: none; background: transparent; color: transparent;
  caret-color: transparent; font-size: 16px;   /* 16px: iOS doesn't zoom the page on focus */
  -webkit-tap-highlight-color: transparent; outline: none; }
.tap-input::selection { background: transparent; }
.cadence { display: flex; flex-direction: column; gap: 8px; }
.cadence-head { display: flex; align-items: baseline; justify-content: space-between; }
.cadence-label { font-size: 14px; font-weight: 500; }
.segmented { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; padding: 4px;
  border-radius: 14px; background: var(--surface-2); }
.seg { min-height: 44px; border: 0; border-radius: 10px; background: transparent; color: var(--ink-2); font-size: 14px; }
.seg[aria-checked="true"], .seg[aria-selected="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.ai-tabs { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.ai-tabs .seg { font-size: 13px; padding: 0 4px; }
.ai-steps { display: flex; flex-direction: column; gap: 10px; }
.ai-steps .copy-row { margin: 4px 0 6px; }
.small-wait { padding: 4px 0; font-size: 14px; color: var(--muted); }
.small-wait .spinner { width: 16px; height: 16px; border-width: 2px; }
.waiting { display: flex; align-items: center; gap: 14px; padding: 28px 4px; font-size: 16px; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }
.success { display: flex; align-items: center; gap: 14px; }
.check { width: 44px; height: 44px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; flex-shrink: 0; }
.success h3 { font-size: 20px; font-weight: 600; }
.rows { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.rows > div { padding: 12px 16px; display: flex; flex-direction: column; gap: 2px; }
.rows > div + div { border-top: 1px solid var(--line); }
.rows .k { font-size: 13px; color: var(--muted); }
.rows .v { font-weight: 500; overflow-wrap: anywhere; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.actions > * { flex: 1 1 180px; }
details.keep { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 4px 16px; }
details.keep summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; font-weight: 500; }
details.keep[open] { padding-bottom: 16px; }
.error-text { color: var(--danger); font-size: 14px; }

@media (max-width: 600px) {
  main { padding-top: 16px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  dialog#sheet, dialog#sheet.narrow { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; margin: 0; border-radius: 0; }
  .live { height: calc(100dvh - 220px); }   /* phoneLiveBox() in app.js uses the same size */
  .signin h1 { font-size: 30px; margin-top: 36px; }
}
