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

:root {
  --bg: #07090c;
  --bg-1: #0d1116;
  --bg-2: #141a21;
  --bg-3: #1c242e;
  --line: #232d39;
  --fg: #e4eaf1;
  --fg-dim: #8c9bad;
  --fg-faint: #5d6b7c;
  --accent: #3ddc97;
  --accent-dim: #1d7a56;
  --danger: #ff5f6d;
  --warn: #ffb454;
  --mine: #16302a;
  --radius: 12px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { 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;
  overflow: hidden;
}

.mono { font-family: var(--mono); }
.tiny { font-size: 12px; color: var(--fg-faint); }
.hint { font-size: 12px; color: var(--fg-dim); margin: -4px 0 12px; }
.error { color: var(--danger); font-size: 13px; margin: 8px 0 0; }
.success { color: var(--accent); }

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

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

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

.center {
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
}

.card {
  width: 100%;
  max-width: 480px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 32px;
  margin: auto;
}

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

.brand {
  font-size: 26px;
  font-weight: 650;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand.small { font-size: 16px; }
.brand .glyph { color: var(--accent); }

.glyph.big { font-size: 34px; display: block; }
.glyph.huge { font-size: 56px; display: block; color: var(--bg-3); }

.lede { color: var(--fg-dim); margin: 14px 0 22px; }

.gate-actions { display: grid; gap: 10px; margin-bottom: 24px; }

.facts { margin: 0 0 18px; padding-left: 18px; color: var(--fg-faint); font-size: 13px; }
.facts li { margin: 4px 0; }

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

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--fg);
  font: inherit;
  font-weight: 550;
  padding: 10px 18px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .12s, border-color .12s, opacity .12s;
}
.btn:hover:not(:disabled) { background: var(--bg-3); border-color: #33414f; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #05130d; border-color: transparent; }
.btn.primary:hover:not(:disabled) { background: #57e8aa; }
.btn.danger { background: transparent; color: var(--danger); border-color: #40252a; }
.btn.danger:hover:not(:disabled) { background: #2a1418; }
.btn.big { padding: 13px 20px; font-size: 15px; }
.btn.block { display: block; width: 100%; margin: 10px 0; }

.icon-btn {
  appearance: none;
  background: transparent;
  border: 1px solid transparent;
  color: var(--fg-dim);
  font-size: 17px;
  width: 36px;
  height: 36px;
  border-radius: 9px;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.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: 20px; }

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

input[type="password"], input[type="text"], input:not([type]), textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--fg);
  font: inherit;
  padding: 11px 13px;
  resize: vertical;
}
input:focus, textarea:focus { outline: 2px solid var(--accent-dim); outline-offset: -1px; border-color: transparent; }

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

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

.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; }

.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: 10px;
  padding: 12px 13px;
  white-space: pre-wrap;
}
.safety { font-size: 17px; text-align: center; line-height: 1.7; }

.warn {
  background: #2a1f0e;
  border: 1px solid #4a3616;
  color: #f3d9a8;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 13px;
  margin: 16px 0;
}
.warn strong { display: block; color: var(--warn); margin-bottom: 3px; }

.drop {
  border: 1.5px dashed var(--line);
  border-radius: 14px;
  padding: 28px 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: 6px; }
.drop .glyph { color: var(--fg-faint); }
.drop.loaded { border-color: var(--accent-dim); border-style: solid; }
.drop.loaded .glyph { color: var(--accent); }

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

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

#sidebar {
  background: var(--bg-1);
  border-right: 1px solid var(--line);
  display: grid;
  grid-template-rows: auto auto auto 1fr auto;
  min-height: 0;
}

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

.me {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 12px 10px;
  padding: 10px 12px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: inherit;
  font: inherit;
  cursor: pointer;
  text-align: left;
}
.me:hover { background: var(--bg-3); }
.me-text { display: grid; min-width: 0; }
.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: 10px 11px;
  border: 0;
  background: transparent;
  color: var(--fg-dim);
  font: inherit;
  border-radius: 9px;
  cursor: pointer;
  text-align: left;
}
.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: #05130d;
  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 14px;
  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: 6px;
  text-align: center;
  color: var(--fg-faint);
  padding: 32px;
}
.empty h2 { margin: 12px 0 0; font-size: 17px; color: var(--fg-dim); font-weight: 600; }
.empty p { margin: 0; font-size: 13px; max-width: 320px; }

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

#room-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  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); }
.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 13px;
  border-radius: 14px;
  white-space: pre-wrap;
}
.msg.mine .bubble { background: var(--mine); border-color: #21493d; }
.msg .meta { font-size: 10.5px; color: var(--fg-faint); padding: 0 5px; }
.msg.pending .bubble { opacity: .55; }
.msg + .msg.same { margin-top: -1px; }

.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: 3px 12px;
  margin: 8px 0;
  text-align: center;
}

.composer {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 12px 16px 16px;
  border-top: 1px solid var(--line);
  background: var(--bg-1);
}
.composer textarea {
  flex: 1;
  max-height: 160px;
  min-height: 44px;
  border-radius: 12px;
  resize: none;
}
.btn.send { width: 44px; height: 44px; padding: 0; flex: none; font-size: 18px; border-radius: 12px; }

/* ── 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); }
.panel-foot { border-top: 1px solid var(--line); display: grid; gap: 0; }
.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: 11px;
  padding: 11px 12px;
  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: 5px 10px; font-size: 12px; }

/* ── 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; }
.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: 14px;
  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; }
.round {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--fg);
  font-size: 20px;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.round:hover { background: var(--bg-3); }
.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; }

/* ── 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: 18px;
  padding: 30px 34px;
  display: grid;
  gap: 10px;
  justify-items: center;
  text-align: center;
  min-width: 300px;
}
.ring-card .row { margin-top: 12px; }
.ring-card small { color: var(--fg-faint); font-family: var(--mono); font-size: 11.5px; }
.pulse { color: var(--accent); animation: pulse 1.3s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .5; transform: scale(.92); } }

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

dialog {
  background: var(--bg-1);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 26px;
  width: min(460px, calc(100vw - 32px));
  font: inherit;
}
dialog::backdrop { background: #04060899; backdrop-filter: blur(4px); }
dialog h2 { margin-top: 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 13.5px;
  z-index: 90;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .5);
  /* 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: 96px; }

/* ── 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: 14px; }
  .grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); padding: 0 10px; }
  .round { width: 48px; height: 48px; font-size: 18px; }
}

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