@font-face {
  font-family: "EnigmaRain";
  src: url("fonts/EnigmaRain.ttf") format("truetype");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #000;
  --panel: #0a0a0a;
  --border: #1a1a1a;
  --border-hi: #0a3d1a;
  --text: #e2e8f0;
  --muted: #666;
  --green: #00ff41;
  --green-dim: #4ade80;
  --danger: #f87171;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: 0;
}

/* ── Login / identity strip ── */
.identity {
  flex-shrink: 0;
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.brand-row {
  display: flex;
  align-items: baseline;
  gap: 8px 12px;
  margin-bottom: 10px;
}

.brand {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--green);
  flex-shrink: 0;
}

.copyright {
  margin: 0;
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.02em;
  color: #8aa892;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.brand-row .ghost,
.brand-row a,
.brand-row .status-pill {
  align-self: center;
}

.status-pill {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid #222;
  background: var(--panel);
  color: #888;
  white-space: nowrap;
  max-width: 55%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-pill.ok {
  color: var(--green);
  border-color: var(--border-hi);
}

.status-pill.warn {
  color: #eab308;
  border-color: #3d3200;
}

.status-pill.err {
  color: var(--danger);
  border-color: #3d1515;
}

.field {
  margin-bottom: 8px;
}

.field label {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.field input[type="text"],
.field input[type="password"] {
  width: 100%;
  padding: 11px 12px;
  border-radius: 8px;
  border: 1px solid #222;
  background: var(--panel);
  color: #f0f0f0;
  outline: none;
  font-size: 16px; /* prevents iOS zoom */
}

.field input:focus {
  border-color: var(--border-hi);
  box-shadow: 0 0 0 2px rgba(0, 255, 65, 0.12);
}

.pw-row {
  display: flex;
  gap: 6px;
}

.pw-row input {
  flex: 1;
  min-width: 0;
}

.pw-row button {
  flex-shrink: 0;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid #222;
  background: var(--panel);
  color: #ccc;
  font-size: 12px;
  font-weight: 600;
}

.hint {
  margin: 4px 0 0;
  font-size: 11px;
  line-height: 1.4;
  color: #555;
}

.advanced {
  margin-top: 4px;
}

.advanced summary {
  font-size: 11px;
  color: #555;
  cursor: pointer;
  user-select: none;
  padding: 4px 0;
}

.advanced-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 6px;
}

.advanced-grid input {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #222;
  background: var(--panel);
  color: #f0f0f0;
  font-size: 14px;
  outline: none;
}

/* ── Main layout ── */
.app {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}

.chat-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.room-label {
  font-size: 12px;
  color: var(--muted);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-label strong {
  color: #ccc;
  font-weight: 600;
}

.room-label .room-cipher-hint {
  color: var(--green);
  font-weight: 500;
  opacity: 0.85;
}

.topbar-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.topbar-actions button {
  padding: 8px 10px;
  font-size: 12px;
}

.banner {
  margin: 8px 12px 0;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 11px;
  line-height: 1.4;
  color: #888;
  background: var(--panel);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.banner strong { color: var(--green); }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}

.msg {
  max-width: 92%;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
}

.msg.mine {
  align-self: flex-end;
  background: #041208;
  border-color: var(--border-hi);
}

.msg.system {
  align-self: center;
  max-width: 95%;
  background: transparent;
  border: none;
  color: #555;
  font-size: 12px;
  padding: 4px 8px;
  text-align: center;
}

.msg-meta {
  display: flex;
  gap: 8px;
  align-items: baseline;
  margin-bottom: 4px;
  font-size: 11px;
  color: var(--muted);
}

.msg-nick {
  color: var(--green);
  font-weight: 600;
}

.msg.mine .msg-nick { color: var(--green-dim); }

.msg-body {
  font-size: 14px;
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
}

.msg-body.cipher {
  font-family: "EnigmaRain", "Consolas", "MS Gothic", monospace;
  font-size: 12px;
  color: var(--green);
  opacity: 0.9;
}

.msg-body.plain { color: #eee; }

.msg-body.locked {
  color: #555;
  font-style: italic;
  font-size: 12px;
}

.composer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px calc(6px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

.btn-voice {
  flex-shrink: 0;
  min-width: 44px;
  padding: 10px 12px;
  font-size: 18px;
  line-height: 1;
}
.btn-voice.recording {
  border-color: #7f1d1d;
  color: #f87171;
  background: #1a0505;
}
.voice-rec-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid #3d1515;
  background: #0a0404;
  font-size: 12px;
  color: #f87171;
  flex-shrink: 0;
}
.voice-rec-bar[hidden] { display: none !important; }
.msg-body.voice {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.msg-body.voice .voice-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.msg-body.voice .voice-play {
  min-width: 44px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid var(--border-hi);
  background: #041208;
  color: var(--green);
  font-size: 16px;
  font-weight: 700;
  padding: 0 12px;
}
.msg-body.voice .voice-play:disabled {
  opacity: 0.35;
  border-color: #333;
  color: #666;
}
.msg-body.voice .voice-meta {
  font-size: 12px;
  color: var(--muted);
}
.msg-body.voice-locked {
  color: #555;
  font-style: italic;
  font-size: 13px;
  user-select: none;
  pointer-events: none;
}

.composer input {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid #222;
  background: var(--panel);
  color: #f0f0f0;
  outline: none;
  font-size: 16px;
}

.composer input:focus {
  border-color: var(--border-hi);
}

.composer input:disabled { opacity: 0.45; }

.composer button[type="submit"] {
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid var(--border-hi);
  background: #041208;
  color: var(--green);
  font-weight: 700;
  font-size: 13px;
}

.composer button:disabled {
  opacity: 0.4;
}

button {
  border: 1px solid #222;
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  color: #ddd;
  background: var(--panel);
}

button:active { background: #111; }

button.ghost {
  color: #ccc;
  background: var(--panel);
}

/* ── Rooms drawer (mobile) ── */
.drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 40;
}

.drawer-backdrop.open { display: block; }

.side {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(320px, 88vw);
  z-index: 50;
  display: flex;
  flex-direction: column;
  background: #050505;
  border-left: 1px solid var(--border);
  transform: translateX(100%);
  transition: transform 0.2s ease;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

.side.open { transform: translateX(0); }

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.side-head h2 {
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #888;
  font-weight: 600;
}

.rooms-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.rooms {
  flex: 1;
  overflow-y: auto;
  padding: 4px 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
}

.room-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  text-align: left;
  padding: 12px;
  border-radius: 8px;
  color: #ddd;
  background: var(--panel);
  border: 1px solid var(--border);
  font-weight: 500;
  font-size: 14px;
}

.room-btn.active {
  background: #041208;
  border-color: var(--border-hi);
  color: var(--green);
}

.room-count {
  font-size: 11px;
  color: var(--muted);
}

.create-col {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 10px 12px;
}

.create-row {
  display: flex;
  gap: 6px;
  padding: 0;
}

.create-row input,
.create-col > input {
  flex: 1;
  min-width: 0;
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #222;
  background: var(--panel);
  color: #f0f0f0;
  font-size: 14px;
  outline: none;
}

.create-row button {
  padding: 10px 12px;
  font-size: 12px;
}

.room-name {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.room-lock {
  flex-shrink: 0;
  font-size: 12px;
}

.lock-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 80;
  padding: 16px;
}

.lock-modal[hidden] {
  display: none;
}

.lock-card {
  width: min(360px, 100%);
  background: #0a0a0a;
  border: 1px solid var(--border-hi);
  border-radius: 10px;
  padding: 16px;
}

.lock-card h3 {
  margin: 0 0 6px;
  color: var(--green);
  font-size: 15px;
}

.lock-card p {
  margin: 0 0 12px;
  color: #8aa892;
  font-size: 13px;
}

.lock-card input {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #222;
  background: #000;
  color: #f0f0f0;
  margin-bottom: 12px;
  outline: none;
}

.lock-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.members {
  border-top: 1px solid var(--border);
  padding: 10px 14px 14px;
  max-height: 30vh;
  overflow-y: auto;
  font-size: 12px;
  color: var(--muted);
}

.members h3 {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #555;
}

.members ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.members li {
  padding: 4px 0;
  color: #aaa;
}

/* Wider screens: side panel always visible */
@media (min-width: 800px) {
  .app {
    flex-direction: row;
  }

  .chat-pane {
    flex: 1;
    min-width: 0;
    border-right: 1px solid var(--border);
  }

  .drawer-backdrop { display: none !important; }

  .side {
    position: relative;
    transform: none;
    width: 280px;
    flex-shrink: 0;
    border-left: none;
    z-index: 1;
  }

  .side-head .close-side,
  #btn-rooms {
    display: none;
  }
}
