/* =====================================================================
   deadp0et — ephemeral e2e encrypted chat
   Aesthetic: deadplug.digital — #0a0a0a / #cc0000 / #e0e0e0
   ===================================================================== */

:root {
  --red:        #cc0000;
  --red-bright: #ff2222;
  --red-dim:    #880000;
  --red-deep:   #3a0000;
  --red-soft:   #ffb4b4;
  --bg:         #0a0a0a;
  --bg-card:    #111111;
  --bg-card-hover: #130000;
  --bg-panel:   rgba(17,17,17,0.9);
  --border:     #2a0000;
  --border-mid: #3a0000;
  --border-med: #4d0000;
  --border-hi:  #cc0000;
  --text:       #e0e0e0;
  --text-dim:   #666666;
  --text-muted: #888888;
  --text-bright:#ffffff;
  --green:      #00cc44;
  --yellow:     #cc8800;
  --danger:     #ff2222;
  --shadow-sm:  0 4px 16px rgba(0,0,0,0.5);
  --shadow-md:  0 8px 32px rgba(0,0,0,0.6);
  --radius:     0;            /* cut-corner cards, not rounded */
  --radius-sm:  0;
  --radius-pill:999px;
  --header-h:   52px;
  --font-mono: "SF Mono", "Cascadia Code", "Fira Code", Consolas, monospace;

  /* ── Extended surface tokens ──── */
  --bg-sunken:     #060606;
  --bg-elevated:   #161616;
  --bg-card-2:     #141414;
  --red-wash:      rgba(204,0,0,0.06);
  --border-subtle: rgba(42,0,0,0.4);
  --green-dim:     rgba(0,204,68,0.4);
  /* type scale */
  --text-xs:   0.625rem;
  --text-sm:   0.75rem;
  --text-base: 0.9375rem;
  --text-md:   1.0625rem;
  --text-lg:   1.25rem;
  --text-xl:   2.125rem;
  /* spacing */
  --sp-1: 4px;  --sp-2: 8px;   --sp-3: 12px;
  --sp-4: 16px; --sp-5: 20px;  --sp-6: 24px;
  /* shadows */
  --shadow-header: 0 2px 24px rgba(0,0,0,0.75);
  --shadow-input:  0 -2px 20px rgba(0,0,0,0.55);
  --shadow-bubble: 0 2px 8px rgba(0,0,0,0.35);
}

/* ── Reset ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; overflow: hidden; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ── Animated CSS grid background ─────────────────────────────── */
.bg-grid {
  position: fixed; inset: 0;
  pointer-events: none; z-index: 0;
  background-image:
    linear-gradient(rgba(204,0,0,0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(204,0,0,0.035) 1px, transparent 1px);
  background-size: 36px 36px;
  animation: gridDrift 30s linear infinite;
}
@keyframes gridDrift {
  0%   { background-position: 0 0; }
  100% { background-position: 36px 36px; }
}

/* ── Scanlines ─────────────────────────────────────────────────── */
.bg-scanlines {
  position: fixed; inset: 0;
  pointer-events: none; z-index: 0;
  background: repeating-linear-gradient(
    0deg, transparent, transparent 3px,
    rgba(0,0,0,0.18) 3px, rgba(0,0,0,0.18) 4px
  );
}

/* ── Vignette ──────────────────────────────────────────────────── */
.vignette {
  position: fixed; inset: 0;
  pointer-events: none; z-index: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% 110%, rgba(180,0,0,0.1) 0%, transparent 65%),
    radial-gradient(ellipse at center, transparent 45%, rgba(0,0,0,0.72) 100%);
}

/* ── App shell ─────────────────────────────────────────────────── */
.app-shell {
  position: relative; z-index: 1;
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh;
  width: min(480px, 100vw);
  margin: 0 auto;
  box-shadow: 0 0 0 1px var(--border), 0 0 80px rgba(204,0,0,0.07);
  background: var(--bg);
  overflow: hidden;
}

/* ── Header ────────────────────────────────────────────────────── */
.app-header {
  flex-shrink: 0;
  height: var(--header-h);
  background: rgba(10,10,10,0.97);
  border-top: 2px solid var(--red-dim);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow-header);
}

.app-header-inner {
  display: flex; align-items: center; gap: 10px;
  height: 100%; padding: 0 16px;
}

/* Logo with spinning rings */
.logo-mark {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  width: 32px; height: 32px;
}

.logo-ring {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 1px solid transparent;
}
.lr-1 {
  border-top-color: var(--red);
  border-right-color: var(--red-dim);
  animation: spin 4s linear infinite;
  opacity: 0.7;
}
.lr-2 {
  inset: -11px;
  border-bottom-color: var(--red-dim);
  animation: spin 7s linear infinite reverse;
  opacity: 0.3;
}
@keyframes spin { to { transform: rotate(360deg); } }

.app-brand {
  display: flex; flex-direction: column; gap: 2px;
  min-width: 0; flex: 1;
}

.app-title {
  font-size: 1.05rem; font-weight: 700;
  font-family: var(--font-mono);
  color: #b0b0b0;
  letter-spacing: 0.02em; line-height: 1;
}

.app-title-p0 {
  color: var(--red);
  text-shadow: 0 0 8px rgba(204,0,0,0.55);
  animation: neonFlicker 6s infinite;
}

.app-brand-line {
  font-size: 0.58rem; letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(220,180,180,0.5);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Status area */
.header-status {
  display: flex; align-items: center; gap: 6px;
  flex-shrink: 0;
}

.status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: background 0.3s, box-shadow 0.3s;
}
/* dot states set via JS class on parent .header-status */
.header-status.s-offline  .status-dot { display: none; }
.header-status.s-waiting  .status-dot {
  background: var(--yellow);
  box-shadow: 0 0 6px var(--yellow);
  animation: dotPulse 1.8s ease-in-out infinite;
}
.header-status.s-connected .status-dot {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
  animation: dotPulse 2.4s ease-in-out infinite;
}
@keyframes dotPulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

.header-badge {
  font-size: 0.58rem;
  font-family: var(--font-mono);
  letter-spacing: 0.1em; text-transform: uppercase;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  white-space: nowrap;
  transition: color 0.3s, border-color 0.3s, background 0.3s;
}
.header-status.s-offline  .header-badge {
  color: rgba(255,120,120,0.65);
  background: rgba(204,0,0,0.05);
  border-color: rgba(180,0,0,0.35);
}
.header-status.s-waiting  .header-badge {
  color: rgba(255,200,80,0.9);
  background: rgba(180,100,0,0.08);
  border-color: rgba(180,100,0,0.4);
}
.header-status.s-connected .header-badge {
  color: rgba(80,220,120,0.9);
  background: rgba(0,160,60,0.07);
  border-color: rgba(0,160,60,0.38);
}

/* ── Neon flicker ──────────────────────────────────────────────── */
@keyframes neonFlicker {
  0%,19%,21%,25%,54%,56%,91%,100% {
    text-shadow: 0 0 6px rgba(255,34,34,0.8), 0 0 20px rgba(255,34,34,0.5), 0 0 50px rgba(204,0,0,0.3);
    opacity: 1;
  }
  20%,24% { opacity: 0;    text-shadow: none; }
  55%     { opacity: 0;    text-shadow: none; }
  92%     { opacity: 0.82; text-shadow: 0 0 2px rgba(255,34,34,0.4); }
  93%     { opacity: 1;    text-shadow: 0 0 6px rgba(255,34,34,0.8), 0 0 20px rgba(255,34,34,0.5); }
  95%     { opacity: 0.88; }
  96%     { opacity: 1; }
}

/* ── Screen system ─────────────────────────────────────────────── */
.screen { display: none; flex: 1; flex-direction: column; overflow: hidden; }
.screen.active { display: flex; animation: screenIn 0.2s ease; }

@keyframes screenIn {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: translateY(0); }
}

.screen-scroll {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 22px 16px;
  scroll-behavior: smooth;
}
.screen-scroll::-webkit-scrollbar { width: 3px; }
.screen-scroll::-webkit-scrollbar-track { background: transparent; }
.screen-scroll::-webkit-scrollbar-thumb { background: var(--border-med); border-radius: 2px; }

.screen-centered {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  min-height: 100%; text-align: center; gap: 16px;
}

/* ── Landing: hero block ───────────────────────────────────────── */
.hero-block {
  display: flex; flex-direction: column; align-items: center;
  padding: 20px 0 24px;
  animation: screenIn 0.4s ease;
}

.hero-logo-wrap {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  width: 80px; height: 80px; margin-bottom: 16px;
}

.hero-ring {
  position: absolute;
  border-radius: 50%;
  border: 1px solid transparent;
}
.hero-ring-1 {
  inset: -8px;
  border-top-color: var(--red);
  border-right-color: var(--red-dim);
  animation: spin 5s linear infinite;
  opacity: 0.6;
}
.hero-ring-2 {
  inset: -18px;
  border-bottom-color: var(--red-dim);
  border-left-color: rgba(204,0,0,0.2);
  animation: spin 9s linear infinite reverse;
  opacity: 0.35;
}

/* glow on the hero shield */
.hero-logo-wrap svg {
  filter: drop-shadow(0 0 8px rgba(204,0,0,0.5)) drop-shadow(0 0 22px rgba(204,0,0,0.25));
  animation: logoPulse 3.5s ease-in-out infinite;
}
@keyframes logoPulse {
  0%, 100% { filter: drop-shadow(0 0 8px rgba(204,0,0,0.5)) drop-shadow(0 0 22px rgba(204,0,0,0.25)); }
  50%       { filter: drop-shadow(0 0 14px rgba(255,34,34,0.75)) drop-shadow(0 0 40px rgba(204,0,0,0.4)); }
}

.hero-wordmark {
  font-family: var(--font-mono);
  font-size: 2.1rem; font-weight: 800;
  letter-spacing: 0.04em; line-height: 1;
  color: var(--text-bright);
  text-shadow: 0 0 4px rgba(255,255,255,0.15);
}
.hero-p0 {
  color: var(--red-bright);
  text-shadow:
    0 0 6px rgba(255,34,34,0.8),
    0 0 20px rgba(255,34,34,0.5),
    0 0 50px rgba(204,0,0,0.3);
  animation: neonFlicker 5s infinite;
}

.hero-status-row {
  display: flex; align-items: center; gap: 7px;
  margin-top: 10px;
}

.hero-status-dot {
  width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0;
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
  animation: dotPulse 2s ease-in-out infinite;
}

.hero-status-text {
  font-family: var(--font-mono);
  font-size: 0.62rem; letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ── Info card (cut-corner) ────────────────────────────────────── */
.info-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border-mid);
  clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 12px, 100% 100%, 12px 100%, 0 calc(100% - 12px));
  padding: 18px;
  margin-bottom: 18px;
  animation: screenIn 0.45s ease;
}

.info-card::before {
  /* top-right corner accent line */
  content: '';
  position: absolute; top: 0; right: 0;
  width: 12px; height: 12px;
  border-top: 1px solid var(--border-med);
  border-right: 1px solid var(--border-med);
}

/* red bloom behind info card */
.info-card::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(135deg, rgba(204,0,0,0.06) 0%, transparent 50%);
  pointer-events: none;
}

.info-card-corner {
  position: absolute; bottom: 0; left: 0;
  width: 12px; height: 12px;
  border-bottom: 1px solid var(--border-med);
  border-left: 1px solid var(--border-med);
  pointer-events: none;
}

.info-card-text {
  font-size: 0.85rem; line-height: 1.68;
  color: rgba(224,224,224,0.72);
  margin-bottom: 14px;
  position: relative; z-index: 1;
}

.chips-row {
  display: flex; flex-wrap: wrap; gap: 7px;
  position: relative; z-index: 1;
}

.chip {
  padding: 4px 10px;
  border: 1px solid rgba(204,0,0,0.22);
  background: rgba(0,0,0,0.3);
  color: var(--red-soft);
  font-size: 0.7rem; letter-spacing: 0.05em;
  font-family: var(--font-mono);
  clip-path: polygon(0 0, calc(100% - 5px) 0, 100% 5px, 100% 100%, 5px 100%, 0 calc(100% - 5px));
}

/* ── Action group ──────────────────────────────────────────────── */
.action-group {
  display: flex; flex-direction: column; gap: 12px;
  animation: screenIn 0.5s ease;
}

/* Divider with diamond */
.divider-row {
  display: flex; align-items: center; gap: 10px;
}
.divider-line {
  flex: 1; height: 1px;
  background: linear-gradient(90deg, transparent, var(--border-mid), transparent);
}
.divider-diamond {
  width: 6px; height: 6px;
  background: var(--red); transform: rotate(45deg);
  box-shadow: 0 0 6px var(--red);
  flex-shrink: 0;
}

/* ── Buttons ───────────────────────────────────────────────────── */
button { -webkit-tap-highlight-color: transparent; }

.btn-primary, .btn-secondary, .btn-ghost {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  cursor: pointer;
  border: 1px solid transparent;
  font-family: inherit; font-weight: 600;
  transition: all 0.15s;
  position: relative; overflow: hidden;
}

/* scan-sweep on primary hover */
.btn-primary::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(180deg, transparent 0%, rgba(255,255,255,0.07) 50%, transparent 100%);
  transform: translateY(-100%);
}
.btn-primary:hover::after {
  animation: scanSweep 0.55s ease-out forwards;
}
@keyframes scanSweep {
  0%   { transform: translateY(-100%); }
  100% { transform: translateY(100%); }
}

.btn-primary {
  padding: 14px 20px; font-size: 0.95rem;
  background: var(--red); color: #fff; border-color: var(--red);
  clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 10px, 100% 100%, 10px 100%, 0 calc(100% - 10px));
  box-shadow: 0 0 20px rgba(204,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.08);
}
.btn-primary:hover, .btn-primary:focus-visible {
  background: var(--red-bright); border-color: var(--red-bright);
  box-shadow: 0 0 28px rgba(255,34,34,0.55), 0 0 0 1px rgba(255,34,34,0.3);
}
.btn-primary:active { transform: scale(0.98); }

.btn-secondary {
  padding: 13px 18px; font-size: 0.9rem;
  background: transparent; color: var(--red-soft);
  border-color: var(--border-med);
  clip-path: polygon(0 0, calc(100% - 8px) 0, 100% 8px, 100% 100%, 8px 100%, 0 calc(100% - 8px));
}
.btn-secondary:hover, .btn-secondary:focus-visible {
  border-color: var(--red);
  background: rgba(204,0,0,0.07);
  color: var(--text-bright);
}
.btn-secondary:active { transform: scale(0.98); }

.btn-ghost {
  padding: 8px 12px; font-size: 0.78rem; font-weight: 500;
  min-height: 44px;
  background: transparent; color: var(--text-dim);
  border: 1px solid var(--border);
}
.btn-ghost:hover, .btn-ghost:focus-visible {
  color: var(--text); border-color: var(--border-med);
}

.btn-sm { padding: 7px 13px; font-size: 0.78rem; min-height: 44px; }
.btn-block { width: 100%; }
.btn-cancel { margin-top: 6px; color: rgba(130,0,0,0.7); border-color: transparent; }
.btn-cancel:hover { color: var(--red-bright); border-color: var(--border); }
.mt-10 { margin-top: 10px; }

button:focus-visible { outline: 2px solid var(--red-dim); outline-offset: 2px; }

/* Input */
.join-row { display: flex; gap: 8px; }

.input-code {
  flex: 1; min-width: 0;
  padding: 13px 14px;
  background: rgba(8,8,8,0.9);
  border: 1px solid var(--border-med);
  color: var(--text-bright);
  font-size: 1rem; font-family: var(--font-mono);
  letter-spacing: 0.2em; text-align: center; text-transform: uppercase;
  outline: none;
  clip-path: polygon(0 0, calc(100% - 8px) 0, 100% 8px, 100% 100%, 8px 100%, 0 calc(100% - 8px));
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-appearance: none;
}
.input-code::placeholder {
  color: var(--text-dim); letter-spacing: 0.1em; font-size: 0.75rem;
}
.input-code:focus {
  border-color: var(--red-dim);
  box-shadow: 0 0 0 2px rgba(204,0,0,0.1), inset 0 0 20px rgba(204,0,0,0.04);
}

.error-msg {
  color: var(--red-bright); font-size: 0.82rem;
  padding: 10px 12px;
  background: rgba(204,0,0,0.07);
  border: 1px solid rgba(204,0,0,0.18);
  border-left: 2px solid var(--red);
}

/* ── Chat screen ───────────────────────────────────────────────── */
.screen-chat { position: relative; }

.chat-messages {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 14px 14px 8px;
  display: flex; flex-direction: column; gap: 5px;
  scroll-behavior: smooth;
  background: var(--bg-sunken);
  overscroll-behavior: contain;
}
.chat-messages::-webkit-scrollbar { width: 3px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border-med); border-radius: 2px; }

/* message wrappers */
.msg { display: flex; flex-direction: column; max-width: 80%; }
.msg-me   { align-self: flex-end;   align-items: flex-end; }
.msg-them { align-self: flex-start; align-items: flex-start; }

/* system messages */
.msg-system {
  align-self: center; max-width: 94%;
  text-align: center;
  font-size: 0.7rem; font-family: var(--font-mono);
  color: var(--text-dim); line-height: 1.55; letter-spacing: 0.02em;
  padding: 5px 12px; margin: 5px 0;
  background: rgba(14,14,14,0.8);
  border: 1px solid var(--border);
  clip-path: polygon(0 0, calc(100% - 6px) 0, 100% 6px, 100% 100%, 6px 100%, 0 calc(100% - 6px));
}

/* bubbles */
.msg-bubble {
  padding: 9px 13px;
  line-height: 1.55; font-size: 0.92rem;
  word-wrap: break-word; overflow-wrap: break-word;
}

.msg-me .msg-bubble {
  background: rgba(170,0,0,0.25);
  border: 1px solid rgba(204,0,0,0.3);
  color: var(--text-bright);
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%);
}

.msg-them .msg-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border-med);
  color: var(--text);
  clip-path: polygon(8px 0, 100% 0, 100% 100%, 0 100%, 0 8px);
}

.msg-ts {
  font-size: 0.62rem; color: var(--text-dim);
  padding: 2px 5px; letter-spacing: 0.04em;
  font-family: var(--font-mono);
}

/* ── Message grouping ──────────────────────────────────────────── */
.msg-group-mid,
.msg-group-end { margin-top: 2px; }

/* hide timestamp on all but the last bubble of a group */
.msg-group-start .msg-footer,
.msg-group-mid   .msg-footer { display: none; }

/* ── Message enter animation ───────────────────────────────────── */
@keyframes msgEnter {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.msg.entering { animation: msgEnter 0.2s ease-out forwards; }

/* ── Typing indicator ──────────────────────────────────────────── */
.typing-indicator {
  flex-shrink: 0;
  display: flex; align-items: center; gap: 4px;
  padding: 5px 18px 3px;
  min-height: 20px;
}
.typing-indicator[hidden] { display: none; }

.typing-dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--text-dim);
  animation: typingBounce 1.3s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.18s; }
.typing-dot:nth-child(3) { animation-delay: 0.36s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0);    opacity: 0.5; }
  30%            { transform: translateY(-5px); opacity: 1;   }
}

/* ── Chat input area ───────────────────────────────────────────── */
.chat-input-area {
  flex-shrink: 0;
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: rgba(10,10,10,0.97);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  position: relative;
  box-shadow: var(--shadow-input);
}

/* subtle encrypted label over input */
.chat-input-area::before {
  content: 'ENCRYPTED';
  position: absolute; top: 4px; left: 50%; transform: translateX(-50%);
  font-size: 0.48rem; letter-spacing: 0.18em;
  font-family: var(--font-mono);
  color: rgba(180,0,0,0.3);
  pointer-events: none;
}

.chat-textarea {
  flex: 1; min-width: 0;
  min-height: 40px; max-height: 120px;
  padding: 10px 13px;
  background: rgba(12,12,12,0.95);
  border: 1px solid var(--border-med);
  color: var(--text-bright);
  font-family: inherit; font-size: 0.93rem; line-height: 1.45;
  resize: none; outline: none;
  clip-path: polygon(0 0, calc(100% - 7px) 0, 100% 7px, 100% 100%, 7px 100%, 0 calc(100% - 7px));
  transition: border-color 0.2s;
  -webkit-appearance: none;
}
.chat-textarea::placeholder { color: var(--text-dim); }
.chat-textarea:focus {
  border-color: var(--red-dim);
  box-shadow: 0 0 0 1px rgba(204,0,0,0.08), inset 0 0 20px rgba(204,0,0,0.03);
}

.btn-send-msg {
  flex-shrink: 0; width: 42px; height: 42px;
  display: flex; align-items: center; justify-content: center;
  background: var(--red); border: none; color: #fff;
  cursor: pointer;
  clip-path: polygon(0 0, calc(100% - 8px) 0, 100% 8px, 100% 100%, 8px 100%, 0 calc(100% - 8px));
  box-shadow: 0 0 16px rgba(204,0,0,0.45);
  transition: background 0.15s, transform 0.1s;
  position: relative; overflow: hidden;
}
.btn-send-msg::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(180deg, transparent, rgba(255,255,255,0.07) 50%, transparent);
  transform: translateY(-100%);
}
.btn-send-msg:hover::after { animation: scanSweep 0.5s ease-out forwards; }
.btn-send-msg:hover  { background: var(--red-bright); }
.btn-send-msg:active { transform: scale(0.93); }
.btn-send-msg:focus-visible { outline: 2px solid var(--red-dim); outline-offset: 2px; }

/* ── Ended screen ──────────────────────────────────────────────── */
.ended-icon {
  opacity: 0.8;
  filter: drop-shadow(0 0 10px rgba(204,0,0,0.3));
}

.ended-title {
  font-family: var(--font-mono);
  font-size: 1.3rem; font-weight: 700;
  color: var(--text-bright);
}

.ended-reason {
  font-size: 0.88rem; color: var(--text-dim);
  max-width: 28ch; line-height: 1.6;
  font-family: var(--font-mono);
  margin-bottom: 4px;
}

/* ── Auth screen ───────────────────────────────────────────────── */
.hero-sub {
  font-size: 0.72rem; font-family: var(--font-mono);
  letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--text-dim); margin-top: 10px;
}

.auth-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border-mid);
  padding: 22px 18px 18px;
  clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 12px, 100% 100%, 12px 100%, 0 calc(100% - 12px));
}
.auth-card::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(135deg, rgba(204,0,0,0.05) 0%, transparent 50%);
  pointer-events: none;
}
.auth-card-corner {
  position: absolute; top: 0; right: 0;
  width: 12px; height: 12px;
  border-top: 1px solid var(--border-med);
  border-right: 1px solid var(--border-med);
  pointer-events: none;
}

.auth-tabs {
  display: flex; gap: 0; margin-bottom: 20px;
  border: 1px solid var(--border-med);
  clip-path: polygon(0 0, calc(100% - 8px) 0, 100% 8px, 100% 100%, 8px 100%, 0 calc(100% - 8px));
  overflow: hidden;
}
.auth-tab {
  flex: 1; padding: 9px; min-height: 44px;
  background: transparent; border: none;
  font-size: 0.82rem; font-weight: 600;
  font-family: var(--font-mono); letter-spacing: 0.06em;
  color: var(--text-dim); cursor: pointer;
  transition: background 0.15s, color 0.15s;
  position: relative; z-index: 1;
}
.auth-tab.active {
  background: rgba(204,0,0,0.12);
  color: var(--red-soft);
  border-bottom: 2px solid var(--red-dim);
}
.auth-tab:hover:not(.active) { background: rgba(255,255,255,0.03); color: var(--text); }

.auth-fields { display: flex; flex-direction: column; gap: 14px; margin-bottom: 14px; }

.field-label {
  display: block;
  font-size: 0.62rem; font-weight: 600;
  letter-spacing: 0.14em; text-transform: uppercase;
  color: rgba(180,0,0,0.75);
  margin-bottom: 5px;
  font-family: var(--font-mono);
}

.field-input {
  display: block; width: 100%;
  padding: 11px 13px;
  background: rgba(6,6,6,0.9);
  border: 1px solid var(--border-med);
  color: var(--text-bright);
  font-size: 1rem; font-family: inherit;
  outline: none;
  clip-path: polygon(0 0, calc(100% - 7px) 0, 100% 7px, 100% 100%, 7px 100%, 0 calc(100% - 7px));
  transition: border-color 0.2s;
  -webkit-appearance: none;
}
.field-input::placeholder { color: var(--text-dim); }
.field-input:focus {
  border-color: var(--red-dim);
  box-shadow: 0 0 0 1px rgba(204,0,0,0.08), inset 0 0 20px rgba(204,0,0,0.03);
}

.auth-error {
  font-size: 0.82rem; color: var(--red-bright);
  padding: 9px 12px; margin-bottom: 12px;
  background: rgba(204,0,0,0.07);
  border: 1px solid rgba(204,0,0,0.18);
  border-left: 2px solid var(--red);
}

.auth-note {
  margin-top: 14px;
  font-size: 0.68rem; line-height: 1.6;
  color: var(--text-dim); font-family: var(--font-mono);
  letter-spacing: 0.02em;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

/* ── Unlock screen ─────────────────────────────────────────────── */
.unlock-icon { opacity: 0.85; filter: drop-shadow(0 0 10px rgba(204,0,0,0.3)); }
.unlock-title {
  font-family: var(--font-mono); font-size: 1.1rem; font-weight: 700;
  color: var(--text-bright);
}
.unlock-sub {
  font-size: 0.82rem; color: var(--text-dim);
  line-height: 1.55; max-width: 28ch; text-align: center;
}
.unlock-input { max-width: 280px; text-align: center; letter-spacing: 0.12em; }

/* ── Home screen ───────────────────────────────────────────────── */
.screen-home { overflow: hidden; }

.home-toolbar {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px 10px;
  border-bottom: 1px solid var(--border);
}
.home-title {
  font-family: var(--font-mono); font-size: 0.78rem;
  letter-spacing: 0.14em; text-transform: uppercase;
  color: rgba(200,0,0,0.8);
  padding-left: 10px; border-left: 2px solid var(--red-dim);
}
.home-toolbar-right { display: flex; gap: 6px; }

.conv-list {
  flex: 1; overflow-y: auto; overflow-x: hidden;
}
.conv-list::-webkit-scrollbar { width: 3px; }
.conv-list::-webkit-scrollbar-thumb { background: var(--border-med); }

.conv-empty {
  text-align: center; padding: 40px 20px;
  font-size: 0.82rem; color: var(--text-dim); line-height: 1.7;
  font-family: var(--font-mono);
}

.conv-item {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid rgba(42,0,0,0.5);
  cursor: pointer; position: relative;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.conv-item::before {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(180deg, transparent 0%, rgba(204,0,0,0.04) 50%, transparent 100%);
  transform: translateY(-100%);
}
.conv-item:hover { background: var(--bg-card-hover); }
.conv-item:hover::before { animation: scanSweep 0.5s ease-out forwards; }

.conv-avatar {
  flex-shrink: 0; width: 42px; height: 42px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(204,0,0,0.1);
  border: 1px solid rgba(204,0,0,0.2);
  font-weight: 800; font-size: 1rem;
  color: var(--red-soft);
  clip-path: polygon(0 0, calc(100% - 6px) 0, 100% 6px, 100% 100%, 6px 100%, 0 calc(100% - 6px));
}

.conv-info { flex: 1; min-width: 0; }
.conv-name {
  display: block; font-weight: 600; font-size: 0.9rem;
  color: var(--text-bright); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.conv-preview {
  display: block; font-size: 0.72rem;
  color: var(--text-dim); font-family: var(--font-mono);
  letter-spacing: 0.02em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-time {
  flex-shrink: 0;
  font-size: 0.65rem; color: var(--text-dim);
  font-family: var(--font-mono);
}
.conv-badge {
  flex-shrink: 0;
  min-width: 18px; height: 18px; padding: 0 5px;
  background: var(--red); color: #fff;
  font-size: 0.68rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-pill);
}
.conv-item.has-unread .conv-name { color: var(--text-bright); }

/* ── Chat screen ───────────────────────────────────────────────── */
.chat-header {
  flex-shrink: 0;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(10,10,10,0.97);
  box-shadow: 0 2px 12px rgba(0,0,0,0.5);
}
.chat-peer-info { flex: 1; min-width: 0; }
.chat-peer-name {
  display: block; font-weight: 700; font-size: 0.95rem;
  color: var(--text-bright); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.chat-peer-sub {
  font-size: 0.6rem; font-family: var(--font-mono);
  letter-spacing: 0.08em; text-transform: uppercase;
  color: rgba(0,200,70,0.6);
}

/* Media preview bar */
.media-preview-wrap {
  flex-shrink: 0;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  background: rgba(10,10,10,0.95);
}
.media-preview { flex: 1; min-width: 0; }
.media-thumb {
  max-height: 80px; max-width: 100%;
  border: 1px solid var(--border-med);
  display: block;
}
.media-file-chip {
  font-size: 0.8rem; color: var(--text-dim);
  font-family: var(--font-mono);
}

/* Attach button */
.btn-attach {
  flex-shrink: 0; width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid var(--border);
  color: var(--text-dim); cursor: pointer;
  clip-path: polygon(0 0, calc(100% - 6px) 0, 100% 6px, 100% 100%, 6px 100%, 0 calc(100% - 6px));
  transition: color 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.btn-attach:hover { color: var(--red-soft); border-color: var(--border-med); }

/* Message: media attachment */
.msg-media { margin-bottom: 4px; }
.msg-media-load {
  display: block; width: 100%;
  padding: 10px 12px;
  background: rgba(8,8,8,0.9);
  border: 1px dashed rgba(204,0,0,0.25);
  color: var(--text-dim); cursor: pointer;
  font-size: 0.78rem; font-family: var(--font-mono);
  letter-spacing: 0.02em; text-align: left;
  clip-path: polygon(0 0, calc(100% - 6px) 0, 100% 6px, 100% 100%, 6px 100%, 0 calc(100% - 6px));
  transition: border-color 0.15s, color 0.15s;
}
.msg-media-load:hover:not(:disabled) {
  border-color: rgba(204,0,0,0.5); color: var(--red-soft);
}
.msg-media-load:disabled { opacity: 0.6; cursor: default; }
.msg-media-img {
  max-width: 100%; max-height: 220px; display: block;
  border: 1px solid var(--border-med);
}

.msg-text { display: block; }
.msg-footer {
  display: flex; align-items: center; gap: 5px;
  padding: 2px 4px;
}
.msg-tick { font-size: 0.65rem; color: var(--text-dim); }
.msg-tick.tick-sent { color: rgba(0,200,70,0.7); }

/* ── Modal ─────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.75);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  backdrop-filter: blur(4px);
}
.modal-overlay[hidden] { display: none; }

.modal-box {
  position: relative; width: 100%; max-width: 340px;
  background: var(--bg-card);
  border: 1px solid var(--border-med);
  padding: 20px;
  clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 12px, 100% 100%, 12px 100%, 0 calc(100% - 12px));
  animation: modalIn 0.22s ease-out;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-box::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(135deg, rgba(204,0,0,0.04) 0%, transparent 45%);
  pointer-events: none;
}
.modal-box-corner {
  position: absolute; top: 0; right: 0;
  width: 12px; height: 12px;
  border-top: 1px solid var(--border-med);
  border-right: 1px solid var(--border-med);
  pointer-events: none;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.modal-title {
  font-family: var(--font-mono); font-size: 0.8rem;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: rgba(200,0,0,0.8);
}
.mt-12 { margin-top: 12px; }

/* ── Trust verification modal ──────────────────────────────────── */
.trust-modal {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.85);
  align-items: center; justify-content: center;
  padding: 20px;
  backdrop-filter: blur(6px);
}
.trust-modal-box {
  position: relative; width: 100%; max-width: 460px;
  background: var(--bg-card);
  border: 1px solid var(--border-med);
  padding: 24px;
  clip-path: polygon(0 0, calc(100% - 14px) 0, 100% 14px, 100% 100%, 14px 100%, 0 calc(100% - 14px));
  animation: modalIn 0.22s ease-out;
}
.trust-modal-eyebrow {
  font-family: var(--font-mono); font-size: 0.78rem;
  letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--red);
  margin-bottom: 12px;
}
.trust-modal-title-changed {
  color: var(--red-bright);
}
.trust-modal-sub {
  font-size: 0.92rem; line-height: 1.5;
  color: #c8c0bb;
  margin: 0 0 18px;
}
.trust-modal-number-wrap {
  background: #050505;
  border: 1px solid var(--red-deep);
  padding: 14px;
  margin: 0 0 14px;
  text-align: center;
}
.trust-modal-number {
  font-family: var(--font-mono);
  font-size: 1.05rem;
  letter-spacing: 0.06em;
  color: #ffb000;
  display: inline-block;
  white-space: pre-wrap; word-break: break-all;
}
.trust-modal-previous {
  font-family: var(--font-mono); font-size: 0.78rem;
  color: #888; margin-bottom: 14px;
}
.trust-modal-ack-row {
  display: flex; align-items: flex-start; gap: 10px;
  font-size: 0.92rem; line-height: 1.45;
  color: #dedede;
  margin-bottom: 18px;
  cursor: pointer;
}
.trust-modal-ack-row input[type="checkbox"] {
  margin-top: 3px;
  width: 16px; height: 16px;
  accent-color: var(--red);
  flex-shrink: 0;
}
.trust-modal-actions {
  display: flex; gap: 10px; justify-content: flex-end;
}

/* ── Safe-area / iOS notch ─────────────────────────────────────── */
@supports (padding-top: env(safe-area-inset-top)) {
  .app-header {
    padding-top: env(safe-area-inset-top, 0);
    height: calc(var(--header-h) + env(safe-area-inset-top, 0));
  }
}
