/* cipher — dark, quiet, no external assets */

:root {
  --bg: #07090c;
  --bg-1: #0c1015;
  --bg-2: #141a21;
  --bg-3: #1d252f;
  --line: #212b36;
  --line-soft: #18202a;
  --fg: #e7edf4;
  --fg-dim: #93a2b4;
  --fg-faint: #647385;
  --accent: #3ddc97;
  --accent-dim: #1d7a56;
  --accent-ink: #04150e;
  --danger: #ff5f6d;
  --warn: #ffb454;
  --mine: #14302a;
  --radius: 14px;
  --radius-lg: 20px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --shadow: 0 18px 50px rgba(0, 0, 0, .45);
  --tap: 44px;
}

* { box-sizing: border-box; }

/* Class rules below set display on elements that are toggled with [hidden].
   Without this, a class like .call { display: grid } outranks the UA rule and
   a "hidden" full-screen overlay would still swallow every click. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

.mono { font-family: var(--mono); }
.tiny { font-size: 12px; color: var(--fg-faint); }
.tiny.note { margin-top: 18px; line-height: 1.6; }
.hint { font-size: 12px; color: var(--fg-dim); margin: -4px 0 12px; }
.error { color: var(--danger); font-size: 13px; margin: 10px 0 0; }
.success { color: var(--accent); }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code {
  font-family: var(--mono);
  font-size: .92em;
  background: var(--bg-3);
  border-radius: 5px;
  padding: 1px 5px;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ── icons ───────────────────────────────────────────────────────────── */

/* The sprite itself must take no space and never paint. */
.sprite { display: none; }

.i {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -4px;
}
.i.big { width: 30px; height: 30px; }
.i.huge { width: 56px; height: 56px; color: var(--bg-3); stroke-width: 1.4; }
.i.chev { width: 18px; height: 18px; color: var(--fg-faint); }

/* ── screens ─────────────────────────────────────────────────────────── */

.screen { display: none; height: 100%; }
body[data-screen="gate"]    #screen-gate,
body[data-screen="create"]  #screen-create,
body[data-screen="unlock"]  #screen-unlock,
body[data-screen="applock"] #screen-applock,
body[data-screen="hidden"]  #screen-hidden { display: flex; }
body[data-screen="app"]     #screen-app { display: grid; }

.center {
  align-items: center;
  justify-content: center;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
  overflow-y: auto;
}

.card {
  width: 100%;
  max-width: 480px;
  background: linear-gradient(180deg, #10151b 0%, var(--bg-1) 120px);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 30px;
  margin: auto;
  box-shadow: var(--shadow);
}

.card h1 { font-size: 21px; margin: 0 0 6px; letter-spacing: -0.015em; }
.card h2 { font-size: 18px; margin: 0 0 12px; letter-spacing: -0.01em; }

/* Icon + title + lede, so every screen announces itself the same way. */
.card-head { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 22px; }
.card-head > div { min-width: 0; }
.card-icon {
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: #10261e;
  border: 1px solid var(--accent-dim);
  color: var(--accent);
}
.card-icon.violet { background: #1c1734; border-color: #5b4a9c; color: #a78bfa; }

.brand {
  font-size: 25px;
  font-weight: 650;
  letter-spacing: -0.025em;
  display: flex;
  align-items: center;
  gap: 9px;
}
.brand.small { font-size: 16px; }
.brand .i { color: var(--accent); width: 24px; height: 24px; }
.brand.small .i { width: 19px; height: 19px; }

.lede { color: var(--fg-dim); margin: 14px 0 22px; }
.lede.tight { margin: 0; font-size: 13.5px; line-height: 1.55; }
.lede.success { display: flex; gap: 8px; align-items: center; }

.gate-actions { display: grid; gap: 9px; margin: 26px 0 22px; }

/* A row that reads as one target: icon, what it does, why you'd pick it. */
.tile-btn {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--fg);
  font: inherit;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .13s, border-color .13s, transform .13s;
}
.tile-btn:hover { background: var(--bg-3); border-color: #2e3a48; }
.tile-btn:active { transform: scale(.988); }
.tile-btn > .i:first-child { color: var(--fg-dim); }
.tile-btn.primary {
  background: linear-gradient(180deg, #143327 0%, #10261e 100%);
  border-color: var(--accent-dim);
}
.tile-btn.primary:hover { background: #17402f; }
.tile-btn.primary > .i:first-child { color: var(--accent); }
.tile-btn.subtle { background: transparent; border-style: dashed; }
.tile-btn.subtle:hover { background: var(--bg-2); border-style: solid; }
.tile-text { display: grid; gap: 2px; min-width: 0; flex: 1; }
.tile-text strong { font-size: 14.5px; font-weight: 600; }
.tile-text small { font-size: 12px; color: var(--fg-faint); line-height: 1.45; }

.facts { margin: 0 0 20px; padding: 0; list-style: none; color: var(--fg-faint); font-size: 12.5px; }
.facts li { margin: 7px 0; display: flex; gap: 9px; align-items: flex-start; line-height: 1.45; }
.facts .i { width: 15px; height: 15px; color: var(--accent-dim); margin-top: 2px; }

.app-promo {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-2);
  color: var(--fg);
  margin-bottom: 18px;
}
.app-promo:hover { background: var(--bg-3); text-decoration: none; }
.app-promo > .i:first-child { color: var(--fg-dim); }

.applock-alt { text-align: center; margin: 16px 0 18px; }
.applock-alt .linkish { display: inline-flex; align-items: center; gap: 7px; text-decoration: none; color: var(--fg-dim); }
.applock-alt .linkish:hover { color: var(--fg); }
.applock-alt .i { width: 16px; height: 16px; }

/* ── controls ────────────────────────────────────────────────────────── */

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--fg);
  font: inherit;
  font-weight: 550;
  padding: 11px 18px;
  min-height: var(--tap);
  border-radius: 11px;
  cursor: pointer;
  text-decoration: none;
  transition: background .12s, border-color .12s, opacity .12s, transform .12s;
}
.btn:hover:not(:disabled) { background: var(--bg-3); border-color: #33414f; text-decoration: none; }
.btn:active:not(:disabled) { transform: scale(.985); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn .i { width: 18px; height: 18px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 620; }
.btn.primary:hover:not(:disabled) { background: #57e8aa; }
.btn.danger { background: transparent; color: var(--danger); border-color: #3d2429; }
.btn.danger:hover:not(:disabled) { background: #2a1418; border-color: #552f36; }
.btn.big { padding: 14px 20px; font-size: 15px; min-height: 50px; }
.btn.block { display: flex; width: 100%; margin: 10px 0; }

.icon-btn {
  appearance: none;
  background: transparent;
  border: 1px solid transparent;
  color: var(--fg-dim);
  width: 38px;
  height: 38px;
  border-radius: 10px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background .12s, color .12s;
}
.icon-btn:hover { background: var(--bg-2); color: var(--fg); }
.icon-btn.on { color: var(--accent); background: var(--bg-3); }

.row { display: flex; gap: 10px; align-items: center; }
.row.end { justify-content: flex-end; margin-top: 22px; }
.row.gap-0 { gap: 2px; }

.field { display: block; margin: 16px 0; }
.field > span { display: block; font-size: 12px; color: var(--fg-dim); margin-bottom: 7px; }

input[type="password"], input[type="text"], input:not([type]), textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--fg);
  font: inherit;
  padding: 12px 14px;
  min-height: var(--tap);
  resize: vertical;
  transition: border-color .12s, box-shadow .12s;
}
input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px rgba(61, 220, 151, .12);
}
input::placeholder, textarea::placeholder { color: #4c5867; }

textarea.code, .code {
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.55;
  word-break: break-all;
}

.check { display: flex; gap: 11px; align-items: flex-start; font-size: 13px; color: var(--fg-dim); margin: 18px 0 0; }
.check input { margin-top: 3px; width: 17px; height: 17px; min-height: 0; accent-color: var(--accent); flex: none; }

.meter { height: 4px; background: var(--bg-3); border-radius: 2px; overflow: hidden; margin: -6px 0 8px; }
.meter i { display: block; height: 100%; width: 0; background: var(--danger); transition: width .2s, background .2s; }

/* Two ways to hand over the same key — file or text. */
.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  padding: 3px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-bottom: 16px;
}
.seg {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--fg-faint);
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  padding: 9px 8px;
  border-radius: 9px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background .12s, color .12s;
}
.seg .i { width: 16px; height: 16px; }
.seg:hover { color: var(--fg-dim); }
.seg.active { background: var(--bg-3); color: var(--fg); }

.fp, .safety {
  display: block;
  font-family: var(--mono);
  font-size: 14px;
  letter-spacing: .06em;
  color: var(--accent);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 13px 14px;
  white-space: pre-wrap;
}
.safety { font-size: 17px; text-align: center; line-height: 1.7; }

.warn {
  background: #241a0c;
  border: 1px solid #47341a;
  color: #f0d6a6;
  border-radius: 12px;
  padding: 13px 15px;
  font-size: 13px;
  line-height: 1.5;
  margin: 16px 0;
}
/* Only a <strong class="wt"> is a heading. :first-child cannot tell the two
   apart — a text node before the tag does not count as a child — and a
   mid-sentence <strong> laid out as a block breaks the paragraph in half. */
.warn strong { color: var(--warn); }
.warn strong.wt { display: flex; align-items: center; gap: 7px; margin-bottom: 4px; }
.warn .i { width: 16px; height: 16px; }

.drop {
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  padding: 30px 16px;
  text-align: center;
  cursor: pointer;
  color: var(--fg-dim);
  transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--accent-dim); background: var(--bg-2); }
.drop-inner { display: grid; gap: 7px; justify-items: center; }
.drop .i { color: var(--fg-faint); }
.drop.loaded { border-color: var(--accent-dim); border-style: solid; background: #0e1c17; }
.drop.loaded .i { color: var(--accent); }

/* ── app shell ───────────────────────────────────────────────────────── */

.app {
  grid-template-columns: 292px 1fr;
  height: 100%;
}

#sidebar {
  background: var(--bg-1);
  border-right: 1px solid var(--line);
  display: grid;
  /* head, level tabs, identity, new-room, room list, footer — the list is the
     one row that grows. */
  grid-template-rows: auto auto auto auto 1fr auto;
  min-height: 0;
  padding-top: env(safe-area-inset-top);
}

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px 10px 18px;
}

.me {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 12px 10px;
  padding: 11px 13px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: inherit;
  font: inherit;
  cursor: pointer;
  text-align: left;
  transition: background .12s;
}
.me:hover { background: var(--bg-3); }
.me-text { display: grid; min-width: 0; flex: 1; }
.me-text strong { font-family: var(--mono); font-size: 12px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.me-text small { font-size: 11px; color: var(--fg-faint); }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--fg-faint); flex: none; }
.dot.online { background: var(--accent); box-shadow: 0 0 8px var(--accent-dim); }
.dot.connecting { background: var(--warn); }
.dot.offline { background: var(--danger); }

.side-actions { padding: 0 12px 10px; }
.side-actions .btn.block { margin: 0; }

.rooms { overflow-y: auto; padding: 4px 8px; min-height: 0; }

.room-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 12px;
  border: 0;
  background: transparent;
  color: var(--fg-dim);
  font: inherit;
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  transition: background .12s, color .12s;
}
.room-item:hover { background: var(--bg-2); color: var(--fg); }
.room-item.active { background: var(--bg-3); color: var(--fg); }
.room-item .rname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.room-item .rmeta { font-size: 11px; color: var(--fg-faint); flex: none; }
.badge {
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 10.5px;
  font-weight: 700;
  border-radius: 9px;
  padding: 1px 6px;
  flex: none;
}
.room-item .live { color: var(--accent); font-size: 11px; }

.side-foot {
  padding: 10px 18px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

/* ── main pane ───────────────────────────────────────────────────────── */

#main { display: grid; min-width: 0; min-height: 0; background: var(--bg); }

.empty {
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  text-align: center;
  color: var(--fg-faint);
  padding: 32px;
}
.empty h2 { margin: 14px 0 0; font-size: 17px; color: var(--fg-dim); font-weight: 600; }
.empty p { margin: 0; font-size: 13px; max-width: 320px; }
.empty .btn { margin-top: 14px; }

#room-view { display: grid; grid-template-rows: auto 1fr auto; min-height: 0; height: 100%; }

#room-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 14px;
  padding-top: calc(11px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: var(--bg-1);
}
.room-title { flex: 1; min-width: 0; display: grid; }
.room-title strong { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-title small { font-size: 11.5px; color: var(--fg-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-tools { display: flex; gap: 2px; }

.messages {
  overflow-y: auto;
  padding: 18px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-height: 0;
  overflow-wrap: anywhere;
}

.msg { max-width: min(680px, 78%); display: grid; gap: 3px; }
.msg.theirs { align-self: flex-start; }
.msg.mine { align-self: flex-end; justify-items: end; }
.msg .who { font-size: 11px; color: var(--fg-faint); font-family: var(--mono); padding: 0 4px; }
.msg .bubble {
  background: var(--bg-2);
  border: 1px solid var(--line);
  padding: 9px 14px;
  border-radius: 16px 16px 16px 5px;
  white-space: pre-wrap;
}
.msg.mine .bubble { background: var(--mine); border-color: #21493d; border-radius: 16px 16px 5px 16px; }
.msg .meta { font-size: 10.5px; color: var(--fg-faint); padding: 0 5px; }
.msg.pending .bubble { opacity: .55; }
.msg + .msg.same { margin-top: -1px; }
.msg.same.theirs .bubble { border-top-left-radius: 5px; }
.msg.same.mine .bubble { border-top-right-radius: 5px; }

.sysline {
  align-self: center;
  color: var(--fg-faint);
  font-size: 11.5px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 4px 13px;
  margin: 8px 0;
  text-align: center;
}

.composer {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 12px 14px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--bg-1);
}
.composer textarea {
  flex: 1;
  max-height: 160px;
  min-height: 46px;
  border-radius: 13px;
  resize: none;
}
.btn.send { width: 46px; height: 46px; min-height: 46px; padding: 0; flex: none; border-radius: 13px; }

/* ── members panel ───────────────────────────────────────────────────── */

.panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 340px;
  max-width: 88vw;
  background: var(--bg-1);
  border-left: 1px solid var(--line);
  display: grid;
  grid-template-rows: auto 1fr auto;
  z-index: 40;
  box-shadow: -20px 0 60px rgba(0, 0, 0, .5);
}
.panel-head, .panel-foot { padding: 14px 16px; display: flex; align-items: center; justify-content: space-between; }
.panel-head { border-bottom: 1px solid var(--line); padding-top: calc(14px + env(safe-area-inset-top)); }
.panel-foot { border-top: 1px solid var(--line); display: grid; gap: 0; padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
.panel-foot .btn.block { margin: 4px 0; }
.panel-body { overflow-y: auto; padding: 8px 12px; }

.member {
  border: 1px solid var(--line);
  background: var(--bg-2);
  border-radius: 12px;
  padding: 12px 13px;
  margin: 8px 0;
  display: grid;
  gap: 7px;
}
.member .top { display: flex; align-items: center; gap: 8px; }
.member .mid { font-family: var(--mono); font-size: 11.5px; flex: 1; overflow: hidden; text-overflow: ellipsis; }
.member .tag { font-size: 10px; color: var(--accent); border: 1px solid var(--accent-dim); border-radius: 6px; padding: 0 5px; }
.member .mfp { font-family: var(--mono); font-size: 10.5px; color: var(--fg-faint); letter-spacing: .04em; }
.member .acts { display: flex; gap: 6px; }
.member .acts .btn { padding: 6px 11px; font-size: 12px; min-height: 34px; }

/* ── call overlay ────────────────────────────────────────────────────── */

.call {
  position: fixed;
  inset: 0;
  background: #04060880;
  backdrop-filter: blur(18px);
  z-index: 60;
  display: grid;
  grid-template-rows: auto 1fr auto;
}
.call-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  padding-top: calc(14px + env(safe-area-inset-top));
}
.call-head strong { font-size: 15px; }
#call-timer { color: var(--accent); font-size: 13px; }
#call-note { margin-left: auto; }

.grid {
  display: grid;
  gap: 10px;
  padding: 0 20px;
  align-content: center;
  justify-content: center;
  overflow: auto;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

.tile {
  position: relative;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 4 / 3;
  display: grid;
  place-items: center;
}
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; background: #000; }
.tile.self video { transform: scaleX(-1); }
.tile.audio-only video { display: none; }
.tile .avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--bg-3);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: 22px;
}
.tile.has-video .avatar { display: none; }
.tile .label {
  position: absolute;
  left: 10px;
  bottom: 9px;
  background: #000000a8;
  border-radius: 7px;
  padding: 3px 8px;
  font-size: 11px;
  font-family: var(--mono);
  display: flex;
  gap: 6px;
  align-items: center;
}
.tile .label .st { color: var(--warn); }
.tile .label .st.ok { color: var(--accent); }
.tile.speaking { border-color: var(--accent); }

.call-bar {
  display: flex;
  gap: 12px;
  justify-content: center;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
}
.round {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--fg);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background .12s, transform .12s;
}
.round .i { width: 22px; height: 22px; }
.round:hover { background: var(--bg-3); }
.round:active { transform: scale(.94); }
.round.off { background: #2a1418; border-color: #40252a; color: var(--danger); }
.round.on { background: var(--accent-dim); border-color: var(--accent); color: #eafff6; }
.round.hang { background: var(--danger); border-color: transparent; color: #2b0a0e; }

/* Mic and camera each carry both glyphs; the class picks which one shows. */
.round .off-icon { display: none; }
.round.icon-off .on-icon { display: none; }
.round.icon-off .off-icon { display: block; }

/* ── ringing ─────────────────────────────────────────────────────────── */

.ring {
  position: fixed;
  inset: 0;
  background: #04060899;
  backdrop-filter: blur(10px);
  display: grid;
  place-items: center;
  z-index: 70;
}
.ring-card {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 30px 34px;
  display: grid;
  gap: 10px;
  justify-items: center;
  text-align: center;
  min-width: 300px;
  box-shadow: var(--shadow);
}
.ring-glyph {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #10261e;
  border: 1px solid var(--accent-dim);
  color: var(--accent);
  margin-bottom: 4px;
}
.ring-glyph .i { width: 28px; height: 28px; }
.ring-card .row { margin-top: 12px; }
.ring-card small { color: var(--fg-faint); font-family: var(--mono); font-size: 11.5px; }
.pulse { animation: pulse 1.3s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .55; transform: scale(.93); } }

/* ── dialogs and toast ───────────────────────────────────────────────── */

dialog {
  background: var(--bg-1);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 26px;
  width: min(460px, calc(100vw - 32px));
  font: inherit;
  box-shadow: var(--shadow);
}
dialog::backdrop { background: #040608bb; backdrop-filter: blur(4px); }
dialog h2 { margin-top: 0; }
dialog h3 .i { width: 16px; height: 16px; color: var(--fg-dim); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(26px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 11px 18px;
  font-size: 13.5px;
  max-width: calc(100vw - 32px);
  text-align: center;
  z-index: 90;
  box-shadow: var(--shadow);
  /* Purely informational, and it sits on top of everything — without this it
     swallows clicks on whatever it happens to cover, such as the hang-up
     button in the call bar directly beneath it. */
  pointer-events: none;
}
.toast.bad { border-color: #40252a; color: #ffb3ba; }

/* Lift it clear of the call controls while a call is on screen. */
#call-overlay:not([hidden]) ~ .toast { bottom: 100px; }

/* ── narrow screens ──────────────────────────────────────────────────── */

.only-narrow { display: none; }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  #sidebar { display: grid; }
  #main { display: none; }
  body[data-pane="room"] #sidebar { display: none; }
  body[data-pane="room"] #main { display: grid; }
  .only-narrow { display: grid; }
  .msg { max-width: 88%; }
  .card { padding: 24px 20px; border-radius: 16px; }
  .grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); padding: 0 10px; }
  .round { width: 52px; height: 52px; }
  dialog { padding: 22px 20px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ── security levels ─────────────────────────────────────────────────── */

/* The accent carries the level. Level 1 keeps the green the app always had;
   level 2 shifts the whole interface to violet, so there is no way to type
   into the wrong space without noticing. */
body[data-space="hidden"],
/* The unlock screen belongs to level 2 as much as the space behind it does,
   so it wears the same colour rather than the open space's green. */
body[data-screen="hidden"] {
  --accent: #a78bfa;
  --accent-dim: #5b4a9c;
  --accent-ink: #150e2b;
  --mine: #241f3b;
}

.linkish {
  appearance: none;
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
}

.spaces {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 0 12px 10px;
}
.space-tab {
  appearance: none;
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--fg-faint);
  font: inherit;
  font-size: 12.5px;
  font-weight: 550;
  padding: 9px 8px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  position: relative;
  transition: background .12s, color .12s, border-color .12s;
}
.space-tab:hover { color: var(--fg); }
.space-tab .space-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  opacity: .5;
}
#tab-open.active  { background: #10261e; border-color: #1d7a56; color: #3ddc97; }
#tab-hidden.active { background: #1e1935; border-color: #5b4a9c; color: #a78bfa; }
.space-tab.active .space-dot { opacity: 1; }
/* Armed = the hidden space is open right now; a dashed edge when it is not. */
#tab-hidden:not(.armed) { border-style: dashed; }
.space-tab.unread::after {
  content: "";
  position: absolute;
  top: 5px;
  right: 7px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

/* Nothing of the hidden space survives a glance at a task switcher. */
body[data-obscured="1"] #screen-app { filter: blur(18px); }

/* ── ephemeral rooms ─────────────────────────────────────────────────── */

.room-item.eph .rname { font-style: italic; }
.room-item .eph-tag {
  font-size: 10px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--warn);
  border: 1px solid #4a3418;
  border-radius: 5px;
  padding: 1px 5px;
  flex: none;
}

/* A composer that looks different is the reminder that this room keeps
   nothing — including for the person typing into it. */
body[data-room="eph"] .composer {
  border-top: 1px solid var(--warn);
  background: linear-gradient(180deg, #1a1409 0%, var(--bg-1) 60%);
}

/* ── level picker in the new-room dialog ─────────────────────────────── */

fieldset.levels {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px 14px;
  margin: 16px 0 0;
  display: grid;
  gap: 8px;
}
fieldset.levels legend {
  font-size: 12px;
  color: var(--fg-dim);
  padding: 0 6px;
}
.choice {
  display: flex;
  gap: 11px;
  align-items: flex-start;
  padding: 10px 11px;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
}
.choice:hover { background: var(--bg-2); }
.choice input { margin-top: 3px; width: 17px; height: 17px; min-height: 0; accent-color: var(--accent); flex: none; }
.choice-body { display: grid; gap: 3px; }
.choice-body strong { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 7px; }
.choice-body strong .i { width: 15px; height: 15px; }
.choice-body small { font-size: 12px; color: var(--fg-faint); line-height: 1.45; }
.choice:has(input:checked) { border-color: var(--accent-dim); background: var(--bg-2); }
.choice.eph:has(input:checked) { border-color: #4a3418; }
.choice.eph:has(input:checked) .choice-body strong { color: var(--warn); }

.field.inline { display: grid; gap: 6px; margin: 4px 0 0; }
.field.inline select {
  background: var(--bg-2);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  min-height: var(--tap);
  font: inherit;
}

/* ── settings ────────────────────────────────────────────────────────── */

#dlg-settings { max-height: calc(100vh - 48px); overflow-y: auto; }
.settings-block {
  border-top: 1px solid var(--line);
  padding-top: 18px;
  margin-top: 20px;
}
.settings-block:first-of-type { border-top: 0; padding-top: 0; margin-top: 0; }
.settings-block h3 {
  font-size: 14px;
  margin: 0 0 7px;
  letter-spacing: -0.005em;
  display: flex;
  align-items: center;
  gap: 8px;
}
.settings-block hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.settings-block .btn.block { margin-top: 10px; }
