:root {
  --bg: #0b0d13;
  --bg-2: #12141c;
  --bg-3: #191c26;
  --line: #262a36;
  --text: #e8eaf2;
  --muted: #8b91a5;
  --accent: #ff4d67;
  --accent-2: #ff7a5c;
  --ok: #35d39a;
  --warn: #ffb020;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: radial-gradient(1200px 700px at 12% -10%, #24203a 0%, transparent 60%),
              radial-gradient(900px 600px at 95% 0%, #10314a 0%, transparent 55%),
              var(--bg);
  color: var(--text);
  font: 14px/1.5 "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }
h1, h2 { margin: 0; font-weight: 600; }

/* ---------------------------------------------------------- 进门 */
.lobby {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 50;
}
.lobby[hidden] { display: none; }
.lobby-card {
  width: 100%;
  max-width: 360px;
  background: linear-gradient(180deg, rgba(30, 33, 46, .96), rgba(18, 20, 28, .96));
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px 24px 22px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .55);
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}
.logo { font-size: 40px; line-height: 1; }
.lobby-card h1 { font-size: 24px; letter-spacing: .06em; }
.lobby-sub { margin: -6px 0 6px; color: var(--muted); font-size: 13px; }
.field { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.field span { font-size: 12px; color: var(--muted); }
.field input {
  background: #0f1119;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  outline: none;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255, 77, 103, .15); }
#input-room { letter-spacing: .22em; text-transform: uppercase; }
.lobby-tip { margin: 0; color: var(--muted); font-size: 12px; }
.lobby-error { margin: 0; min-height: 18px; color: var(--accent-2); font-size: 12px; }

/* ---------------------------------------------------------- 通用控件 */
.btn {
  border: 1px solid var(--line);
  background: var(--bg-3);
  border-radius: 10px;
  padding: 9px 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: #232838; border-color: #333a4d; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.primary.off { background: #2a2f3f; color: var(--muted); font-weight: 400; }
.btn.ghost { background: rgba(255, 255, 255, .03); }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.block { width: 100%; padding: 11px; }

/* ---------------------------------------------------------- 顶栏 */
#main { height: 100%; display: flex; flex-direction: column; }
#main[hidden] { display: none; }

.topbar {
  height: 52px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 13, 19, .85);
  backdrop-filter: blur(10px);
}
.brand { font-size: 15px; letter-spacing: .04em; }
.room-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  border-radius: 999px;
  padding: 5px 12px;
  cursor: pointer;
  font-size: 12px;
  color: var(--muted);
}
.room-chip:hover { border-color: var(--accent); }
.room-chip b { color: var(--text); letter-spacing: .18em; }
.copy-hint { color: var(--accent); opacity: .85; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #555c70; box-shadow: 0 0 0 3px rgba(255, 255, 255, .04); }
.dot.on { background: var(--ok); }
.dot.error { background: var(--accent); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.who { color: var(--muted); font-size: 12px; }

/* ---------------------------------------------------------- 布局 */
.layout {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 336px;
}
.layout.wide { grid-template-columns: minmax(0, 1fr); }
.layout.wide .side { display: none; }

.stage { min-width: 0; display: flex; flex-direction: column; }
.video-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: #000;
}
#video { width: 100%; height: 100%; display: block; object-fit: contain; background: #000; }

.video-mask {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(8, 9, 13, .82);
  text-align: center;
  padding: 20px;
  transition: opacity .2s;
}
.video-mask[hidden] { display: none; }
.mask-inner { color: var(--muted); }
.mask-inner p { margin: 8px 0 0; }
.mask-sub { font-size: 12px; color: #6d7488; max-width: 420px; }
.spinner {
  width: 30px; height: 30px; margin: 0 auto;
  border: 3px solid rgba(255, 255, 255, .15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------- 播放控制 */
.controls {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--bg-2);
  border-top: 1px solid var(--line);
}
.icon-btn {
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  cursor: pointer;
}
.icon-btn:hover { background: rgba(255, 255, 255, .07); }
.time { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.time b { color: var(--text); font-weight: 500; }
.seek { flex: 1 1 auto; min-width: 40px; }
.ctrl-right { display: flex; align-items: center; gap: 8px; }
.volume { width: 78px; }
.rate {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 6px;
  font-size: 12px;
  cursor: pointer;
}

input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  height: 16px;
  background: transparent;
  cursor: pointer;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: #333a4d;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  margin-top: -4px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
}
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: #333a4d; }
input[type=range]::-moz-range-thumb { width: 12px; height: 12px; border: none; border-radius: 50%; background: var(--accent); }

.statusbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 14px 8px;
  font-size: 12px;
  color: var(--muted);
  background: var(--bg-2);
}
.statusbar .sep { opacity: .4; }
.statusbar .grow { flex: 1 1 auto; }
.statusbar .ok { color: var(--ok); }
.statusbar .warn { color: var(--warn); }

/* ---------------------------------------------------------- 侧栏 */
.side {
  border-left: 1px solid var(--line);
  background: var(--bg-2);
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.panel {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.panel h2 { font-size: 13px; color: var(--muted); font-weight: 500; letter-spacing: .05em; display: flex; align-items: center; gap: 6px; }
.count { background: #2a2f3f; color: var(--text); border-radius: 999px; padding: 1px 8px; font-size: 11px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.row .url {
  flex: 1 1 auto;
  min-width: 0;
  background: #0f1119;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 10px;
  outline: none;
  font-size: 12px;
}
.row .url:focus { border-color: var(--accent); }
.mini { flex: 0 0 58px; font-size: 12px; color: var(--muted); }
.switch { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); cursor: pointer; flex: 1 1 100%; }
.switch input { accent-color: var(--accent); width: 15px; height: 15px; }

.call-state {
  font-size: 12px;
  color: var(--muted);
  background: #0f1119;
  border: 1px dashed var(--line);
  border-radius: 9px;
  padding: 7px 10px;
}
.call-state.live { color: var(--ok); border-style: solid; border-color: rgba(53, 211, 154, .4); }
.call-state.err { color: var(--accent-2); border-color: rgba(255, 122, 92, .4); }
.meter { height: 6px; border-radius: 3px; background: #0f1119; overflow: hidden; }
.meter i {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--ok), var(--warn));
  transition: width .08s linear;
}
.note { margin: 0; font-size: 11px; color: #6d7488; line-height: 1.5; }

.members { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.members li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  background: #0f1119;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 7px 10px;
}
.members .avatar {
  width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #3a3f55, #262a36);
  font-size: 11px; color: #cfd3e0;
}
.members .tag { margin-left: auto; font-size: 11px; color: var(--muted); }
.members .tag.speaking { color: var(--ok); }

/* ---------------------------------------------------------- 提示条 */
.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%);
  background: rgba(25, 28, 38, .97);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .5);
  z-index: 80;
  max-width: 88vw;
  text-align: center;
}
.toast[hidden] { display: none; }

/* ---------------------------------------------------------- 窄屏 */
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(180px, 46vh) 1fr; }
  .side { border-left: none; border-top: 1px solid var(--line); }
  .copy-hint { display: none; }
  .volume { width: 54px; }
  .who { display: none; }
}

/* ---------------------------------------------------------- 后台 */
.login-wrap {
  min-height: calc(100vh - 52px);
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-wrap[hidden] { display: none; }
#admin-main { padding: 16px; }
#admin-main[hidden] { display: none; }
.admin-grid {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
  max-width: 1180px;
  margin: 0 auto;
}
.admin-grid .panel { gap: 10px; }

.link-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.link-list li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: #0f1119;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 10px;
}
.link-main { min-width: 0; flex: 1 1 auto; }
.link-title { font-size: 13px; }
.link-url { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-note { font-size: 11px; color: #6d7488; margin-top: 3px; word-break: break-all; }
.link-ops { display: flex; gap: 6px; flex: 0 0 auto; }
.btn.danger { color: var(--accent-2); }
.btn.danger:hover { border-color: var(--accent-2); background: rgba(255, 122, 92, .08); }

/* 播放页里的可点选列表 */
.link-list.pick li { cursor: pointer; align-items: center; }
.link-list.pick li:hover { border-color: var(--accent); background: #171b27; }
.link-list.pick .idx {
  width: 20px; height: 20px; border-radius: 6px; flex: 0 0 auto;
  background: #262a36; color: var(--muted); font-size: 11px; display: grid; place-items: center;
}
.link-list.pick .link-title { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-list.pick .link-tag {
  font-size: 11px; color: #6d7488; flex: 0 1 auto; max-width: 42%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mini-link { margin-left: auto; font-size: 11px; font-weight: 400; color: var(--accent); text-decoration: none; }
.mini-link:hover { text-decoration: underline; }

@media (max-width: 900px) {
  .admin-grid { grid-template-columns: minmax(0, 1fr); }
}

/* ---------------------------------------------------------- 音量面板 */
.vrow { display: flex; align-items: center; gap: 8px; }
.vrow > span { flex: 1 1 auto; font-size: 12px; color: var(--muted); }
.vrow > b { font-size: 12px; font-weight: 500; font-variant-numeric: tabular-nums; }
input[type=range].vslider { width: 100%; height: 30px; margin: 0 0 4px; }
input[type=range].vslider::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; }
input[type=range].vslider::-webkit-slider-thumb { width: 18px; height: 18px; margin-top: -6px; }
input[type=range].vslider::-moz-range-track { height: 6px; border-radius: 3px; }
input[type=range].vslider::-moz-range-thumb { width: 18px; height: 18px; }
.panel[hidden] { display: none !important; }

/* ---------------------------------------------------------- 移动端 */
.mtabs { display: none; }
.mtab[hidden] { display: none !important; }
.hidden-desktop { display: none; }

@media (max-width: 900px) {
  /* 单列纵向：播放器 → 标签栏 → 面板 */
  .layout {
    display: flex;
    flex-direction: column;
    grid-template-columns: none;
    grid-template-rows: none;
  }
  .stage { flex: 0 0 auto; }
  .video-wrap { flex: 0 0 auto; height: 32vh; min-height: 170px; }
  .side { flex: 1 1 auto; min-height: 0; padding: 10px; gap: 10px; }

  /* 侧栏面板按标签切换 */
  .side > .panel { display: none; }
  .side[data-active="links"] > .panel[data-tab="links"],
  .side[data-active="source"] > .panel[data-tab="source"],
  .side[data-active="call"] > .panel[data-tab="call"],
  .side[data-active="volume"] > .panel[data-tab="volume"] { display: flex; }

  /* 标签栏 */
  .mtabs {
    flex: 0 0 auto;
    display: flex;
    gap: 6px;
    padding: 8px 10px;
    overflow-x: auto;
    background: var(--bg-2);
    border-top: 1px solid var(--line);
    -webkit-overflow-scrolling: touch;
  }
  .mtab {
    flex: 1 0 auto;
    min-height: 38px;
    padding: 0 14px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--bg-3);
    color: var(--muted);
    font-size: 13px;
    white-space: nowrap;
    cursor: pointer;
  }
  .mtab.active {
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    border-color: transparent;
    color: #fff;
    font-weight: 600;
  }

  /* 触控热区 */
  .hidden-desktop { display: inline-block; }
  .icon-btn { width: 40px; height: 40px; font-size: 17px; }
  .controls { padding: 6px 10px; gap: 8px; }
  .topbar { height: 50px; padding: 0 10px; gap: 8px; }
  .room-chip { padding: 7px 10px; }
  .btn { padding: 10px 14px; }
  .panel { padding: 11px; }
  .lobby-card { padding: 22px 18px 18px; }
}

/* 移动端地址栏会伸缩，用动态视口高度避免底部被挡住 */
@supports (height: 100dvh) {
  html, body { height: 100dvh; }
  @media (max-width: 900px) {
    .video-wrap { height: 32dvh; }
  }
}

/* iPhone 刘海屏底部安全区 */
@supports (padding: env(safe-area-inset-bottom)) {
  @media (max-width: 900px) {
    .side { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
    .mtabs { padding-left: calc(10px + env(safe-area-inset-left)); padding-right: calc(10px + env(safe-area-inset-right)); }
  }
}

/* 窄屏控制条改两行，避免横向溢出（音量改到「音量」面板里调） */
@media (max-width: 900px) {
  .controls { flex-wrap: wrap; row-gap: 6px; }
  .seek { flex: 1 1 100%; order: 2; min-height: 26px; }
  .ctrl-right { order: 3; width: 100%; justify-content: flex-end; gap: 10px; }
  #volume { display: none; }
}

/* 窄屏状态栏保持一行，过长省略 */
@media (max-width: 900px) {
  .statusbar { font-size: 11px; gap: 6px; }
  #sync-status { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #quality-info, #delay-info { white-space: nowrap; }
}

/* ---------------------------------------------------------- 房主模式 */
.role-chip {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--muted);
  white-space: nowrap;
}
.role-chip.host { border-color: rgba(255, 77, 103, .5); background: rgba(255, 77, 103, .16); color: #ffd9df; }
.role-chip[hidden] { display: none; }

button:disabled, input:disabled, select:disabled { opacity: .45; cursor: not-allowed; }
.link-list.pick.locked li { opacity: .5; cursor: not-allowed; }
.link-list.pick.locked li:hover { border-color: var(--line); background: #0f1119; }
.members .tag.host { color: var(--accent); }
.members li .btn.small { margin-left: 8px; padding: 4px 9px; font-size: 11px; }

/* ---------------------------------------------------------- 全屏控制条 */
.fs-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  display: none;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  background: linear-gradient(180deg, rgba(8, 9, 13, 0), rgba(8, 9, 13, .9) 45%);
  transition: opacity .25s;
}
.video-wrap:fullscreen .fs-bar,
.video-wrap:-webkit-full-screen .fs-bar { display: flex; }
.fs-bar.idle { opacity: 0; pointer-events: none; }
.fs-bar .time { color: #d7dae4; }
.fs-bar .seek { flex: 1 1 160px; }
.fs-bar .fs-state { font-size: 12px; color: var(--muted); white-space: nowrap; }
.fs-bar .fs-state.live { color: var(--ok); }
.fs-bar .fs-state.err { color: var(--accent-2); }
.video-wrap:fullscreen,
.video-wrap:-webkit-full-screen { background: #000; }

@media (max-width: 900px) {
  .fs-bar { padding: 8px 10px; gap: 6px; }
  /* 窄屏排成：播放+时间 / 进度条 / 一排按钮 / 通话状态 */
  .fs-bar #fs-play { order: -3; }
  .fs-bar .time { order: -2; }
  .fs-bar .seek { flex: 1 1 100%; order: -1; }
  .fs-bar .fs-state { order: 3; flex: 1 1 auto; }
  .fs-bar #fs-exit { order: 4; }
  .role-chip { font-size: 11px; padding: 2px 8px; }
}
