/* app.css – Dunkle, iPhone-optimierte Oberfläche */
:root {
  --bg: #0b0f14; --card: #161c24; --card-2: #212934; --text: #f2f5f8; --muted: #94a1b2;
  --accent: #4fd1a5; --accent-ink: #06231a; --red: #ef4b55; --amber: #f5b945; --line: #29323e;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { font: 17px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif; overscroll-behavior: none; -webkit-user-select: none; user-select: none; }
h1 { font-size: 30px; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 24px; margin: 0; }
h3 { font-size: 17px; margin: 14px 0 0; }
p { margin: 0; }
button { font: inherit; color: inherit; border: 0; cursor: pointer; touch-action: manipulation; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.screen { min-height: 100dvh; max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px;
  padding: calc(env(safe-area-inset-top) + 14px) 16px calc(env(safe-area-inset-bottom) + 16px); }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.icon-btn { width: 46px; height: 46px; border-radius: 50%; background: var(--card); font-size: 20px; flex: none; }
.status { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 14px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); }
.status.online .dot { background: var(--accent); }
.status.offline .dot { background: var(--red); }

.banner { background: var(--card); color: var(--muted); border-radius: 14px; padding: 11px 14px; font-size: 14px; }
.banner.danger { background: #3a1419; color: #ffc9cd; }
.contacts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.contact { display: flex; align-items: center; gap: 12px; background: var(--card); border-radius: 18px; padding: 10px 10px 10px 12px; }
.contact-name { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { width: 46px; height: 46px; border-radius: 50%; background: var(--card-2); color: var(--accent); display: grid; place-items: center; font-weight: 700; flex: none; }
.avatar.large { width: 112px; height: 112px; font-size: 44px; }
.mini { width: 46px; height: 46px; border-radius: 50%; background: var(--card-2); flex: none; font-size: 17px; }
.mini.call-btn { background: var(--accent); color: var(--accent-ink); font-size: 21px; }
.empty { flex: 1; display: flex; flex-direction: column; justify-content: center; text-align: center; color: var(--muted); gap: 6px; padding: 24px; }
.empty-title { color: var(--text); font-size: 20px; font-weight: 650; }
.bottom-action { position: sticky; bottom: calc(env(safe-area-inset-bottom) + 12px); }

.btn { width: 100%; min-height: 56px; border-radius: 16px; background: var(--card-2); font-weight: 650; padding: 12px 18px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: #3a1419; color: #ffb4ba; }
.btn:active, .round:active, .mini:active { transform: scale(.97); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.qr { width: min(100%, 340px); aspect-ratio: 1; align-self: center; border-radius: 14px; background: #fff; }
.camera { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 18px; background: #000; }
.warn { color: var(--amber); font-size: 14px; text-align: center; }
.muted { color: var(--muted); font-size: 14px; }
input { width: 100%; min-height: 54px; font-size: 18px; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 0 14px; -webkit-user-select: text; user-select: text; }
.mono { display: block; font: 15px/1.7 ui-monospace, Menlo, monospace; background: var(--card); padding: 12px 14px; border-radius: 14px; word-break: break-word; -webkit-user-select: text; user-select: text; }

.call { justify-content: space-between; text-align: center; }
.call-head { display: flex; flex-direction: column; align-items: center; gap: 10px; padding-top: 4vh; }
#call-name { font-size: 30px; overflow-wrap: anywhere; }
#call-state { color: var(--muted); font-variant-numeric: tabular-nums; }
.sas { background: var(--card); border-radius: 20px; padding: 14px; display: flex; flex-direction: column; gap: 6px; }
.sas-label, .sas-help { color: var(--muted); font-size: 14px; }
.sas-emojis { font-size: 42px; letter-spacing: 8px; line-height: 1.25; }
.e2ee { color: var(--accent); font-size: 13px; font-weight: 600; }
.e2ee.bad { color: var(--amber); }
.controls, .call-actions { display: flex; justify-content: center; gap: 28px; }
.round { width: 84px; display: flex; flex-direction: column; align-items: center; gap: 6px; background: none; font-size: 12px; color: var(--muted); }
.round .glyph { width: 72px; height: 72px; border-radius: 50%; display: grid; place-items: center; background: var(--card-2); color: var(--text); font-size: 27px; }
.round[aria-pressed="true"] .glyph { background: var(--text); color: var(--bg); }
.round.big .glyph { width: 80px; height: 80px; font-size: 30px; font-weight: 700; }
.round.red .glyph { background: var(--red); color: #fff; }
.round.green .glyph { background: var(--accent); color: var(--accent-ink); }
.toast { position: fixed; left: 16px; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 92px); max-width: 528px; margin: 0 auto; background: var(--text); color: var(--bg); border-radius: 14px; padding: 12px 16px; font-size: 15px; font-weight: 550; text-align: center; z-index: 10; }

/* Symbole */
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 26px; height: 26px; fill: currentColor; display: block; flex: none; }
.icon.small { width: 18px; height: 18px; }
.icon-btn, .mini { display: grid; place-items: center; }
.icon-btn .icon, .mini .icon { width: 22px; height: 22px; }
.round .glyph .icon { width: 32px; height: 32px; }
.round.big .glyph .icon { width: 38px; height: 38px; }
.top-actions { display: flex; gap: 8px; }
.banner { display: flex; align-items: center; gap: 9px; }
.btn { display: flex; align-items: center; justify-content: center; gap: 8px; }
.btn.small { min-height: 46px; padding: 8px 12px; font-size: 15px; border-radius: 13px; }
.mini.quiet { background: transparent; color: var(--muted); }
.contact-name { background: none; text-align: left; padding: 8px 0; }
.empty-mark { width: 64px; height: 64px; margin: 0 auto 8px; border-radius: 50%; background: var(--card); color: var(--accent); display: grid; place-items: center; }

/* Erster Start */
.welcome { justify-content: center; gap: 18px; }
.welcome-mark { width: 84px; height: 84px; border-radius: 24px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; }
.welcome-mark .icon { width: 44px; height: 44px; }
.welcome h1 { font-size: 38px; }
.lead { color: var(--muted); font-size: 20px; }
.steps { margin: 6px 0 10px; padding: 0; list-style: none; counter-reset: step; display: flex; flex-direction: column; gap: 10px; }
.steps li { counter-increment: step; position: relative; background: var(--card); border-radius: 16px; padding: 13px 14px 13px 54px; color: var(--muted); font-size: 15px; }
.steps li strong { display: block; color: var(--text); font-size: 16px; }
.steps li::before { content: counter(step); position: absolute; left: 14px; top: 14px; width: 28px; height: 28px; border-radius: 50%; background: var(--card-2); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 14px; }

/* Karten, Anleitung, Schalter */
.card { background: var(--card); border-radius: 16px; padding: 14px; display: flex; flex-direction: column; gap: 4px; }
.card h3 { margin: 0; }
.card p { color: var(--muted); font-size: 15px; }
.toggle { flex-direction: row; align-items: center; justify-content: space-between; font-weight: 600; }
.toggle input { width: 26px; height: 26px; min-height: 0; accent-color: var(--accent); flex: none; }

/* Kontaktliste mit Chat */
.contact .avatar { position: relative; }
.presence { position: absolute; right: -1px; bottom: -1px; width: 14px; height: 14px; border-radius: 50%; background: var(--accent); border: 3px solid var(--card); }
.badge { min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: var(--accent); color: var(--accent-ink); font-size: 13px; font-weight: 700; display: grid; place-items: center; flex: none; }

/* Chat */
/* Höhe und Position folgen der iPhone-Tastatur (siehe syncViewport in app.js). */
.chat { position: fixed; top: var(--app-top, 0px); left: 0; right: 0; height: var(--app-h, 100dvh); max-width: 560px; margin: 0 auto; display: flex; flex-direction: column;
  padding: calc(env(safe-area-inset-top) * var(--top-safe, 1) + 8px) 0 calc(env(safe-area-inset-bottom) * var(--bottom-safe, 1) + 8px); }
.update-bar { position: fixed; left: 16px; right: 16px; top: calc(env(safe-area-inset-top) + 8px); max-width: 528px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 8px 8px 16px; background: var(--card-2); border: 1px solid var(--line); border-radius: 14px; font-size: 15px; font-weight: 600; z-index: 11; }
.update-bar button { min-height: 40px; padding: 0 14px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.chat-head { display: flex; align-items: center; gap: 8px; padding: 0 12px 8px; border-bottom: 1px solid var(--line); }
.chat-title { flex: 1; min-width: 0; }
.chat-title h2 { font-size: 19px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-title .status { font-size: 13px; }
.icon-btn.accent { background: var(--accent); color: var(--accent-ink); }
.chat-menu { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; background: var(--card); border-bottom: 1px solid var(--line); }
.menu-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 15px; font-weight: 600; }
select { font: inherit; color: var(--text); background: var(--card-2); border: 0; border-radius: 10px; min-height: 42px; padding: 0 10px; }
.chat-log { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; gap: 6px; padding: 12px; }
.chat-empty { margin: auto; max-width: 280px; text-align: center; color: var(--muted); font-size: 15px; }
.bubble { max-width: 82%; padding: 8px 12px 6px; border-radius: 18px; background: var(--card-2); align-self: flex-start; white-space: pre-wrap; overflow-wrap: anywhere; -webkit-user-select: text; user-select: text; }
.bubble.out { align-self: flex-end; background: #17594a; }
.bubble-meta { display: flex; justify-content: flex-end; gap: 5px; margin-top: 2px; color: #b5c1cf; font-size: 11px; -webkit-user-select: none; user-select: none; }
.chat-note { display: flex; align-items: center; justify-content: center; gap: 5px; padding: 3px 12px 6px; color: var(--muted); font-size: 12px; text-align: center; }
.chat-note .icon { width: 13px; height: 13px; }
.composer { display: flex; align-items: flex-end; gap: 8px; padding: 0 12px; }
.composer textarea { flex: 1; min-width: 0; min-height: 46px; max-height: 130px; resize: none; padding: 11px 15px; font: inherit; font-size: 17px; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 23px; -webkit-user-select: text; user-select: text; }
.composer textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }
.send { width: 46px; height: 46px; flex: none; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; }
.send:disabled { background: var(--card-2); color: var(--muted); cursor: default; }

/* Videoanruf */
.call { position: relative; }
.call > :not(video) { position: relative; z-index: 1; }
.call.video-on { background: #000; }
.remote-video { position: fixed; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; z-index: 0; }
.local-video { position: fixed; z-index: 2; top: calc(env(safe-area-inset-top) + 12px); right: 12px; width: 104px; height: 150px; object-fit: cover; border-radius: 16px; background: #111; border: 2px solid rgba(255,255,255,.25); }
.local-video.mirror { transform: scaleX(-1); }
.call.video-on .call-head { padding-top: 0; text-shadow: 0 1px 6px rgba(0,0,0,.7); }
.call.video-on .avatar.large { display: none; }
.call.video-on #call-name { font-size: 22px; }
.call.video-on .sas { background: rgba(10,14,20,.72); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }
.call.video-on .controls, .call.video-on .call-actions { padding: 10px 0; border-radius: 22px; background: rgba(10,14,20,.55); }
.call.video-on .round span:last-child { color: #e4e9ef; }
.controls { flex-wrap: wrap; row-gap: 14px; }

/* Fotos und Sprachnachrichten */
.attach { width: 46px; height: 46px; flex: none; border-radius: 50%; background: var(--card); color: var(--muted); display: grid; place-items: center; }
.bubble.has-photo { padding: 4px 4px 5px; }
.bubble.has-photo .bubble-meta { padding: 0 8px; }
.photo { display: block; padding: 0; background: var(--card); border-radius: 15px; overflow: hidden; max-width: 100%; }
.photo img { display: block; width: 240px; max-width: 100%; height: auto; max-height: 340px; object-fit: cover; background: var(--card); }
.voice { display: flex; align-items: center; gap: 9px; width: 216px; max-width: 100%; }
.voice-play { width: 38px; height: 38px; flex: none; border-radius: 50%; background: var(--text); color: var(--bg); display: grid; place-items: center; }
.voice-play .icon { width: 20px; height: 20px; }
.voice-track { flex: 1; height: 4px; border-radius: 2px; background: rgba(255,255,255,.25); overflow: hidden; }
.voice-bar { display: block; width: 100%; height: 100%; background: var(--text); transform: scaleX(0); transform-origin: left; }
.voice-time { flex: none; font-size: 12px; font-variant-numeric: tabular-nums; color: #d5dde7; }
.recording { display: flex; align-items: center; gap: 10px; padding: 0 12px; min-height: 46px; }
.rec-dot { width: 11px; height: 11px; border-radius: 50%; background: var(--red); flex: none; animation: rec 1.1s ease-in-out infinite; }
.rec-time { font-variant-numeric: tabular-nums; font-weight: 650; }
.rec-label { flex: 1; color: var(--muted); font-size: 14px; }
@keyframes rec { 50% { opacity: .25; } }
.viewer { position: fixed; inset: 0; z-index: 30; background: #000; display: flex; align-items: center; justify-content: center; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-close { position: absolute; top: calc(env(safe-area-inset-top) + 10px); right: 14px; background: rgba(40,44,50,.85); }

/* Verifiziert */
.verified-mark { display: inline-grid; place-items: center; width: 17px; height: 17px; margin-left: 6px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); vertical-align: -2px; }
.verified-mark .icon { width: 13px; height: 13px; }

/* App-Sperre */
.lock { position: fixed; inset: 0; z-index: 40; background: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: calc(env(safe-area-inset-top) + 12px) 24px calc(env(safe-area-inset-bottom) + 12px); text-align: center; }
.lock h2 { font-size: 20px; }
.lock-mark { width: 58px; height: 58px; border-radius: 18px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; }
.lock-form { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; }
.lock-field { position: relative; }
.lock-field input { padding-right: 104px; font-size: 18px; text-align: left; }
.lock-show { position: absolute; right: 6px; top: 6px; width: 90px; min-height: 42px; border-radius: 11px; background: var(--card-2); font-size: 14px; font-weight: 600; }
.lock-error { min-height: 22px; font-size: 14px; color: #ffc9cd; }
.lock-link { min-height: 44px; padding: 0 14px; background: none; color: var(--muted); font-size: 15px; font-weight: 600; }
.danger-text { color: #ff9aa2; }
@media (max-height: 700px) { .lock-mark { display: none; } }
/* Mit offener Tastatur rückt die Eingabe nach oben statt unter die Tastatur. */
.lock { justify-content: flex-start; padding-top: calc(env(safe-area-inset-top) + 12vh); }

/* Einladung per Link */
.center { text-align: center; }
.link-box { max-height: 112px; overflow-y: auto; font-size: 12px; line-height: 1.45; word-break: break-all; }
.invite-input { width: 100%; resize: none; padding: 12px 14px; font: 14px/1.4 ui-monospace, Menlo, monospace; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 14px; -webkit-user-select: text; user-select: text; }
#pair-choice h3 { color: var(--muted); font-size: 14px; font-weight: 600; margin-top: 8px; }

/* Prüfcode */
.sas-actions { display: grid; grid-template-columns: 1fr 1.5fr; gap: 8px; margin-top: 4px; }
.sas.verified { outline: 2px solid var(--accent); }
@media (max-height: 700px) { .avatar.large { width: 72px; height: 72px; font-size: 30px; } .call-head { padding-top: 0; } .sas-emojis { font-size: 34px; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
