/* ===== 主题变量 ===== */
/* 浅色（默认） */
:root {
  --bg: #f4f5f8;
  --panel: #ffffff;
  --line: #dfe3ec;
  --text: #1b2130;
  --muted: #677086;
  --accent: #2563eb;
  --accent-2: #16a34a;
  --warn: #d97706;
  --err: #dc2626;
}

/* 深色：跟随系统（未手动指定时） */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --panel: #171a21;
    --line: #262b36;
    --text: #e8eaf0;
    --muted: #8a93a6;
    --accent: #3b82f6;
    --accent-2: #22c55e;
    --warn: #f59e0b;
    --err: #ef4444;
  }
}

/* 手动指定 */
:root[data-theme="dark"] {
  --bg: #0f1115;
  --panel: #171a21;
  --line: #262b36;
  --text: #e8eaf0;
  --muted: #8a93a6;
  --accent: #3b82f6;
  --accent-2: #22c55e;
  --warn: #f59e0b;
  --err: #ef4444;
}
:root[data-theme="light"] {
  --bg: #f4f5f8;
  --panel: #ffffff;
  --line: #dfe3ec;
  --text: #1b2130;
  --muted: #677086;
  --accent: #2563eb;
  --accent-2: #16a34a;
  --warn: #d97706;
  --err: #dc2626;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.hidden { display: none !important; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 18px; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.status { font-size: 13px; color: var(--muted); }
.status.ok { color: var(--accent-2); }
.status.warn { color: var(--warn); }
.status.err { color: var(--err); }

/* 主题切换按钮 */
.theme-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 6px 12px;
  font-size: 13px;
  border-radius: 999px;
}
.theme-btn:hover { color: var(--text); border-color: var(--muted); }

.view { padding: 16px; }

/* ---------- 主机视图 ---------- */
.pair-area { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.qr-wrap img {
  background: #fff;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  width: min(280px, 70vw);
  height: auto;
  image-rendering: pixelated;
}
.code-wrap { text-align: center; }
.code-label { font-size: 13px; color: var(--muted); letter-spacing: 2px; }
.code {
  font-size: 52px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 14px;
  text-indent: 14px;
  color: var(--accent);
  margin: 4px 0;
}
.code-hint { font-size: 13px; color: var(--muted); margin-top: 4px; }
.link-row { display: flex; gap: 8px; width: min(420px, 100%); }
.link-row input {
  flex: 1;
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
}
.actions { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; align-items: center; }

/* ---------- 按钮 ---------- */
button {
  font: inherit;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: filter .15s, transform .05s;
}
button:active { transform: scale(.97); }
button:disabled { opacity: .45; cursor: not-allowed; }
.big {
  min-height: 56px;
  padding: 12px 24px;
  font-size: 17px;
  font-weight: 700;
  background: var(--accent);
  color: #fff;
  width: min(420px, 100%);
}
.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 10px 18px;
  font-size: 14px;
}
.ghost:hover { color: var(--text); border-color: var(--muted); }

/* ---------- 配对视图 ---------- */
.join-box { max-width: 360px; margin: 8vh auto 0; display: flex; flex-direction: column; gap: 14px; text-align: center; }
.join-box h2 { font-size: 22px; }
.muted { color: var(--muted); font-size: 13px; }
#joinCodeInput {
  font-size: 40px;
  text-align: center;
  letter-spacing: 18px;
  text-indent: 18px;
  font-variant-numeric: tabular-nums;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  padding: 12px 0;
  width: 100%;
}
#joinCodeInput:focus { outline: 2px solid var(--accent); border-color: transparent; }
.error { color: var(--err); font-size: 13px; min-height: 18px; }

/* ---------- 传输视图 ---------- */
#view-transfer { display: flex; flex-direction: column; gap: 12px; flex: 1; }
.sender { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.sender .big { width: auto; flex: 1; min-width: 200px; }
.receiver {
  flex: 1;
  min-height: 300px;
  background: #000;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.receiver img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  cursor: pointer;
}
/* 图片查看区固定黑底（不随主题变化），内部文字固定白色系 */
.receiver-placeholder { color: rgba(255, 255, 255, .75); text-align: center; font-size: 14px; line-height: 1.8; }
.receiver-title { font-size: 16px; color: #fff; font-weight: 600; }
.progress { font-size: 13px; color: var(--muted); }
.receiver .progress {
  position: absolute;
  bottom: 12px;
  left: 0;
  right: 0;
  text-align: center;
  background: rgba(0, 0, 0, .6);
  padding: 4px;
  border-radius: 8px;
  color: rgba(255, 255, 255, .85);
}

/* 图片栏操作按钮 */
.receiver-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.receiver-actions button {
  background: var(--accent);
  color: #fff;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 10px;
}

/* ---------- 拍照 / 扫码视图 ---------- */
#view-scan video {
  width: 100%;
  max-height: 62dvh;
  object-fit: contain;
  background: #000;
  border-radius: 14px;
  border: 1px solid var(--line);
}
/* 取景：容器跟随视频比例自适应，完整显示画面（不裁切） */
.cam-wrap {
  min-height: 30dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  border-radius: 14px;
  border: 1px solid var(--line);
  overflow: hidden;
}
.cam-wrap video {
  max-width: 100%;
  max-height: 62dvh;
  width: auto;
  height: auto;
}
/* 发送前预览：固定正方形容器，图片 contain + 旋转，布局恒定（按钮不跳动） */
.preview-wrap {
  width: min(100%, 56dvh);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  background: #000;
  border-radius: 14px;
  border: 1px solid var(--line);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.preview-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: transform .15s;
}
.capture-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.capture-bar .big { width: auto; min-width: 160px; }
.scan-hint { color: var(--muted); font-size: 14px; }

/* ---------- 全图模式：整页只显示图片 ---------- */
.fullscreen {
  position: fixed;
  inset: 0;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
}
.fullscreen img {
  max-width: 100vw;
  max-height: 100dvh;
  object-fit: contain;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: #232936;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 99;
  box-shadow: 0 4px 20px rgba(0, 0, 0, .5);
  max-width: 90vw;
  text-align: center;
}
