:root {
  --bg: #0b0f14;
  --panel: #131a23;
  --panel-2: #1b2531;
  --ink: #e6edf3;
  --muted: #8b98a5;
  --accent: #2ea8ff;
  --accent-2: #15c8a0;
  --danger: #ff5a5a;
  --line: #243140;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
  background: var(--bg);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(1200px 600px at 50% -10%, #16202c 0%, var(--bg) 60%);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem 1rem 3rem;
  /* Edge-to-edge (Android app, notched phones): keep content clear of the
     status bar, navigation bar and cutouts. */
  padding: calc(2rem + env(safe-area-inset-top, 0px))
           calc(1rem + env(safe-area-inset-right, 0px))
           calc(3rem + env(safe-area-inset-bottom, 0px))
           calc(1rem + env(safe-area-inset-left, 0px));
}

/* Solid backdrop under the status bar so scrolled content never runs
   beneath the clock and icons. Zero height where there is no inset. */
body::before {
  content: "";
  position: fixed;
  top: 0; left: 0; right: 0;
  height: env(safe-area-inset-top, 0px);
  background: var(--bg);
  z-index: 1000;
  pointer-events: none;
}

header { text-align: center; margin-bottom: 1.5rem; }
header h1 { font-size: 2.6rem; margin: 0; letter-spacing: -1px; }
.accent { color: var(--accent); }
.tagline { color: var(--muted); margin: .3rem 0 0; font-size: .95rem; }

main { width: 100%; max-width: 560px; }

.status-bar {
  display: flex; align-items: center; gap: .6rem;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .6rem 1rem; margin-bottom: 1rem;
  font-size: .9rem;
}
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot-idle { background: var(--muted); }
.dot-wait { background: #f0b400; box-shadow: 0 0 8px #f0b40088; }
.dot-live { background: var(--accent-2); box-shadow: 0 0 10px var(--accent-2); }
.crypto-badge { color: var(--accent-2); font-weight: 600; }
#dtls { margin-left: auto; }
.crypto-badge.pqc { color: var(--accent); }

.sas-panel {
  display: flex; flex-direction: column; gap: .3rem;
  background: var(--panel-2); border: 1px solid var(--accent);
  border-radius: 10px; padding: .7rem .9rem; margin-bottom: 1rem;
}
.sas-label { font-size: .78rem; color: var(--muted); }
.sas-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .3rem; }
.sas-actions[hidden] { display: none; }
.sas-status { font-size: .8rem; color: #f0b400; }
.sas-status.ok { color: var(--accent-2); }
.sas-panel.verified { border-color: var(--accent-2); }
.crypto-badge.verified { color: var(--accent-2); }
.p-verify { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; font-size: .75rem; color: #f0b400; }
.p-verify.ok { color: var(--accent-2); }
.p-verify button { padding: .25rem .6rem; font-size: .75rem; }
.msg-from.unverified { color: #f0b400; }
.role-buttons { flex-wrap: wrap; }
.invite-row { display: flex; flex-wrap: wrap; gap: .5rem; margin: .8rem 0 0; }
.invite-row[hidden] { display: none; }
.end-notice {
  margin: 0 0 1rem; padding: .7rem .9rem; border-radius: 10px; font-size: .85rem; line-height: 1.45;
  border: 1px solid var(--danger); background: rgba(255, 90, 90, .08); color: var(--ink);
}
.end-notice[hidden] { display: none; }
.sas-value {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 1.15rem; letter-spacing: .04rem; color: var(--accent);
  user-select: all;
}

.participants-panel {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 10px; padding: .7rem .9rem; margin-bottom: 1rem;
}
.participants-panel[hidden] { display: none; }
.participants-head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: .85rem; font-weight: 600; margin-bottom: .4rem;
}
#participants { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .35rem; }
.participant {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .15rem .6rem;
  padding: .4rem .5rem; border-radius: 8px; background: var(--panel); border: 1px solid var(--line);
  font-size: .85rem;
}
.p-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.p-state { font-size: .75rem; color: var(--muted); text-align: right; }
.p-state-secure { color: var(--accent-2); }
.p-state-live, .p-state-wait { color: #f0b400; }
.p-state-down { color: var(--danger); }
.p-sas {
  grid-column: 1 / -1;
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: .9rem; color: var(--accent); user-select: all;
}
.participants-panel .hint { margin-top: .5rem; font-size: .75rem; }
.msg-from { display: block; font-size: .7rem; font-weight: 700; color: var(--accent); margin-bottom: .1rem; }

.pane {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.2rem 1.3rem; margin-bottom: 1rem;
}
.pane h2 { margin: 0 0 1rem; font-size: 1.1rem; }

.role-buttons { display: flex; gap: .8rem; }
.hint { color: var(--muted); font-size: .85rem; margin: 1rem 0 0; line-height: 1.45; }
.muted { color: var(--muted); }
.error { color: var(--danger); font-size: .85rem; margin: .6rem 0 0; }

.method { display: flex; gap: 1.2rem; margin-bottom: 1rem; font-size: .92rem; }
.method label { display: flex; align-items: center; gap: .4rem; cursor: pointer; }
.method input { accent-color: var(--accent); }

.server-row { margin-bottom: 1.1rem; }
.server-row label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .4rem; }
.server-row input {
  width: 100%; font: inherit; padding: .55rem .8rem; border-radius: 8px;
  background: var(--panel-2); color: var(--ink); border: 1px solid var(--line);
  font-family: ui-monospace, "Cascadia Code", monospace; font-size: .85rem;
}
.server-row input:focus { outline: none; border-color: var(--accent); }

.server-settings {
  margin-bottom: 1.1rem; padding: .6rem .8rem; border-radius: 10px;
  background: var(--panel-2); border: 1px solid var(--line);
}
.server-settings[hidden] { display: none; }
.server-settings summary { cursor: pointer; font-size: .88rem; font-weight: 600; }
.server-settings[open] summary { margin-bottom: .8rem; }
.server-settings .server-row { margin-bottom: .8rem; }
.server-settings .server-row input { background: var(--panel); }
.turn-creds { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.settings-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.server-settings .hint { margin-top: .6rem; font-size: .78rem; }
.server-settings .hint.error-text { color: var(--danger); }

.code {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 2.4rem; letter-spacing: .4rem; text-align: center;
  color: var(--accent); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 1rem; margin: .8rem 0; user-select: all;
}
.code-input {
  width: 100%; font-family: ui-monospace, monospace; font-size: 1.6rem;
  letter-spacing: .3rem; text-align: center; text-transform: uppercase;
  padding: .7rem; border-radius: 10px; margin: .5rem 0 1rem;
  background: var(--panel-2); color: var(--ink); border: 1px solid var(--line);
}
.code-input:focus { outline: none; border-color: var(--accent); }

button {
  font: inherit; cursor: pointer; border-radius: 8px; padding: .6rem 1rem;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--ink);
  transition: transform .05s ease, background .15s ease, border-color .15s ease;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: not-allowed; }
.primary { background: var(--accent); border-color: var(--accent); color: #04121f; font-weight: 600; }
.danger { background: var(--danger); border-color: var(--danger); color: #2a0606; font-weight: 600; }
.ghost { background: transparent; }
.ghost.active { border-color: var(--danger); color: var(--danger); }

.blob-group { margin-bottom: 1.1rem; }
.blob-group label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .4rem; }
textarea {
  width: 100%; min-height: 96px; resize: vertical;
  background: var(--panel-2); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px; padding: .7rem;
  font-family: ui-monospace, "Cascadia Code", monospace; font-size: .78rem;
  word-break: break-all;
}
textarea:focus { outline: none; border-color: var(--accent); }
.blob-group button { margin-top: .5rem; }

.call-controls { display: flex; gap: .8rem; margin-bottom: 1rem; }

.chat { display: flex; flex-direction: column; }
#chat-log {
  list-style: none; margin: 0 0 .8rem; padding: .6rem;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 8px; height: 240px; overflow-y: auto;
  display: flex; flex-direction: column; gap: .4rem;
}
.msg { padding: .45rem .7rem; border-radius: 10px; max-width: 80%; font-size: .9rem; line-height: 1.35; }
.msg-me { align-self: flex-end; background: var(--accent); color: #04121f; }
.msg-them { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); }
.msg-sys { align-self: center; color: var(--muted); font-size: .8rem; font-style: italic; }

#chat-form { display: flex; gap: .6rem; }
#chat-input {
  flex: 1; font: inherit; padding: .6rem .8rem; border-radius: 8px;
  background: var(--panel-2); color: var(--ink); border: 1px solid var(--line);
}
#chat-input:focus { outline: none; border-color: var(--accent); }

footer { margin-top: 1.5rem; max-width: 560px; text-align: center; }
footer small { color: var(--muted); line-height: 1.5; }
