:root {
  --bg: #f5f5f2; --card: #ffffff; --fg: #1c1c1a; --muted: #6b6b66; --border: #e2e2dc;
  --accent: #1f5f99; --accent-fg: #ffffff; --danger: #b3261e; --ok: #2e7d32;
  --user: #1f5f99; --user-fg: #fff; --agent: #ffffff; --system: #fff4e5;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212; --card: #1d1d1c; --fg: #ececea; --muted: #a2a29c; --border: #33332f;
    --accent: #79b0e8; --accent-fg: #0e1a26; --danger: #ef7b72; --ok: #7bc47f;
    --user: #2b5b88; --user-fg: #fff; --agent: #1d1d1c; --system: #3a2f1c;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body { font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; min-height: 100vh; }
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 .5rem; }
h2 { font-size: 1.1rem; margin: 1.25rem 0 .5rem; }
.card h2:first-child, .card h1:first-child { margin-top: 0; }
h3 { font-size: 1rem; margin: 1rem 0 .25rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hint { color: var(--muted); font-size: .85rem; margin: .25rem 0 0; }
.center { text-align: center; }
.hidden { display: none !important; }
.error { color: var(--danger); font-weight: 600; }
.ok { color: var(--ok); font-weight: 600; }

/* header */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1rem;
  padding: .5rem 1rem; background: var(--card); border-bottom: 1px solid var(--border);
  padding-top: max(.5rem, env(safe-area-inset-top)); }
.brand { font-weight: 700; text-decoration: none; color: var(--fg); white-space: nowrap; }
.nav { display: flex; gap: .25rem; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { padding: .35rem .6rem; border-radius: 8px; text-decoration: none; color: var(--muted); white-space: nowrap; }
.nav a.on, .nav a:hover { background: var(--bg); color: var(--fg); }
.badge { display: inline-block; min-width: 1.2em; padding: 0 .35em; border-radius: 999px; background: var(--danger);
  color: #fff; font-size: .75rem; text-align: center; }

/* layout */
.page { max-width: 760px; margin: 0 auto; padding: 1.25rem 16px 3rem; }
body.narrow .page { max-width: 420px; padding-top: 3rem; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; margin: .75rem 0; }
.card.attention { border-color: var(--accent); }
details.card summary { cursor: pointer; font-weight: 600; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row form { margin: 0; }
.list { list-style: none; padding: 0; margin: .5rem 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .7rem .9rem; background: var(--card); border: 1px solid var(--border); border-radius: 10px; margin: .4rem 0; }
.list li.unread { border-color: var(--accent); }
.links { padding-left: 1.1rem; margin: .25rem 0; word-break: break-all; }
.tag { display: inline-block; font-size: .78rem; padding: .05rem .5rem; border-radius: 999px; background: var(--bg);
  border: 1px solid var(--border); color: var(--muted); }
.tag.public { color: var(--ok); border-color: var(--ok); }
.tag.danger { color: var(--danger); border-color: var(--danger); }
pre.details { white-space: pre-wrap; word-break: break-word; background: var(--bg); padding: .6rem .8rem; border-radius: 8px; font-size: .9rem; }
code.key { display: block; word-break: break-all; background: var(--bg); padding: .5rem .7rem; border-radius: 8px; margin: .5rem 0; }
img.qr { display: block; margin: .5rem auto; background: #fff; padding: 8px; border-radius: 8px; }

/* forms */
label { display: block; font-weight: 600; margin: .8rem 0 .25rem; }
input, textarea, select { width: 100%; font: inherit; color: var(--fg); background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: .6rem .75rem; }
select { width: auto; }
.row input { width: auto; flex: 1; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
button { font: inherit; font-weight: 600; border: 0; border-radius: 8px; padding: .6rem 1rem; cursor: pointer;
  background: var(--accent); color: var(--accent-fg); }
form > button[type=submit]:last-child { margin-top: 1rem; }
.row button { margin-top: 0 !important; }
button.secondary { background: transparent; color: var(--fg); border: 1px solid var(--border); }
button.danger { color: var(--danger); }
button.link { background: none; border: 0; padding: .25rem; color: var(--accent); font-weight: 500; }
button.link.danger { color: var(--danger); }
button:disabled { opacity: .5; cursor: default; }
.search { margin: .75rem 0; }

/* chat */
main.chat { display: flex; flex-direction: column; max-width: 820px; margin: 0 auto; width: 100%;
  height: calc(100vh - 53px); height: calc(100dvh - 53px); }
.convs { border-right: 1px solid var(--border); overflow-y: auto; padding: .75rem; background: var(--card); }
.convs a { display: flex; flex-direction: column; padding: .5rem .6rem; border-radius: 8px; text-decoration: none; color: var(--fg); }
.convs a.on, .convs a:hover { background: var(--bg); }
.convs a.new { font-weight: 700; color: var(--accent); margin-bottom: .5rem; }
.convs .title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.convs .when { font-size: .75rem; color: var(--muted); }
.thread { display: flex; flex-direction: column; min-width: 0; min-height: 0; flex: 1; }
.thread-head { display: flex; align-items: center; gap: .75rem; justify-content: space-between; padding: .5rem 1rem;
  border-bottom: 1px solid var(--border); }
.thread-head strong { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-head form { margin: 0; }
.messages { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .6rem; }
.msg { max-width: min(680px, 88%); padding: .6rem .9rem; border-radius: 14px; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--user); color: var(--user-fg); }
.msg.user .body { white-space: pre-wrap; }
.msg.agent { align-self: flex-start; background: var(--agent); border: 1px solid var(--border); }
.msg.system { align-self: center; background: var(--system); font-size: .9rem; white-space: pre-wrap; }
.msg .when { font-size: .7rem; opacity: .6; margin-top: .2rem; text-align: right; }
.msg.agent .when { text-align: left; }
.job-label { font-size: .78rem; font-weight: 600; color: var(--muted); margin-bottom: .2rem; }
.card-msg { align-self: stretch; max-width: 100%; background: var(--card); border: 1px solid var(--accent);
  border-radius: 12px; }
.card-msg .card-title { font-weight: 600; }
.card-msg form { margin-top: .5rem; }
.card-msg .row { margin-top: .6rem; }
.card-msg .when { text-align: left; }
a.button { display: inline-block; margin-top: .5rem; padding: .55rem 1rem; border-radius: 8px; background: var(--accent);
  color: var(--accent-fg); font-weight: 600; text-decoration: none; }
.load-earlier { align-self: center; }
.msg p { margin: .3rem 0; }
.msg ul, .msg ol { margin: .3rem 0; padding-left: 1.3rem; }
.msg pre { white-space: pre-wrap; background: var(--bg); padding: .5rem; border-radius: 6px; }
.msg code { font-size: .9em; }
.empty { margin: auto; max-width: 480px; text-align: left; }
.status { display: flex; align-items: center; gap: .5rem; padding: .25rem 1rem; color: var(--muted); font-size: .9rem; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1s infinite alternate; }
@keyframes pulse { from { opacity: .3; } to { opacity: 1; } }
.composer { display: flex; gap: .5rem; padding: .75rem 1rem 0; }
.composer textarea { resize: none; max-height: 40vh; }
.composer button { align-self: flex-end; }
.thread > .hint { padding: .25rem 1rem max(.5rem, env(safe-area-inset-bottom)); }
.only-mobile { display: none; }
.empty h2 { margin-bottom: 1rem; }
.quick { display: flex; flex-wrap: wrap; gap: .5rem; }
.quick button { font-weight: 500; border-radius: 999px; }

/* onboarding */
.invisible { visibility: hidden; }
.wizard .step h1 { margin-top: .25rem; }
.wizard .steps { margin: 0; }
.wizard textarea { resize: vertical; }
.wizard-nav { margin-top: 1.25rem; }
button.wide { width: 100%; margin-top: 1.25rem; }
.choices { display: flex; gap: .5rem; }
.choice, .chip { display: inline-flex; align-items: center; gap: .4rem; font-weight: 500; margin: 0; cursor: pointer;
  padding: .5rem .8rem; border: 1px solid var(--border); border-radius: 999px; background: var(--bg); }
.choice input, .chip input { width: auto; margin: 0; accent-color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: .5rem; margin: .5rem 0 .25rem; }
.chip:has(input:checked), .choice:has(input:checked) { border-color: var(--accent); background: var(--card);
  outline: 1px solid var(--accent); }

@media (max-width: 720px) {
  .brand { display: none; }
  main.chat { grid-template-columns: 1fr; }
  .convs { display: none; }
  .convs.open { display: block; position: fixed; inset: 53px 0 0 0; z-index: 5; }
  .only-mobile { display: inline-block; }
}

/* handoff */
.handoff-banner { display: block; padding: .6rem 1rem; background: var(--accent); color: var(--accent-fg);
  text-decoration: none; font-weight: 500; }
main.live { display: flex; flex-direction: column; height: calc(100vh - 53px); height: calc(100dvh - 53px); }
.live-bar { display: flex; gap: .75rem; align-items: center; justify-content: space-between; flex-wrap: wrap;
  padding: .6rem 1rem; border-bottom: 1px solid var(--border); background: var(--card); }
.live-bar form { margin: 0; }
.live-why { min-width: 0; flex: 1 1 260px; }
.screen { flex: 1; min-height: 0; background: #000; }
.live-foot { display: flex; justify-content: space-between; align-items: center; gap: .5rem;
  padding: .4rem 1rem max(.4rem, env(safe-area-inset-bottom)); }
.live-state { display: inline-flex; gap: .5rem; align-items: center; }
.kbd-input { position: fixed; left: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; border: 0; padding: 0; }

/* ChatGPT sign-in for the family AI */
.chatgpt-connect { margin: .75rem 0; }
.chatgpt-connect .device p { margin: .35rem 0; word-break: break-all; }
.device-code { font: 700 1.6rem/1.2 ui-monospace, monospace; letter-spacing: .08em; }
.alt-key { margin-top: 1rem; }
