/* ============================================================
   迹 · 通信 — 样式
   与 a.dcy.me 同一设计语言：暖纸白/墨色 + 玄黑/宣纸白，朱砂点睛
   ============================================================ */

:root {
  --bg: #faf8f4;
  --surface: #ffffff;
  --fg: #211d18;
  --muted: #837b70;
  --line: #e8e2d8;
  --line-2: #d8d0c2;
  --accent: #b0524a;
  --accent-soft: rgba(176, 82, 74, .12);
  --ok: #2f9e63;
  --danger: #c04a44;
  --danger-soft: rgba(192, 74, 68, .12);
  --shadow: 0 10px 30px rgba(33, 29, 24, .10);
  --shadow-lift: 0 18px 44px rgba(33, 29, 24, .16);
  --radius: 14px;
  --radius-s: 9px;
  --serif: "ZCOOL XiaoWei", "Songti SC", "STSong", "Noto Serif SC", "SimSun", serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
          "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --bar-h: 56px;
  --dock-h: 84px;
}

[data-theme="dark"] {
  --bg: #111013;
  --surface: #1a191d;
  --fg: #eae5dc;
  --muted: #97918a;
  --line: #2a2823;
  --line-2: #3a362f;
  --accent: #cf7f6f;
  --accent-soft: rgba(207, 127, 111, .14);
  --ok: #58b98a;
  --danger: #d4685f;
  --danger-soft: rgba(212, 104, 95, .16);
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  --shadow-lift: 0 18px 44px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

/* 组件样式常覆写 display，统一强制 hidden 生效 */
[hidden] { display: none !important; }

html { height: 100%; }

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--fg);
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  transition: background .35s ease, color .35s ease;
}

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
svg { display: block; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
::selection { background: var(--accent); color: #fff; }

/* ---------- 通用元件 ---------- */

.brand {
  font-family: var(--serif);
  font-size: 30px; font-weight: 700; line-height: 1;
  letter-spacing: .05em;
}
.brand-dot {
  display: inline-block; width: 7px; height: 7px; margin-left: 3px;
  background: var(--accent); border-radius: 50%;
}

.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px clamp(18px, 5vw, 48px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.topnav { display: flex; align-items: center; gap: clamp(14px, 3vw, 26px); }
.head-meta { font-size: 13px; letter-spacing: .12em; color: var(--muted); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border: 1px solid var(--line);
  border-radius: 50%; background: var(--surface); color: var(--fg);
  transition: transform .2s, border-color .2s;
}
.icon-btn:hover { transform: scale(1.08); border-color: var(--accent); }
.icon-btn svg { width: 17px; height: 17px; margin: auto; }

[data-theme="light"] .i-sun { display: none; }
[data-theme="dark"] .i-moon { display: none; }

.micro {
  font-size: 11px; font-weight: 500;
  letter-spacing: .14em; color: var(--muted);
}

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px; height: 46px; padding: 0 24px;
  border-radius: 999px; font-size: 14.5px; white-space: nowrap;
  transition: background-color .25s, color .25s, border-color .25s, transform .1s;
}
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }

.btn-ghost { border: 1px solid var(--line-2); color: var(--fg); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

.notice {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px; margin-bottom: 20px;
  border: 1px solid var(--danger); border-radius: var(--radius-s);
  font-size: 13.5px; color: var(--danger);
  background: var(--danger-soft);
}
.notice svg { width: 16px; height: 16px; flex: none; margin-top: 3px; }

/* ---------- 大厅 ---------- */

.lobby-main { max-width: 1160px; margin: 0 auto; }

.hero {
  min-height: calc(58vh - 70px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 7vh 20px 5vh;
}
.hero-title {
  font-family: var(--serif);
  font-size: clamp(120px, 26vw, 220px);
  font-weight: 700; line-height: 1; margin: 0;
  letter-spacing: .04em;
}
.hero-quote {
  margin: 22px 0 0; font-size: clamp(15px, 2.2vw, 18px);
  color: var(--muted); letter-spacing: .3em;
}
.hero-meta {
  margin: 14px 0 0; font-size: 13px;
  color: var(--muted); letter-spacing: .12em;
}

.panel {
  max-width: 480px; margin: 0 auto;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); padding: clamp(20px, 4vw, 30px);
  box-shadow: var(--shadow);
}

.field + .btn { margin-top: 18px; }
.field-line { display: flex; align-items: center; gap: 6px; }

.field input[type="text"] {
  flex: 1; min-width: 0; height: 46px; padding: 0 14px;
  background: var(--bg); border: 1px solid var(--line-2);
  border-radius: var(--radius-s); color: var(--fg);
  font-size: 16.5px; font-family: inherit;
  transition: border-color .2s;
}
.field input[type="text"]::placeholder { color: var(--muted); opacity: .7; }
.field input[type="text"]:focus { outline: none; border-color: var(--accent); }

.row-create .btn-primary { width: 100%; }

.rule {
  position: relative; margin: 26px 0; text-align: center;
  border-top: 1px solid var(--line);
}
.rule span {
  position: relative; top: -0.85em; display: inline-block;
  padding: 0 12px; background: var(--surface);
  font-size: 12px; letter-spacing: .1em; color: var(--muted);
}

.row-join { display: flex; align-items: flex-end; gap: 12px; }
.row-join .field { flex: 1; }
.row-join .field input { font-family: var(--mono); font-size: 15px; }
.row-join .btn { height: 46px; }

.trust {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin: 26px 0 0; font-size: 12.5px; letter-spacing: .08em; color: var(--muted);
}
.trust svg { width: 14px; height: 14px; flex: none; color: var(--accent); }

/* ---------- 页脚 ---------- */

.footer {
  border-top: 1px solid var(--line);
  text-align: center; padding: 44px 20px 54px; color: var(--muted);
}
.footer-quote { font-family: var(--serif); letter-spacing: .2em; margin: 0; font-size: 15px; }
.footer-quote small { display: block; margin-top: 6px; font-size: 12px; letter-spacing: .1em; }
.footer-copy { margin: 16px 0 0; font-size: 12px; letter-spacing: .08em; }

@media (max-width: 640px) {
  .topbar { padding: 12px 16px; }
  .lobby-main { padding: 0 4px; }
  .hero { min-height: calc(48vh - 60px); }
  .panel { margin: 0 12px; }
  .row-join { flex-direction: column; align-items: stretch; gap: 14px; }
  .row-join .btn { width: 100%; }
  .head-meta { display: none; }
}

/* ---------- 通话页 ---------- */

.room, .stage {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}
.stage { position: relative; background: var(--bg); }

.room-bar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  height: calc(var(--bar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.room-bar .brand { font-size: 24px; }

.room-id {
  display: inline-flex; align-items: center; gap: 8px;
  max-width: 38vw; height: 34px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); font-size: 12.5px; color: var(--muted);
  transition: border-color .2s, color .2s;
}
.room-id:hover { border-color: var(--accent); color: var(--fg); }
.room-id span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-id svg { width: 13px; height: 13px; flex: none; }

.room-meta {
  display: flex; align-items: center; gap: 10px; margin-left: auto;
  font-size: 12.5px; color: var(--muted); white-space: nowrap;
}
.meta-item { display: inline-flex; align-items: center; gap: 6px; }
.meta-item svg { width: 14px; height: 14px; }
.sep { width: 1px; height: 14px; background: var(--line-2); }

.dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.dot-idle { background: var(--accent); animation: breathe 1.6s ease-in-out infinite; }
.dot-ok   { background: var(--ok); }
.dot-off  { background: var(--muted); }
@keyframes breathe { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }

/* —— 视频网格 —— */

.grid {
  position: absolute; inset: 0;
  display: grid; grid-template-columns: 1fr;
  grid-auto-rows: minmax(0, 1fr); gap: 10px;
  padding: calc(var(--bar-h) + env(safe-area-inset-top) + 10px)
           10px
           calc(var(--dock-h) + env(safe-area-inset-bottom) + 10px)
           10px;
  background: var(--bg);
}

.grid[data-count="2"],
.grid[data-count="3"],
.grid[data-count="4"] { grid-template-columns: repeat(2, 1fr); }
.grid[data-count="5"],
.grid[data-count="6"],
.grid[data-count="7"],
.grid[data-count="8"],
.grid[data-count="9"] { grid-template-columns: repeat(3, 1fr); }

/* 横长窗口：2 人左右排布最自然（默认行为）；
   竖长窗口（分屏 / 竖屏显示器 / 半屏窗口）：改为上下堆叠，避免两侧被压成窄条 */
@media (min-width: 641px) and (max-aspect-ratio: 5/6) {
  .grid[data-count="2"],
  .grid[data-count="3"],
  .grid[data-count="4"] { grid-template-columns: 1fr; }
  .grid[data-count="5"],
  .grid[data-count="6"],
  .grid[data-count="7"],
  .grid[data-count="8"],
  .grid[data-count="9"] { grid-template-columns: repeat(2, 1fr); }
}

.grid.has-main, .grid.presenting {
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: minmax(0, 2.4fr) minmax(0, 1fr);
  grid-auto-rows: minmax(0, 1fr);
}
.grid.has-main .tile.main,
.grid.presenting .tile.main { grid-column: 1 / -1; grid-row: 1; }

.tile {
  position: relative; background: #0c0b0a;
  border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; min-height: 0; min-width: 0;
  cursor: pointer; transition: border-color .2s, box-shadow .3s;
}
.tile.main { border-color: var(--line-2); cursor: zoom-in; box-shadow: var(--shadow); }
.tile.presenting { border-color: var(--accent); }

.tile-video,
.tile-share {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; background: #0c0b0a; display: none;
}
.tile-video { object-fit: contain; }
.tile-video.on, .tile-share.on { display: block; }
.tile-video.fit, .tile-share.fit { object-fit: contain; }
.tile-video.mirror { transform: scaleX(-1); }

/* 全屏播放时保持完整画面不裁切 */
video:fullscreen { object-fit: contain; }
video:-webkit-full-screen { object-fit: contain; }

.tile-avatar {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  display: flex; align-items: center; justify-content: center;
  width: 76px; height: 76px; border-radius: 50%;
  border: 1px solid var(--line-2); color: var(--fg);
  font-family: var(--serif); font-size: 30px;
  background: var(--surface);
}
@media (max-width: 640px) {
  .tile-avatar { width: 60px; height: 60px; font-size: 24px; }
}

.tile-tag {
  position: absolute; left: 10px; bottom: 10px; right: 10px;
  display: flex; align-items: center; gap: 8px; pointer-events: none;
}
.tile-tag > span {
  display: inline-flex; align-items: center; gap: 5px;
  height: 26px; padding: 0 10px; border-radius: 999px;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  font-size: 12px;
}
.t-name { color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60%; }
.t-you { color: var(--muted); }

/* 麦克风 / 摄像头状态徽标：常显；开=绿、关=实红 */
.tile-tag > span.t-st {
  width: 26px; height: 26px; padding: 0; justify-content: center;
}
.t-st svg { width: 15px; height: 15px; }
.t-st .ic-off { display: none; }
.t-st[data-on="1"] { background: var(--accent-soft); border-color: transparent; color: var(--ok); }
.t-st[data-on="0"] { background: var(--danger); border-color: transparent; color: #fff; }
.t-st[data-on="0"] .ic-on { display: none; }
.t-st[data-on="0"] .ic-off { display: block; }
.t-st-mic { margin-left: auto; }

.t-live { color: var(--accent); }
.t-live::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
}

/* —— 等待 / 结束面板 —— */

.waiting, .ended {
  position: absolute; inset: 0; z-index: 20;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px;
  text-align: center;
  padding: calc(var(--bar-h) + 24px) 24px calc(var(--dock-h) + 24px);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
}
.waiting[hidden], .ended[hidden] { display: none; }

.pulse-dot {
  position: relative; width: 8px; height: 8px; border-radius: 50%;
  background: var(--ok); margin-bottom: 8px;
}
.pulse-dot::after {
  content: ""; position: absolute; inset: -7px; border-radius: 50%;
  border: 1px solid var(--ok); opacity: 0;
  animation: ping 2.2s ease-out infinite;
}
@keyframes ping {
  0%   { transform: scale(.5); opacity: .55; }
  70%, 100% { transform: scale(1.15); opacity: 0; }
}

.waiting-title { font-family: var(--serif); font-size: 24px; letter-spacing: .1em; }
.waiting-sub { font-size: 14px; color: var(--muted); letter-spacing: .06em; }

.invite-qr {
  margin-top: 18px; padding: 10px; border-radius: var(--radius-s);
  background: #fff; line-height: 0;
  border: 1px solid var(--line); box-shadow: var(--shadow);
}
.invite-qr img, .invite-qr canvas { width: 148px; height: 148px; display: block; }
.qr-hint { margin-top: 8px; font-size: 12px; letter-spacing: .12em; color: var(--muted); }

.invite-row {
  display: flex; gap: 8px; margin-top: 18px; width: min(460px, 100%);
}
.invite-input {
  flex: 1; min-width: 0; height: 46px; padding: 0 14px;
  background: var(--surface); border: 1px solid var(--line-2);
  border-radius: 999px; color: var(--muted); font-size: 13px;
}
.invite-input:focus { outline: none; border-color: var(--accent); }
.invite-row .btn { flex: none; }

.ended-actions { display: flex; gap: 10px; margin-top: 14px; }

/* —— 控制条 —— */

.dock {
  position: absolute;
  bottom: calc(16px + env(safe-area-inset-bottom));
  left: 50%; transform: translateX(-50%); z-index: 30;
  display: flex; gap: 4px; padding: 8px;
  border: 1px solid var(--line); border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
}
.dock[hidden] { display: none; }

.ctl {
  position: relative; display: flex; align-items: center; justify-content: center;
  width: 48px; height: 48px; border-radius: 50%; color: var(--fg);
  transition: background-color .2s, color .2s, border-color .2s;
}
.ctl:hover { background: var(--accent-soft); }
.ctl svg { width: 20px; height: 20px; }

.ctl .ic-off { display: none; }
/* 关闭态：中性描边；语义红只留给挂断 */
.ctl[data-on="0"] { color: var(--muted); background: var(--bg); border: 1px solid var(--line-2); }
.ctl[data-on="0"]:hover { border-color: var(--accent); color: var(--fg); }
.ctl[data-on="0"] .ic-on { display: none; }
.ctl[data-on="0"] .ic-off { display: block; }

.ctl-danger { background: var(--danger); color: #fff; }
.ctl-danger:hover { filter: brightness(1.1); background: var(--danger); }

/* —— Toast —— */

.toast {
  position: absolute;
  bottom: calc(var(--dock-h) + env(safe-area-inset-bottom) + 24px);
  left: 50%; transform: translate(-50%, 6px); z-index: 40;
  max-width: min(420px, calc(100vw - 48px));
  padding: 9px 16px;
  border: 1px solid var(--line-2); border-radius: 999px;
  background: var(--surface); color: var(--fg);
  font-size: 13px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* —— 小屏适配 —— */

@media (max-width: 640px) {
  .room-bar { gap: 8px; }
  .room-bar .brand { font-size: 20px; }
  .room-id { max-width: 34vw; height: 30px; padding: 0 9px; font-size: 12px; }
  .room-meta { gap: 8px; font-size: 12px; }
  .meta-item svg { width: 13px; height: 13px; }
  .tile-tag { left: 8px; bottom: 8px; right: 8px; gap: 6px; }
  .tile-tag > span { height: 24px; padding: 0 8px; font-size: 11.5px; }
  .tile-tag > span.t-st { width: 26px; height: 26px; padding: 0; }
  .invite-row { flex-wrap: wrap; }
  .invite-row .btn { flex: 1 1 100%; }
  .waiting-title { font-size: 21px; }
  .waiting, .ended { padding: calc(var(--bar-h) + 16px) 16px calc(var(--dock-h) + 16px); }
  .dock {
    left: 12px; right: 12px; transform: none; justify-content: center;
  }
}

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