/* Self-hosted JetBrains Mono — no external requests to Google (H1) */
@font-face {
  font-family: 'JetBrains Mono';
  src: url('/fonts/JetBrainsMono-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'JetBrains Mono';
  src: url('/fonts/JetBrainsMono-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #0a0a0a;
  --surface: #161616;
  --surface-2: #222222;
  --border: #2e2e2e;
  --text: #f0f0f0;
  --text-secondary: #d4d4d4;
  --text-dim: #777777;
  --accent: #e0e0e0;
  --green: #30d158;
  --red: #ff453a;
  --orange: #ff9f0a;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

html, body {
  height: 100%;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Helvetica Neue', 'Roboto', sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}

.hidden {
  display: none !important;
}

/* Animated Background Canvas */
#ghost-bg {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

/* App Container */
.app {
  position: relative;
  z-index: 1;
  height: 100%;
  height: 100dvh;
  max-width: 500px;
  margin: 0 auto;
}

/* Screens */
.screen {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ===== WELCOME SCREEN ===== */
.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: calc(20px + var(--safe-top)) 24px calc(16px + var(--safe-bottom));
  justify-content: center;
}

.welcome-header {
  text-align: center;
  margin-bottom: 48px;
}

.logo {
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface-2) 100%);
  border: 1px solid var(--border);
  border-radius: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  font-weight: 700;
  margin: 0 auto 16px;
  color: #f0f0f0;
}

.ghost-title {
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 6px;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.92);
  text-shadow: 0 0 30px rgba(255, 255, 255, 0.2), 0 0 80px rgba(255, 255, 255, 0.06);
  margin-bottom: 8px;
  width: 100%;
  max-width: 100%;
  text-align: center;
}

.welcome-header h1 {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 6px;
}

.subtitle {
  color: rgba(255, 255, 255, 0.4);
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-size: 14px;
  font-weight: 400;
  letter-spacing: 3px;
  text-transform: uppercase;
}

.welcome-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Primary Button */
.btn-main {
  width: 100%;
  height: 54px;
  background: #f0f0f0;
  color: #0a0a0a;
  border: none;
  border-radius: 14px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.1s, opacity 0.1s;
  -webkit-touch-callout: none;
  user-select: none;
}

.btn-main:active {
  transform: scale(0.97);
  opacity: 0.85;
}

.btn-main:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-main svg {
  width: 20px;
  height: 20px;
  fill: #0a0a0a;
}

/* Divider */
.divider {
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--text-dim);
  font-size: 14px;
  padding: 4px 0;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Join Form */
.join-form {
  display: flex;
  gap: 10px;
}

.join-form input {
  flex: 1;
  height: 50px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0 16px;
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

.join-form input:focus {
  border-color: #888;
}

.join-form input::placeholder {
  color: var(--text-dim);
}

.btn-join {
  height: 50px;
  padding: 0 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.btn-join:active {
  background: var(--surface-2);
}

.btn-join:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Privacy Toggle */
.privacy-switch {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border-radius: 12px;
  cursor: pointer;
  -webkit-touch-callout: none;
  user-select: none;
}

.privacy-switch input {
  display: none;
}

.switch-track {
  width: 51px;
  height: 31px;
  background: var(--border);
  border-radius: 16px;
  position: relative;
  transition: background 0.25s;
  flex-shrink: 0;
}

.switch-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  background: white;
  border-radius: 50%;
  transition: transform 0.25s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.privacy-switch input:checked + .switch-track {
  background: var(--green);
}

.privacy-switch input:checked + .switch-track::after {
  transform: translateX(20px);
}

.switch-label {
  font-size: 15px;
  color: var(--text-dim);
}

/* App Promo Banner */
.app-promo {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  -webkit-touch-callout: none;
  user-select: none;
}

.app-promo:active {
  background: var(--surface-2);
  transform: scale(0.98);
}

.app-promo-icon {
  width: 44px;
  height: 44px;
  background: rgba(10, 132, 255, 0.12);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.app-promo-icon.android {
  background: rgba(61, 220, 132, 0.12);
}

.app-promo-icon.ios {
  background: rgba(255, 255, 255, 0.08);
}

.app-promo-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.app-promo-text strong {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.app-promo-text span {
  font-size: 13px;
  color: var(--text-dim);
}

.app-promo-arrow {
  flex-shrink: 0;
  fill: none;
  stroke: var(--text-dim);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}


/* Welcome Footer */
.welcome-footer {
  display: flex;
  justify-content: center;
  gap: 20px;
  padding-top: 32px;
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.25);
  letter-spacing: 1px;
  flex-wrap: wrap;
}

/* ===== WAITING SCREEN ===== */
.waiting {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-top: calc(24px + var(--safe-top));
  padding-bottom: calc(24px + var(--safe-bottom));
  text-align: center;
}

.loader {
  width: 44px;
  height: 44px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 28px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.waiting-text {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 24px;
}

.room-code {
  display: none;
}

.btn-copy {
  width: 40px;
  height: 40px;
  background: var(--surface-2);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.btn-copy svg {
  width: 20px;
  height: 20px;
  fill: var(--text-dim);
}

.btn-copy:active {
  background: var(--border);
}

.btn-copy-link {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  max-width: 320px;
  padding: 16px 28px;
  background: var(--surface-2);
  color: white;
  border: none;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.1s, background 0.15s, transform 0.1s;
  margin-bottom: 12px;
  -webkit-touch-callout: none;
}

.btn-copy-link svg {
  fill: white;
  flex-shrink: 0;
}

.btn-copy-link:active {
  opacity: 0.8;
  transform: scale(0.97);
}

.btn-copy-link.copied {
  background: var(--green);
}

.hint {
  font-size: 14px;
  color: var(--text-dim);
  margin-bottom: 32px;
  line-height: 1.4;
}

.btn-text {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  padding: 12px 20px;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-text:active {
  color: var(--text);
}

/* ===== CHAT SCREEN ===== */
.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: calc(12px + var(--safe-top));
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  min-height: 56px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-dot {
  width: 10px;
  height: 10px;
  background: var(--green);
  border-radius: 50%;
}

.status-dot.disconnected {
  background: var(--red);
}

.status-text {
  font-size: 14px;
  color: var(--text-dim);
  font-weight: 500;
}

.header-right {
  display: flex;
  gap: 8px;
}

.btn-icon {
  width: 44px;
  height: 44px;
  background: var(--surface);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
}

.btn-icon svg {
  width: 22px;
  height: 22px;
  fill: var(--text-dim);
}

.btn-icon:active {
  background: var(--surface-2);
  transform: scale(0.93);
}

.btn-icon:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.btn-icon.verified svg {
  fill: var(--green);
}

.btn-call svg {
  fill: var(--green);
}

.btn-call.calling {
  background: var(--red);
}

.btn-call.calling svg {
  fill: white;
}

/* Verify Panel */
.verify-panel {
  padding: 20px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  text-align: center;
}

.verify-hint {
  font-size: 14px;
  color: var(--text-dim);
  margin-bottom: 16px;
  line-height: 1.4;
}

.safety-code {
  display: block;
  padding: 16px;
  background: var(--bg);
  border-radius: 10px;
  font-family: 'SF Mono', 'Menlo', 'Roboto Mono', monospace;
  font-size: 15px;
  letter-spacing: 2px;
  word-break: break-all;
  margin-bottom: 16px;
}

.fingerprint-hidden {
  display: none;
}

.verify-buttons {
  display: flex;
  gap: 12px;
}

.btn-verify-ok,
.btn-verify-no {
  flex: 1;
  height: 48px;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.1s, transform 0.1s;
}

.btn-verify-ok {
  background: var(--green);
  color: white;
}

.btn-verify-no {
  background: var(--red);
  color: white;
}

.btn-verify-ok:active,
.btn-verify-no:active {
  opacity: 0.8;
  transform: scale(0.97);
}

/* Messages */
.messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.message {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 16px;
  line-height: 1.4;
  animation: fadeIn 0.2s;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

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

.message.sent {
  background: #d0d0d0;
  color: #0a0a0a;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.message.received {
  background: var(--surface-2);
  color: var(--text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.message.system {
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
  align-self: center;
  max-width: 100%;
  padding: 6px 0;
}

.message-time {
  font-size: 11px;
  opacity: 0.6;
  margin-top: 4px;
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 16px 2px;
  color: var(--text-dim);
  font-size: 13px;
}

.typing-dots {
  display: flex;
  gap: 3px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  background: var(--text-dim);
  border-radius: 50%;
  animation: typing-pulse 1.2s infinite;
  opacity: 0.3;
}

.typing-dots span:nth-child(1) { animation-delay: 0s; }
.typing-dots span:nth-child(2) { animation-delay: 0.4s; }
.typing-dots span:nth-child(3) { animation-delay: 0.8s; }

@keyframes typing-pulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

/* Input Area */
.input-area {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 10px 12px;
  padding-bottom: calc(10px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.input-area textarea {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  padding: 11px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  line-height: 1.4;
  resize: none;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.2s;
}

.input-area textarea:focus {
  border-color: #888;
}

.input-area textarea::placeholder {
  color: var(--text-dim);
}

.btn-send {
  width: 44px;
  height: 44px;
  background: #e0e0e0;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s, background 0.15s;
  flex-shrink: 0;
}

.btn-send svg {
  width: 22px;
  height: 22px;
  fill: #0a0a0a;
  margin-left: 2px;
}

.btn-send:active {
  transform: scale(0.9);
}

/* ===== OVERLAYS ===== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.96);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.2s;
}

/* Call Screen */
.call-screen {
  text-align: center;
  padding: 40px 24px;
  width: 100%;
}

.call-info {
  margin-bottom: 60px;
}

.call-badge {
  display: inline-block;
  padding: 8px 18px;
  background: rgba(48, 209, 88, 0.12);
  border: 1px solid rgba(48, 209, 88, 0.25);
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  color: var(--green);
  margin-bottom: 24px;
}

.call-timer {
  font-size: 56px;
  font-weight: 200;
  font-family: 'SF Mono', 'Menlo', 'Roboto Mono', monospace;
  letter-spacing: 4px;
}

.call-controls {
  display: flex;
  justify-content: center;
  gap: 40px;
}

.call-control-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.btn-label {
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 500;
}

.btn-label-end {
  color: var(--red);
}

.btn-round {
  width: 68px;
  height: 68px;
  border: none;
  border-radius: 50%;
  background: var(--surface-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s, background 0.15s;
}

.btn-round svg {
  width: 28px;
  height: 28px;
  fill: var(--text);
}

.btn-round:active {
  transform: scale(0.9);
}

.btn-round.muted {
  background: var(--red);
}

.btn-round.muted svg {
  fill: white;
}

.btn-end {
  background: var(--red);
}

.btn-end svg {
  fill: white;
}

.mute-icon.hidden {
  display: none;
}

.speaker-icon.hidden {
  display: none;
}

.btn-round.speaker-on {
  background: var(--accent);
}

.btn-round.speaker-on svg {
  fill: white;
}

/* Incoming Call */
.incoming-screen {
  text-align: center;
  padding: 40px 24px;
  width: 100%;
}

.incoming-pulse {
  width: 110px;
  height: 110px;
  background: var(--green);
  border-radius: 50%;
  margin: 0 auto 36px;
  animation: pulse 1.5s ease-out infinite;
  display: flex;
  align-items: center;
  justify-content: center;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(48, 209, 88, 0.5); }
  70% { box-shadow: 0 0 0 35px rgba(48, 209, 88, 0); }
  100% { box-shadow: 0 0 0 0 rgba(48, 209, 88, 0); }
}

.incoming-text {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 52px;
}

.incoming-controls {
  display: flex;
  justify-content: center;
  gap: 56px;
}

.btn-decline {
  background: var(--red);
}

.btn-decline svg {
  fill: white;
}

.btn-accept {
  background: var(--green);
}

.btn-accept svg {
  fill: white;
}

/* ===== ALERTS ===== */
.alerts {
  position: fixed;
  top: calc(12px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: calc(100% - 24px);
  max-width: 420px;
}

.security-alert {
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  animation: slideDown 0.3s, fadeOut 0.3s 4.7s forwards;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeOut {
  to { opacity: 0; }
}

.security-alert.severity-high {
  border-color: var(--red);
}

.security-alert.severity-medium {
  border-color: var(--orange);
}

.security-alert-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.security-alert-icon {
  font-size: 16px;
}

.security-alert-title {
  font-size: 15px;
  font-weight: 600;
}

.security-alert-message {
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.4;
}

/* M4: CSS rules replacing inline style="" attributes — allows removing 'unsafe-inline' from CSP */
#room-id-display {
  display: none;
}

#share-room-btn {
  display: none;
  background: var(--accent);
}

#share-room-btn.visible {
  display: flex;
}

#copy-feedback {
  display: none;
  color: var(--green);
}

#copy-feedback.visible {
  display: block;
}

#connecting-leave-btn {
  margin-top: 24px;
}

/* Message self-destruct exit animation */
.message-deleting {
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.3s, transform 0.3s;
}

/* Toast exit animation */
.toast-fading {
  opacity: 0;
  transition: opacity 0.3s;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 0;
  display: none;
}

/* Selection */
::selection {
  background: #555;
  color: white;
}

/* Focus visible */
:focus-visible {
  outline: 2px solid #888;
  outline-offset: 2px;
}

button:focus:not(:focus-visible),
input:focus:not(:focus-visible),
textarea:focus:not(:focus-visible) {
  outline: none;
}

/* Toast notification */
.toast-notification {
  position: fixed;
  top: calc(16px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  color: var(--text);
  padding: 14px 24px;
  border-radius: 12px;
  border: 1px solid var(--border);
  font-size: 15px;
  font-weight: 500;
  z-index: 10000;
  opacity: 1;
  transition: opacity 0.3s;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

/* ===== MOBILE — phones up to 480px ===== */
@media (max-width: 480px) {
  .welcome {
    padding: calc(16px + var(--safe-top)) 20px calc(12px + var(--safe-bottom));
  }

  .welcome-header {
    margin-bottom: 36px;
  }

  .welcome-content {
    gap: 14px;
  }

  .call-timer {
    font-size: 44px;
  }

  .call-controls {
    gap: 32px;
  }

  .btn-round {
    width: 64px;
    height: 64px;
  }

  .incoming-controls {
    gap: 48px;
  }
}

/* Small phones (iPhone SE, etc.) */
@media (max-width: 380px) {
  .welcome-header {
    margin-bottom: 24px;
  }

  .logo {
    width: 64px;
    height: 64px;
    font-size: 28px;
    border-radius: 18px;
  }

  .welcome-header h1 {
    font-size: 28px;
  }

  .btn-main {
    height: 50px;
    font-size: 16px;
  }

  .join-form input,
  .btn-join {
    height: 48px;
  }

  .btn-round {
    width: 60px;
    height: 60px;
  }

  .btn-round svg {
    width: 24px;
    height: 24px;
  }
}

/* Keyboard open — hide non-essential */
@media (max-height: 500px) {
  .welcome-header {
    margin-bottom: 16px;
  }

  .welcome-header .logo {
    display: none;
  }

  .welcome-footer {
    display: none;
  }

  .app-promo {
    display: none !important;
  }

  .privacy-switch {
    display: none;
  }

  .welcome-content {
    gap: 10px;
  }
}

/* Medium height — compact mode */
@media (max-height: 700px) and (min-height: 501px) {
  .welcome-header {
    margin-bottom: 28px;
  }

  .logo {
    width: 64px;
    height: 64px;
    font-size: 28px;
  }

  .welcome-footer {
    padding-top: 16px;
  }
}
