/* =============================================================================
   AnonYChat — Dark-Mode First Responsive CSS
   Author: Full-Stack Security Architect
   =============================================================================

   Design system:
   – CSS custom properties for theming
   – Mobile-first responsive layout
   – WCAG 2.2 AA contrast ratios
   – No @import from external sources (CSP compliant)
   ============================================================================= */

/* ── Reset & Base ─────────────────────────────────────────────────────────── */

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

:root {
  /* Colour palette — dark mode primary */
  --bg-page:        #0d0f14;
  --bg-surface:     #161920;
  --bg-surface-2:   #1e2230;
  --bg-surface-3:   #252a3a;

  --accent-primary: #4f8ef7;
  --accent-primary-h: #3a73d8;
  --accent-success: #34d399;
  --accent-warn:    #fbbf24;
  --accent-danger:  #f87171;
  --accent-topic:   #a78bfa;

  --text-primary:   #e8eaf0;
  --text-secondary: #8e95a9;
  --text-muted:     #555e73;

  --border-subtle:  rgba(255,255,255,0.07);
  --border-mid:     rgba(255,255,255,0.14);

  --bubble-you:     #1a3a6a;
  --bubble-you-border: #2d5aa8;
  --bubble-stranger:  #1e2538;
  --bubble-stranger-border: #2f3a55;
  --bubble-system:  rgba(251,191,36,0.08);
  --bubble-system-border: rgba(251,191,36,0.3);

  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-xl: 28px;

  --shadow-card: 0 8px 40px rgba(0,0,0,0.5);
  --shadow-btn:  0 2px 12px rgba(0,0,0,0.4);

  --font-sans: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;

  --transition-fast: 150ms ease;
  --transition-med:  260ms ease;
}

/* Light mode override — triggered by system preference */
@media (prefers-color-scheme: light) {
  :root {
    --bg-page:        #f0f2f7;
    --bg-surface:     #ffffff;
    --bg-surface-2:   #f5f7fb;
    --bg-surface-3:   #e8ecf5;
    --text-primary:   #1a1d2e;
    --text-secondary: #4a5068;
    --text-muted:     #9098b1;
    --border-subtle:  rgba(0,0,0,0.07);
    --border-mid:     rgba(0,0,0,0.14);
    --bubble-you:     #dbeafe;
    --bubble-you-border: #93c5fd;
    --bubble-stranger:  #f1f5f9;
    --bubble-stranger-border: #cbd5e1;
    --bubble-system:  rgba(251,191,36,0.1);
    --bubble-system-border: rgba(202,138,4,0.35);
    --shadow-card: 0 4px 20px rgba(0,0,0,0.1);
  }
}

html {
  font-family: var(--font-sans);
  font-size: clamp(14px, 1.5vw, 16px);
  color: var(--text-primary);
  background: var(--bg-page);
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ── Utility ──────────────────────────────────────────────────────────────── */

.hidden {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ── Ban Overlay ─────────────────────────────────────────────────────────── */

#ban-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.92);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.ban-card {
  background: var(--bg-surface);
  border: 1px solid var(--accent-danger);
  border-radius: var(--radius-xl);
  padding: 2.5rem 3rem;
  max-width: 440px;
  width: 100%;
  text-align: center;
  box-shadow: 0 0 60px rgba(248,113,113,0.2), var(--shadow-card);
  animation: banSlideIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes banSlideIn {
  from { transform: translateY(-24px) scale(0.95); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

.ban-icon   { font-size: 3rem; margin-bottom: 0.75rem; }
.ban-title  { font-size: 1.5rem; font-weight: 700; color: var(--accent-danger); margin-bottom: 0.5rem; }
.ban-desc   { color: var(--text-secondary); line-height: 1.6; margin-bottom: 1.5rem; }
.ban-timer-label { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); margin-bottom: 0.4rem; }

.ban-countdown {
  font-family: var(--font-mono);
  font-size: 2.4rem;
  font-weight: 700;
  color: var(--accent-warn);
  letter-spacing: 0.04em;
  margin-bottom: 1rem;
}

.ban-strikes {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ── App Shell ───────────────────────────────────────────────────────────── */

#app {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ── Header ──────────────────────────────────────────────────────────────── */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.5rem;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  gap: 1rem;
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text-primary);
  user-select: none;
}

.logo-icon   { font-size: 1.5rem; }
.logo-text   { letter-spacing: -0.01em; }
.logo-text strong { color: var(--accent-primary); }

.header-tagline {
  font-size: 0.75rem;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

@media (max-width: 480px) {
  .header-tagline { display: none; }
}

/* ── Main Content ────────────────────────────────────────────────────────── */

.main-content {
  flex: 1;
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 2rem 1rem;
  position: relative;
}

/* ── Screens ─────────────────────────────────────────────────────────────── */

.screen {
  display: none;
  width: 100%;
  max-width: 700px;
  animation: screenFade 0.25s ease both;
}

.screen.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

@keyframes screenFade {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* ── Start Screen ────────────────────────────────────────────────────────── */

.start-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: 2.5rem 2rem;
  max-width: 520px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-card);
}

.start-heading {
  font-size: clamp(1.4rem, 4vw, 2rem);
  font-weight: 700;
  margin-bottom: 0.75rem;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-topic));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.start-sub {
  color: var(--text-secondary);
  line-height: 1.65;
  margin-bottom: 1.5rem;
}

.start-rules {
  list-style: none;
  margin-bottom: 2rem;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.start-rules li {
  color: var(--text-secondary);
  font-size: 0.9rem;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.start-rules li::before {
  content: '→';
  color: var(--accent-primary);
  flex-shrink: 0;
  margin-top: 0.05em;
}

/* ── Waiting Screen ──────────────────────────────────────────────────────── */

.waiting-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.waiting-text {
  color: var(--text-secondary);
  font-size: 1.1rem;
}

.spinner {
  width: 52px; height: 52px;
  border: 4px solid var(--border-mid);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

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

/* ── Chat Screen ─────────────────────────────────────────────────────────── */

.chat-layout {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: calc(100dvh - 120px);
  min-height: 400px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}

#screen-chat.active {
  align-items: stretch;
}

/* ── Message List ────────────────────────────────────────────────────────── */

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scroll-behavior: smooth;
}

/* Custom scrollbar */
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb {
  background: var(--border-mid);
  border-radius: 3px;
}

/* ── Chat Bubbles ────────────────────────────────────────────────────────── */

.bubble {
  display: flex;
  flex-direction: column;
  max-width: 75%;
  gap: 0.25rem;
  animation: bubbleIn 0.18s ease both;
}

@keyframes bubbleIn {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}

.bubble.you      { align-self: flex-end; align-items: flex-end; }
.bubble.stranger { align-self: flex-start; align-items: flex-start; }
.bubble.system   { align-self: center; align-items: center; max-width: 90%; }

.bubble-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.1rem;
}

.bubble.you      .bubble-label { color: var(--accent-primary); }
.bubble.stranger .bubble-label { color: var(--accent-success); }
.bubble.system   .bubble-label { display: none; }

.bubble-text {
  display: block;
  padding: 0.65rem 1rem;
  border-radius: var(--radius-lg);
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
  font-size: 0.95rem;
}

.bubble.you .bubble-text {
  background: var(--bubble-you);
  border: 1px solid var(--bubble-you-border);
  border-bottom-right-radius: var(--radius-sm);
  color: var(--text-primary);
}

.bubble.stranger .bubble-text {
  background: var(--bubble-stranger);
  border: 1px solid var(--bubble-stranger-border);
  border-bottom-left-radius: var(--radius-sm);
  color: var(--text-primary);
}

.bubble.system .bubble-text {
  background: var(--bubble-system);
  border: 1px solid var(--bubble-system-border);
  border-radius: var(--radius-md);
  color: var(--accent-warn);
  font-size: 0.88rem;
  text-align: center;
  padding: 0.5rem 1.25rem;
}

/* ── Input Area ──────────────────────────────────────────────────────────── */

.chat-input-area {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-surface-2);
  align-items: flex-end;
}

.msg-input {
  flex: 1;
  resize: none;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-surface-3);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-md);
  padding: 0.65rem 0.9rem;
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  max-height: 120px;
  overflow-y: auto;
  field-sizing: content; /* modern auto-grow */
}

.msg-input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(79,142,247,0.2);
}

.msg-input::placeholder { color: var(--text-muted); }

/* ── Action Bar ──────────────────────────────────────────────────────────── */

.chat-actions {
  display: flex;
  gap: 0.5rem;
  padding: 0.6rem 1rem 0.8rem;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-surface-2);
  flex-wrap: wrap;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1;
  padding: 0.6rem 1.1rem;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition:
    background var(--transition-fast),
    transform   var(--transition-fast),
    box-shadow  var(--transition-fast),
    opacity     var(--transition-fast);
  user-select: none;
  white-space: nowrap;
  box-shadow: var(--shadow-btn);
}

.btn:active  { transform: scale(0.96); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--accent-primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-primary-h);
}

.btn-secondary {
  background: var(--bg-surface-3);
  color: var(--text-secondary);
  border: 1px solid var(--border-mid);
}
.btn-secondary:hover:not(:disabled) {
  color: var(--text-primary);
  background: var(--bg-surface-2);
}

.btn-accent {
  background: rgba(167,139,250,0.15);
  color: var(--accent-topic);
  border: 1px solid rgba(167,139,250,0.3);
}
.btn-accent:hover:not(:disabled) {
  background: rgba(167,139,250,0.25);
}

.btn-danger {
  background: rgba(248,113,113,0.12);
  color: var(--accent-danger);
  border: 1px solid rgba(248,113,113,0.25);
}
.btn-danger:hover:not(:disabled) {
  background: rgba(248,113,113,0.22);
}

.btn-lg {
  font-size: 1.05rem;
  padding: 0.8rem 2rem;
  border-radius: var(--radius-lg);
}

.btn-send {
  flex-shrink: 0;
  min-width: 72px;
  align-self: flex-end;
}

/* ── Footer ──────────────────────────────────────────────────────────────── */

.app-footer {
  padding: 0.7rem 1.5rem;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

kbd {
  display: inline-block;
  padding: 0.1em 0.4em;
  font-family: var(--font-mono);
  font-size: 0.8em;
  background: var(--bg-surface-3);
  border: 1px solid var(--border-mid);
  border-radius: 4px;
  vertical-align: middle;
}

/* ── Connection Status Badge ─────────────────────────────────────────────── */

#conn-badge {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-mid);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  z-index: 100;
  box-shadow: var(--shadow-card);
  transition: opacity var(--transition-med);
}

#conn-badge .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
}

#conn-badge.connected    { color: var(--accent-success); }
#conn-badge.connected .dot { background: var(--accent-success); box-shadow: 0 0 0 3px rgba(52,211,153,0.2); }

#conn-badge.connecting   { color: var(--accent-warn); }
#conn-badge.connecting .dot { background: var(--accent-warn); animation: pulse 1s ease infinite; }

#conn-badge.disconnected { color: var(--accent-danger); }
#conn-badge.disconnected .dot { background: var(--accent-danger); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* ── Skip Confirm Toast ──────────────────────────────────────────────────── */

#skip-toast {
  position: fixed;
  bottom: 4rem;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  background: var(--bg-surface-3);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-md);
  padding: 0.65rem 1.25rem;
  font-size: 0.88rem;
  color: var(--text-secondary);
  box-shadow: var(--shadow-card);
  z-index: 200;
  pointer-events: none;
  opacity: 1;
  transition: opacity var(--transition-med);
}

#skip-toast.hidden { opacity: 0; }

/* ── Responsive adjustments ──────────────────────────────────────────────── */

@media (max-width: 600px) {
  .main-content { padding: 0; }

  .start-card {
    border-radius: 0;
    border-left: none;
    border-right: none;
    min-height: calc(100dvh - 120px);
    justify-content: center;
    display: flex;
    flex-direction: column;
  }

  .chat-layout {
    border-radius: 0;
    border-left: none;
    border-right: none;
    height: calc(100dvh - 108px);
  }

  .bubble { max-width: 90%; }
  .chat-actions { gap: 0.4rem; }
  .btn { font-size: 0.82rem; padding: 0.55rem 0.85rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
