/* 密聊室 —— 视觉系统 v3（Telegram 蓝，浅/深色自适应，零外部资源） */
:root {
  --bg: #F1F5F9;
  --bg-wash: radial-gradient(1200px 600px at 50% -10%, rgba(42, 171, 238, 0.09), transparent 60%);
  --surface: #FFFFFF;
  --surface-2: #EBF1F7;
  --ink: #1A2733;
  --ink-soft: #5B6C7A;
  --ink-faint: #90A0AE;
  --line: #DCE6EF;
  --line-strong: #C4D4E2;
  --accent: #229ED9;
  --accent-2: #2AABEE;
  --accent-ink: #FFFFFF;
  --accent-soft: rgba(42, 171, 238, 0.12);
  --bubble-me: linear-gradient(135deg, #D9EFFF, #C8E7FC);
  --bubble-me-border: #B0DBF7;
  --bubble-peer: #FFFFFF;
  --err: #C0453A;
  --warn: #9A6B12;
  --shadow-sm: 0 1px 2px rgba(20, 40, 60, 0.06), 0 2px 8px rgba(20, 40, 60, 0.05);
  --shadow-md: 0 2px 6px rgba(20, 40, 60, 0.07), 0 12px 32px rgba(20, 40, 60, 0.10);
  --glass: rgba(241, 245, 249, 0.72);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0E1621;
    --bg-wash: radial-gradient(1200px 600px at 50% -10%, rgba(42, 171, 238, 0.08), transparent 60%);
    --surface: #17212B;
    --surface-2: #1E2C3A;
    --ink: #E4EDF4;
    --ink-soft: #8CA0B3;
    --ink-faint: #5C7186;
    --line: #243447;
    --line-strong: #2F4459;
    --accent: #4FB3F2;
    --accent-2: #2AABEE;
    --accent-ink: #FFFFFF;
    --accent-soft: rgba(79, 179, 242, 0.14);
    --bubble-me: linear-gradient(135deg, #2B5278, #234869);
    --bubble-me-border: #35618D;
    --bubble-peer: #182533;
    --err: #E0796C;
    --warn: #D9A960;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35), 0 2px 10px rgba(0, 0, 0, 0.25);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.4), 0 16px 40px rgba(0, 0, 0, 0.45);
    --glass: rgba(14, 22, 33, 0.72);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  background-image: var(--bg-wash);
  background-repeat: no-repeat;
  color: var(--ink);
  font: 15px/1.75 "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei UI", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--accent-soft); }

/* ---------- 首页 ---------- */
.home {
  max-width: 25rem;
  margin: 0 auto;
  padding: 4rem 1.25rem 2.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
  animation: rise 0.5s ease both;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
.brand { text-align: center; margin-bottom: 0.75rem; }
.brand .mark {
  width: 58px;
  height: 58px;
  margin: 0 auto 0.9rem;
  display: block;
  color: var(--accent);
  filter: drop-shadow(0 6px 16px var(--accent-soft));
}
.brand h1 {
  margin: 0;
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: 0.5em;
  text-indent: 0.5em; /* 视觉居中补偿 */
}
.brand p {
  margin: 0.55rem 0 0;
  color: var(--ink-soft);
  font-size: 0.8rem;
  letter-spacing: 0.18em;
  text-indent: 0.18em;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.35rem 1.4rem 1.45rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 0.95rem;
  transition: box-shadow 0.25s ease, border-color 0.25s ease;
}
.card:focus-within { box-shadow: var(--shadow-md); border-color: var(--line-strong); }
.card h2 {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-soft);
  letter-spacing: 0.3em;
}

.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field span { font-size: 0.78rem; color: var(--ink-soft); }
.field input, .field select {
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0.62rem 0.85rem;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
}
.field input::placeholder { color: var(--ink-faint); }
#join-room { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; letter-spacing: 0.12em; }

button.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-ink);
  border: none;
  border-radius: 10px;
  padding: 0.68rem 1.1rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  cursor: pointer;
  box-shadow: 0 2px 10px var(--accent-soft);
  transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.2s ease;
}
button.primary:hover { filter: brightness(1.06); box-shadow: 0 4px 16px var(--accent-soft); }
button.primary:active { transform: translateY(1px); }
button.primary:disabled { opacity: 0.5; cursor: default; }

button.ghost {
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  padding: 0.28rem 0.75rem;
  cursor: pointer;
  color: var(--ink-soft);
  font-size: 0.85rem;
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}
button.ghost:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
button.ghost.big { font-size: 1.25rem; line-height: 1; padding: 0.42rem 0.8rem; border-radius: 12px; }

/* 顶部弹窗提示：错误等重要消息，固定悬浮在屏幕顶部，任何滚动位置都看得见 */
.toast {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0) + 14px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  max-width: min(90vw, 26rem);
  background: var(--surface);
  color: var(--err);
  border: 1px solid var(--line-strong);
  border-left: 4px solid var(--err);
  border-radius: 12px;
  padding: 0.6rem 1.1rem;
  font-size: 0.88rem;
  line-height: 1.6;
  box-shadow: var(--shadow-md);
  animation: toastIn 0.28s ease both;
  text-align: center;
}
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, -12px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.tiny {
  color: var(--ink-faint);
  font-size: 0.72rem;
  text-align: center;
  line-height: 1.8;
  max-width: 21rem;
  margin: 0.5rem auto 0;
}

/* ---------- 房间 ---------- */
.room {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 54rem;
  margin: 0 auto;
  width: 100%;
}
.room-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1.1rem;
  border-bottom: 1px solid var(--line);
  background: var(--glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  position: relative;
  z-index: 2;
}
.room-id-wrap { display: flex; align-items: baseline; gap: 0.6rem; min-width: 0; }
.room-label { font-size: 0.72rem; color: var(--ink-faint); letter-spacing: 0.2em; }
.room-code {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 1.02rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--accent);
}
.room-meta { display: flex; align-items: center; gap: 0.45rem; }
.tag {
  font-size: 0.7rem;
  color: var(--ink-soft);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.14rem 0.62rem;
  white-space: nowrap;
}

/* 重连提示：悬浮胶囊 */
.banner {
  position: absolute;
  top: 3.6rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  background: var(--surface);
  color: var(--warn);
  border: 1px solid var(--line-strong);
  font-size: 0.8rem;
  padding: 0.35rem 1rem;
  border-radius: 999px;
  box-shadow: var(--shadow-md);
  animation: rise 0.3s ease both;
}

.msgs {
  flex: 1;
  overflow-y: auto;
  padding: 1.15rem 1.1rem 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.sys {
  align-self: center;
  font-size: 0.72rem;
  color: var(--ink-faint);
  padding: 0.08rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
}

.msg { display: flex; flex-direction: column; max-width: 82%; align-self: flex-start; animation: msgIn 0.25s ease both; }
.msg.me { align-self: flex-end; align-items: flex-end; }
@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
.msg-row { display: flex; gap: 0.55rem; align-items: flex-end; }
.msg-col { display: flex; flex-direction: column; min-width: 0; }
.msg.me .msg-col { align-items: flex-end; }

.avatar {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.82rem;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, hsl(var(--av-h, 165) 42% 46%), hsl(var(--av-h, 165) 48% 34%));
  box-shadow: var(--shadow-sm);
  margin-bottom: 0.15rem;
  user-select: none;
}

.msg .meta { font-size: 0.7rem; color: var(--ink-faint); margin: 0 0.35rem 0.22rem; }
.msg .bubble {
  background: var(--bubble-peer);
  border: 1px solid var(--line);
  border-radius: 16px 16px 16px 5px;
  padding: 0.55rem 0.9rem;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: var(--shadow-sm);
}
.msg.me .bubble {
  background: var(--bubble-me);
  border-color: var(--bubble-me-border);
  border-radius: 16px 16px 5px 16px;
}
.msg .bubble img.thumb {
  display: block;
  max-width: 100%;
  max-height: 280px;
  border-radius: 10px;
  cursor: zoom-in;
  transition: filter 0.2s ease;
}
.msg .bubble img.thumb:hover { filter: brightness(1.05); }
.msg .bubble img.full { display: block; max-width: 100%; border-radius: 10px; }
.msg .bubble video { display: block; max-width: 100%; max-height: 320px; border-radius: 10px; background: #000; }

.filecard { display: flex; align-items: center; gap: 0.75rem; min-width: 13.5rem; padding: 0.15rem 0; }
.filecard .ficon { font-size: 1.45rem; }
.filecard .finfo { flex: 1; min-width: 0; }
.filecard .fname { font-weight: 600; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filecard .fsize { font-size: 0.73rem; color: var(--ink-soft); }
.fsize { font-size: 0.73rem; color: var(--ink-soft); margin-top: 0.25rem; }
.filecard button { flex-shrink: 0; }
.progress {
  height: 4px;
  background: var(--surface-2);
  border-radius: 2px;
  margin-top: 0.4rem;
  overflow: hidden;
}
.progress i {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.15s;
  border-radius: 2px;
}

/* ---------- 输入区 ---------- */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 0.55rem;
  padding: 0.75rem 1.1rem calc(0.75rem + env(safe-area-inset-bottom, 0));
  border-top: 1px solid var(--line);
  background: var(--glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.composer textarea {
  flex: 1;
  resize: none;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 13px;
  padding: 0.55rem 0.9rem;
  max-height: 9rem;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.composer textarea:focus { outline: none; border-color: var(--accent); background: var(--surface); }
.composer textarea::placeholder { color: var(--ink-faint); }

/* ---------- 遮罩 ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--glass);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.overlay-box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.7rem 2.3rem;
  text-align: center;
  box-shadow: var(--shadow-md);
}
.overlay-box p { margin: 0.9rem 0 0; font-size: 0.88rem; color: var(--ink-soft); }
.spinner {
  width: 30px;
  height: 30px;
  margin: 0 auto;
  border: 3px solid var(--surface-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2s; }
  .home, .msg, .banner, .toast { animation: none; }
  button.primary, .card, .field input, .composer textarea { transition: none; }
}

@media (max-width: 480px) {
  .home { padding-top: 2.5rem; }
  .msg { max-width: 88%; }
  .room-head { padding: 0.6rem 0.8rem; }
  .msgs { padding: 0.9rem 0.8rem 0.6rem; }
  .composer { padding: 0.6rem 0.8rem calc(0.6rem + env(safe-area-inset-bottom, 0)); }
}

[hidden] { display: none !important; }
