/* 土豆聊天室 · 暗色 + 土豆橙主题（与 CS 主页同风格） */

:root {
  --bg: #0f1115;            /* 深色底 */
  --panel: #1b1e26;         /* 卡片 */
  --panel-soft: #232731;    /* 输入框 / 他人气泡 */
  --panel-hover: #2a2f3a;
  --primary: #f5a623;       /* 土豆橙 */
  --primary-dark: #d98d12;
  --primary-soft: rgba(245, 166, 35, 0.14);
  --text: #e8e6e1;
  --muted: #8b909c;
  --border: #2a2f3a;
  --bubble-me: #f5a623;     /* 自己发的消息：土豆橙气泡（白字） */
  --bubble-them: #232731;
  --danger: #ef4444;
  --success: #22c55e;
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

/* ---------------- auth ---------------- */

.auth-view {
  height: var(--vvh, 100vh);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: min(92vw, 400px);
  background: var(--panel);
  border-radius: 18px;
  padding: 32px 28px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.45);
  border: 1px solid var(--border);
}

.auth-card h1 {
  margin: 0;
  text-align: center;
  font-size: 1.7rem;
  letter-spacing: 0.02em;
}

.subtitle {
  margin: 4px 0 22px;
  text-align: center;
  color: var(--muted);
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 18px;
  background: var(--bg);
  padding: 4px;
  border-radius: 10px;
}

.tab {
  border: none;
  background: transparent;
  padding: 9px;
  min-height: 44px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
}

.tab.active {
  background: var(--panel-soft);
  color: var(--primary);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-form input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 13px;
  background: var(--panel-soft);
  color: var(--text);
}

.auth-form input::placeholder {
  color: var(--muted);
}

.auth-form button,
.composer button {
  border: none;
  border-radius: 10px;
  background: var(--primary);
  color: #1a1406;
  padding: 11px 16px;
  font-weight: 600;
  cursor: pointer;
}

.auth-form button:hover,
.composer button:hover {
  background: var(--primary-dark);
}

.auth-msg {
  min-height: 20px;
  margin-top: 14px;
  font-size: 0.9rem;
}

.auth-msg.error {
  color: var(--danger);
}

.auth-msg.success {
  color: var(--success);
}

/* 登录卡片下方「忘记密码？」入口 */
.forgot-pw {
  align-self: center;
  font-size: 0.85rem;
  color: var(--muted);
  text-decoration: none;
  padding: 4px 8px;
  min-height: 30px;
}

.forgot-pw:hover {
  color: var(--primary);
}

/* ---------------- main layout ---------------- */

.main-view {
  height: var(--vvh, 100vh);
  display: flex;
  flex-direction: column;
}

@supports (height: 100dvh) {
  .main-view {
    height: var(--vvh, 100dvh);
  }
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: calc(12px + env(safe-area-inset-top)) 20px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.brand-title {
  font-weight: 700;
  font-size: 1.1rem;
}

.online-count {
  font-size: 0.8rem;
}

.me-info {
  display: flex;
  flex-direction: column;
  font-size: 0.85rem;
  margin-left: 6px;
  min-width: 0;
}

.me-info strong {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-shrink: 0;
}

.ghost {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  border-radius: 8px;
  padding: 6px 12px;
  min-height: 44px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  line-height: 1.4;
}

.ghost:hover {
  background: var(--panel-hover);
}

.top-actions .ghost {
  min-height: 0;
  padding: 5px 11px;
  font-size: 0.8rem;
  white-space: nowrap;
}

.room-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
}

.chat {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}

.message-list {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  max-width: 68%;
  padding: 9px 13px;
  border-radius: 14px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  word-break: break-word;
}

.msg.me {
  align-self: flex-end;
  background: var(--bubble-me);
  color: #1a1406;
  border-bottom-right-radius: 4px;
}

.msg.me .msg-who,
.msg.me .msg-head {
  color: rgba(26, 20, 6, 0.65);
}

.msg.them {
  align-self: flex-start;
  background: var(--bubble-them);
  border-bottom-left-radius: 4px;
}

.msg-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 3px;
}

.msg-who {
  font-weight: 600;
}

.msg-text {
  white-space: pre-wrap;
  line-height: 1.5;
}

.composer {
  border-top: 1px solid var(--border);
  background: var(--panel);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.composer textarea {
  flex: 1;
  resize: vertical;
  min-height: 44px;
  max-height: 160px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--panel-soft);
  color: var(--text);
}

.composer textarea::placeholder {
  color: var(--muted);
}

.composer button {
  min-width: 88px;
  align-self: flex-end;
}

/* ---------------- online player panel ---------------- */

.online-panel {
  border-left: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.online-title {
  margin: 0;
  padding: 16px 18px 10px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--muted);
}

.online-list {
  list-style: none;
  margin: 0;
  padding: 0 12px 12px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.online-list li {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 8px;
  border-radius: 8px;
}

.online-name {
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.online-uname {
  font-size: 0.72rem;
  margin-left: auto;
  flex-shrink: 0;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #3a4150;
  flex-shrink: 0;
}

.dot.online {
  background: #22c55e;
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.7);
}

/* ---------------- overlays / modals ---------------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.overlay-card {
  width: min(92vw, 420px);
  max-height: var(--overlay-h, 80vh);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.overlay-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.overlay-head h3 {
  margin: 0;
}

.overlay-card input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--panel-soft);
  color: var(--text);
}

.overlay-card input::placeholder {
  color: var(--muted);
}

.modal-msg {
  min-height: 20px;
  font-size: 0.9rem;
}

.modal-msg.error {
  color: var(--danger);
}

.modal-msg.success {
  color: var(--success);
}

/* 网页内消息通知横幅（手机浏览器 / 无原生通知时的兜底） */
.toast-banner {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  max-width: min(92vw, 420px);
  background: rgba(35, 39, 49, 0.98);
  color: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  animation: toast-in 0.25s ease-out;
}

.toast-banner .toast-title {
  font-weight: 600;
  color: var(--primary);
}

.toast-banner .toast-body {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@keyframes toast-in {
  from {
    transform: translate(-50%, -10px);
    opacity: 0;
  }
  to {
    transform: translate(-50%, 0);
    opacity: 1;
  }
}

/* ---------------- responsive ---------------- */

/* 手机端：在线面板隐藏（信息都在顶栏的在线人数里），聊天区全屏 */
@media (max-width: 1024px) {
  .room-body {
    grid-template-columns: 1fr;
  }

  .online-panel {
    display: none;
  }

  .msg {
    max-width: 85%;
  }

  /* 16px 字号可避免 iOS 聚焦输入框时自动放大页面 */
  .composer textarea {
    font-size: 16px;
  }

  .topbar {
    padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  }

  .message-list {
    padding: 14px;
  }
}
