:root {
  color-scheme: dark;
  font-family: Inter, "Microsoft YaHei", system-ui, sans-serif;
  background: #08111f;
  color: #e9f1ff;
  --panel: rgba(18, 31, 51, 0.9);
  --line: rgba(148, 177, 220, 0.18);
  --accent: #56c7ff;
  --good: #5ee6a8;
  --danger: #ff758a;
  --page-bg: radial-gradient(circle at 20% 0%, #17395c 0, transparent 42%), #08111f;
  --text: #e9f1ff;
  --muted: #a9bad2;
  --input-bg: rgba(3,10,20,.65);
  --bar-bg: rgba(8,17,31,.88);
  --surface: #111f33;
  --surface-soft: #16253b;
  --surface-active: #153b37;
  --controls-bg: linear-gradient(transparent, rgba(8,17,31,.97) 25%);
  --chat-bg: rgba(7,15,27,.82);
  --chat-bubble: #16263b;
  --chat-own: #17415b;
  --placeholder: radial-gradient(circle at 50% 42%, #19304c, #020711 68%);
}

:root[data-theme="light"] { color-scheme: light; --panel: rgba(255,255,255,.94); --line: rgba(41,76,112,.18); --accent: #0577b5; --good: #16845d; --danger: #c63852; --page-bg: radial-gradient(circle at 20% 0%, #d7efff 0, transparent 44%), #eef4fa; --text: #142437; --muted: #5f7389; --input-bg: rgba(246,250,255,.96); --bar-bg: rgba(249,252,255,.92); --surface: #f7fbff; --surface-soft: #e9f1f8; --surface-active: #d9f4e8; --controls-bg: linear-gradient(transparent, rgba(238,244,250,.98) 25%); --chat-bg: rgba(248,252,255,.94); --chat-bubble: #e7eff7; --chat-own: #d8effb; --placeholder: radial-gradient(circle at 50% 42%, #dbeaf5, #b8ccdc 72%); }
@media (prefers-color-scheme: light) { :root:not([data-theme]) { color-scheme: light; --panel: rgba(255,255,255,.94); --line: rgba(41,76,112,.18); --accent: #0577b5; --good: #16845d; --danger: #c63852; --page-bg: radial-gradient(circle at 20% 0%, #d7efff 0, transparent 44%), #eef4fa; --text: #142437; --muted: #5f7389; --input-bg: rgba(246,250,255,.96); --bar-bg: rgba(249,252,255,.92); --surface: #f7fbff; --surface-soft: #e9f1f8; --surface-active: #d9f4e8; --controls-bg: linear-gradient(transparent, rgba(238,244,250,.98) 25%); --chat-bg: rgba(248,252,255,.94); --chat-bubble: #e7eff7; --chat-own: #d8effb; --placeholder: radial-gradient(circle at 50% 42%, #dbeaf5, #b8ccdc 72%); } }

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--page-bg); color: var(--text); }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.gate, .admin-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.card { width: min(440px, 100%); padding: 30px; border: 1px solid var(--line); border-radius: 22px; background: var(--panel); box-shadow: 0 28px 80px rgba(0,0,0,.34); backdrop-filter: blur(18px); }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 750; letter-spacing: .04em; }
.brand-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--good); box-shadow: 0 0 18px var(--good); }
h1 { margin: 22px 0 8px; font-size: clamp(26px, 6vw, 38px); }
p { color: var(--muted); line-height: 1.65; }
.field { display: grid; gap: 8px; margin-top: 22px; }
label { color: var(--text); font-size: 14px; }
input { width: 100%; border: 1px solid var(--line); background: var(--input-bg); color: var(--text); border-radius: 12px; padding: 13px 14px; outline: none; }
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(86,199,255,.12); }
.primary { width: 100%; margin-top: 16px; border: 0; border-radius: 12px; padding: 13px 16px; background: linear-gradient(120deg, #38bdf8, #6366f1); color: white; font-weight: 700; }
.primary:disabled { opacity: .55; cursor: wait; }
.message { min-height: 24px; color: var(--danger); font-size: 14px; margin-top: 12px; }
.meta { display: flex; justify-content: space-between; margin-top: 18px; color: #8093ad; font-size: 13px; }

.room { height: 100vh; height: 100dvh; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 16px 22px; border-bottom: 1px solid var(--line); background: var(--bar-bg); backdrop-filter: blur(12px); position: sticky; top: 0; z-index: 5; }
.status { color: #98abc3; font-size: 14px; }
.status strong { color: var(--good); }
.playback-button { margin-left: 8px; border: 1px solid rgba(86,199,255,.45); border-radius: 999px; padding: 5px 9px; background: #15364b; color: #bdeaff; }
.call-stage { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 340px); }
.grid { min-width: 0; min-height: 0; overflow: auto; display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); grid-auto-flow: dense; align-content: start; gap: 16px; padding: 18px; }
.empty { grid-column: 1 / -1; text-align: center; color: #8ea1bc; padding: 60px 20px; }
.tile { position: relative; overflow: hidden; background: #030915; border: 1px solid var(--line); border-radius: 18px; }
.tile.has-video { grid-column: 1 / -1; min-height: 260px; aspect-ratio: 16/9; cursor: zoom-in; touch-action: manipulation; }
.grid.multiple-video .tile.has-video { grid-column: span 6; }
.grid.multiple-video .tile.has-video.primary-video { grid-column: 1 / -1; }
.tile.no-video { grid-column: span 3; min-height: 108px; aspect-ratio: 16/9; }
.tile.no-video.name-only { min-height: 48px; aspect-ratio: auto; background: var(--surface-soft); }
.tile.name-only .tile-placeholder, .tile.name-only video { display: none; }
.tile.name-only .tile-label { position: static; display: block; width: 100%; padding: 14px 12px; background: transparent; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile.in-page-fullscreen { position: fixed; z-index: 30; inset: 0; width: 100vw; height: 100vh; height: 100dvh; max-width: none; max-height: none; aspect-ratio: auto; border: 0; border-radius: 0; cursor: zoom-out; background: #000; }
.tile.in-page-fullscreen::after { content: "双击退出"; position: absolute; right: 14px; top: max(14px, env(safe-area-inset-top)); padding: 7px 10px; border-radius: 999px; background: rgba(0,0,0,.58); color: #fff; font-size: 12px; pointer-events: none; }
.grid.tile-focus-active { overflow: visible; }
.tile video { width: 100%; height: 100%; object-fit: contain; background: #020711; }
.tile-placeholder { position: absolute; inset: 0; display: grid; place-items: center; background: var(--placeholder); color: #477798; font-size: clamp(48px, 10vw, 88px); }
.room.camera-flipped .tile video { transform: scaleX(-1); }
.tile-label { position: absolute; left: 12px; bottom: 12px; padding: 6px 9px; border-radius: 8px; background: rgba(0,0,0,.58); font-size: 12px; }
.controls { flex: 0 0 auto; display: flex; justify-content: center; gap: 12px; padding: 15px 15px max(15px, env(safe-area-inset-bottom)); background: var(--controls-bg); }
.control { min-width: 112px; border: 1px solid var(--line); border-radius: 999px; padding: 11px 16px; background: var(--surface-soft); color: var(--text); }
.control.active { border-color: rgba(94,230,168,.5); background: var(--surface-active); color: var(--text); }
.control.settings { min-width: 46px; width: 46px; padding-inline: 0; font-size: 20px; }
.control.leave { background: #512030; color: #ffd4dc; }
.settings-panel { position: fixed; z-index: 18; right: 18px; bottom: 84px; width: min(390px, calc(100vw - 24px)); padding: 14px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: 0 18px 50px rgba(0,0,0,.28); }
.settings-title { margin-bottom: 10px; color: #91a7c3; font-size: 12px; }
.settings-toggle { display: flex; align-items: center; justify-content: space-between; gap: 16px; cursor: pointer; }
.settings-toggle span { display: grid; gap: 5px; }
.settings-toggle small { color: #91a7c3; line-height: 1.4; }
.settings-toggle input { flex: 0 0 auto; width: 22px; height: 22px; }
.settings-choice { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.settings-choice span { display: grid; gap: 5px; }
.settings-choice small { color: #71869d; line-height: 1.4; }
.settings-choice select { flex: 0 0 auto; max-width: 122px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 9px; background: var(--input-bg); color: var(--text); }
.settings-divider { height: 1px; margin: 12px 0; background: var(--line); }
.p2p-status { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); color: #7fcdf5; font-size: 12px; }
.tile.p2p { border-color: rgba(86,199,255,.55); }
.remote-audio { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.device-menu { position: fixed; z-index: 20; width: min(320px, calc(100vw - 24px)); max-height: min(420px, 70vh); overflow: auto; padding: 8px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: 0 18px 50px rgba(0,0,0,.3); }
.device-menu-title { padding: 8px 10px; color: #91a7c3; font-size: 12px; }
.device-option { display: block; width: 100%; padding: 10px 12px; border: 0; border-radius: 9px; background: transparent; color: var(--text); text-align: left; }
.device-option:hover, .device-option.active { background: #203957; }
.device-option:disabled { color: #8090a6; cursor: default; }

.chat-panel { min-width: 0; min-height: 0; display: flex; flex-direction: column; border-left: 1px solid var(--line); background: var(--chat-bg); }
.chat-header { flex: 0 0 auto; display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.chat-header small { color: #8296b1; font-size: 11px; }
.chat-messages { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.chat-empty, .chat-system { margin: auto; color: #8193aa; font-size: 13px; text-align: center; }
.chat-system { margin: 0; padding: 7px 9px; border-radius: 9px; background: rgba(255,117,138,.1); color: #ffb8c4; }
.chat-message { align-self: flex-start; width: min(90%, 290px); }
.chat-message.own { align-self: flex-end; }
.chat-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 5px 4px; color: #91a6bf; font-size: 11px; }
.chat-meta strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #bcd2ea; }
.chat-text { padding: 9px 11px; border: 1px solid var(--line); border-radius: 12px 12px 12px 4px; background: var(--chat-bubble); color: var(--text); line-height: 1.45; overflow-wrap: anywhere; white-space: pre-wrap; }
.chat-message.own .chat-text { border-color: rgba(86,199,255,.34); border-radius: 12px 12px 4px 12px; background: var(--chat-own); }
.chat-form { flex: 0 0 auto; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.chat-form textarea { width: 100%; min-height: 42px; max-height: 110px; resize: vertical; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; outline: none; background: var(--input-bg); color: var(--text); line-height: 1.35; }
.chat-form textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(86,199,255,.12); }
.chat-form button { min-height: 42px; border: 0; border-radius: 11px; padding: 0 14px; background: #2875a4; color: #fff; font-weight: 650; }

.admin-panel { width: min(720px, 100%); }
.admin-panel .card { width: 100%; }
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.switch-row { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; padding: 14px; border: 1px solid var(--line); border-radius: 12px; }
.switch-row input { width: 22px; height: 22px; }
.admin-actions { display: flex; gap: 12px; margin-top: 20px; }
.admin-actions .primary { margin: 0; }
.secondary { border: 1px solid var(--line); background: transparent; color: #c9d7e8; border-radius: 12px; padding: 12px 16px; }
.notice { color: var(--good); min-height: 24px; margin-top: 12px; }
.room-name { color: #8fcce9; font-size: 13px; font-weight: 600; }
.room-admin { margin-top: 28px; padding-top: 22px; border-top: 1px solid var(--line); }
.room-admin h2 { margin: 0 0 12px; }
.room-create { display: grid; grid-template-columns: 1fr 1fr auto; align-items: end; gap: 12px; }
.room-create .field { margin: 0; }
.room-create .primary { width: auto; margin: 0; white-space: nowrap; }
.room-list { display: grid; gap: 8px; margin-top: 18px; }
.room-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: rgba(3,10,20,.38); }
.room-row div { display: grid; gap: 4px; min-width: 0; }
.room-row small, .room-empty { color: #8fa2ba; overflow-wrap: anywhere; }
.room-delete { border: 1px solid rgba(255,117,138,.4); border-radius: 9px; padding: 8px 11px; background: #421d29; color: #ffd4dc; }
@media (max-width: 900px) {
  .topbar { align-items: flex-start; flex-wrap: wrap; gap: 8px 14px; padding: 11px 14px; }
  .status { width: 100%; line-height: 1.45; }
  .call-stage { grid-template-columns: 1fr; grid-template-rows: minmax(0, 3fr) minmax(180px, 2fr); }
  .grid { gap: 10px; padding: 10px; align-content: start; }
  .tile.has-video, .grid.multiple-video .tile.has-video, .grid.multiple-video .tile.has-video.primary-video { grid-column: 1 / -1; min-height: 0; }
  .tile.no-video { grid-column: span 6; min-height: 76px; }
  .tile.no-video.name-only { grid-column: span 4; min-height: 44px; }
  .chat-panel { border-left: 0; border-top: 1px solid var(--line); }
  .chat-header { padding: 10px 12px; }
  .chat-messages { padding: 10px 12px; gap: 9px; }
  .chat-form { padding: 9px 10px; }
  .controls { justify-content: flex-start; gap: 7px; padding: 10px 10px max(10px, env(safe-area-inset-bottom)); overflow-x: auto; scrollbar-width: none; }
  .controls::-webkit-scrollbar { display: none; }
  .control { flex: 0 0 auto; min-width: auto; padding: 10px 13px; }
  .control span { display: none; }
}
@media (max-width: 620px) { .admin-grid { grid-template-columns: 1fr; } .switch-row { grid-column: auto; } .gate, .admin-shell { padding: 14px; } .card { padding: 22px 18px; } .chat-header small { display: none; } .chat-form textarea { font-size: 16px; } }
@media (max-width: 720px) { .room-create { grid-template-columns: 1fr; } .room-create .primary { width: 100%; } }
