/* ds.css — Portal 设计系统：按钮 / 卡片 / 弹层 / 表单 / 列表等交互原语。
   规则：普通按钮 10px、CTA 12px、卡片 16px、弹层 14/22px、Tag 才用胶囊。
   门户页面使用完整样式；Agent 复用控件与弹层，页面布局由自己的样式负责。 */

* { box-sizing: border-box; }
body.ds {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  overflow-y: auto;
}
body.ds a { color: inherit; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  height: 56px; padding: 0 max(18px, calc(50vw - 36rem));
  background: color-mix(in srgb, var(--page) 82%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; letter-spacing: .1px; text-decoration: none; font-size: 15px; }
.brand-logo { width: 22px; height: 22px; border-radius: 7px; }
.nav { display: flex; align-items: center; gap: 2px; margin-left: 6px; }
.nav-item {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 11px; border-radius: 8px; text-decoration: none;
  color: var(--text-secondary); font-size: 14px;
  position: relative; isolation: isolate;
  transition: background var(--motion-ui) ease, color var(--motion-ui) ease, transform var(--motion-fast) var(--ease-out);
}
.nav-item .i { opacity: .85; }
.nav-item:hover { background: var(--surface-muted); color: var(--text); }
.nav-item.on { color: var(--text); font-weight: 600; }
.nav-item.on:hover { background: transparent; }
/* 当前页高亮：单独一层，view-transition-name 让它在两页之间滑过去 */
.nav-pill {
  position: absolute; inset: 0; z-index: -1; border-radius: inherit;
  background: var(--brand-soft); view-transition-name: nav-pill;
}
.spacer { flex: 1; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border: 0; border-radius: 50%;
  background: transparent; color: var(--text-secondary);
  transition: background var(--motion-ui) ease, color var(--motion-ui) ease, transform var(--motion-fast) var(--ease-out);
}
.icon-btn:hover { background: var(--surface-muted); color: var(--text); }
.icon-btn.sm { width: 26px; height: 26px; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 650; text-transform: uppercase;
}
.avatar.lg { width: 56px; height: 56px; font-size: 24px; }
.game-icon-img { width: 22px; height: 22px; }
.game-icon .i { width: 19px; height: 19px; }

/* ---------- 弹出菜单 / 选择器 ---------- */
.pop-wrap { position: relative; }
.pop {
  position: absolute; right: 0; top: 42px; min-width: 200px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-popover);
  box-shadow: var(--shadow-raised); padding: 6px; display: none; z-index: 40;
  transform-origin: top right;
}
.pop.on { display: block; animation: menu-in 170ms var(--ease-out); }
.pop.closing { display: block; pointer-events: none; animation: menu-out var(--motion-exit) var(--ease-in) forwards; }
@keyframes menu-in { from { opacity: 0; transform: translateY(-4px) scale(.97); } }
@keyframes menu-out { to { opacity: 0; transform: translateY(-2px) scale(.98); } }
.pop-head { padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.pop-title { font-size: 13px; color: var(--text-tertiary); }
.pop-name { font-weight: 600; color: var(--text); }
.pop-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 10px; border: 0; border-radius: 8px; background: transparent;
  color: var(--text); font-size: 14px; text-align: left;
  transition: background var(--motion-fast) ease;
}
.pop-item:hover { background: var(--surface-muted); }
.pop-item .check { margin-left: auto; color: var(--brand); visibility: hidden; }
.pop-item.on .check { visibility: visible; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius-control);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-size: 14px; cursor: pointer; text-decoration: none;
  transition: background var(--motion-ui) ease, border-color var(--motion-ui) ease, color var(--motion-ui) ease,
    box-shadow var(--motion-ui) ease, transform 160ms var(--ease-out);
}
.btn:hover { background: var(--surface-muted); border-color: color-mix(in srgb, var(--text) 18%, var(--border-strong)); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--brand-soft), 0 0 0 1px var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); box-shadow: 0 2px 10px color-mix(in srgb, var(--brand) 26%, transparent); }
.btn.cta { border-radius: var(--radius-cta); padding: 10px 18px; font-weight: 600; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-muted); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--border-strong)); }
.btn.danger:hover { background: color-mix(in srgb, var(--danger) 8%, transparent); }
.btn:disabled { opacity: .55; cursor: default; pointer-events: none; }
/* pending：按钮里自动出现 spinner（配 withPending() 用） */
.btn.pending { position: relative; color: transparent !important; pointer-events: none; opacity: 1; }
.btn.pending > * { opacity: 0; }
.btn.pending::after {
  content: ''; position: absolute; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent;
  color: var(--text); animation: spin .7s linear infinite, fadein 120ms ease;
}
.btn.primary.pending::after { color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 卡片 / 分区 ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-card); box-shadow: var(--shadow-card);
}
.section { margin: 34px 0 0; }
.section-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.section-title { display: inline-flex; align-items: center; gap: 7px; font-size: 17px; font-weight: 650; margin: 0; }
.section-title .i { color: var(--text-tertiary); }
.section-sub { color: var(--text-tertiary); font-size: 13px; }
.divider { height: 1px; background: var(--border); border: 0; margin: 0; }

/* ---------- 列表行 ---------- */
.list-row { display: flex; align-items: center; gap: 12px; padding: 13px 16px; }
.list-row + .list-row { border-top: 1px solid var(--border); }
.list-main { flex: 1; min-width: 0; }
.list-title { color: var(--text); font-size: 14.5px; }
.list-sub { color: var(--text-tertiary); font-size: 12.5px; margin-top: 2px; }

/* ---------- 表单 ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; color: var(--text-secondary); }
.input, .textarea {
  width: 100%; padding: 10px 12px; border-radius: var(--radius-control);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-size: 14.5px;
  transition: border-color var(--motion-ui) ease, box-shadow var(--motion-ui) ease;
}
.input:focus, .textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.textarea { min-height: 110px; resize: vertical; }
.field-hint { font-size: 12.5px; color: var(--text-tertiary); }
.field-err { font-size: 13px; color: var(--danger); min-height: 18px; }

/* ---------- Tag / Badge / 头像文字 ---------- */
.badge, .tag {
  display: inline-flex; align-items: center; gap: 4px;
  border-radius: 999px; font-size: 12px; padding: 2px 9px;
  background: var(--surface-muted); color: var(--text-secondary); border: 1px solid var(--border);
}
.badge.brand, .tag.brand { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.badge.ok { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.badge.warn { background: color-mix(in srgb, #d97706 12%, transparent); color: #b45309; border-color: transparent; }

/* ---------- 弹层 ---------- */
.dialog-mask {
  position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center;
  background: rgba(16, 16, 20, .34); backdrop-filter: blur(3px);
  animation: fadein 180ms ease; padding: 20px;
}
.dialog-mask.closing { pointer-events: none; animation: fade-out 160ms ease forwards; }
.dialog-mask.closing .dialog, .dialog-mask.closing .palette { animation: dialog-out 140ms var(--ease-in) forwards; }
.dialog {
  width: min(94vw, 440px); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-large); box-shadow: var(--shadow-raised);
  animation: dialog-in 240ms var(--ease-out); overflow: hidden;
}
@keyframes dialog-in { from { opacity: 0; transform: translateY(10px) scale(.97); } }
@keyframes fade-out { to { opacity: 0; } }
@keyframes dialog-out { to { opacity: 0; transform: translateY(4px) scale(.98); } }
.dialog-head { display: flex; align-items: center; gap: 10px; padding: 18px 20px 0; }
.dialog-title { margin: 0; font-size: 17px; font-weight: 650; flex: 1; }
.dialog-body { padding: 14px 20px 4px; color: var(--text-secondary); font-size: 14.5px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 18px 20px 20px; }

/* ---------- Toast ---------- */
.toast-wrap { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  background: color-mix(in srgb, var(--text) 92%, transparent); color: var(--page);
  padding: 9px 16px; border-radius: 12px; font-size: 13.5px;
  box-shadow: var(--shadow-raised); animation: toast-in 260ms var(--ease-out);
}
.toast.out { animation: toast-out 180ms var(--ease-in) forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(.96); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px) scale(.98); } }
.toast.warn { background: var(--danger); color: #fff; }

/* ---------- 空状态 / 骨架 ---------- */
.empty { color: var(--text-tertiary); font-size: 13.5px; padding: 18px 0; text-align: center; }
.skeleton {
  border-radius: 10px;
  background: linear-gradient(100deg, var(--surface-muted) 30%, var(--border) 50%, var(--surface-muted) 70%);
  background-size: 200% 100%; animation: sk 1.2s linear infinite;
}
@keyframes sk { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.reveal { animation: reveal 300ms var(--ease-out) both; animation-delay: calc(var(--i, 0) * 45ms); }
@keyframes reveal { from { opacity: 0; transform: translateY(8px); } }
@media (max-width: 640px) {
  .topbar { padding: 0 10px; gap: 6px; height: 52px; }
  .brand span { display: none; }        /* 手机只留 logo，省出空间 */
  .brand-logo { width: 26px; height: 26px; }
  .nav { margin-left: 0; gap: 0; }
  .nav-item { white-space: nowrap; padding: 10px 11px; }   /* 点击区 ≥40px */
  .theme-wrap { display: none; }        /* 手机主题切换挪进头像菜单 */
  .icon-btn { width: 40px; height: 40px; }
}
@keyframes pop { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes fadein { from { opacity: 0; } }
[hidden] { display: none !important; }

/* 账号菜单里的外观分段控件 */
.menu-theme { padding: 6px 10px 8px; }
.menu-theme-title { font-size: 12px; color: var(--text-tertiary); margin-bottom: 6px; }
.menu-theme .seg { display: inline-flex; background: var(--surface-muted); border-radius: 9px; padding: 3px; gap: 2px; }
.menu-theme .seg-item { border: 0; background: transparent; color: var(--text-secondary); padding: 5px 9px; border-radius: 7px; font: inherit; font-size: 12.5px; cursor: pointer; }
.menu-theme .seg-item.on { background: var(--surface); color: var(--text); font-weight: 600; }

/* 分段控件滑块（ds.js segThumb）：选中背景作为独立一层滑动，文字只做颜色过渡 */
.seg.has-thumb { position: relative; isolation: isolate; }
.seg.has-thumb .seg-item { position: relative; z-index: 1; transition: color var(--motion-ui) ease; }
.seg.has-thumb .seg-item.on { background: transparent; box-shadow: none; }
.seg-thumb {
  position: absolute; top: 3px; bottom: 3px; left: 0; z-index: 0; border-radius: 8px;
  background: var(--surface); box-shadow: var(--shadow-card), 0 0 0 1px var(--border);
  transition: transform 260ms var(--ease-out), width 260ms var(--ease-out);
}
.seg-thumb.instant { transition: none; }
.menu-theme .seg-thumb { border-radius: 7px; }

/* 移动端/触屏的按压反馈 + popover 不溢出 */
.btn:active, .nav-item:active, .icon-btn:active, .seg-item:active {
  transform: scale(var(--press-scale)); transition-duration: var(--motion-press);
}
.pop { max-width: calc(100vw - 24px); }
.pop-item:active { background: var(--surface-muted); }

/* ---------- 手机底部 tabbar ---------- */
.tabbar { display: none; }
@media (max-width: 640px) {
  .nav { display: none; }                 /* 顶栏只留 logo + 头像，导航交给底部 */
  body.ds { padding-bottom: 68px; }
  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    display: flex; align-items: stretch;
    background: color-mix(in srgb, var(--page) 92%, transparent);
    backdrop-filter: blur(14px); border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .tabbar .tab {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    padding: 7px 0 7px; color: var(--text-tertiary); font-size: 11px; text-decoration: none;
    transition: color var(--motion-ui) ease;
  }
  .tabbar .tab-ic {
    position: relative; isolation: isolate; display: inline-flex; align-items: center; justify-content: center;
    width: 48px; height: 28px; transition: transform var(--motion-fast) var(--ease-out);
  }
  .tabbar .tab:active .tab-ic { transform: scale(.9); transition-duration: var(--motion-press); }
  .tabbar .tab .i { width: 20px; height: 20px; }
  .tabbar .tab.on { color: var(--brand); }
  .tab-pill { position: absolute; inset: 0; z-index: -1; border-radius: 999px; background: var(--brand-soft); view-transition-name: tab-pill; }
}

/* ---------- 命令面板 ---------- */
.palette-mask { align-items: flex-start; padding-top: 12vh; }
.palette {
  width: min(92vw, 520px); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-large); box-shadow: var(--shadow-raised); overflow: hidden;
  animation: dialog-in 220ms var(--ease-out);
}
.palette-input {
  width: 100%; border: 0; border-bottom: 1px solid var(--border); padding: 15px 18px;
  background: transparent; color: var(--text); font: inherit; font-size: 15px;
}
.palette-input:focus { outline: none; }
.palette-list { max-height: 42vh; overflow-y: auto; padding: 6px; }
.palette-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px;
  border: 0; border-radius: 10px; background: transparent; color: var(--text); font: inherit; font-size: 14.5px; text-align: left;
}
.palette-item { transition: background var(--motion-fast) ease; }
.palette-item.on { background: var(--surface-muted); }
.palette-item .palette-label { flex: 1; }
.palette-item .palette-hint { color: var(--text-tertiary); font-size: 12.5px; }
.palette-empty { color: var(--text-tertiary); font-size: 13.5px; padding: 14px; text-align: center; }
.palette-icon { width: 18px; height: 18px; }

/* Shared identity and keyboard states. */
.topbar { min-height: 64px; height: 64px; padding-inline: max(24px, calc((100vw - 1152px) / 2)); }
.topbar .nav-item, .topbar .icon-btn, .topbar .acc-btn { min-height: 44px; }
.nav-item.on::after { content: ''; position: absolute; bottom: 4px; left: 12px; right: 12px; height: 2px; background: var(--brand); border-radius: 2px; }
:where(a, button, input, select, textarea, summary):focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; }
.passkey-form { display: flex; flex-direction: column; gap: 12px; text-align: left; width: 100%; color: var(--text); }
.passkey-form h1 { font-size: 28px; margin: 0; line-height: 1.4; }
.passkey-form p { margin: 0; line-height: 1.7; }
.passkey-form .eyebrow { font-size: 12px; color: var(--text-secondary); letter-spacing: .06em; }
.passkey-form .login-sub { color: var(--text-secondary); font-size: 14px; }
.passkey-form .btn { min-height: 44px; white-space: normal; }
.passkey-form .field-label { margin-top: 8px; }
.passkey-form .field-err:empty { display: none; }
.passkey-form .recovery-codes { font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; background: var(--surface-muted); border: 1px solid var(--border); border-radius: 12px; padding: 16px; user-select: all; }
.recovery-confirm { display: flex; gap: 10px; align-items: center; min-height: 44px; font-size: 14px; }
.recovery-confirm input { width: 20px; height: 20px; }
@media (max-width: 640px) { .topbar { padding-inline: 16px; } .tabbar .tab { min-width: 0; font-size: 10px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; } }
@media (max-width: 640px) { .topbar .brand span { display: inline; } }

html[data-theme="dark"] .badge.brand { color: var(--link); }
.password-fields { display: flex; flex-direction: column; gap: 10px; }
.password-fields > .btn { margin-top: 8px; }
