:root {
  --bg: #f5f5f7; --surface: #fff; --hover: #fbfbfd;
  --text: #1d1d1f; --text-2: #6e6e73; --text-3: #86868b; --text-4: #aeaeb2;
  --faint: #d2d2d7; --hairline: rgba(0,0,0,0.07); --track: #e8e8ed;
  --accent: #0071e3; --live: #30d158; --danger: #ff3b30;
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', sans-serif;
  --r-pill: 999px; --r-thumb: 12px; --r-card: 18px; --r-panel: 22px; --r-sheet: 16px;
  --sh-card: 0 1px 2px rgba(0,0,0,0.04), 0 8px 24px rgba(0,0,0,0.05);
  --sh-panel: 0 1px 3px rgba(0,0,0,0.05), 0 14px 40px rgba(0,0,0,0.05);
  --ease-spring: cubic-bezier(0.32, 0.72, 0, 1);
  --top: env(safe-area-inset-top); --bottom: env(safe-area-inset-bottom);
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 16px;
  line-height: 1.4; -webkit-font-smoothing: antialiased; overscroll-behavior: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
#app { height: 100%; max-width: 720px; margin: 0 auto; position: relative; }
.view { height: 100%; display: flex; flex-direction: column; position: relative; min-width: 0; }
.view[hidden] { display: none; }

/* ── rooms ── */
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: calc(var(--top) + 8px) 16px calc(var(--bottom) + 24px); }
.lt { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; padding: 36px 4px 12px; }
.nav-c { position: absolute; top: 0; left: 0; right: 0; z-index: 50; height: calc(var(--top) + 44px);
  padding-top: var(--top); display: flex; align-items: center; justify-content: center;
  background: rgba(245,245,247,.72); backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px); border-bottom: 1px solid transparent; }
.nav-c-t { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; opacity: 0; transition: opacity .25s; }
.nav-c.show { border-bottom-color: var(--hairline); }
.nav-c.show .nav-c-t { opacity: 1; }
.nav-act { position: absolute; right: 8px; bottom: 0; width: 44px; height: 44px; display: grid;
  place-items: center; color: var(--accent); }
.nudge { margin-bottom: 14px; }
.nudge[hidden] { display: none; }
.nudge .row-t { color: var(--accent); font-weight: 600; }
.org { font-size: 13px; font-weight: 600; color: var(--text-3); text-transform: uppercase;
  letter-spacing: .02em; padding: 18px 6px 8px; }
.panel { background: var(--surface); border-radius: var(--r-panel); box-shadow: var(--sh-panel);
  overflow: hidden; }
.room { display: flex; align-items: center; gap: 12px; padding: 12px 16px; color: var(--text);
  position: relative; min-height: 68px; }
.room + .room::before, .row + .row::before { content: ""; position: absolute; top: 0; right: 0;
  left: 68px; border-top: 1px solid var(--hairline); }
.row + .row::before { left: 16px; }
.room:active, .row-btn:active { background: var(--hover); }
.av { width: 44px; height: 44px; border-radius: 50%; flex: none; display: grid; place-items: center;
  font-weight: 600; font-size: 17px; color: #fff; background: #8e8e93; }
.room-main { flex: 1; min-width: 0; }
.room-top { display: flex; align-items: baseline; gap: 8px; }
.room-n { flex: 1; font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; }
.room-time { font-size: 13px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.room-last { font-size: 14px; color: var(--text-2); white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; margin-top: 2px; }
.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: var(--r-pill);
  background: var(--accent); color: #fff; font-size: 12px; font-weight: 600; display: grid;
  place-items: center; font-variant-numeric: tabular-nums; }
.empty { color: var(--text-3); text-align: center; padding: 48px 24px; }

/* ── room ── */
.bar { flex: none; display: flex; align-items: center; padding: var(--top) 4px 0;
  height: calc(var(--top) + 52px); background: rgba(245,245,247,.72);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--hairline); z-index: 10; }
.back, .bar-gap { width: 44px; height: 44px; display: grid; place-items: center; flex: none; }
.bar-title { flex: 1; display: flex; flex-direction: column; align-items: center; min-width: 0; }
.bar-t { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-s { font-size: 12px; color: var(--text-3); }
.msgs { flex: 1; overflow-y: auto; padding: 12px 12px 8px; display: flex; flex-direction: column;
  gap: 2px; -webkit-overflow-scrolling: touch; }
.day { align-self: center; font-size: 12px; color: var(--text-3); padding: 14px 0 6px; }
.m { display: flex; flex-direction: column; max-width: 78%; align-self: flex-start; }
.m.mine { align-self: flex-end; align-items: flex-end; }
.m .who { font-size: 12px; color: var(--text-3); padding: 8px 12px 2px; display: flex; gap: 6px;
  align-items: center; }
.ai { font-size: 10px; font-weight: 700; letter-spacing: .04em; color: var(--accent);
  border: 1px solid rgba(0,113,227,.35); border-radius: var(--r-pill); padding: 0 5px; line-height: 15px; }
.b { padding: 8px 13px; border-radius: 19px; background: var(--surface); box-shadow: var(--sh-card);
  overflow-wrap: anywhere; font-size: 16px; line-height: 1.4; }
.m.mine .b { background: var(--accent); color: #fff; box-shadow: none; }
.m.mine .b a { color: #fff; text-decoration: underline; }
.m .t { font-size: 11px; color: var(--text-4); padding: 2px 12px 0; font-variant-numeric: tabular-nums; }
.draft { align-self: stretch; max-width: none; margin: 10px 0; background: var(--surface);
  border-radius: var(--r-card); box-shadow: var(--sh-card); padding: 12px 14px; }
.draft-h { font-size: 12px; color: var(--text-3); display: flex; gap: 6px; align-items: center; }
.draft textarea { width: 100%; margin: 8px 0 10px; font: inherit; border: 1px solid var(--hairline);
  border-radius: var(--r-thumb); padding: 9px 11px; resize: none; background: var(--hover); color: var(--text); }
.draft-a { display: flex; gap: 8px; justify-content: flex-end; }
.btn { height: 36px; padding: 0 16px; border-radius: var(--r-pill); background: var(--accent);
  color: #fff; font-weight: 600; font-size: 15px; }
.btn.ghost { background: var(--track); color: var(--text); }
.btn:active { transform: scale(.97); }
.composer { flex: none; display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 10px max(8px, var(--bottom)); background: rgba(245,245,247,.82);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--hairline); }
.composer textarea { flex: 1; font: inherit; font-size: 16px; line-height: 1.35; resize: none;
  max-height: 140px; border: 1px solid var(--faint); border-radius: 20px; padding: 8px 14px;
  background: var(--surface); color: var(--text); outline: none; }
.composer textarea:focus { border-color: var(--text-4); }
.send { width: 36px; height: 36px; border-radius: 50%; background: var(--accent); color: #fff;
  display: grid; place-items: center; flex: none; margin-bottom: 1px;
  transition: opacity .2s, transform .15s; }
.send:disabled { opacity: .3; }
.send:active { transform: scale(.92); }

/* ── gate ── */
.gate { margin: auto; width: 100%; max-width: 360px; padding: 32px 24px calc(var(--bottom) + 32px);
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; }
.mark { width: 72px; height: 72px; border-radius: 20px; display: grid; place-items: center;
  background: linear-gradient(135deg, #0071e3 0%, #5e5ce6 100%); color: #fff; font-size: 34px;
  font-weight: 700; box-shadow: 0 14px 40px rgba(0,113,227,.25); margin-bottom: 8px; }
.gate-t { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.gate-s { color: var(--text-2); }
#gate-form { width: 100%; display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
#gate-form[hidden] { display: none; }
#gate-name { font: inherit; height: 48px; border-radius: var(--r-thumb); border: 1px solid var(--faint);
  padding: 0 14px; background: var(--surface); outline: none; text-align: center; }
#gate-go { height: 48px; border-radius: var(--r-thumb); }
.gate-err { color: var(--danger); font-size: 14px; }

/* ── sheets ── */
.scrim { position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.28); opacity: 0;
  pointer-events: none; transition: opacity .25s ease; }
.scrim.open { opacity: 1; pointer-events: auto; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 71; max-width: 720px; margin: 0 auto;
  max-height: 86vh; overflow-y: auto; background: var(--bg); border-radius: 22px 22px 0 0;
  padding: 10px 16px max(24px, var(--bottom)); transform: translateY(calc(100% + 40px));
  transition: transform .4s var(--ease-spring); }
.sheet.open { transform: translateY(0); box-shadow: 0 -8px 40px rgba(0,0,0,.16); }
.grab { width: 38px; height: 5px; border-radius: var(--r-pill); background: var(--faint); margin: 0 auto 14px; }
.sheet-t { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; padding: 0 4px 14px; }
.sec { font-size: 13px; font-weight: 600; color: var(--text-3); text-transform: uppercase;
  letter-spacing: .02em; padding: 20px 6px 8px; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; min-height: 52px;
  position: relative; width: 100%; text-align: left; }
.row-main { flex: 1; display: flex; flex-direction: column; }
.row-t { font-size: 16px; }
.row-s { font-size: 13px; color: var(--text-3); }
.row .av { width: 32px; height: 32px; font-size: 14px; }
.danger { color: var(--danger); }
.cap { font-size: 13px; color: var(--text-2); padding: 10px 6px 0; overflow-wrap: anywhere; }
.toggle { appearance: none; -webkit-appearance: none; width: 51px; height: 31px; flex: none;
  border-radius: var(--r-pill); background: var(--track); position: relative; cursor: pointer;
  transition: background .2s; }
.toggle::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px;
  border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.2);
  transition: transform .25s var(--ease-spring); }
.toggle:checked { background: var(--live); }
.toggle:checked::after { transform: translateX(20px); }
.toast { position: fixed; left: 50%; bottom: calc(var(--bottom) + 84px); z-index: 90;
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none; background: rgba(29,29,31,.9);
  color: #fff; font-size: 14px; padding: 9px 16px; border-radius: var(--r-pill);
  transition: opacity .2s, transform .3s var(--ease-spring); max-width: 86vw; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ── formatted text (Jarl's answers) ── */
.md p { margin: 0 0 8px; }
.md > :last-child { margin-bottom: 0; }
.md ul, .md ol { margin: 2px 0 10px; padding-left: 20px; }
.md li { margin: 3px 0; padding-left: 2px; }
.md li::marker { color: var(--text-3); }
.md .lead, .md h4 { font-weight: 650; font-size: 15px; margin: 12px 0 4px; letter-spacing: -0.01em; }
.md > .lead:first-child, .md > h4:first-child { margin-top: 0; }
.md code { font: 14px ui-monospace, 'SF Mono', Menlo, monospace; background: var(--hover);
  border: 1px solid var(--hairline); border-radius: 6px; padding: 0 4px; }
.md strong { font-weight: 650; }
.m.mine .md code { background: rgba(255,255,255,.18); border-color: transparent; }

/* ── Jarl: a full-width card with its avatar, not a narrow bubble ── */
.m .who .av { width: 20px; height: 20px; font-size: 11px; }
.m .who-n { font-weight: 600; color: var(--text-2); }
.m.bot { max-width: 100%; align-self: stretch; }
.m.bot .b { border-radius: var(--r-card); padding: 12px 15px; font-size: 15.5px; line-height: 1.45;
  border: 1px solid var(--hairline); box-shadow: none; }

/* ── wide screens: rooms left, room right ── */
body.wide #app { max-width: 1280px; display: grid; grid-template-columns: 340px 1fr; }
body.wide #v-rooms { border-right: 1px solid var(--hairline); }
body.wide #v-rooms .nav-c { position: relative; flex: none; border-bottom-color: var(--hairline); }
body.wide #v-rooms .nav-c-t { opacity: 1; }
body.wide #v-rooms .lt { display: none; }
body.wide #v-rooms .scroll { padding-top: 12px; }
body.wide .back { visibility: hidden; }
body.wide .msgs { padding: 18px 28px 12px; }
body.wide .m { max-width: 64%; }
body.wide .m.bot { max-width: 760px; align-self: flex-start; }
body.wide .composer { padding: 10px 28px max(12px, var(--bottom)); }
.room.on { background: var(--hover); }
.room.on .room-n { color: var(--accent); }
.empty-pane { margin: auto; display: flex; flex-direction: column; align-items: center; gap: 12px;
  color: var(--text-3); }
.empty-pane .mark { width: 56px; height: 56px; font-size: 26px; border-radius: 16px; margin: 0; }

/* ── dark: follows the device (the Jarl app is dark) ── */
@media (prefers-color-scheme: dark) {
  :root { --bg: #000; --surface: #1c1c1e; --hover: #2c2c2e; --text: #f5f5f7; --text-2: #aeaeb2;
    --text-3: #8e8e93; --text-4: #636366; --faint: #3a3a3c; --hairline: rgba(255,255,255,0.1);
    --track: #3a3a3c; --accent: #0a84ff; --live: #30d158;
    --sh-card: none; --sh-panel: none; }
  .nav-c, .bar { background: rgba(0,0,0,.72); }
  .composer { background: rgba(0,0,0,.82); }
  .composer textarea { border-color: #3a3a3c; }
  .panel { border: 1px solid var(--hairline); }
  .m.mine .b { background: #0a84ff; }
  .sheet { background: #000; }
  .toast { background: rgba(58,58,60,.95); }
  .ai { border-color: rgba(10,132,255,.5); }
}

@media (prefers-reduced-motion: reduce) {
  .sheet, .scrim, .toast, .toggle::after { transition-duration: .01ms; }
}
