:root {
  --bg: #fbf7f2;
  --bg-2: #f3ece3;
  --surface: #ffffff;
  --surface-2: #f7f2ec;
  --text: #1d1a24;
  --muted: #6d6778;
  --border: #e8e0d6;
  --accent: #ff6b4a;
  --accent-ink: #ffffff;
  --accent-soft: #ffe6df;
  --accent-2: #6c5ce7;
  --good: #1fa971;
  --danger: #e5484d;
  --shadow: 0 1px 2px rgba(29, 26, 36, .06), 0 8px 24px rgba(29, 26, 36, .07);
  --shadow-lg: 0 20px 60px rgba(29, 26, 36, .14);
  --radius: 18px;
  --font-display: 'Bricolage Grotesque', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14121a;
    --bg-2: #1b1823;
    --surface: #1f1c28;
    --surface-2: #282433;
    --text: #f3f0f7;
    --muted: #a39eb0;
    --border: #332e40;
    --accent: #ff7a5c;
    --accent-ink: #1a0e0a;
    --accent-soft: #3b231f;
    --accent-2: #8f83ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .3);
    --shadow-lg: 0 20px 60px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 10% -10%, color-mix(in srgb, var(--accent) 12%, transparent), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, color-mix(in srgb, var(--accent-2) 12%, transparent), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--font-display); margin: 0; letter-spacing: -0.02em; }
p { margin: 0; }

/* ---------- Screens ---------- */
.screen { display: none; min-height: 100vh; min-height: 100dvh; }
.screen[data-active] { display: flex; flex-direction: column; animation: fade-in .35s ease; }
.screen-center[data-active] { align-items: center; justify-content: center; padding: 24px 16px; }
@keyframes fade-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Primitives ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 28px;
  box-shadow: var(--shadow-lg);
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: 999px;
  padding: 12px 20px; font-weight: 600; cursor: pointer;
  transition: transform .12s ease, background .2s ease, box-shadow .2s ease, opacity .2s;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 35%, transparent); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, black); }
.btn-ghost { background: var(--surface-2); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg-2); }
.btn-good { background: var(--good); color: #fff; }
.btn-block { width: 100%; }
.link-btn { background: none; border: 0; padding: 4px 0; color: var(--muted); cursor: pointer; font-weight: 500; }
.link-btn:hover { color: var(--text); }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }

.field { display: grid; gap: 6px; margin: 20px 0 16px; text-align: left; }
.field span { font-size: 14px; font-weight: 600; color: var(--muted); }
.field input, .field select, .prompt-input input, .chat-form input {
  width: 100%; padding: 14px 16px; border-radius: 14px;
  border: 1px solid var(--border); background: var(--surface-2); outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.field input:focus, .field select:focus, .chat-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.form-error { color: var(--danger); font-size: 14px; min-height: 20px; margin-top: 10px; }
.hint { color: var(--muted); font-size: 13px; margin-top: 8px; }
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; font-weight: 600; color: var(--muted); }

/* ---------- Logo ---------- */
.logo { position: relative; width: 56px; height: 36px; margin: 0 auto 12px; }
.logo span { position: absolute; top: 0; width: 36px; height: 36px; border-radius: 50%; }
.logo span:first-child { left: 0; background: var(--accent); }
.logo span:last-child { right: 0; background: var(--accent-2); opacity: .85; mix-blend-mode: multiply; animation: nudge 3s ease-in-out infinite; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .logo span:last-child { mix-blend-mode: screen; } }
@keyframes nudge { 50% { transform: translateX(-6px); } }
.logo-sm { width: 30px; height: 20px; margin: 0; }
.logo-sm span { width: 20px; height: 20px; }

/* ---------- Avatars ---------- */
.avatar {
  --size: 40px;
  width: var(--size); height: var(--size); border-radius: 50%; flex: none;
  background: var(--hue, var(--accent-2)) center / cover no-repeat;
  color: #fff; display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 700; font-size: calc(var(--size) * .4);
  user-select: none;
}
.avatar-sm { --size: 30px; }
.avatar-md { --size: 64px; }
.avatar-lg { --size: 72px; }
.avatar-xl { --size: 104px; }

/* ---------- Auth ---------- */
.auth-card { width: 100%; max-width: 480px; padding: 36px 32px 24px; text-align: center; }
.brand { font-size: 40px; font-weight: 800; }
.tagline { color: var(--muted); margin-top: 6px; }
.tagline em { font-style: normal; color: var(--accent); font-weight: 600; }
.avatar-picker { position: relative; display: inline-block; cursor: pointer; }
.avatar-picker .avatar { box-shadow: 0 0 0 5px var(--surface), 0 0 0 7px var(--border); transition: transform .2s; }
.avatar-picker:hover .avatar { transform: scale(1.03); }
.avatar-picker-badge {
  position: absolute; right: -2px; bottom: -2px; width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center;
  border: 3px solid var(--surface);
}

.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin: 24px 0 20px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); }
.tab { border: 0; background: none; padding: 10px; border-radius: 999px; font-weight: 600; color: var(--muted); cursor: pointer; transition: background .2s, color .2s; }
.tab[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.auth-form { text-align: left; animation: fade-in .25s ease; }
.auth-form .field { margin: 0 0 14px; min-width: 0; }
.auth-form .field em { font-style: normal; font-weight: 400; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-hint { color: var(--muted); font-size: 12px; }
.field-error { color: var(--danger); font-size: 13px; }
.field-error:empty { display: none; }
.field input[aria-invalid="true"], .field select[aria-invalid="true"] { border-color: var(--danger); }
.field select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 15px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 36px; }
.hint-tight { margin: -6px 0 14px; }
.password-wrap { position: relative; }
.password-wrap input { padding-right: 64px; }
.reveal { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); border: 0; background: none; color: var(--muted); font-size: 13px; font-weight: 600; cursor: pointer; padding: 6px 8px; }
.reveal:hover { color: var(--text); }
.avatar-row { display: flex; align-items: center; gap: 18px; margin-bottom: 18px; }
.avatar-row .hint { margin-top: 2px; }
.avatar-row .avatar-picker .avatar { box-shadow: 0 0 0 4px var(--surface), 0 0 0 6px var(--border); }
.avatar-row .avatar-picker-badge { width: 28px; height: 28px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; color: var(--muted); line-height: 1.45; margin: 4px 0 6px; cursor: pointer; }
.check input { width: 18px; height: 18px; margin-top: 1px; accent-color: var(--accent); flex: none; }
.auth-form .btn-block { margin-top: 12px; }
.switch-hint { text-align: center; color: var(--muted); font-size: 14px; margin-top: 4px; }
.link-accent { color: var(--accent); font-weight: 600; }
.link-accent:hover { color: var(--accent); text-decoration: underline; }

.forgot-row { text-align: right; margin: -6px 0 4px; font-size: 14px; }
.form-title { font-size: 24px; margin-bottom: 8px; }
.form-intro { color: var(--muted); line-height: 1.5; margin-bottom: 20px; }
.form-intro strong { color: var(--text); word-break: break-all; }
.form-success { color: var(--good); font-size: 14px; margin-top: 10px; line-height: 1.4; }
.form-success[hidden] { display: none; }
.verify-card { text-align: center; }
.verify-card .form-intro { margin-top: 4px; }
.mail-icon { width: 72px; height: 72px; margin: 0 auto 16px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }

/* ---------- Account menu ---------- */
.account { position: relative; }
.account summary { list-style: none; cursor: pointer; }
.account summary::-webkit-details-marker { display: none; }
.account summary svg { color: var(--muted); transition: transform .2s; }
.account[open] summary svg { transform: rotate(180deg); }
.menu {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 220px; z-index: 30;
  padding: 6px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  animation: fade-in .15s ease;
}
.menu-email { font-size: 13px; color: var(--muted); padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-item { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 10px; border-radius: 10px; cursor: pointer; font-size: 14px; }
.menu-item:hover { background: var(--surface-2); }
.logout-btn { color: var(--danger); }

/* ---------- Activity prompt ---------- */
.center-main { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px 16px 64px; }
.greeting { color: var(--muted); font-weight: 500; margin-bottom: 12px; }
.prompt-wrap { width: 100%; max-width: 720px; text-align: center; }
.prompt-title { font-size: clamp(36px, 7vw, 64px); font-weight: 800; line-height: 1.02; margin-bottom: 32px; }
.prompt-input {
  display: flex; gap: 8px; padding: 8px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  transition: box-shadow .2s, border-color .2s;
}
.prompt-input:focus-within { border-color: var(--accent); box-shadow: 0 0 0 5px var(--accent-soft), var(--shadow-lg); }
.prompt-input input { border: 0; background: transparent; font-size: 18px; padding: 12px 18px; min-width: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 20px; }
.chip {
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px;
  padding: 8px 14px; font-size: 14px; cursor: pointer; color: var(--muted); transition: all .15s;
}
.chip:hover { color: var(--text); border-color: var(--accent); transform: translateY(-1px); }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 24px;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand-sm { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-weight: 800; font-size: 20px; }
.me-pill { display: flex; color: var(--text); align-items: center; gap: 8px; padding: 4px 12px 4px 4px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-weight: 600; font-size: 14px; }

/* ---------- Matches ---------- */
.matches-main { width: 100%; max-width: 1100px; margin: 0 auto; padding: 24px 24px 64px; }
.status-card {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 20px 24px; border-radius: var(--radius);
  background: linear-gradient(120deg, var(--accent-soft), color-mix(in srgb, var(--accent-2) 14%, var(--surface)));
  border: 1px solid var(--border);
}
.my-activity { font-family: var(--font-display); font-size: clamp(20px, 3vw, 28px); font-weight: 700; margin-top: 4px; word-break: break-word; }
.matches-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 32px 0 16px; }
.matches-head h2 { font-size: 24px; }
.live { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 0 var(--good); animation: ping 1.8s infinite; }
@keyframes ping { 70% { box-shadow: 0 0 0 8px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.match-card {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 14px;
  padding: 24px 20px 18px; border-radius: var(--radius); cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s;
  animation: pop-in .35s ease both;
}
.match-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
.match-card[data-state="requested"] { border-color: var(--accent); background: linear-gradient(var(--accent-soft), var(--surface) 60%); }
.match-card[data-state="requested-you"] { border-color: var(--good); }
@keyframes pop-in { from { opacity: 0; transform: scale(.96); } }
.match-info { width: 100%; }
.match-name { font-weight: 600; }
.match-activity { color: var(--muted); margin-top: 4px; font-size: 15px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word; }
.match-foot { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border); }
.score { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.score b { color: var(--text); }
.score-bar { width: 44px; height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.score-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: inherit; }
.match-cta { font-size: 13px; font-weight: 600; color: var(--accent); }
.match-card[data-state="requested-you"] .match-cta { color: var(--good); }

.empty { display: none; text-align: center; padding: 56px 16px; max-width: 420px; margin: 0 auto; }
.empty[data-show] { display: block; }
.empty h3 { font-size: 22px; margin: 24px 0 8px; }
.empty p { color: var(--muted); line-height: 1.5; }
.radar { position: relative; width: 96px; height: 96px; margin: 0 auto; }
.radar span { position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--accent); opacity: 0; animation: radar 2.4s ease-out infinite; }
.radar span:nth-child(2) { animation-delay: .8s; }
.radar span:nth-child(3) { animation-delay: 1.6s; }
.radar::after { content: ''; position: absolute; inset: 38px; border-radius: 50%; background: var(--accent); }
@keyframes radar { from { transform: scale(.3); opacity: .9; } to { transform: scale(1); opacity: 0; } }

/* ---------- Toasts ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 50; display: grid; gap: 10px; width: min(380px, calc(100vw - 32px)); }
.toast {
  display: grid; grid-template-columns: auto 1fr; gap: 12px 14px; align-items: center;
  padding: 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  animation: slide-up .3s ease both;
}
.toast.leaving { animation: slide-out .25s ease forwards; }
.toast-text strong { display: block; }
.toast-text p { color: var(--muted); font-size: 14px; margin-top: 2px; word-break: break-word; }
.toast-actions { grid-column: 1 / -1; display: flex; gap: 8px; }
.toast-actions .btn { flex: 1; padding: 10px 14px; }
.toast-simple { grid-template-columns: 1fr; }
@keyframes slide-up { from { opacity: 0; transform: translateY(12px); } }
@keyframes slide-out { to { opacity: 0; transform: translateX(24px); } }

/* ---------- Room ---------- */
#screen-room[data-active] { height: 100vh; height: 100dvh; }
.room-topbar { position: static; }
.room-activity { font-family: var(--font-display); font-weight: 700; font-size: 20px; margin-top: 2px; word-break: break-word; }
.chat-toggle { position: relative; display: none; }
.chat-toggle .dot { position: absolute; top: 6px; right: 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.room-body { flex: 1; display: grid; grid-template-columns: 1fr 340px; min-height: 0; }
.stage { position: relative; padding: 16px; min-height: 0; display: flex; }
.tile { position: relative; overflow: hidden; border-radius: 24px; background: #0f0d14; }
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile-remote { flex: 1; }
.tile-local {
  position: absolute; right: 32px; top: 32px; width: clamp(120px, 20vw, 220px); aspect-ratio: 4 / 3;
  box-shadow: 0 10px 30px rgba(0,0,0,.4); border: 2px solid rgba(255,255,255,.15); z-index: 2;
}
.tile-local video { transform: scaleX(-1); }
.tile-placeholder {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  color: #cfc9da; background: radial-gradient(circle at 50% 40%, #2a2536, #0f0d14);
}
.tile-placeholder[hidden] { display: none; }
.tile-label { position: absolute; left: 12px; bottom: 12px; padding: 4px 10px; border-radius: 999px; background: rgba(0,0,0,.55); color: #fff; font-size: 13px; font-weight: 500; }
.tile-local .tile-label { left: 8px; bottom: 8px; font-size: 12px; }

.controls {
  position: absolute; left: 50%; bottom: 32px; transform: translateX(-50%); z-index: 3;
  display: flex; gap: 12px; padding: 10px; border-radius: 999px;
  background: rgba(20, 18, 26, .7); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.ctrl {
  display: inline-flex; align-items: center; gap: 8px; height: 52px; min-width: 52px; padding: 0 14px; justify-content: center;
  border: 0; border-radius: 999px; background: rgba(255,255,255,.14); color: #fff; cursor: pointer; transition: background .15s;
}
.ctrl:hover { background: rgba(255,255,255,.24); }
.ctrl svg { width: 24px; height: 24px; }
.ctrl .off { display: none; }
.ctrl[aria-pressed="false"] { background: #fff; color: #1d1a24; }
.ctrl[aria-pressed="false"] .on { display: none; }
.ctrl[aria-pressed="false"] .off { display: block; }
.ctrl:disabled { opacity: .4; cursor: not-allowed; }
.ctrl-leave { background: var(--danger); font-weight: 600; padding: 0 20px; }
.ctrl-leave:hover { background: color-mix(in srgb, var(--danger) 85%, black); }

.chat { display: flex; flex-direction: column; min-height: 0; border-left: 1px solid var(--border); background: var(--surface); }
.chat-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.chat-head h3 { font-size: 18px; }
.chat-close { display: none; font-size: 18px; }
.chat-log { list-style: none; margin: 0; padding: 16px; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 85%; padding: 10px 14px; border-radius: 18px; background: var(--surface-2); line-height: 1.4; word-break: break-word; align-self: flex-start; border-bottom-left-radius: 6px; }
.msg.mine { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-left-radius: 18px; border-bottom-right-radius: 6px; }
.msg-system { align-self: center; font-size: 13px; color: var(--muted); text-align: center; padding: 4px 8px; }
.chat-form { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); }
.chat-form input { padding: 12px 14px; }
.chat-form .btn { padding: 10px 16px; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .room-body { grid-template-columns: 1fr; }
  .chat-toggle { display: inline-flex; }
  .chat {
    position: fixed; inset: auto 0 0 0; height: 70dvh; z-index: 20; border-left: 0; border-top: 1px solid var(--border);
    border-radius: 24px 24px 0 0; box-shadow: var(--shadow-lg); transform: translateY(100%); transition: transform .3s ease;
  }
  .chat[data-open] { transform: none; }
  .chat-close { display: block; }
}
@media (max-width: 560px) {
  .topbar { padding: 12px 16px; }
  .matches-main { padding: 16px 16px 48px; }
  .status-card { flex-direction: column; align-items: flex-start; }
  .prompt-input { flex-direction: column; border-radius: 24px; }
  .prompt-input .btn { width: 100%; }
  .auth-card { padding: 28px 18px 20px; border-radius: 22px; }
  .field-row { grid-template-columns: 1fr; gap: 0; }
  .stage { padding: 8px; }
  .tile-local { right: 18px; top: 18px; }
  .controls { bottom: 20px; }
  .ctrl-leave span { display: none; }
  .me-pill span { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
