:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eaeeec;
  --text: #15201b;
  --muted: #5d6b64;
  --accent: #0f8a6a;
  --accent-ink: #ffffff;
  --mine: #d6f2e6;
  --theirs: #ffffff;
  --danger: #c0392b;
  --warn: #9a6a00;
  --border: #d9e0dc;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 5%);
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1720;
    --surface: #17212b;
    --surface-2: #1f2c38;
    --text: #e6edf0;
    --muted: #8b9aa5;
    --accent: #2fc193;
    --accent-ink: #062018;
    --mine: #14463a;
    --theirs: #1f2c38;
    --danger: #ff6b5e;
    --warn: #f0c060;
    --border: #2a3947;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }

.screen {
  min-height: 100dvh;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}
.home-inner, .wait-inner { max-width: 440px; margin: 0 auto; display: grid; gap: 16px; }

.brand { text-align: center; padding: 24px 0 8px; }
.logo { width: 64px; height: 64px; margin: 0 auto 8px; border-radius: 18px; background: var(--accent);
  display: grid; place-items: center; }
.logo svg { width: 42px; height: 42px; fill: var(--accent-ink); }
.logo .lock { fill: none; stroke: var(--accent); stroke-width: 2.4; stroke-linejoin: round; }
h1 { margin: 0; font-size: 28px; letter-spacing: -0.02em; }
h2 { margin: 0 0 4px; font-size: 17px; }
.tagline { margin: 6px auto 0; color: var(--muted); max-width: 34ch; }

.field { display: grid; gap: 6px; }
.field span { font-size: 14px; color: var(--muted); }
input, textarea {
  width: 100%; border: 1px solid var(--border); background: var(--surface); border-radius: 12px;
  padding: 12px 14px; outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); }
.card p { margin: 0 0 12px; color: var(--muted); font-size: 15px; }
.join { display: flex; gap: 8px; }
.join input { flex: 1; min-width: 0; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  letter-spacing: 0.02em; text-transform: uppercase; font-size: 15px; padding: 12px 10px; }
.join input::placeholder { letter-spacing: 0; }

.btn { border: 1px solid var(--border); background: var(--surface-2); border-radius: 12px;
  padding: 12px 18px; font-weight: 600; cursor: pointer; min-height: 48px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; width: 100%; }
.join .btn { width: auto; }
.btn:active { transform: translateY(1px); }
.link-btn { justify-self: start; background: none; border: 0; color: var(--accent); font-weight: 600;
  padding: 8px 0; cursor: pointer; }

.error-text { color: var(--danger); margin: 8px 0 0 !important; font-size: 14px; }
.warning { color: var(--warn); background: var(--surface); border: 1px solid var(--border);
  padding: 12px; border-radius: 12px; margin: 0; }
.fine { text-align: center; font-size: 13px; color: var(--muted); margin: 0; }

.share { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px 16px; text-align: center; box-shadow: var(--shadow); }
.label { margin: 0; color: var(--muted); font-size: 14px; }
.code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: clamp(20px, 6.4vw, 28px);
  font-weight: 700; letter-spacing: 0.06em; margin: 8px 0 16px; user-select: all; }
.code.big { font-size: 40px; text-align: center; letter-spacing: 0.12em; }
.share-actions { display: grid; grid-template-columns: 1fr 1.6fr; gap: 8px; }
.hint { color: var(--muted); font-size: 14px; margin: 12px 0 0; }

.progress { display: flex; align-items: center; gap: 12px; padding: 4px 2px; }
.progress p { margin: 0; font-weight: 600; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--border);
  border-top-color: var(--accent); animation: spin 0.9s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.steps { margin: 0; padding: 0 0 0 4px; list-style: none; display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
.steps li { display: flex; gap: 8px; }
.steps li::before { content: "•"; color: var(--accent); }
.steps li.warn { color: var(--warn); }
.fail { background: var(--surface); border: 1px solid var(--danger); border-radius: var(--radius); padding: 16px; }
.fail-msg { margin: 0 0 6px; font-weight: 700; color: var(--danger); }
.fail-hint { margin: 0 0 14px; color: var(--muted); overflow-wrap: anywhere; font-size: 14px; }

/* ---------- chat ---------- */
.chat { display: flex; flex-direction: column; height: 100dvh; padding: 0; }
.chat-head { display: flex; align-items: center; gap: 8px; background: var(--surface);
  border-bottom: 1px solid var(--border); padding: max(8px, env(safe-area-inset-top)) 8px 8px; }
.peer { flex: 1; min-width: 0; display: grid; }
.peer strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.secure { font-size: 12px; color: var(--accent); }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border: 0; background: none;
  border-radius: 50%; cursor: pointer; flex: none; }
.icon-btn svg, .send svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round; }
.sas-chip { border: 1px solid var(--border); background: var(--surface-2); border-radius: 999px;
  padding: 6px 12px; font: 600 13px ui-monospace, Consolas, monospace; cursor: pointer; }

.messages { flex: 1; overflow-y: auto; padding: 12px 12px 4px; display: flex; flex-direction: column; gap: 6px;
  overscroll-behavior: contain; }
.msg { max-width: min(80%, 520px); padding: 8px 12px 6px; border-radius: 16px; background: var(--theirs);
  box-shadow: var(--shadow); align-self: flex-start; overflow-wrap: anywhere; white-space: pre-wrap;
  border: 1px solid var(--border); }
.msg.mine { align-self: flex-end; background: var(--mine); border-color: transparent; }
.msg .meta { display: block; text-align: right; font-size: 11px; color: var(--muted); margin-top: 2px; }
.sys { align-self: center; font-size: 13px; color: var(--muted); background: var(--surface-2);
  border-radius: 999px; padding: 4px 12px; text-align: center; max-width: 90%; }
.sys.err { color: var(--danger); }
.file { display: grid; gap: 6px; min-width: 220px; }
.file .fname { font-weight: 600; overflow-wrap: anywhere; }
.file .fsize { font-size: 13px; color: var(--muted); }
.file progress { width: 100%; height: 6px; accent-color: var(--accent); }
.file a { color: var(--accent); font-weight: 600; }
.file img, .file video { max-width: 100%; border-radius: 10px; display: block; }

.composer { display: flex; align-items: flex-end; gap: 6px; padding: 8px 8px max(8px, env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--border); }
.composer textarea { resize: none; max-height: 140px; border-radius: 22px; padding: 11px 16px; line-height: 1.35; }
.attach { color: var(--muted); }
.send { width: 46px; height: 46px; flex: none; border-radius: 50%; border: 0; background: var(--accent);
  color: var(--accent-ink); display: grid; place-items: center; cursor: pointer; }
.send svg { width: 22px; height: 22px; }
.composer.disabled { opacity: 0.5; pointer-events: none; }

.sheet { border: 0; border-radius: 20px; background: var(--surface); color: var(--text); padding: 20px;
  max-width: 380px; width: calc(100% - 32px); }
.sheet::backdrop { background: rgb(0 0 0 / 45%); }
.sheet h2 { font-size: 20px; }
.sheet p { color: var(--muted); }
