/* ===========================================================
   LADYBUG — STYLES
   Light theme · Editorial typography · Crimson→amber accents
   =========================================================== */

:root {
  --bg: #fafaf7;
  --bg-elev: #ffffff;
  --bg-soft: #f3f1ec;
  --ink: #0e0e10;
  --ink-soft: #2a2a2e;
  --muted: #6b6b73;
  --muted-2: #9a9aa3;
  --line: #e7e4dc;
  --line-strong: #d8d4c9;

  --red: #E63946;
  --red-deep: #c62b38;
  --amber: #E89321;
  --amber-deep: #c97a14;

  --grad: linear-gradient(92deg, var(--red) 0%, #ee5c2e 38%, #f07a25 64%, var(--amber) 100%);
  --grad-soft: linear-gradient(92deg, rgba(230,57,70,.10), rgba(232,147,33,.10));

  --shadow-sm: 0 1px 2px rgba(15,15,20,.04), 0 1px 1px rgba(15,15,20,.03);
  --shadow-md: 0 8px 24px -10px rgba(15,15,20,.10), 0 4px 10px -6px rgba(15,15,20,.06);
  --shadow-lg: 0 24px 60px -20px rgba(15,15,20,.18), 0 8px 20px -10px rgba(15,15,20,.08);

  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 22px;
  --radius-xl: 28px;

  --font-display: 'Fraunces', 'Times New Roman', serif;
  --font-body: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;

  --topbar-h: 64px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* Subtle paper texture */
body::before {
  content: '';
  position: fixed; inset: 0;
  pointer-events: none;
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(230,57,70,.06), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(232,147,33,.05), transparent 60%);
  z-index: 0;
}

button { font-family: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
input { font-family: inherit; }
input:focus, button:focus { outline: none; }
input:focus-visible, button:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }

/* ===================== TOP BAR ===================== */
.topbar {
  position: sticky; top: 0; z-index: 50;
  height: var(--topbar-h);
  background: rgba(250,250,247,.85);
  backdrop-filter: saturate(140%) blur(14px);
  -webkit-backdrop-filter: saturate(140%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  height: 100%;
  max-width: 1100px; margin: 0 auto;
  padding: 0 22px;
  display: flex; align-items: center; justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-dot {
  width: 22px; height: 22px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ff6b75 0%, var(--red) 50%, var(--red-deep) 100%);
  box-shadow: inset 0 -3px 6px rgba(0,0,0,.18), 0 2px 8px rgba(230,57,70,.35);
  position: relative;
}
.brand-dot::before, .brand-dot::after {
  content: ''; position: absolute; background: #0e0e10; border-radius: 50%;
}
.brand-dot::before { width: 4px; height: 4px; top: 5px; left: 5px; }
.brand-dot::after  { width: 3px; height: 3px; top: 12px; left: 11px; }
.brand-name {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 22px;
  letter-spacing: -0.01em;
}
.topnav { display: flex; align-items: center; gap: 6px; }
.nav-btn {
  font-weight: 600; font-size: 14px;
  padding: 9px 14px; border-radius: 999px;
  color: var(--muted);
  display: inline-flex; align-items: center; gap: 6px;
  transition: color .15s, background .15s;
}
.nav-btn:hover { color: var(--ink); background: var(--bg-soft); }
.nav-btn.active { color: var(--ink); background: var(--bg-soft); }
.nav-badge {
  font-size: 11px; font-weight: 700;
  background: var(--red); color: #fff;
  padding: 1px 7px; border-radius: 999px;
  min-width: 18px; text-align: center;
}
.logout-btn {
  font-weight: 600; font-size: 13px;
  padding: 8px 13px; border-radius: 999px;
  color: var(--muted); border: 1px solid var(--line);
  margin-left: 6px;
  transition: color .15s, border-color .15s, background .15s;
}
.logout-btn:hover { color: var(--ink); border-color: var(--line-strong); background: var(--bg-soft); }

/* ===================== SCREENS ===================== */
.screen {
  display: none;
  position: relative; z-index: 1;
  min-height: calc(var(--app-h, 100dvh) - var(--topbar-h));
  padding: 28px 22px 60px;
}
.screen.active { display: block; }

/* ===================== USERNAME SCREEN ===================== */
.username-wrap {
  max-width: 720px; margin: 0 auto;
  padding-top: 24px;
  text-align: center;
  animation: rise .6s cubic-bezier(.2,.7,.2,1) both;
}
.hero-tag {
  display: inline-block;
  font-size: 12px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
  color: var(--muted);
  padding: 6px 12px; border-radius: 999px;
  background: var(--bg-soft);
  margin-bottom: 20px;
}
.hero-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(36px, 6vw, 64px);
  line-height: 1.04;
  letter-spacing: -0.025em;
  margin: 0 0 16px;
  color: var(--ink);
}
.hero-title .nowrap { white-space: nowrap; }
.hero-title .amp { color: var(--red); font-style: italic; font-weight: 700; }
.grad {
  background: var(--grad);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
  background-size: 200% 100%;
  animation: gradShift 6s ease-in-out infinite;
}
.hero-sub {
  color: var(--muted);
  font-size: 17px; max-width: 460px; margin: 0 auto 32px;
}
.username-card {
  max-width: 460px; margin: 0 auto;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-md);
  text-align: left;
}
.field-label {
  display: block;
  font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .1em;
  color: var(--muted);
  margin-bottom: 8px;
}
.input-row {
  display: flex; gap: 8px; align-items: stretch;
  background: var(--bg);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 4px 4px 4px 14px;
  transition: border-color .15s, box-shadow .15s;
}
.input-row:focus-within {
  border-color: var(--red);
  box-shadow: 0 0 0 4px rgba(230,57,70,.10);
}
.input-row input {
  flex: 1; min-width: 0;
  border: 0; background: transparent;
  font-size: 16px; font-weight: 500;
  padding: 12px 0;
  color: var(--ink);
}
.input-row input::placeholder { color: var(--muted-2); }
.dice-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 42px; height: 42px;
  border-radius: 10px;
  color: var(--muted);
  transition: color .15s, background .15s, transform .15s;
}
.dice-btn:hover { background: var(--bg-soft); color: var(--ink); transform: rotate(-12deg); }
.hint {
  font-size: 12px; color: var(--muted);
  margin: 10px 2px 18px;
  min-height: 16px;
}
.hint.error { color: var(--red); }
.hint.ok    { color: #1f8a4a; }
.cta-btn {
  width: 100%;
  padding: 14px 18px;
  border-radius: var(--radius);
  background: var(--ink); color: #fff;
  font-weight: 700; font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .12s, background .15s, box-shadow .15s;
  position: relative; overflow: hidden;
}
.cta-btn:not(:disabled):hover {
  background: linear-gradient(92deg, var(--red), var(--amber));
  box-shadow: 0 10px 24px -10px rgba(230,57,70,.5);
}
.cta-btn:not(:disabled):active { transform: translateY(1px); }
.cta-btn:disabled { opacity: .45; cursor: not-allowed; }
.legal {
  margin-top: 22px;
  font-size: 12px; color: var(--muted-2);
}

/* ===================== HOME SCREEN ===================== */
.home-wrap {
  max-width: 760px; margin: 0 auto;
  padding-top: 30px;
  text-align: center;
  animation: rise .55s cubic-bezier(.2,.7,.2,1) both;
}
.welcome {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  margin-bottom: 18px;
}
.welcome-tag {
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .12em;
  color: var(--muted);
}
.welcome-name {
  font-weight: 700; color: var(--ink);
}
.home-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(34px, 5.5vw, 56px);
  line-height: 1.06;
  letter-spacing: -0.025em;
  margin: 0 0 12px;
}
.home-sub {
  color: var(--muted);
  font-size: 16px; margin: 0 auto 36px;
}

.home-actions {
  display: flex; flex-direction: column; align-items: center;
  gap: 14px;
  margin-bottom: 40px;
}
.big-cta {
  width: min(440px, 100%);
  padding: 22px 26px;
  background: var(--ink);
  color: #fff;
  border-radius: 22px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  text-align: left;
  position: relative; overflow: hidden;
  transition: transform .15s, box-shadow .2s;
  box-shadow: 0 12px 30px -12px rgba(15,15,20,.35);
}
.big-cta::before {
  content: '';
  position: absolute; inset: 0;
  background: var(--grad);
  opacity: 0;
  transition: opacity .25s;
}
.big-cta > * { position: relative; z-index: 1; }
.big-cta:hover { transform: translateY(-2px); box-shadow: 0 18px 40px -14px rgba(230,57,70,.5); }
.big-cta:hover::before { opacity: 1; }
.big-cta:active { transform: translateY(0); }
.big-cta-label {
  display: block;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 30px;
  letter-spacing: -0.02em;
  line-height: 1;
}
.big-cta-sub {
  display: block;
  font-size: 13px; opacity: .7;
  margin-top: 6px;
}
.big-cta-arrow {
  display: inline-flex; align-items: center; justify-content: center;
  width: 46px; height: 46px;
  border-radius: 50%;
  background: rgba(255,255,255,.12);
  transition: transform .25s;
}
.big-cta:hover .big-cta-arrow { transform: translateX(4px) rotate(-8deg); background: rgba(255,255,255,.2); }
.ghost-cta {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 18px;
  border-radius: 999px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  color: var(--ink);
  font-weight: 600; font-size: 14px;
  transition: border-color .15s, background .15s;
}
.ghost-cta:hover { border-color: var(--line-strong); background: var(--bg-soft); }

.home-stats {
  display: inline-flex; gap: 38px;
  padding: 16px 28px;
  border-radius: 18px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}
.stat-num {
  font-family: var(--font-display);
  font-weight: 800; font-size: 28px;
  color: var(--ink);
  line-height: 1;
}
.stat-label {
  font-size: 11px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .12em;
  margin-top: 4px;
}

/* ===================== FRIENDS SCREEN ===================== */
.friends-wrap {
  max-width: 720px; margin: 0 auto;
  padding-top: 14px;
  animation: rise .5s cubic-bezier(.2,.7,.2,1) both;
}
.section-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(30px, 4vw, 42px);
  letter-spacing: -0.02em;
  margin: 0 0 6px;
}
.section-sub {
  color: var(--muted);
  margin: 0 0 24px;
}
.friends-list {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.friend-row {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  transition: background .15s;
  cursor: pointer;
}
.friend-row:last-child { border-bottom: 0; }
.friend-row:hover { background: var(--bg-soft); }
.friend-avatar {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--grad);
  color: #fff; font-weight: 700; font-size: 16px;
  display: inline-flex; align-items: center; justify-content: center;
  flex: 0 0 auto;
  text-transform: uppercase;
}
.friend-info { flex: 1; min-width: 0; }
.friend-name { font-weight: 600; color: var(--ink); }
.friend-meta { font-size: 12px; color: var(--muted); margin-top: 2px; display: flex; align-items: center; gap: 6px; }
.online-dot { width: 8px; height: 8px; border-radius: 50%; background: #19a558; box-shadow: 0 0 0 3px rgba(25,165,88,.18); }
.offline-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted-2); }
.unread-pill {
  font-size: 10px; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--red); color: #fff;
  margin-left: 4px;
}
.unread-pill[hidden] { display: none !important; }

.friends-section-header {
  font-size: 11px; font-weight: 700;
  letter-spacing: .14em; text-transform: uppercase;
  color: var(--muted);
  padding: 14px 18px 6px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--line);
}
.friend-row.request-row {
  background: linear-gradient(0deg, rgba(230,57,70,.025), rgba(232,147,33,.025));
}
.friend-row.request-row .friend-meta { color: var(--red); font-weight: 600; }
.friend-action.accept-req { color: #19a558; }
.friend-action.accept-req:hover { color: #fff; background: #19a558; }

.friend-actions { display: flex; gap: 6px; }
.friend-action {
  width: 36px; height: 36px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted);
  transition: color .15s, background .15s;
}
.friend-action:hover { color: var(--ink); background: var(--bg-soft); }
.friend-action.danger:hover { color: var(--red); background: rgba(230,57,70,.08); }

.empty-state {
  text-align: center;
  padding: 56px 20px;
}
.empty-glyph {
  font-family: var(--font-display);
  font-size: 80px; color: var(--line-strong);
  line-height: .6;
  margin-bottom: 8px;
}
.empty-title { font-weight: 700; font-size: 18px; margin-bottom: 4px; }
.empty-sub { color: var(--muted); font-size: 14px; }

/* ===================== MATCHMAKING ===================== */
.match-wrap {
  max-width: 640px; margin: 0 auto;
  text-align: center;
  padding-top: 30px;
  position: relative;
  animation: rise .5s cubic-bezier(.2,.7,.2,1) both;
}
.cancel-match {
  position: absolute; top: 0; right: 0;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  color: var(--muted);
  font-weight: 600; font-size: 13px;
  transition: color .15s, border-color .15s;
}
.cancel-match:hover { color: var(--red); border-color: var(--red); }

.match-orbit {
  width: 220px; height: 220px;
  margin: 30px auto 36px;
  position: relative;
}
.orbit-ring {
  position: absolute; inset: 0;
  border-radius: 50%;
  border: 2px solid transparent;
  border-top-color: var(--red);
  border-right-color: var(--amber);
  animation: orbit 2.4s linear infinite;
}
.orbit-ring.r2 {
  inset: 22px;
  border-top-color: var(--amber);
  border-left-color: var(--red);
  animation-duration: 1.8s;
  animation-direction: reverse;
}
.orbit-ring.r3 {
  inset: 50px;
  border-top-color: var(--red-deep);
  border-bottom-color: var(--amber-deep);
  animation-duration: 1.4s;
}
.orbit-core {
  position: absolute; inset: 0; margin: auto;
  width: 60px; height: 60px;
  border-radius: 50%;
  background: var(--grad);
  background-size: 200% 200%;
  animation: gradShift 3s ease-in-out infinite, pulse 2s ease-in-out infinite;
  box-shadow: 0 0 50px rgba(230,57,70,.4);
}

.match-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(28px, 4.5vw, 44px);
  letter-spacing: -0.02em;
  margin: 0 0 10px;
}
.match-text {
  background: linear-gradient(92deg, var(--ink) 0%, var(--ink) 30%, var(--red) 50%, var(--amber) 70%, var(--ink) 100%);
  background-size: 250% 100%;
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
  animation: shimmer 2.6s linear infinite;
}
.match-status {
  color: var(--muted);
  font-size: 15px;
  margin-bottom: 36px;
  min-height: 22px;
}

.tip-box {
  display: inline-block;
  text-align: left;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-left: 4px solid var(--red);
  padding: 14px 22px;
  border-radius: 14px;
  max-width: 480px;
  box-shadow: var(--shadow-sm);
}
.tip-label {
  font-size: 11px; font-weight: 700;
  letter-spacing: .14em; text-transform: uppercase;
  color: var(--red); margin-bottom: 4px;
}
.tip-text {
  font-size: 15px; color: var(--ink-soft);
  transition: opacity .35s;
}
.tip-text.fade { opacity: 0; }

/* ===================== CHAT ===================== */
.screen-chat { padding: 0; }
.chat-wrap {
  max-width: 820px; margin: 0 auto;
  display: flex; flex-direction: column;
  /* Use the dynamic viewport unit for mobile browsers that resize,
     fall back to JS-set --app-h for older iOS Safari. */
  height: calc(var(--app-h, 100dvh) - var(--topbar-h));
  background: var(--bg-elev);
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

.chat-header {
  display: flex; align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-elev);
  gap: 10px;
}
.chat-back {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  border-radius: 10px;
  color: var(--muted);
  transition: color .15s, background .15s;
  flex: 0 0 auto;
}
.chat-back:hover { color: var(--ink); background: var(--bg-soft); }
.chat-peer { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.peer-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--grad);
  color: #fff; font-weight: 700; font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center;
  text-transform: uppercase;
  flex: 0 0 auto;
}
.peer-meta { min-width: 0; }
.peer-name {
  font-weight: 700; font-size: 15px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.peer-status { font-size: 12px; color: var(--muted); }
.peer-status.live::before {
  content: ''; display: inline-block;
  width: 7px; height: 7px; border-radius: 50%;
  background: #19a558;
  margin-right: 6px; vertical-align: middle;
}
.chat-actions { display: flex; gap: 4px; flex: 0 0 auto; }
.icon-btn {
  width: 38px; height: 38px;
  border-radius: 10px;
  color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
  transition: color .15s, background .15s;
}
.icon-btn:hover { background: var(--bg-soft); color: var(--ink); }
.icon-btn.skip-btn:hover { color: var(--amber-deep); background: rgba(232,147,33,.1); }
.icon-btn.end-btn:hover { color: var(--red); background: rgba(230,57,70,.1); }
.icon-btn.added { color: var(--red); background: rgba(230,57,70,.08); }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 22px 18px 14px;
  display: flex; flex-direction: column;
  gap: 8px;
  background:
    linear-gradient(var(--bg-elev), var(--bg-elev)) padding-box,
    radial-gradient(800px 400px at 50% 0%, rgba(230,57,70,.04), transparent 70%);
}
.system-msg {
  text-align: center;
  font-size: 12px; color: var(--muted);
  background: var(--bg-soft);
  padding: 6px 12px;
  border-radius: 999px;
  align-self: center;
  margin: 8px 0;
  max-width: 90%;
}
.bubble {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.45;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  animation: bubbleIn .25s cubic-bezier(.2,.7,.2,1) both;
  position: relative;
}
.bubble.me {
  align-self: flex-end;
  background: var(--ink);
  color: #fff;
  border-bottom-right-radius: 6px;
}
.bubble.them {
  align-self: flex-start;
  background: var(--bg-soft);
  color: var(--ink);
  border-bottom-left-radius: 6px;
}
.bubble + .bubble.me, .bubble + .bubble.them {
  margin-top: -2px;
}

.typing-indicator {
  padding: 4px 22px 0;
  height: 22px;
  display: flex; align-items: center; gap: 4px;
  font-size: 12px; color: var(--muted);
}
.typing-indicator[hidden] { display: none !important; }
.typing-indicator span:not(.typing-text) {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted);
  animation: typingDot 1.2s ease-in-out infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: .15s; }
.typing-indicator span:nth-child(3) { animation-delay: .30s; }
.typing-text { margin-left: 6px; font-style: italic; }

.composer {
  display: flex; gap: 8px;
  padding: 12px 14px 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--bg-elev);
}
.composer input {
  flex: 1; min-width: 0;
  padding: 13px 16px;
  border-radius: 999px;
  background: var(--bg);
  border: 1.5px solid var(--line);
  font-size: 15px;
  color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
.composer input:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 4px rgba(230,57,70,.10);
}
.send-btn {
  width: 46px; height: 46px;
  border-radius: 50%;
  background: var(--ink); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  transition: transform .12s, background .15s;
  flex: 0 0 auto;
}
.send-btn:not(:disabled):hover { background: var(--red); }
.send-btn:active { transform: scale(.94); }
.send-btn:disabled { opacity: .4; cursor: not-allowed; }
.send-btn svg { transform: translate(-1px, 1px); }

/* ===================== TOAST ===================== */
.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff;
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 100;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.error { background: var(--red); }
.toast.success { background: #19a558; }

/* ===================== MODAL ===================== */
.modal {
  position: fixed; inset: 0;
  background: rgba(15,15,20,.4);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  padding: 20px;
  animation: fadeIn .15s ease-out;
}
.modal[hidden] { display: none !important; }
.toast[hidden]  { display: none !important; }
.modal-card {
  background: var(--bg-elev);
  border-radius: var(--radius-lg);
  padding: 26px;
  max-width: 380px; width: 100%;
  box-shadow: var(--shadow-lg);
  animation: modalIn .25s cubic-bezier(.2,.7,.2,1) both;
}
.modal-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 22px;
  margin: 0 0 6px;
}
.modal-text { color: var(--muted); margin: 0 0 20px; font-size: 14px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
.modal-btn {
  padding: 10px 18px;
  border-radius: 10px;
  font-weight: 600; font-size: 14px;
  transition: background .15s, color .15s;
}
.modal-cancel {
  background: var(--bg-soft); color: var(--ink);
}
.modal-cancel:hover { background: var(--line); }
.modal-confirm {
  background: var(--red); color: #fff;
}
.modal-confirm:hover { background: var(--red-deep); }

/* ===================== ANIMATIONS ===================== */
@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes gradShift {
  0%, 100% { background-position: 0% 50%; }
  50%      { background-position: 100% 50%; }
}
@keyframes shimmer {
  0%   { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}
@keyframes orbit {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.08); }
}
@keyframes bubbleIn {
  from { opacity: 0; transform: translateY(6px) scale(.96); }
  to   { opacity: 1; transform: translateY(0)   scale(1); }
}
@keyframes typingDot {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30%           { transform: translateY(-4px); opacity: 1; }
}
@keyframes fadeIn {
  from { opacity: 0; } to { opacity: 1; }
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(10px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ===================== RESPONSIVE ===================== */
@media (max-width: 640px) {
  .topbar-inner { padding: 0 16px; }
  .brand-name { font-size: 19px; }
  .nav-btn { padding: 8px 11px; font-size: 13px; }
  .logout-btn { padding: 7px 10px; font-size: 12px; }

  .screen { padding: 22px 16px 50px; }
  .screen-chat { padding: 0; }

  .username-card { padding: 18px; }
  .hero-sub { font-size: 15px; }

  .home-stats { gap: 22px; padding: 14px 20px; }
  .stat-num { font-size: 24px; }

  .match-orbit { width: 180px; height: 180px; margin: 22px auto 28px; }
  .orbit-ring.r2 { inset: 18px; }
  .orbit-ring.r3 { inset: 40px; }
  .orbit-core { width: 50px; height: 50px; }
  .cancel-match { top: -4px; }

  .chat-wrap { border-left: 0; border-right: 0; }
  .messages { padding: 18px 14px 10px; }
  .bubble { max-width: 82%; font-size: 14.5px; }
  .composer { padding: 10px 12px 12px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .composer input { padding: 11px 14px; font-size: 14.5px; }
  .send-btn { width: 42px; height: 42px; }
  .peer-name { font-size: 14px; }
  .icon-btn { width: 36px; height: 36px; }
  .chat-back { width: 36px; height: 36px; }
}
@media (max-width: 380px) {
  .nav-btn span:not(.nav-badge) { display: none; }
  .chat-actions { gap: 2px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
