/* p2p-talk — native messaging/call app, dark-first (light supported). No web fonts, no CDNs.
   Theming: DARK is the default (:root). Light applies via prefers-color-scheme AND data-theme. */

:root {
  color-scheme: dark light;
  --bg: #0e1116;
  --bg-grad: #141b27;
  --bar: #151b23;            /* app bar + composer */
  --surface: #1b222c;        /* theirs bubble, sheet */
  --surface-2: #232c38;      /* inputs, round grey button */
  --ink: #e9eef5;
  --ink-soft: #93a0b1;
  --ink-faint: #6b7889;
  --line: #273140;
  --accent: #0a84ff;         /* Recursive-blue family (bright for dark) */
  --accent-ink: #ffffff;
  --mine: #0a84ff;
  --mine-ink: #ffffff;
  --call-green: #28c76f;
  --end-red: #ff4d4f;
  --logo-sub: #ffffff;       /* "SOFTWARE DEVELOPMENT" text in the logo */
  --ring: rgba(10, 132, 255, .45);
  --shadow: 0 8px 30px rgba(0, 0, 0, .4);
}
/* Light theme — forced via data-theme, and followed from the OS unless data-theme="dark". */
:root[data-theme="light"] {
  --bg: #eef1f6; --bg-grad: #e3e9f3; --bar: #ffffff; --surface: #ffffff; --surface-2: #e9edf3;
  --ink: #10151c; --ink-soft: #5c6775; --ink-faint: #8a94a3; --line: #e2e7ef;
  --accent: #0072e7; --mine: #0072e7; --logo-sub: #1d2433;
  --call-green: #17a85a; --end-red: #e5484d; --ring: rgba(0, 114, 231, .3);
  --shadow: 0 8px 30px rgba(20, 27, 38, .12);
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #eef1f6; --bg-grad: #e3e9f3; --bar: #ffffff; --surface: #ffffff; --surface-2: #e9edf3;
    --ink: #10151c; --ink-soft: #5c6775; --ink-faint: #8a94a3; --line: #e2e7ef;
    --accent: #0072e7; --mine: #0072e7; --logo-sub: #1d2433;
    --call-green: #17a85a; --end-red: #e5484d; --ring: rgba(0, 114, 231, .3);
    --shadow: 0 8px 30px rgba(20, 27, 38, .12);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.ic { width: 24px; height: 24px; display: block; }

/* App height tracks the visual viewport (keyboard-aware); falls back to 100%. */
.screen { position: fixed; left: 0; top: 0; width: 100%; height: var(--vvh, 100%); display: flex; flex-direction: column; }

/* Theme-swapped logo (no chip, no white box) */
.logo { width: min(74vw, 320px); height: auto; display: none; }
.logo--dark { display: block; }
:root[data-theme="light"] .logo--dark { display: none; }
:root[data-theme="light"] .logo--light { display: block; }
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .logo--dark { display: none; }
  :root:not([data-theme="dark"]) .logo--light { display: block; }
}

/* ============ JOIN ============ */
.join {
  background: radial-gradient(130% 80% at 50% -5%, var(--bg-grad), var(--bg) 62%);
  align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 40px) 24px calc(env(safe-area-inset-bottom) + 18px);
  text-align: center;
}
.join-inner { width: 100%; max-width: 380px; margin: auto 0; display: flex; flex-direction: column; align-items: center; }
.brand { margin-bottom: 26px; }
.join-title { margin: 0; font-size: 1.9rem; font-weight: 700; letter-spacing: -0.02em; }
.join-sub { margin: 8px 0 30px; color: var(--ink-soft); font-size: 0.95rem; max-width: 300px; }
.join-form { width: 100%; display: flex; flex-direction: column; gap: 11px; }
.join-hint { margin: 4px 2px 0; color: var(--ink-faint); font-size: 0.78rem; line-height: 1.45; }
.join-footer { color: var(--ink-faint); font-size: 0.72rem; }

.field {
  font: inherit; width: 100%; min-height: 52px; padding: 14px 16px; text-align: center;
  border: 1.5px solid var(--line); border-radius: 14px; background: var(--surface);
  color: var(--ink); -webkit-appearance: none; appearance: none; transition: border-color .15s, box-shadow .15s;
}
.field::placeholder { color: var(--ink-faint); }
.field:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--ring); }

.btn-primary {
  font: inherit; font-weight: 650; min-height: 52px; margin-top: 4px; border: 0; border-radius: 14px;
  background: var(--accent); color: var(--accent-ink); cursor: pointer; transition: transform .06s, filter .15s;
}
.btn-primary:active { transform: scale(.985); }
.btn-primary:disabled { opacity: .5; }
.btn-secondary {
  font: inherit; font-weight: 600; min-height: 46px; padding: 0 16px; border: 1px solid var(--line);
  border-radius: 12px; background: var(--surface-2); color: var(--ink); cursor: pointer; align-self: flex-start;
}
.note  { margin: 2px 0 0; color: var(--call-green); font-size: 0.86rem; font-weight: 600; }
.error { margin: 2px 0 0; color: var(--end-red); font-size: 0.86rem; font-weight: 600; }

/* ============ CHAT ============ */
.chat { background: var(--bg); }
.appbar {
  display: flex; align-items: center; gap: 10px; flex: 0 0 auto;
  padding: calc(env(safe-area-inset-top) + 8px) 8px 8px; background: var(--bar);
  border-bottom: 1px solid var(--line);
}
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px;
  border: 0; border-radius: 50%; background: transparent; color: var(--accent); cursor: pointer;
}
.icon-btn:active { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.appbar-title { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; }
.room-name { font-weight: 650; font-size: 1.02rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-status { font-size: 0.78rem; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-status[data-state="online"] { color: var(--call-green); }
.room-status[data-state="relay"] { color: #e0a654; }
.room-status[data-state="incall"] { color: var(--accent); }
.room-status[data-state="left"] { color: var(--end-red); }
.room-status[data-state="reconnecting"], .room-status[data-state="offline"] { color: var(--end-red); }
.room-status[data-state="poor"] { color: #e0a654; }

/* Brand "talk" wordmark — Walkway Expand outlines (SVG paths; no font shipped to the browser) */
.talk-word { display: block; width: min(52vw, 220px); height: auto; color: var(--accent); margin: 10px 0 32px; }

/* Signal-strength bars */
.appbar-title { min-width: 0; }
.room-sub { display: flex; align-items: center; gap: 8px; min-width: 0; }
#room-status { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 13px; }
.bars .bar { width: 3px; border-radius: 1px; background: var(--ink-faint); opacity: .45; }
.bars .bar:nth-child(1) { height: 4px; } .bars .bar:nth-child(2) { height: 7px; }
.bars .bar:nth-child(3) { height: 10px; } .bars .bar:nth-child(4) { height: 13px; }
.bars .bar.on { background: var(--call-green); opacity: 1; }
.bars--lg { height: 24px; gap: 4px; }
.bars--lg .bar { width: 5px; }
.bars--lg .bar:nth-child(1) { height: 8px; } .bars--lg .bar:nth-child(2) { height: 14px; }
.bars--lg .bar:nth-child(3) { height: 19px; } .bars--lg .bar:nth-child(4) { height: 24px; }

/* Connection banner over the chat */
.conn-banner {
  flex: 0 0 auto; width: 100%; margin: 0; border: 0; padding: 9px 12px; cursor: default;
  font: inherit; font-weight: 650; color: #fff; text-align: center;
}
.conn-banner[data-kind="bad"] { background: var(--end-red); }
.conn-banner[data-kind="warn"] { background: #c9821f; }
.conn-banner[data-kind="ok"] { background: var(--call-green); }

.call-meta { display: flex; align-items: center; gap: 10px; min-height: 26px; }

.avatar {
  flex: 0 0 auto; width: 38px; height: 38px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 1rem;
  background: var(--accent); color: var(--accent-ink); text-transform: uppercase;
}
.avatar--xl { width: 112px; height: 112px; font-size: 2.8rem; box-shadow: var(--shadow); }

.min-banner {
  flex: 0 0 auto; display: flex; align-items: center; gap: 8px; justify-content: center;
  margin: 0; padding: 10px; border: 0; width: 100%; background: var(--call-green); color: #fff;
  font: inherit; font-weight: 650; cursor: pointer;
}
.min-banner .ic { width: 18px; height: 18px; }

.messages {
  list-style: none; margin: 0; padding: 14px 12px; flex: 1 1 auto; overflow-y: auto;
  -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; gap: 4px;
}
.messages li { max-width: 80%; width: fit-content; }
.bubble { padding: 8px 12px; border-radius: 18px; line-height: 1.35; word-break: break-word; }
.msg-mine { align-self: flex-end; }
.msg-mine .bubble { background: var(--mine); color: var(--mine-ink); border-bottom-right-radius: 6px; }
.msg-theirs { align-self: flex-start; }
.msg-theirs .bubble { background: var(--surface); color: var(--ink); border-bottom-left-radius: 6px; }
.msg-sys {
  align-self: center; max-width: 90%; text-align: center; color: var(--ink-soft);
  font-size: 0.76rem; background: var(--surface); padding: 4px 11px; border-radius: 12px; margin: 4px 0;
}
.time { display: block; font-size: 0.64rem; opacity: .7; margin-top: 3px; text-align: right; }
.msg-theirs .time { text-align: left; }

/* Voice clip bubble */
.clip { display: flex; align-items: center; gap: 10px; min-width: 190px; }
.clip-play {
  flex: 0 0 auto; width: 36px; height: 36px; border-radius: 50%; border: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center; background: var(--accent); color: #fff;
}
.clip-play .ic { width: 20px; height: 20px; }
.msg-mine .clip-play { background: rgba(255, 255, 255, .25); }
.clip-bar { flex: 1; height: 4px; border-radius: 2px; background: color-mix(in srgb, currentColor 25%, transparent); position: relative; }
.clip-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: 2px; background: currentColor; }
.clip-dur { flex: 0 0 auto; font-size: 0.74rem; font-variant-numeric: tabular-nums; opacity: .85; }

/* Composer */
.composer {
  flex: 0 0 auto; display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 10px calc(env(safe-area-inset-bottom) + 8px); background: var(--bar); border-top: 1px solid var(--line);
}
.composer-input {
  font: inherit; flex: 1; min-height: 44px; padding: 11px 16px;
  border: 1px solid var(--line); border-radius: 22px; background: var(--surface); color: var(--ink);
  -webkit-appearance: none; appearance: none;
}
.composer-input:focus { outline: none; border-color: var(--accent); }
.comp-btn {
  flex: 0 0 auto; width: 44px; height: 44px; border: 0; border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center; background: var(--accent); color: #fff;
}
.comp-btn.mic { background: var(--surface-2); color: var(--ink); touch-action: none; }
.comp-btn.mic.recording { background: var(--end-red); color: #fff; }

.rec-overlay {
  position: absolute; left: 12px; right: 12px; bottom: calc(env(safe-area-inset-bottom) + 62px);
  padding: 11px 14px; border-radius: 14px; background: var(--surface);
  box-shadow: var(--shadow); display: flex; align-items: center; gap: 10px; font-size: 0.88rem;
}
.rec-dot { width: 11px; height: 11px; border-radius: 50%; background: var(--end-red); animation: blink 1s steps(2) infinite; }
#rec-timer { font-variant-numeric: tabular-nums; font-weight: 650; }
.rec-hint { color: var(--ink-soft); margin-left: auto; font-size: 0.76rem; }
@keyframes blink { 50% { opacity: .25; } }

/* ============ CALL overlay ============ */
.call {
  z-index: 30; background: radial-gradient(120% 70% at 50% 0%, var(--bg-grad), var(--bg) 70%);
  padding: calc(env(safe-area-inset-top) + 6px) 20px calc(env(safe-area-inset-bottom) + 30px);
  align-items: center;
}
.call-head { width: 100%; display: flex; }
.call-body { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; }
.call-name { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.01em; }
.call-state { color: var(--ink-soft); font-size: 1rem; }
.call-state.ring { animation: softpulse 1.6s ease-in-out infinite; }
.call-quality { color: var(--ink-faint); font-size: 0.8rem; min-height: 1em; }
@keyframes softpulse { 50% { opacity: .5; } }

.tap-hear {
  margin-top: 8px; display: inline-flex; align-items: center; gap: 8px; font: inherit; font-weight: 600;
  padding: 10px 16px; border: 0; border-radius: 999px; background: #e0a654; color: #201400; cursor: pointer;
}
.tap-hear .ic { width: 18px; height: 18px; }

.call-actions { display: flex; gap: 26px; align-items: flex-end; justify-content: center; }
.action { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.action span { font-size: 0.78rem; color: var(--ink-soft); }
.round {
  width: 68px; height: 68px; border: 0; border-radius: 50%; cursor: pointer; color: #fff;
  display: flex; align-items: center; justify-content: center; transition: transform .06s;
}
.round:active { transform: scale(.94); }
.round .ic { width: 30px; height: 30px; }
.round.green { background: var(--call-green); }
.round.red { background: var(--end-red); }
.round.grey { background: var(--surface-2); color: var(--ink); }
.round.grey.on { background: var(--ink); color: var(--bg); }  /* muted */

/* Which action buttons show, per call state */
.call[data-call="incoming"] .act-mute, .call[data-call="incoming"] .act-end { display: none; }
.call[data-call="outgoing"] .act-decline, .call[data-call="outgoing"] .act-answer, .call[data-call="outgoing"] .act-mute { display: none; }
.call[data-call="active"] .act-decline, .call[data-call="active"] .act-answer { display: none; }

/* ============ Info sheet ============ */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 40; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; background: var(--bar);
  border-radius: 20px 20px 0 0; padding: 10px 20px calc(env(safe-area-inset-bottom) + 22px);
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; animation: sheetup .22s ease;
}
@keyframes sheetup { from { transform: translateY(100%); } }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--line); align-self: center; margin: 2px 0 6px; }
.sheet-title { margin: 0; font-size: 1.05rem; }
.diag { font: 0.78rem/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.sheet-hint { margin: 0; color: var(--ink-faint); font-size: 0.78rem; line-height: 1.5; }
#log-dump { font: 0.68rem/1.35 ui-monospace, Menlo, monospace; width: 100%; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); padding: 8px; }

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

/* ============ Language switcher + Help ============ */
.join-top {
  position: absolute; top: calc(env(safe-area-inset-top) + 10px); right: 14px;
  display: flex; align-items: center; gap: 6px; z-index: 5;
}
.pill-btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 6px 12px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 650; font-size: 0.82rem; cursor: pointer;
}
.pill-btn .lang-flag { font-size: 1.05rem; line-height: 1; }
.pill-btn .lang-code { letter-spacing: .02em; }

.sheet-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sheet-label { font-weight: 650; }

.help-modal {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; background: var(--bar);
  border-radius: 20px 20px 0 0; max-height: 86vh; display: flex; flex-direction: column;
  box-shadow: var(--shadow); animation: sheetup .22s ease;
}
.help-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px 10px 10px 20px; border-bottom: 1px solid var(--line);
}
.help-head h3 { margin: 0; font-size: 1.15rem; }
.help-body {
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 16px 20px calc(env(safe-area-inset-bottom) + 22px);
}
.help-steps { margin: 0; padding: 0; list-style: none; counter-reset: step; display: flex; flex-direction: column; gap: 14px; }
.help-steps li { position: relative; padding-left: 42px; line-height: 1.45; color: var(--ink); }
.help-steps li::before {
  counter-increment: step; content: counter(step);
  position: absolute; left: 0; top: 0; width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 0.9rem;
  display: flex; align-items: center; justify-content: center;
}
.help-tip, .help-privacy {
  margin: 18px 0 0; padding: 12px 14px; border-radius: 12px; background: var(--surface);
  color: var(--ink-soft); font-size: 0.88rem; line-height: 1.5;
}
.help-privacy { margin-top: 10px; }

/* ============ Add to Home Screen ============ */
.a2hs { align-items: center; text-align: center; z-index: 50; padding-bottom: calc(env(safe-area-inset-bottom) + 20px); }
.a2hs-ill {
  width: 66px; height: 66px; margin: 6px auto 4px; border-radius: 18px;
  background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center;
}
.a2hs-ill svg { width: 34px; height: 34px; }
.a2hs-title { text-align: center; margin: 4px 0 2px; }
.a2hs-text { text-align: center; max-width: 320px; margin: 0 auto; color: var(--ink-soft); }
.a2hs-actions { display: flex; flex-direction: column; gap: 8px; width: 100%; margin-top: 4px; }
.a2hs-actions .btn-primary, .a2hs-actions .btn-secondary { width: 100%; align-self: stretch; text-align: center; }
.btn-ghost {
  font: inherit; font-weight: 600; min-height: 42px; border: 0; border-radius: 12px; background: transparent;
  color: var(--ink-faint); cursor: pointer;
}

.help-a2hs {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 18px; padding: 11px 14px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--accent);
  font: inherit; font-weight: 650; cursor: pointer;
}
.help-a2hs .ic { width: 18px; height: 18px; }
