:root {
  color-scheme: dark;
  --bg: #0e0b14;
  --bg-soft: #171222;
  --surface: #1f1830;
  --text: #f6f2ff;
  --muted: #b8aecb;
  --pink: #ff4d8d;
  --violet: #8b6cff;
  --cyan: #5ce1e6;
  --line: rgba(255, 255, 255, 0.1);
  --radius: 18px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: "Noto Sans TC", "PingFang HK", "Microsoft JhengHei", sans-serif;
  background:
    radial-gradient(circle at top right, rgba(255, 77, 141, 0.18), transparent 32%),
    radial-gradient(circle at top left, rgba(139, 108, 255, 0.2), transparent 28%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  max-width: 100%;
}

.container {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(16px);
  background: rgba(14, 11, 20, 0.78);
  border-bottom: 1px solid var(--line);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  min-height: 72px;
  padding: 8px 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.logo-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--pink), var(--violet));
}

.nav {
  display: none;
  gap: 22px;
  color: var(--muted);
}

.nav a[aria-current="page"] {
  color: var(--text);
}

.nav-unread {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  margin-left: 6px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--pink);
  color: white;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.4;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn-primary {
  background: linear-gradient(135deg, var(--pink), var(--violet));
  color: white;
}

.btn-outline,
.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}

.btn-lg {
  min-height: 48px;
  padding: 12px 22px;
}

.btn-sm {
  min-height: 36px;
  padding: 8px 12px;
  font-size: 14px;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.hero,
.page-hero {
  padding: 56px 0 28px;
}

.hero-inner {
  max-width: 760px;
}

.eyebrow {
  color: var(--cyan);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 700;
  margin: 0 0 12px;
}

h1 {
  font-size: clamp(30px, 7vw, 64px);
  line-height: 1.12;
  margin: 0 0 16px;
}

h2 {
  margin: 0;
  font-size: 28px;
}

.hero-copy {
  color: var(--muted);
  font-size: 18px;
  max-width: 640px;
}

.search-bar {
  margin-top: 28px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px 8px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow);
}

.search-icon {
  color: var(--muted);
  display: grid;
  place-items: center;
}

.search-bar input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 0;
  outline: none;
  color: var(--text);
  font: inherit;
  padding: 10px 4px;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 24px;
}

.popular,
.browse-section,
.sell-section {
  padding: 24px 0 72px;
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.text-link {
  color: var(--cyan);
  font-weight: 700;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 18px;
}

.pcard {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

a.pcard-link {
  display: block;
  color: inherit;
  transition: transform 0.15s ease;
}

a.pcard-link:hover {
  transform: translateY(-2px);
}

a.pcard-open {
  display: block;
  color: inherit;
}

.pcard-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  padding: 0 16px 16px;
}

.pcard-delete {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.btn-danger {
  background: transparent;
  color: #ffc2d6;
  border: 1px solid rgba(255, 77, 141, 0.75);
}

.btn-danger:hover {
  background: rgba(255, 77, 141, 0.16);
}

.btn-danger:disabled {
  opacity: 0.55;
  cursor: wait;
  transform: none;
}

.pcard-delete-error {
  flex-basis: 100%;
  margin: 0;
  color: #ffc2d6;
  font-size: 0.92rem;
}

.delete-listing-name {
  color: var(--text);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.listing-seller-actions {
  margin: 16px 0 0;
}

.seller-bio {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.listing-contact {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  margin-top: 16px;
}

.listing-report {
  display: grid;
  gap: 10px;
  margin-top: 20px;
  justify-items: start;
}

.report-toggle {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  font-size: 0.92rem;
  color: var(--muted);
  cursor: pointer;
  text-decoration: underline;
}

.report-form {
  display: grid;
  gap: 12px;
  width: 100%;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.report-form fieldset {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  border: 0;
}

.report-form legend {
  padding: 0;
  margin-bottom: 8px;
  font-weight: 700;
}

.report-form label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.report-form label.report-details {
  display: grid;
  gap: 8px;
  font-weight: 700;
}

.report-form textarea {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  font: inherit;
  padding: 12px;
  resize: vertical;
}

.inbox-list {
  display: grid;
  gap: 12px;
}

.inbox-item {
  display: grid;
  gap: 4px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-soft);
  color: inherit;
}

.purchase-requests {
  margin-top: 32px;
  display: grid;
  gap: 12px;
}

.purchase-requests h2 {
  margin: 0;
  font-size: 1.2rem;
}

.purchase-item .pcard-actions {
  padding: 8px 0 0;
  justify-content: flex-start;
}

.purchase-item .pcard-meta,
.purchase-item .pcard-delete-error {
  margin: 0;
}

.admin-panel {
  display: grid;
  gap: 14px;
}

.admin-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.admin-filters .btn-outline[aria-pressed="false"] {
  color: var(--muted);
}

.admin-report-details {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.purchase-progress {
  color: var(--muted);
}

.inbox-item strong {
  font-size: 1.05rem;
}

.inbox-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.message-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 18px;
}

.message-bubble {
  width: min(100%, 520px);
  padding: 12px 14px;
  border-radius: 16px;
}

.message-mine {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(255, 77, 141, 0.28), rgba(139, 108, 255, 0.28));
}

.message-theirs {
  align-self: flex-start;
  background: var(--bg-soft);
  border: 1px solid var(--line);
}

.message-who,
.message-time {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.message-content {
  margin: 4px 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message-form {
  display: grid;
  gap: 12px;
  width: min(720px, 100%);
}

.edit-form {
  width: min(640px, 100%);
}

.listing-detail {
  display: grid;
  gap: 24px;
}

.listing-media,
.listing-panel {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.listing-panel {
  padding: 24px;
  display: grid;
  gap: 12px;
  align-content: start;
}

.listing-media .pcard-art,
.listing-media .pcard-photo {
  height: min(520px, 78vw);
}

.listing-price {
  margin: 0;
  font-size: 32px;
}

.listing-description {
  margin: 0;
  white-space: pre-wrap;
}

.listing-back {
  display: inline-block;
  margin-top: 12px;
}

.pcard-art {
  height: 250px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 18px;
}

.pcard-photo {
  display: block;
  width: 100%;
  height: 250px;
  object-fit: cover;
}

.pcard-initial {
  font-size: 72px;
  font-weight: 800;
  line-height: 1;
  opacity: 0.92;
}

.pcard-group {
  font-weight: 700;
  letter-spacing: 0.04em;
}

.pcard-body {
  padding: 16px;
}

.pcard-meta {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
}

.pcard-body h3 {
  margin: 0 0 12px;
  font-size: 16px;
}

.pcard-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.price {
  font-weight: 800;
}

.badge {
  font-size: 12px;
  color: var(--cyan);
  border: 1px solid rgba(92, 225, 230, 0.35);
  border-radius: 999px;
  padding: 4px 8px;
}

.badge-sold {
  color: #ffc2d6;
  border-color: rgba(255, 77, 141, 0.8);
  background: rgba(255, 77, 141, 0.18);
}

.badge-reserved {
  color: #ffd98a;
  border-color: rgba(255, 196, 77, 0.8);
  background: rgba(255, 196, 77, 0.16);
}

.badge-group {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.badge-demo {
  color: var(--muted);
  border-color: var(--line);
}

.pcard-desc {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.browse-error {
  color: #ffc2d6;
}

.empty,
.result-count {
  color: var(--muted);
}

.sell-layout {
  display: grid;
  gap: 24px;
}

.sell-form,
.preview-panel {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}

.sell-form {
  display: grid;
  gap: 14px;
}

.sell-form .btn-lg {
  width: 100%;
}

.sell-form label {
  display: grid;
  gap: 8px;
  font-weight: 700;
}

.sell-form textarea {
  width: 100%;
  min-height: 120px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  padding: 12px;
  resize: vertical;
}

.sell-form input,
.sell-form select,
.auth-form input {
  width: 100%;
  min-height: 46px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  padding: 0 12px;
}

.sell-form input:focus,
.sell-form textarea:focus,
.sell-form select:focus,
.auth-form input:focus {
  outline: 2px solid rgba(139, 108, 255, 0.75);
  outline-offset: 1px;
}

.auth-status {
  display: flex;
  align-items: center;
}

.auth-user {
  display: flex;
  align-items: center;
  gap: 8px;
}

.auth-label,
.auth-email {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.auth-email {
  max-width: 18ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-section {
  padding: 8px 0 72px;
}

.auth-card {
  width: min(480px, 100%);
  margin: 0 auto;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  display: grid;
  gap: 16px;
}

.auth-card h2 {
  margin: 0;
}

.auth-card p,
.auth-note {
  color: var(--muted);
  margin: 0;
}

.sell-form input[type="file"] {
  padding: 10px 12px;
  height: auto;
}

.upload-preview {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  overflow: hidden;
}

.upload-preview img {
  display: block;
  width: 100%;
  max-height: 260px;
  object-fit: contain;
}

.auth-card strong {
  color: var(--text);
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.auth-tabs button {
  min-height: 44px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.auth-tabs button[aria-selected="true"] {
  border-color: transparent;
  color: white;
  background: linear-gradient(135deg, var(--pink), var(--violet));
}

.auth-form {
  display: grid;
  gap: 14px;
}

.auth-form label {
  display: grid;
  gap: 8px;
  font-weight: 700;
}

.auth-form .btn-lg {
  width: 100%;
}

.auth-switch button {
  background: none;
  border: 0;
  padding: 0;
  color: var(--cyan);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.auth-pending-note {
  color: var(--muted);
  margin-top: 0;
}

.form-message {
  margin: 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(92, 225, 230, 0.1);
  color: var(--cyan);
}

.form-message.error {
  background: rgba(255, 77, 141, 0.14);
  color: #ffc2d6;
}

.form-message.info {
  background: rgba(139, 108, 255, 0.16);
  color: #ddd4ff;
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.login-dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-soft);
  color: var(--text);
  padding: 24px;
  width: min(420px, calc(100vw - 32px));
  box-shadow: var(--shadow);
}

.login-dialog::backdrop {
  background: rgba(0, 0, 0, 0.62);
}

.login-dialog h2 {
  margin: 0 0 8px;
}

.login-dialog p {
  color: var(--muted);
  margin: 0 0 16px;
}

.auth-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 40;
  margin: 0;
  padding: 12px 16px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  max-width: min(420px, calc(100% - 32px));
}

.site-footer {
  border-top: 1px solid var(--line);
  padding: 24px 0 40px;
  color: var(--muted);
}

.footer-inner p {
  margin: 0 0 6px;
}

.nav-mobile-link {
  display: inline-flex;
}

@media (min-width: 760px) {
  .nav {
    display: flex;
  }

  .nav-mobile-link {
    display: none;
  }

  .sell-layout {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }

  .listing-detail {
    grid-template-columns: minmax(260px, 420px) 1fr;
    align-items: start;
  }
}

@media (max-width: 640px) {
  .section-heading {
    flex-direction: column;
    align-items: flex-start;
  }

  .header-actions .btn-ghost {
    display: none;
  }

  .auth-email {
    display: none;
  }

  .search-bar {
    flex-wrap: wrap;
    border-radius: 22px;
    padding: 12px;
  }

  .search-submit {
    width: 100%;
  }

  .pcard-art,
  .pcard-photo {
    height: 220px;
  }
}

/* ---- 手機版及使用體驗優化 ---- */

/* 長文字（商品名稱、訊息、補充說明）唔會撐爆版面 */
h1,
h2,
h3,
.hero-copy,
.pcard-body,
.pcard-meta,
.listing-panel,
.inbox-item,
.auth-card,
.form-message,
.message-bubble,
.login-dialog,
.report-form,
.preview-panel {
  overflow-wrap: anywhere;
}

.inbox-item > *,
.inbox-title-row > *,
.pcard-row > *,
.listing-panel > * {
  min-width: 0;
}

.inbox-title-row {
  align-items: flex-start;
}

.inbox-title-row .badge,
.pcard-row .badge {
  flex-shrink: 0;
  white-space: nowrap;
}

.listing-panel .badge {
  justify-self: start;
}

/* 鍵盤操作：清楚嘅焦點框 */
a:focus-visible,
button:focus-visible,
.btn:focus-visible,
input[type="radio"]:focus-visible,
input[type="file"]:focus-visible {
  outline: 2px solid rgba(139, 108, 255, 0.9);
  outline-offset: 2px;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn-primary:disabled {
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--line);
  opacity: 1;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -64px;
  z-index: 60;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
  font-weight: 700;
}

.skip-link:focus {
  top: 12px;
}

main:focus {
  outline: none;
}

.report-form input[type="radio"] {
  flex: none;
  width: 20px;
  height: 20px;
  accent-color: var(--pink);
}

.report-form label {
  min-height: 44px;
}

.login-dialog {
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
}

.auth-toast {
  bottom: max(24px, env(safe-area-inset-bottom));
}

.site-footer {
  padding-bottom: max(40px, calc(env(safe-area-inset-bottom) + 24px));
}

.pcard-lock-note {
  margin: 0;
  padding: 0 16px 16px;
  font-size: 0.92rem;
}

#listing-owner-actions .pcard-lock-note {
  display: block;
  padding: 0;
}

@media (min-width: 760px) and (max-width: 1023px) {
  /* 平板：導覽已有「瀏覽小卡」同「出售小卡」，隱藏重複按鈕令頂欄保持一行 */
  .header-actions > .btn-ghost,
  .header-actions > .btn-primary {
    display: none;
  }

  .nav {
    gap: 16px;
  }
}

@media (max-width: 759px) {
  /* 手機頂欄會有兩至三行，唔固定喺畫面頂，留多啲空間畀內容同鍵盤 */
  .site-header {
    position: static;
  }

  .header-inner {
    gap: 8px;
  }

  .btn-sm,
  .nav-mobile-link {
    min-height: 44px;
  }

  .btn:not(.btn-lg) {
    min-height: 44px;
  }

  .hero,
  .page-hero {
    padding: 36px 0 20px;
  }

  .hero-copy {
    font-size: 16px;
  }

  h2 {
    font-size: 24px;
  }

  .popular,
  .browse-section,
  .sell-section {
    padding-bottom: 48px;
  }

  .listing-panel {
    padding: 18px;
  }

  .listing-price {
    font-size: 28px;
  }

  .sell-form,
  .preview-panel,
  .auth-card {
    padding: 16px;
  }

  .sell-form textarea,
  .report-form textarea {
    min-height: 96px;
  }

  .text-link,
  .report-toggle {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
  }

  .dialog-actions .btn {
    flex: 1 1 140px;
  }

  .pcard-actions > .btn {
    flex: 1 1 120px;
  }

  .pcard-delete {
    flex: 1 1 120px;
    align-items: stretch;
  }

  .pcard-delete .btn {
    width: 100%;
  }

  .admin-filters {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .message-bubble {
    width: min(100%, 86%);
  }

  .auth-switch button {
    min-height: 44px;
    padding: 0 6px;
  }

  .logo {
    min-height: 44px;
  }
}
