.skip-link {
  position: absolute;
  left: -9999px;
}
.skip-link:focus {
  left: 1rem;
  top: 1rem;
  z-index: 1000;
  padding: 0.5rem 1rem;
  background: var(--bg-elevated);
  border-radius: var(--radius);
  color: var(--text);
}

:root {
  --bg: #0f1218;
  --bg-elevated: #171b24;
  --bg-card: #1c2230;
  --border: #2a3344;
  --text: #e8ecf4;
  --text-muted: #9aa6bc;
  --accent: #6ea8fe;
  --accent-soft: rgba(110, 168, 254, 0.15);
  --foil: #e8c547;
  --foil-soft: rgba(232, 197, 71, 0.18);
  --danger: #f07178;
  --radius: 14px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --font: "Segoe UI", "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

/* 全局 [hidden] 优先级：避免 .btn/.cart-fab 的 display:inline-flex 覆盖 [hidden] */
[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 10% -10%, #1a2740 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #241a30 0%, transparent 50%),
    var(--bg);
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

body.scroll-lock {
  overflow: hidden;
  touch-action: none;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.wrap {
  width: min(1200px, calc(100% - 2rem));
  margin: 0 auto;
  padding-left: env(safe-area-inset-left, 0);
  padding-right: env(safe-area-inset-right, 0);
}

header.site-header {
  padding: 1.75rem 0 1.25rem;
}

/* Brand left · account / actions top-right (common web pattern) */
.header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.65rem 1rem;
}

.header-brand {
  min-width: 0;
  flex: 1 1 auto;
}

.site-header h1,
.header-brand h1 {
  margin: 0 0 0.3rem;
  font-size: clamp(1.35rem, 4.2vw, 2.1rem);
  letter-spacing: 0.02em;
  line-height: 1.2;
}

.site-header .subtitle,
.header-brand .subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.4;
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.4rem;
  flex: 0 1 auto;
  max-width: min(100%, 28rem);
  /* Stay visually pinned top-right; wrap under brand only if forced */
  margin-top: 0.1rem;
  padding-top: env(safe-area-inset-top, 0);
}

.auth-area .auth-email,
.header-actions .auth-email,
.header-actions .admin-email {
  display: inline-block;
  max-width: 11rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
  font-size: 0.82rem;
  line-height: 1.2;
  padding: 0 0.15rem;
  vertical-align: middle;
}

/* Login: compact pill, still ≥ ~44px touch height on touch devices via media below */
.header-actions .btn-sm {
  min-height: 2.15rem;
  padding: 0.3rem 0.85rem;
  font-size: 0.84rem;
  font-weight: 600;
}

.header-actions .header-login {
  border-color: rgba(110, 168, 254, 0.45);
  color: var(--accent);
  background: var(--accent-soft);
}

.header-actions .header-login:hover {
  border-color: var(--accent);
  filter: brightness(1.06);
  text-decoration: none;
}

.header-actions a.btn {
  text-decoration: none;
}

.header-actions a.btn:hover {
  text-decoration: none;
}

/* Login modal form (was inline on index.html) */
#login-form {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

#login-form label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

#login-form input {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  font-size: 1rem; /* ≥16px avoids iOS zoom on focus */
  min-height: 2.75rem;
}

#login-form input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

#login-form .form-hint {
  color: var(--text-muted);
  font-size: 0.82rem;
  min-height: 1em;
  margin: 0;
}

.view-tabs {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.9rem;
}

.view-tab {
  min-height: 2.75rem;
  padding: 0.3rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.view-tab.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
  margin-top: 0.75rem;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.flag-any {
  background: rgba(167, 139, 250, 0.2);
  color: #c4b5fd;
  border: 1px solid rgba(167, 139, 250, 0.4);
}

.flag-exact {
  background: rgba(248, 113, 113, 0.18);
  color: #fca5a5;
  border: 1px solid rgba(248, 113, 113, 0.4);
}

.card-note {
  margin: 0.35rem 0 0;
  font-size: 0.75rem;
  color: #c9b27a;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.stats strong {
  color: var(--text);
  font-weight: 600;
}

/* 使用说明折叠区 */
.guide {
  margin: 0 auto 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  overflow: hidden;
}

.guide summary {
  cursor: pointer;
  padding: 0.7rem 1rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.guide summary::before {
  content: "▸";
  transition: transform 0.2s;
  font-size: 0.75rem;
}

.guide[open] summary::before {
  transform: rotate(90deg);
}

.guide summary::-webkit-details-marker {
  display: none;
}

.guide-body {
  padding: 0.25rem 1rem 1rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

@media (max-width: 640px) {
  .guide-body {
    grid-template-columns: 1fr;
  }
}

/* Very narrow: hide email text, keep actions */
@media (max-width: 380px) {
  .header-actions .auth-email,
  .header-actions .admin-email {
    display: none;
  }
}

.guide-section h3 {
  margin: 0.5rem 0 0.6rem;
  font-size: 0.95rem;
  color: var(--text);
}

.guide-section ol {
  margin: 0 0 0.6rem;
  padding-left: 1.2rem;
  font-size: 0.85rem;
  line-height: 1.7;
  color: var(--text-muted);
}

.guide-section p {
  margin: 0.4rem 0;
  font-size: 0.85rem;
  line-height: 1.7;
  color: var(--text-muted);
}

.guide-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  margin: 0.4rem 0;
}

.guide-table th,
.guide-table td {
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.guide-table th {
  color: var(--text);
  font-weight: 600;
}

.guide-table td {
  color: var(--text-muted);
}

.guide-table code,
.guide-note code {
  font-family: var(--font);
  background: var(--accent-soft);
  color: var(--accent);
  padding: 0.05rem 0.3rem;
  border-radius: 4px;
  font-size: 0.85em;
}

.guide-note {
  margin: 0.5rem 0 0;
  font-size: 0.85rem;
  color: var(--danger);
}

.toolbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 0.85rem 0;
  padding-top: max(0.65rem, env(safe-area-inset-top, 0px));
  background: rgba(15, 18, 24, 0.92);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid transparent;
  transition: transform 0.22s ease, box-shadow 0.22s ease;
  will-change: transform;
}

/* 打开筛选时抬到遮罩之上（sticky 会形成层叠上下文） */
body.dd-open .toolbar {
  z-index: 50;
}

.toolbar.is-stuck {
  border-bottom-color: var(--border);
}

.toolbar-inner {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.75rem;
  align-items: center;
}

.search-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.search-row .search {
  flex: 1;
  min-width: 0;
}

/* 桌面端不需要折叠按钮 */
.filter-toggle {
  display: none;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  min-height: 2.75rem;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
}

.filter-toggle[aria-expanded="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.filter-toggle-dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--accent);
}

.filter-toggle-dot[hidden] {
  display: none !important;
}

.search {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.55rem 1rem;
  min-height: 2.75rem;
}

.search:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search input {
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  /* ≥16px 避免 iOS 聚焦自动放大 */
  font-size: 16px;
  min-width: 0;
}

.search input::placeholder {
  color: var(--text-muted);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: stretch;
}

.dd-scrim {
  position: fixed;
  inset: 0;
  z-index: 40;
  /* 轻点遮罩即可关闭，不压暗太多 */
  background: transparent;
}

.dd-scrim[hidden] {
  display: none !important;
}

/* 挂到 body、锚定在筛选按钮下方（手机） */
.dd-menu.is-portal {
  display: block;
  position: fixed;
  z-index: 60;
  top: 0;
  left: 0;
  right: auto;
  bottom: auto;
  min-width: 9.5rem;
  max-width: min(18rem, calc(100vw - 1rem));
  max-height: min(50vh, 360px);
  overflow: auto;
  overscroll-behavior: contain;
  margin: 0;
  padding: 0.35rem;
  list-style: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #1a2030;
  box-shadow: var(--shadow);
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

/* 自定义下拉：完全自绘，不依赖原生 option 颜色 */
.dd {
  position: relative;
  min-width: 0;
}

.dd-trigger {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 2.65rem;
  max-width: min(18rem, 86vw);
  padding: 0.4rem 0.8rem 0.4rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  text-align: left;
  touch-action: manipulation;
}

.dd-trigger:hover {
  border-color: #3d4b63;
}

.dd.open .dd-trigger,
.dd-trigger:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  outline: none;
}

.dd-label {
  flex-shrink: 0;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.dd-value {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

.dd-caret {
  flex-shrink: 0;
  width: 0.55rem;
  height: 0.55rem;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  transform: rotate(45deg) translateY(-1px);
  transition: transform 0.15s ease;
}

.dd.open .dd-caret {
  transform: rotate(225deg) translateY(-1px);
}

.dd-menu {
  display: none;
  position: absolute;
  top: calc(100% + 0.35rem);
  left: 0;
  z-index: 40;
  min-width: 100%;
  max-width: min(22rem, 92vw);
  max-height: min(18rem, 50vh);
  overflow: auto;
  overscroll-behavior: contain;
  margin: 0;
  padding: 0.35rem;
  list-style: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #1a2030;
  box-shadow: var(--shadow);
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

.dd.open .dd-menu {
  display: block;
}

.dd-option {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #e8ecf4;
  font: inherit;
  font-size: 0.95rem;
  text-align: left;
  padding: 0.7rem 0.85rem;
  min-height: 2.75rem;
  cursor: pointer;
  /* 允许在选项上纵向滑动，由父级 .dd-menu 承接滚动 */
  touch-action: pan-y;
  white-space: nowrap;
}

.dd-option:hover,
.dd-option:focus-visible {
  background: rgba(110, 168, 254, 0.16);
  color: #ffffff;
  outline: none;
}

.dd-option[aria-selected="true"] {
  background: rgba(110, 168, 254, 0.28);
  color: #ffffff;
  font-weight: 600;
}

main {
  padding: 1.25rem 0 3rem;
}

.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 1rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 1rem;
}

.card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  text-align: left;
  padding: 0;
  color: inherit;
  font: inherit;
  width: 100%;
  -webkit-user-select: none;
  user-select: none;
}

.card-hit {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}

.card:hover,
.card:focus-within {
  transform: translateY(-3px);
  border-color: #3f4f6c;
  box-shadow: var(--shadow);
}

.card-hit:focus-visible {
  outline: none;
}

@media (hover: none) {
  .card:hover {
    transform: none;
    box-shadow: none;
  }
  .card:active {
    transform: scale(0.98);
    border-color: #3f4f6c;
  }
}

.card-img-wrap {
  position: relative;
  aspect-ratio: 5 / 7;
  background: #0a0d12;
  overflow: hidden;
}

.card-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* 闪/数量放到标题行，避免盖住卡图上的印刷牌名 */
.card-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.35rem;
  margin-bottom: 0.15rem;
}

.card-flags {
  display: flex;
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.25rem;
  max-width: 42%;
}

.flag {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 0.12rem 0.38rem;
  border-radius: 999px;
  line-height: 1.3;
  white-space: nowrap;
}

.flag-foil {
  background: linear-gradient(135deg, #c9a227, #f0d978);
  color: #1a1405;
}

.flag-qty {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid rgba(110, 168, 254, 0.35);
}

.flag-price {
  background: #fff3d6;
  color: #8a6a00;
  border: 1px solid rgba(201, 162, 39, 0.5);
}

.flag-market {
  background: rgba(154, 163, 178, 0.15);
  color: var(--muted, #9aa3b2);
  border: 1px solid rgba(154, 163, 178, 0.25);
}

/* Chinese inventory with only English face art (no zhs printing in data sources) */
.flag-no-zhs-art {
  background: rgba(248, 180, 80, 0.15);
  color: #e0a84a;
  border: 1px solid rgba(224, 168, 74, 0.4);
  font-size: 0.72rem;
}

.card-body {
  padding: 0.7rem 0.75rem 0.85rem;
}

.card-name {
  flex: 1;
  min-width: 0;
  font-size: 0.92rem;
  font-weight: 600;
  margin: 0;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-name-en {
  margin: 0 0 0.35rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.card-meta-extra {
  margin-top: 0.2rem;
}

.card-mana {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  color: var(--text);
  opacity: 0.85;
}

.card-seller {
  margin: 0.4rem 0 0;
  font-size: 0.75rem;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal.open {
  display: flex;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.modal-panel {
  position: relative;
  width: min(920px, 100%);
  max-height: min(90vh, 900px);
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: minmax(220px, 320px) 1fr;
  gap: 0;
  -webkit-overflow-scrolling: touch;
}

.modal-handle {
  display: none;
}

.modal-art {
  background: #0a0d12;
  padding: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-art img {
  width: 100%;
  max-width: 320px;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.modal-content {
  padding: 1.25rem 1.35rem 1.5rem;
}

.modal-content h2 {
  margin: 0 0 0.2rem;
  font-size: 1.35rem;
  padding-right: 2.5rem;
  line-height: 1.3;
  word-break: break-word;
}

.modal-content .en-name {
  margin: 0 0 0.85rem;
  color: var(--text-muted);
}

.modal-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.tag {
  font-size: 0.78rem;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.tag.foil {
  border-color: var(--foil);
  color: var(--foil);
  background: var(--foil-soft);
}

.detail-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.45rem 0.85rem;
  font-size: 0.92rem;
  margin-bottom: 1rem;
}

.detail-grid dt {
  color: var(--text-muted);
}

.detail-grid dd {
  margin: 0;
  word-break: break-word;
}

.oracle {
  white-space: pre-wrap;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  font-size: 0.92rem;
  color: #d5dceb;
  line-height: 1.55;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 1rem;
}

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 2.55rem;
  padding: 0.45rem 0.95rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font: inherit;
  font-size: 0.92rem;
  cursor: pointer;
  touch-action: manipulation;
  text-decoration: none;
}

.btn:hover {
  border-color: #4a5b78;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #061018;
  font-weight: 600;
}

.btn-primary:hover {
  filter: brightness(1.05);
}

.btn-primary.is-in {
  background: transparent;
  border-color: var(--accent);
  color: var(--accent);
}

.btn-ghost {
  background: transparent;
}

.btn-danger-ghost {
  background: transparent;
  border-color: rgba(240, 113, 120, 0.45);
  color: #f5a0a5;
}

.btn-sm {
  min-height: 2rem;
  padding: 0.25rem 0.65rem;
  font-size: 0.82rem;
}

.card-media {
  position: relative;
}

/* 叠在卡图右下角，不挡文字区牌名 */
.card-add {
  position: absolute;
  right: 0.4rem;
  bottom: 0.4rem;
  z-index: 2;
  min-height: 2rem;
  padding: 0.28rem 0.6rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(8, 12, 20, 0.78);
  color: #fff;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  touch-action: manipulation;
}

.card-add:hover,
.card-add.is-in {
  background: rgba(110, 168, 254, 0.92);
  color: #061018;
  border-color: transparent;
}

.card-add.is-in {
  box-shadow: 0 0 0 1px rgba(110, 168, 254, 0.4);
}

/* 意向清单 FAB */
.cart-fab {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1rem, env(safe-area-inset-bottom));
  z-index: 30;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 3rem;
  padding: 0.55rem 1rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--accent);
  color: #061018;
  font: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  box-shadow: var(--shadow);
  cursor: pointer;
  touch-action: manipulation;
}

.cart-fab-count {
  min-width: 1.35rem;
  height: 1.35rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: #061018;
  color: #fff;
  font-size: 0.78rem;
  line-height: 1.35rem;
  text-align: center;
}

.cart-fab-count[hidden] {
  display: none !important;
}

/* 清单面板 */
.cart {
  position: fixed;
  inset: 0;
  z-index: 55;
  display: none;
}

.cart.open {
  display: block;
}

.cart-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.cart-panel {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: min(420px, 100%);
  background: var(--bg-elevated);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.cart-handle {
  display: none;
}

.cart-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1.1rem 1.1rem 0.55rem;
  position: relative;
}

.cart-header h2 {
  margin: 0;
  font-size: 1.2rem;
}

.cart-sub {
  margin: 0.25rem 0 0;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.cart-header .modal-close {
  position: static;
  flex-shrink: 0;
}

.cart-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.35rem 1.1rem 0.5rem;
}

.cart-tip {
  margin: 0;
  padding: 0 1.1rem 0.65rem;
  color: var(--text-muted);
  font-size: 0.78rem;
  line-height: 1.4;
}

.cart-body {
  flex: 1;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0.25rem 0.85rem 1rem;
}

.cart-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 2.5rem 1rem;
}

.cart-group {
  margin-bottom: 1rem;
}

.cart-group-head {
  margin: 0 0 0.55rem;
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  background: rgba(110, 168, 254, 0.08);
  border: 1px solid rgba(110, 168, 254, 0.2);
}

.cart-group-title {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--accent);
}

.cart-group-contact {
  margin: 0.3rem 0 0;
  font-size: 0.86rem;
  color: var(--text);
  line-height: 1.4;
  word-break: break-word;
}

.cart-group-contact.muted {
  color: var(--text-muted);
  font-size: 0.78rem;
}

.cart-contact-label {
  display: inline-block;
  margin-right: 0.4rem;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 700;
}

.cart-item {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: 0.65rem;
  align-items: center;
  padding: 0.55rem;
  margin-bottom: 0.45rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-card);
  position: relative;
}

.cart-item img {
  width: 56px;
  height: 78px;
  object-fit: cover;
  border-radius: 6px;
  background: #0a0d12;
}

.cart-item-main {
  min-width: 0;
}

.cart-item-name {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.3;
}

.cart-item-meta {
  margin: 0.2rem 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.cart-item-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.35rem;
}

.cart-qty {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.1rem;
}

.cart-qty button {
  width: 2.75rem;
  height: 2.75rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.cart-qty span {
  min-width: 1.2rem;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 600;
}

.cart-footer {
  border-top: 1px solid var(--border);
  padding: 0.75rem 1.1rem calc(0.85rem + env(safe-area-inset-bottom, 0px));
  background: var(--bg-elevated);
}

.cart-summary {
  font-size: 0.95rem;
  color: var(--text-muted);
}

.cart-summary strong {
  color: var(--text);
}

/* 截图模式：浅色整页，方便发给卖家 */
.cart.shot-mode .cart-backdrop {
  background: #e8ecf2;
}

.cart.shot-mode .cart-panel {
  width: min(560px, 100%);
  left: 50%;
  right: auto;
  transform: translateX(-50%);
  border: 0;
  border-radius: 0;
  background: #fff;
  color: #1a1f2a;
  box-shadow: none;
}

.cart.shot-mode .cart-header h2,
.cart.shot-mode .cart-item-name,
.cart.shot-mode .cart-summary strong,
.cart.shot-mode .cart-qty span,
.cart.shot-mode .cart-qty button {
  color: #12161f;
}

.cart.shot-mode .cart-sub,
.cart.shot-mode .cart-tip,
.cart.shot-mode .cart-item-meta,
.cart.shot-mode .cart-empty,
.cart.shot-mode .cart-summary {
  color: #5b6578;
}

.cart.shot-mode .cart-group-title {
  color: #1a5fb4;
}

.cart.shot-mode .cart-group-head {
  background: #eef4ff;
  border-color: #c9daf8;
}

.cart.shot-mode .cart-group-contact {
  color: #12161f;
}

.cart.shot-mode .cart-group-contact.muted {
  color: #5b6578;
}

.cart.shot-mode .cart-contact-label {
  background: #d6e6ff;
  color: #1450a0;
}

.cart.shot-mode .cart-item {
  background: #f4f6fa;
  border-color: #d5dbe8;
}

.cart.shot-mode .cart-toolbar,
.cart.shot-mode .cart-tip,
.cart.shot-mode .modal-close {
  display: none;
}

.cart.shot-mode .btn {
  border-color: #c5cedd;
  color: #1a1f2a;
}

.cart.shot-mode .cart-footer {
  background: #fff;
  border-top-color: #d5dbe8;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(5.5rem, calc(4.5rem + env(safe-area-inset-bottom)));
  transform: translateX(-50%);
  z-index: 70;
  max-width: min(90vw, 22rem);
  padding: 0.65rem 1rem;
  border-radius: 999px;
  background: rgba(20, 26, 38, 0.94);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  pointer-events: none;
}

.toast[hidden] {
  display: none !important;
}

.modal-close {
  position: absolute;
  top: 0.65rem;
  right: 0.65rem;
  z-index: 2;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
  touch-action: manipulation;
}

.modal-close:hover {
  border-color: var(--accent);
}

footer {
  padding: 0 0 max(2rem, calc(1rem + env(safe-area-inset-bottom, 0px)));
  color: var(--text-muted);
  font-size: 0.82rem;
  text-align: center;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* ========== 手机 / 窄屏 ========== */
@media (max-width: 720px) {
  .wrap {
    width: min(1200px, calc(100% - 1.1rem));
  }

  header.site-header {
    padding: 1rem 0 0.75rem;
    padding-top: max(1rem, env(safe-area-inset-top, 0px));
  }

  .header-top {
    align-items: center;
    gap: 0.5rem 0.65rem;
  }

  .header-brand .subtitle {
    font-size: 0.82rem;
    line-height: 1.35;
  }

  .header-actions {
    max-width: none;
    gap: 0.35rem;
  }

  /* Prefer ≥44px touch targets on phones */
  .header-actions .btn-sm {
    min-height: 2.5rem;
    padding: 0.35rem 0.75rem;
    font-size: 0.82rem;
  }

  .auth-area .auth-email,
  .header-actions .auth-email,
  .header-actions .admin-email {
    max-width: 6.5rem;
    font-size: 0.75rem;
  }

  .stats {
    gap: 0.35rem 0.85rem;
    margin-top: 0.7rem;
    font-size: 0.82rem;
  }

  .toolbar {
    padding: 0.5rem 0 0.55rem;
  }

  /* 下滑浏览时收起工具栏，上滑再显示 */
  .toolbar.is-collapsed {
    transform: translateY(calc(-100% - 2px));
    pointer-events: none;
    visibility: hidden;
    box-shadow: none;
  }

  .toolbar-inner {
    grid-template-columns: 1fr;
    gap: 0.45rem;
  }

  .filter-toggle {
    display: inline-flex;
  }

  .search {
    min-height: 2.65rem;
    padding: 0.45rem 0.85rem;
  }

  /* 默认折叠筛选；点「筛选」再展开 */
  .filters {
    display: none;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: visible;
    gap: 0.4rem;
    padding: 0.05rem 0 0.15rem;
    margin: 0 -0.15rem;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    overscroll-behavior-x: contain;
  }

  .toolbar.filters-open .filters {
    display: flex;
  }

  .filters::-webkit-scrollbar {
    display: none;
  }

  .dd {
    flex: 0 0 auto;
  }

  .dd-trigger {
    max-width: none;
    min-height: 2.45rem;
    padding: 0.32rem 0.65rem;
    font-size: 0.84rem;
  }

  .dd-value {
    max-width: 4.5rem;
  }

  /* 手机菜单走 .dd-menu.is-portal，避免被 .filters overflow 裁剪 */

  .dd-option {
    font-size: 1rem;
    padding: 0.8rem 0.9rem;
    min-height: 3rem;
  }

  main {
    padding: 0.7rem 0 2rem;
  }

  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.6rem;
  }

  .card {
    border-radius: 12px;
  }

  .card-body {
    padding: 0.5rem 0.55rem 0.6rem;
  }

  .card-name {
    font-size: 0.8rem;
    -webkit-line-clamp: 2;
  }

  .card-name-en {
    display: none;
  }

  .card-meta {
    font-size: 0.68rem;
  }

  .card-seller {
    font-size: 0.68rem;
    margin-top: 0.3rem;
  }

  .flag {
    font-size: 0.62rem;
    padding: 0.1rem 0.32rem;
  }

  /* 详情：底部抽屉 */
  .modal {
    align-items: flex-end;
    justify-content: stretch;
    padding: 0;
  }

  .modal-panel {
    width: 100%;
    max-width: none;
    max-height: min(92dvh, 920px);
    grid-template-columns: 1fr;
    border-radius: 18px 18px 0 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  .modal-handle {
    display: block;
    width: 2.4rem;
    height: 0.28rem;
    margin: 0.55rem auto 0.15rem;
    border-radius: 999px;
    background: #3a455c;
  }

  .modal-art {
    padding: 0.5rem 1rem 0.25rem;
  }

  .modal-art img {
    max-width: min(260px, 62vw);
  }

  .modal-content {
    padding: 0.65rem 1rem calc(1.1rem + env(safe-area-inset-bottom, 0px));
  }

  .modal-content h2 {
    font-size: 1.2rem;
  }

  .modal-close {
    top: 0.55rem;
    right: 0.55rem;
    width: 2.65rem;
    height: 2.65rem;
    background: rgba(28, 34, 48, 0.92);
  }

  .detail-grid {
    font-size: 0.9rem;
    gap: 0.5rem 0.75rem;
  }

  .oracle {
    font-size: 0.9rem;
    padding: 0.75rem 0.85rem;
  }

  footer {
    font-size: 0.78rem;
  }

  .card-add {
    font-size: 0.7rem;
    min-height: 2.75rem;
    padding: 0.22rem 0.5rem;
  }

  .cart-fab {
    right: max(0.75rem, env(safe-area-inset-right));
    bottom: max(0.85rem, env(safe-area-inset-bottom));
  }

  .cart-panel {
    top: auto;
    left: 0;
    right: 0;
    width: 100%;
    max-height: min(92dvh, 920px);
    border-left: 0;
    border-top: 1px solid var(--border);
    border-radius: 18px 18px 0 0;
  }

  .cart-handle {
    display: block;
    width: 2.4rem;
    height: 0.28rem;
    margin: 0.55rem auto 0.1rem;
    border-radius: 999px;
    background: #3a455c;
  }

  .cart.shot-mode .cart-panel {
    left: 0;
    transform: none;
    width: 100%;
    max-height: 100dvh;
    border-radius: 0;
  }

  .cart.shot-mode .cart-handle {
    background: #c5cedd;
  }
}

/* 超窄屏：仍保持双列，略再压缩 */
@media (max-width: 360px) {
  .grid {
    gap: 0.45rem;
  }

  .card-name {
    font-size: 0.75rem;
  }
}

/* 横屏手机：详情可左右排 */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 480px) {
  .modal {
    align-items: center;
    padding: 0.5rem;
  }

  .modal-panel {
    grid-template-columns: minmax(160px, 38vw) 1fr;
    max-height: 94dvh;
    border-radius: 14px;
    width: min(920px, 100%);
  }

  .modal-handle {
    display: none;
  }

  .modal-art img {
    max-width: 100%;
  }
}

/* 图片加载失败降级文案（onImgError 给父容器加 .img-failed） */
.card-img-wrap.img-failed::after,
.modal-art.img-failed::after,
.cart-item.img-failed::after {
  content: "图加载失败";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  color: #8b94a7;
  pointer-events: none;
}

.modal-art.img-failed {
  position: relative;
}

/* 分页：加载更多按钮 */
.load-more {
  grid-column: 1 / -1;
  justify-self: center;
  margin: 1.2rem 0;
  padding: 0.6rem 1.4rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(8, 12, 20, 0.78);
  color: #fff;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  touch-action: manipulation;
}
.load-more:hover {
  background: rgba(110, 168, 254, 0.92);
  color: #061018;
  border-color: transparent;
}

/* 偏好减少动效的用户：禁用动画/过渡 */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
