:root {
  --bg0: #ffffff;
  --bg1: #f7f9fc;
  --bg2: #eef2f7;
  --line: rgba(15, 23, 42, 0.1);
  --text: #1e293b;
  --muted: #64748b;
  --accent: #0f9f7a;
  --accent-dim: rgba(15, 159, 122, 0.12);
  --card: #ffffff;
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: "Cascadia Code", Consolas, "SF Mono", monospace;
  --radius: 10px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --shadow: 0 4px 16px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: #ffffff;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
}
body { overflow-x: hidden; }

.bg-grid, .bg-glow { display: none; }

/* —— 全站统一顶栏 —— */
.site-bar,
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 48px;
}
.site-bar-left,
.brand-lockup {
  display: flex;
  gap: 14px;
  align-items: center;
  min-width: 0;
  flex: 1;
}
.site-bar-right {
  margin-left: auto;
  display: flex;
  gap: 8px;
  align-items: center;
  flex: 0 0 auto;
}

.site-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  text-decoration: none;
  color: inherit;
  min-width: 0;
}
.site-brand:hover .brand { color: var(--accent); }

.logo-mark {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  flex: 0 0 auto;
  background:
    url("/icons/icon.svg") center / cover no-repeat,
    linear-gradient(135deg, #0f9f7a, #0ea5e9);
}
.brand { font-weight: 750; font-size: 0.95rem; color: var(--text); line-height: 1.1; }
.brand-sub { color: var(--muted); font-size: 0.64rem; line-height: 1.2; }
.page-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 顶栏 Tab */
.site-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  padding: 3px;
  border-radius: 10px;
  background: var(--bg1);
  border: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.site-nav::-webkit-scrollbar { display: none; }
.site-nav a {
  flex: 0 0 auto;
  padding: 7px 12px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 650;
  white-space: nowrap;
  border: 1px solid transparent;
  line-height: 1;
}
.site-nav a:hover {
  color: var(--text);
  background: #fff;
}
.site-nav a.active {
  color: #0b7a5e;
  background: #fff;
  border-color: rgba(15, 159, 122, 0.28);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  font-weight: 750;
}

.site-nav-toggle { display: none; }

/* 手机导航抽屉 */
.site-nav-drawer {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
}
.site-nav-drawer.hidden { display: none !important; }
.site-nav-drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
}
.site-nav-drawer-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: min(78dvh, 560px);
  background: #fff;
  border-radius: 16px 16px 0 0;
  border-top: 1px solid var(--line);
  box-shadow: 0 -8px 32px rgba(15, 23, 42, 0.18);
  display: flex;
  flex-direction: column;
  padding-bottom: calc(12px + var(--safe-bottom));
}
.site-nav-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.site-nav-drawer-list {
  display: grid;
  gap: 6px;
  padding: 12px 14px;
  overflow: auto;
}
.site-nav-drawer-link {
  display: block;
  padding: 14px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  font-size: 0.95rem;
  background: var(--bg1);
}
.site-nav-drawer-link.active {
  border-color: rgba(15, 159, 122, 0.4);
  background: rgba(15, 159, 122, 0.1);
  color: #0b7a5e;
}
body.nav-drawer-open { overflow: hidden; }

/* 手机底栏 */
.site-bottom-nav {
  display: none;
}
.site-bottom-item {
  appearance: none;
  border: 0;
  background: transparent;
  font: inherit;
  color: var(--muted);
  text-decoration: none;
  text-align: center;
  padding: 8px 4px;
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: 8px;
  cursor: pointer;
}
.site-bottom-item.active {
  color: #0b7a5e;
  background: rgba(15, 159, 122, 0.1);
}

/* 兼容旧类名 */
.nav-home {
  display: none;
}

.device-chip {
  font-family: var(--mono);
  font-size: 0.62rem;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: var(--bg1);
  white-space: nowrap;
}

.home-main,
.page-main,
main {
  width: min(1100px, calc(100% - 24px));
  margin: 0 auto;
  padding: 12px 0 18px;
  position: relative;
  z-index: 1;
}
.page-main {
  min-height: calc(100dvh - 100px);
  display: flex;
  flex-direction: column;
}
.panel.fill { flex: 1; min-height: 0; }
.grow { flex: 1; min-height: 0; }

.hero.compact {
  display: grid;
  grid-template-columns: 1.3fr auto;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow);
}
.hero h1 {
  margin: 0;
  font-size: 1.25rem;
  color: var(--text);
}
.lede {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(64px, 1fr));
  gap: 8px;
}
.stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--bg1);
  text-align: center;
}
.stat span {
  display: block;
  font-family: var(--mono);
  font-size: 0.9rem;
  color: var(--accent);
  line-height: 1.2;
  font-weight: 700;
}
.stat label { color: var(--muted); font-size: 0.66rem; }

.home-apps {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
@media (min-width: 900px) {
  .home-apps { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
.app-card {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  text-decoration: none;
  color: inherit;
  background: #fff;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.app-card:hover {
  border-color: rgba(15, 159, 122, 0.45);
  box-shadow: 0 6px 20px rgba(15, 159, 122, 0.1);
}
.app-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--accent-dim);
  font-size: 1.15rem;
  flex: 0 0 auto;
  color: var(--accent);
}
.app-icon-chat svg,
.app-icon-poker svg { display: block; }
.app-icon-poker { color: var(--accent, #0f9f7a); }
.app-name { font-weight: 700; }
.app-desc { color: var(--muted); font-size: 0.76rem; margin-top: 2px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 6px 12px;
  color: var(--text);
  background: #fff;
  text-decoration: none;
  cursor: pointer;
  font-size: 0.78rem;
  white-space: nowrap;
}
.btn:hover { background: var(--bg1); }
.btn.primary {
  border-color: transparent;
  background: var(--accent);
  color: #fff;
  font-weight: 650;
}
.btn.primary:hover { filter: brightness(0.95); }
.btn.ghost { background: var(--bg1); }
.btn.danger {
  border-color: rgba(209, 75, 87, 0.35);
  color: var(--danger, #d14b57);
}
.btn:disabled { opacity: 0.45; cursor: default; }
.upload-btn { cursor: pointer; }

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 10px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}
.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.panel-head h2 { margin: 0; font-size: 0.9rem; }
.hint { color: var(--muted); font-size: 0.7rem; margin: 4px 0 0; }
.hint.tight { margin: 0; }
.fb-actions { display: flex; gap: 6px; align-items: center; }

/* —— 紧凑聊天 —— */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* —— 微信登录 —— */
.auth-slot {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.auth-login-btn {
  white-space: nowrap;
}
.auth-user {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 220px;
}
.auth-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg2);
  flex: 0 0 auto;
}
.auth-avatar-fallback {
  display: inline-block;
  background: linear-gradient(135deg, #0f9f7a, #0ea5e9);
}
.auth-nick {
  font-size: 0.78rem;
  font-weight: 650;
  color: var(--text);
  max-width: 96px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.auth-logout-btn {
  padding: 5px 8px;
  font-size: 0.72rem;
}

.login-main {
  display: flex;
  justify-content: center;
  padding: 48px 16px 64px;
  min-height: calc(100dvh - 48px);
  background:
    radial-gradient(900px 420px at 15% -10%, rgba(15, 159, 122, 0.12), transparent 60%),
    radial-gradient(700px 360px at 90% 0%, rgba(14, 165, 233, 0.1), transparent 55%),
    var(--bg1);
}
.login-card {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 28px 24px 22px;
  text-align: center;
}
.login-card h1 {
  margin: 0 0 8px;
  font-size: 1.35rem;
  font-weight: 750;
}
.login-lede {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 0.9rem;
}
.login-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  min-height: 120px;
}
.login-hint {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 0.75rem;
}
.login-error {
  margin: 12px 0 0;
  color: #b91c1c;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.8rem;
  text-align: left;
}
.login-setup {
  text-align: left;
  color: var(--text);
  font-size: 0.85rem;
  line-height: 1.55;
}
.login-setup .muted,
.login-alt .muted,
.muted {
  color: var(--muted);
}
.login-setup code {
  font-family: var(--mono);
  font-size: 0.78rem;
  background: var(--bg1);
  padding: 1px 5px;
  border-radius: 4px;
}
.wx-qr-box {
  width: 300px;
  min-height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-alt {
  margin: 0;
}
@media (max-width: 640px) {
  .auth-nick { max-width: 64px; }
  .login-main { padding: 28px 12px 48px; }
  .wx-qr-box { width: 260px; min-height: 260px; }
}

/* 跨模块共用的元信息样式（日记/聊天 ID、相对时间等） */
.chat-empty {
  color: var(--muted);
  text-align: center;
  padding: 24px 8px;
  font-size: 0.78rem;
}
.chat-nick { color: var(--accent); font-weight: 700; }
.chat-time { color: var(--muted); }
.chat-rel {
  margin-left: 6px;
  color: #94a3b8;
  font-size: 0.95em;
}
.chat-rel::before {
  content: "·";
  margin-right: 6px;
  color: #cbd5e1;
}
.chat-id {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 0.58rem;
  color: #cbd5e1;
  letter-spacing: 0.01em;
  user-select: all;
}

/* 固定底栏（勿随内容上移） */
.footer {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  margin: 0;
  padding: 8px 14px calc(8px + var(--safe-bottom));
  color: var(--muted);
  font-size: 0.68rem;
  border-top: 1px solid var(--line);
  background: #fff;
}
.footer a { color: var(--accent); text-decoration: none; }
body:has(> .footer) {
  padding-bottom: calc(40px + var(--safe-bottom));
}

[data-ui="mobile"] .home-apps { grid-template-columns: 1fr; }
[data-ui="mobile"] .brand-sub { display: none; }
[data-ui="mobile"] .hero.compact { grid-template-columns: 1fr; }
[data-ui="mobile"] .site-bar .brand-sub { display: none !important; }
[data-ui="mobile"] .home-main,
[data-ui="mobile"] .page-main,
[data-ui="mobile"] main {
  width: calc(100% - 16px);
  padding: 10px 0 14px;
}

/* 手机：顶栏不再挤半个 Tab —— 菜单按钮 + 底栏 */
@media (max-width: 820px) {
  .site-nav { display: none; }
  .site-nav-toggle { display: inline-flex; }
  .site-bottom-nav {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 55;
    gap: 2px;
    padding: 6px 8px calc(6px + var(--safe-bottom));
    background: #fff;
    border-top: 1px solid var(--line);
    box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.06);
  }
  body.has-bottom-nav {
    padding-bottom: calc(58px + var(--safe-bottom));
  }
  body.has-bottom-nav .footer { display: none; }
  .device-chip { display: none; }
}
html[data-ui="mobile"] .site-nav { display: none; }
html[data-ui="mobile"] .site-nav-toggle { display: inline-flex; }
html[data-ui="mobile"] .site-bottom-nav {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 55;
  gap: 2px;
  padding: 6px 8px calc(6px + var(--safe-bottom));
  background: #fff;
  border-top: 1px solid var(--line);
  box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.06);
}
html[data-ui="mobile"] body.has-bottom-nav {
  padding-bottom: calc(58px + var(--safe-bottom));
}
html[data-ui="mobile"] body.has-bottom-nav .footer { display: none; }
html[data-ui="mobile"] .device-chip { display: none; }

@media (max-width: 900px) {
  .hero.compact { grid-template-columns: 1fr; }
  .home-apps { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
