:root {
  --bg: #1a1a1b;
  --card: #2a2a2b;
  --gold: #b8860b;
  --text: #ffffff;
  --muted: #b0b0b0;
  --border: #3a3a3b;
  --danger: #ff5555;
  --radius: 8px;
  --btn-radius: 6px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
*::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

html,
body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  background: #0d0d0e;
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  overflow: hidden;
  overscroll-behavior: none;
}

.hidden {
  display: none !important;
}

.app-shell {
  width: 100%;
  max-width: 480px;
  height: 100%;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
  overflow: hidden;
  box-shadow: 0 0 0 1px #111;
}

.page {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
  overscroll-behavior: none;
}
.page.active {
  display: flex;
}
.page-list {
  min-height: 0;
}
.page-chat {
  min-height: 0;
}

/* banner */
.banner {
  position: absolute;
  top: var(--safe-t);
  left: 0;
  right: 0;
  z-index: 50;
  background: rgba(184, 134, 11, 0.18);
  border-bottom: 1px solid var(--gold);
  color: var(--gold);
  text-align: center;
  padding: 8px 12px;
  font-size: 13px;
}

/* login */
.page-login {
  align-items: center;
  justify-content: center;
  padding: 24px 20px calc(24px + var(--safe-b));
  background:
    radial-gradient(ellipse at 50% 0%, rgba(184, 134, 11, 0.12), transparent 55%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 22px 22px;
  position: relative;
}
.brand-mark {
  width: 40px;
  height: 2px;
  background: var(--gold);
  margin: 0 auto 16px;
}
.login-title {
  margin: 0;
  text-align: center;
  font-size: 26px;
  font-weight: 600;
  letter-spacing: 0.08em;
}
.login-sub {
  margin: 6px 0 22px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.2em;
}
.field {
  display: block;
  margin-bottom: 14px;
}
.field span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}
.field input {
  width: 100%;
  height: 44px;
  border-radius: var(--btn-radius);
  border: 1px solid var(--border);
  background: #1f1f20;
  color: var(--text);
  padding: 0 12px;
  outline: none;
  font-size: 16px; /* 防 iOS 缩放 */
}
.field input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 1px rgba(184, 134, 11, 0.35);
}
.field.shake input {
  animation: shake 0.35s ease;
  border-color: var(--danger);
}
@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-6px);
  }
  75% {
    transform: translateX(6px);
  }
}
.error-text {
  color: var(--danger);
  font-size: 13px;
  margin: -4px 0 10px;
}
.btn-primary {
  appearance: none;
  border: 1px solid var(--gold);
  background: var(--gold);
  color: var(--bg);
  height: 44px;
  border-radius: var(--btn-radius);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
}
.btn-block {
  width: 100%;
}
.btn-primary:active {
  filter: brightness(0.92);
}
.hint {
  margin: 16px 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

/* topbar */
.topbar {
  flex-shrink: 0;
  padding-top: var(--safe-t);
  background: var(--bg);
  position: relative;
  z-index: 5;
}
.topbar-inner,
.chat-top {
  display: flex;
  align-items: center;
  min-height: 52px;
  padding: 0 14px;
}
.topbar-inner h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
}
.online-count {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
  border: 1px solid var(--border);
  padding: 4px 8px;
  border-radius: 999px;
}
.logout-link {
  margin-left: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}
.logout-link:active {
  color: var(--gold);
  border-color: rgba(184, 134, 11, 0.45);
}
.gold-line {
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  opacity: 0.85;
}
.icon-btn {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  border-radius: var(--btn-radius);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.icon-btn.plus {
  font-size: 24px;
  color: var(--gold);
  border-color: rgba(184, 134, 11, 0.45);
}
.peer-meta {
  flex: 1;
  margin-left: 10px;
  min-width: 0;
}
.peer-name {
  font-weight: 600;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.peer-status {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}
.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #666;
  display: inline-block;
}
.dot.online {
  background: var(--gold);
  box-shadow: 0 0 0 2px rgba(184, 134, 11, 0.25);
}

/* sessions */
.session-list {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding-bottom: 8px;
}
.session-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.session-item:active {
  background: rgba(255, 255, 255, 0.03);
}
.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: var(--bg);
  background: var(--gold);
  border: 1px solid rgba(184, 134, 11, 0.5);
  flex-shrink: 0;
  text-transform: uppercase;
}
.avatar.lg {
  width: 84px;
  height: 84px;
  font-size: 32px;
  margin: 0 auto 12px;
}
.sess-body {
  flex: 1;
  min-width: 0;
}
.sess-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.sess-name {
  font-weight: 600;
}
.sess-time {
  color: var(--muted);
  font-size: 11px;
  flex-shrink: 0;
}
.sess-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 4px;
  gap: 8px;
}
.sess-preview {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.empty-state {
  position: absolute;
  left: 0;
  right: 0;
  top: 38%;
  text-align: center;
  color: var(--muted);
  pointer-events: none;
  z-index: 1;
}
.empty-icon {
  font-size: 36px;
  color: var(--gold);
  opacity: 0.55;
  margin-bottom: 8px;
}
.admin-cmd-bar {
  position: relative;
  flex-shrink: 0;
  z-index: 5;
  margin: 0 12px calc(12px + var(--safe-b));
  background: var(--card);
  border: 1px solid rgba(184, 134, 11, 0.55);
  border-radius: 10px;
  padding: 12px;
}
.admin-cmd-title {
  font-weight: 600;
  color: var(--gold);
  font-size: 14px;
  margin-bottom: 4px;
}
.admin-cmd-hint {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}
.admin-cmd-row {
  display: flex;
  gap: 8px;
}
.admin-cmd-row input {
  flex: 1;
  min-width: 0;
  height: 40px;
  border-radius: var(--btn-radius);
  border: 1px solid var(--border);
  background: #1f1f20;
  color: var(--text);
  padding: 0 10px;
  outline: none;
  font-size: 14px;
}
.admin-cmd-row input:focus {
  border-color: var(--gold);
}
.admin-cmd-row .btn-primary {
  width: auto;
  padding: 0 14px;
  height: 40px;
  flex-shrink: 0;
}
.admin-backup-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.btn-ghost {
  height: 34px;
  padding: 0 10px;
  border-radius: var(--btn-radius);
  border: 1px solid rgba(184, 134, 11, 0.55);
  background: transparent;
  color: var(--gold);
  font-size: 12px;
  cursor: pointer;
}
.btn-ghost:active {
  background: rgba(184, 134, 11, 0.12);
}
.admin-cmd-log {
  margin: 10px 0 0;
  max-height: 72px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  color: var(--muted);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
}
.admin-cmd-log:empty {
  display: none;
  margin: 0;
}

/* chat */
.msg-stream {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 12px 12px 8px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.msg-row {
  display: flex;
  margin-bottom: 12px;
}
.msg-row.mine {
  justify-content: flex-end;
}
.msg-row.system {
  justify-content: center;
}
.bubble {
  max-width: 78%;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--border);
  word-break: break-word;
  line-height: 1.45;
}
.msg-row.mine .bubble {
  background: var(--gold);
  color: var(--bg);
  border-color: var(--gold);
}
.msg-row.system .bubble {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 12px;
  max-width: 90%;
  text-align: center;
  white-space: pre-wrap;
}
.bubble img.thumb,
.bubble .video-thumb {
  display: block;
  max-width: 200px;
  max-height: 200px;
  border-radius: var(--radius);
  object-fit: cover;
  cursor: pointer;
}
.video-thumb {
  position: relative;
  width: 200px;
  height: 140px;
  background: #111;
  overflow: hidden;
}
.video-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.video-thumb .play {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  font-size: 28px;
}
.msg-meta {
  margin-top: 4px;
  font-size: 11px;
  opacity: 0.75;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.msg-row:not(.mine) .msg-meta {
  justify-content: flex-start;
  color: var(--muted);
}
.msg-row.mine .msg-meta {
  color: rgba(26, 26, 27, 0.75);
}

.composer {
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 8px 10px calc(8px + var(--safe-b));
  background: var(--card);
  border-top: 1px solid var(--border);
}
.input-wrap {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: var(--btn-radius);
  background: #1f1f20;
  padding: 6px 8px;
}
.input-wrap:focus-within {
  border-color: var(--gold);
}
#msg-input {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  resize: none;
  max-height: 100px;
  outline: none;
  font-size: 16px;
  line-height: 1.4;
  font-family: inherit;
}
.btn-send {
  height: 40px;
  padding: 0 14px;
  border-radius: var(--btn-radius);
  border: 1px solid var(--gold);
  background: var(--gold);
  color: var(--bg);
  font-weight: 600;
  cursor: pointer;
}
.plus-menu {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: calc(64px + var(--safe-b));
  background: var(--card);
  border: 1px solid var(--gold);
  border-radius: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 12px;
  z-index: 8;
}
.plus-menu button {
  height: 44px;
  border: 1px solid var(--border);
  background: #1f1f20;
  color: var(--text);
  border-radius: var(--btn-radius);
  cursor: pointer;
}
.emoji-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(56px + var(--safe-b));
  max-height: 180px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  z-index: 7;
}
.emoji-panel button {
  border: none;
  background: transparent;
  font-size: 22px;
  padding: 6px 0;
  cursor: pointer;
}

/* lightbox */
.lightbox {
  position: absolute;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox img,
.lightbox video {
  max-width: 100%;
  max-height: 100%;
  display: none;
}
.lightbox.show-img img {
  display: block;
}
.lightbox.show-video video {
  display: block;
  width: 100%;
}
.lightbox-close {
  position: absolute;
  top: calc(12px + var(--safe-t));
  right: 12px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card);
  color: #fff;
  font-size: 22px;
}

.upload-toast {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: calc(80px + var(--safe-b));
  z-index: 30;
  background: var(--card);
  border: 1px solid var(--gold);
  border-radius: 8px;
  padding: 12px;
}
.upload-label {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}
.progress {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.progress i {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--gold);
  transition: width 0.15s linear;
}

/* call */
.call-layer {
  position: absolute;
  inset: 0;
  z-index: 60;
  background: #0a0a0b;
  display: flex;
  flex-direction: column;
}
.call-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(184, 134, 11, 0.15), transparent 60%),
    #0a0a0b;
}
.remote-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
  z-index: 1;
}
.local-video {
  position: absolute;
  right: 12px;
  top: calc(16px + var(--safe-t));
  width: 112px;
  height: 160px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--gold);
  z-index: 3;
  background: #111;
}
.call-info {
  position: relative;
  z-index: 2;
  text-align: center;
  padding: calc(80px + var(--safe-t)) 20px 20px;
  margin-top: auto;
  margin-bottom: auto;
}
.call-layer.video-mode .call-info {
  margin-top: 0;
  padding-top: calc(24px + var(--safe-t));
  text-shadow: 0 1px 4px #000;
}
.call-name {
  font-size: 22px;
  font-weight: 600;
}
.call-state,
.call-timer {
  color: var(--muted);
  margin-top: 8px;
  font-size: 14px;
}
.call-timer {
  color: var(--gold);
  letter-spacing: 0.08em;
}
.call-qos {
  margin-top: 10px;
  font-size: 12px;
  color: var(--danger);
}
.call-actions {
  position: relative;
  z-index: 4;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 20px 16px calc(28px + var(--safe-b));
}
.circle {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 11px;
  cursor: pointer;
}
.circle.accept {
  background: var(--gold);
  color: var(--bg);
  border-color: var(--gold);
}
.circle.reject,
.circle.hang {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.circle.on {
  border-color: var(--gold);
  color: var(--gold);
}

.msg-actions {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: calc(24px + var(--safe-b));
  z-index: 45;
  background: var(--card);
  border: 1px solid var(--gold);
  border-radius: 10px;
  overflow: hidden;
}
.msg-actions button {
  display: block;
  width: 100%;
  height: 48px;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
}
.msg-actions button:last-child {
  border-bottom: none;
  color: var(--muted);
}
#btn-recall {
  color: var(--gold);
}

.msg-row.mine .bubble.recalled,
.bubble.recalled {
  opacity: 0.7;
  font-style: italic;
}

@media (min-width: 481px) {
  body {
    background: #050505;
  }
}
