  :root {
    --felt-deep: #072a1e;
    --felt: #0a3d2c;
    --felt-light: #0f4d3a;
    --felt-rim: #14543f;
    --gold: #c9a961;
    --gold-bright: #d4af37;
    --gold-soft: #e8d9a8;
    --gold-dim: #8a7440;
    --ivory: #f5efe1;
    --ivory-dim: #d8cfb8;
    --ink: #1a1a1a;
    --blood: #c0392b;
    --blood-deep: #962d22;
    --shadow-deep: 0 18px 40px -12px rgba(0, 0, 0, 0.65);
    --shadow-card: 0 8px 18px -6px rgba(0, 0, 0, 0.55), 0 2px 4px rgba(0, 0, 0, 0.35);
    --shadow-card-up: 0 14px 28px -8px rgba(0, 0, 0, 0.7), 0 4px 8px rgba(0, 0, 0, 0.45);
  }

  * { box-sizing: border-box; margin: 0; padding: 0; }

  html, body { min-height: 100%; }

  body {
    font-family: 'Outfit', -apple-system, sans-serif;
    color: var(--ivory);
    background-color: var(--felt-deep);
    background-image:
      radial-gradient(ellipse 80% 60% at 50% 0%, rgba(201, 169, 97, 0.08), transparent 60%),
      radial-gradient(ellipse 100% 80% at 50% 50%, var(--felt-light) 0%, var(--felt) 45%, var(--felt-deep) 100%),
      url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.08 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
    background-attachment: fixed;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
  }
  html {
    scrollbar-width: none;
    -ms-overflow-style: none;
  }
  ::-webkit-scrollbar {
    display: none;
  }

  .app {
    max-width: 1240px;
    margin: 0 auto;
    padding: 48px 32px 80px;
    position: relative;
  }

  /* ====== Header ====== */
  .header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 32px;
    padding-bottom: 28px;
    margin-bottom: 32px;
    border-bottom: 1px solid rgba(201, 169, 97, 0.25);
    position: relative;
  }
  .header::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 120px;
    height: 2px;
    background: linear-gradient(90deg, var(--gold-bright), transparent);
  }

  .brand {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }
  .brand .eyebrow {
    font-family: 'Outfit', sans-serif;
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.42em;
    text-transform: uppercase;
    color: var(--gold);
  }
  .brand h1 {
    font-family: 'Cinzel', serif;
    font-weight: 800;
    font-size: clamp(34px, 4.6vw, 56px);
    line-height: 0.95;
    letter-spacing: 0.04em;
    color: var(--ivory);
    text-shadow: 0 2px 18px rgba(0, 0, 0, 0.5);
  }
  .brand h1 .accent { color: var(--gold-bright); }
  .brand .subtitle {
    font-family: 'Cormorant Garamond', serif;
    font-style: italic;
    font-size: 16px;
    color: var(--ivory-dim);
    letter-spacing: 0.02em;
    margin-top: 4px;
  }

  .stats {
    display: flex;
    gap: 28px;
    align-items: stretch;
  }
  .stat {
    text-align: right;
    min-width: 90px;
  }
  .stat .label {
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.3em;
    text-transform: uppercase;
    color: var(--gold-dim);
    margin-bottom: 4px;
  }
  .stat .value {
    font-family: 'Cinzel', serif;
    font-weight: 700;
    font-size: 38px;
    line-height: 1;
    color: var(--gold-bright);
    text-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
  }
  .stat.missing .value { color: var(--ivory-dim); }
  .stat .of {
    font-size: 13px;
    color: var(--gold-dim);
    font-weight: 400;
    margin-left: 2px;
  }

  /* ====== Action bar ====== */
  .actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 28px;
  }
  .btn {
    font-family: 'Outfit', sans-serif;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--gold-soft);
    background: transparent;
    border: 1px solid rgba(201, 169, 97, 0.45);
    padding: 11px 22px;
    border-radius: 2px;
    cursor: pointer;
    transition: all 0.25s ease;
    position: relative;
    overflow: hidden;
  }
  .btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, var(--gold-bright), var(--gold));
    opacity: 0;
    transition: opacity 0.25s ease;
    z-index: -1;
  }
  .btn:hover {
    color: var(--felt-deep);
    border-color: var(--gold-bright);
    transform: translateY(-1px);
    box-shadow: 0 6px 16px -4px rgba(201, 169, 97, 0.4);
  }
  .btn:hover::before { opacity: 1; }
  .btn:active { transform: translateY(0); }
  .btn.danger { border-color: rgba(192, 57, 43, 0.5); color: #e8a59f; }
  .btn.danger::before { background: linear-gradient(135deg, var(--blood), var(--blood-deep)); }
  .btn.danger:hover { color: var(--ivory); border-color: var(--blood); }

  /* ====== Progress bar ====== */
  .progress-wrap {
    margin-bottom: 36px;
  }
  .progress {
    height: 6px;
    background: rgba(0, 0, 0, 0.35);
    border-radius: 3px;
    overflow: hidden;
    border: 1px solid rgba(201, 169, 97, 0.2);
    position: relative;
  }
  .progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--gold-dim), var(--gold-bright), var(--gold-soft));
    width: 0%;
    transition: width 0.5s cubic-bezier(0.22, 1, 0.36, 1);
    box-shadow: 0 0 12px rgba(212, 175, 55, 0.6);
  }

  /* ====== Tag filter bar ====== */
  .tags {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    margin-bottom: 32px;
    align-items: center;
  }
  .tag-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
  }
  .tag-divider {
    width: 1px;
    align-self: stretch;
    background: linear-gradient(to bottom, transparent, rgba(201, 169, 97, 0.4), transparent);
    margin: 0 4px;
  }
  .tags .tags-label {
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.3em;
    text-transform: uppercase;
    color: var(--gold-dim);
    margin-right: 4px;
  }
  .tag {
    font-family: 'Outfit', sans-serif;
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.05em;
    color: var(--gold-soft);
    background: transparent;
    border: 1px solid rgba(201, 169, 97, 0.35);
    padding: 8px 16px;
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 7px;
  }
  .tag .sym {
    font-size: 14px;
    line-height: 1;
  }
  .tag .sym.red { color: var(--blood); }
  .tag .sym.black { color: var(--ivory); }
  .tag .sym.gold { color: var(--gold-bright); }
  .tag .count {
    font-size: 11px;
    color: var(--gold-dim);
    font-variant-numeric: tabular-nums;
  }
  .tag:hover {
    border-color: var(--gold);
    color: var(--ivory);
    transform: translateY(-1px);
  }
  .tag.active {
    background: linear-gradient(135deg, var(--gold-bright), var(--gold));
    color: var(--felt-deep);
    border-color: var(--gold-bright);
    box-shadow: 0 4px 14px -2px rgba(212, 175, 55, 0.5);
  }
  .tag.active .count { color: var(--felt-deep); opacity: 0.7; }
  .tag.active .sym.red { color: var(--blood-deep); }
  .tag.active .sym.black { color: var(--felt-deep); }
  .tag.active .sym.gold { color: var(--felt-deep); }

  /* ====== Card box (牌盒) ====== */
  .box-section {
    display: flex;
    justify-content: center;
    margin-bottom: 44px;
    perspective: 1200px;
  }
  .cardbox {
    position: relative;
    width: 280px;
    height: 180px;
    transform-style: preserve-3d;
    transform: rotateX(-18deg);
    transition: transform 0.6s ease, filter 0.3s ease, opacity 0.3s ease;
    cursor: pointer;
    outline: none;
  }
  .cardbox:hover { transform: rotateX(-12deg) translateY(-4px); }
  .cardbox:focus-visible {
    box-shadow: 0 0 0 2px var(--gold-bright);
    border-radius: 8px;
  }

  /* Box owned / not owned states */
  .cardbox.owned .box-checkmark {
    position: absolute;
    top: 10px;
    right: 12px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--gold-bright), var(--gold));
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4), 0 0 12px rgba(212, 175, 55, 0.4);
    z-index: 3;
  }
  .cardbox.owned .box-checkmark::after {
    content: '';
    width: 9px;
    height: 6px;
    border-left: 2px solid var(--felt-deep);
    border-bottom: 2px solid var(--felt-deep);
    transform: rotate(-45deg) translate(1px, -1px);
  }
  .cardbox.owned .body .box-sub { color: var(--gold-bright); }
  .cardbox:not(.owned) {
    filter: grayscale(0.85) brightness(0.55);
    opacity: 0.65;
  }
  .cardbox:not(.owned):hover {
    filter: grayscale(0.4) brightness(0.8);
    opacity: 0.9;
  }
  .cardbox:not(.owned) .box-checkmark { display: none; }

  .cardbox .face {
    position: absolute;
    border-radius: 6px;
    background:
      linear-gradient(135deg, #2a1d10 0%, #1a1208 100%);
    border: 1px solid rgba(201, 169, 97, 0.4);
    box-shadow:
      inset 0 0 30px rgba(0, 0, 0, 0.6),
      0 20px 40px -10px rgba(0, 0, 0, 0.7);
  }
  .cardbox .face::before {
    content: '';
    position: absolute;
    inset: 8px;
    border: 1px solid rgba(201, 169, 97, 0.25);
    border-radius: 3px;
    pointer-events: none;
  }

  /* Box body (front face) */
  .cardbox .body {
    width: 280px;
    height: 110px;
    bottom: 0;
    left: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
  }
  .cardbox .body .box-title {
    font-family: 'Cinzel', serif;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.42em;
    color: var(--gold);
    text-transform: uppercase;
  }
  .cardbox .body .box-count {
    font-family: 'Cinzel', serif;
    font-size: 42px;
    font-weight: 800;
    color: var(--gold-bright);
    line-height: 1;
    text-shadow: 0 2px 14px rgba(212, 175, 55, 0.4);
  }
  .cardbox .body .box-count .of {
    font-size: 16px;
    color: var(--gold-dim);
    font-weight: 500;
  }
  .cardbox .body .box-sub {
    font-family: 'Cormorant Garamond', serif;
    font-style: italic;
    font-size: 13px;
    color: var(--ivory-dim);
    margin-top: 2px;
  }

  /* Box lid (top face, half-open) */
  .cardbox .lid {
    width: 280px;
    height: 70px;
    top: 0;
    left: 0;
    transform-origin: top center;
    transform: rotateX(-42deg);
    border-bottom: none;
    border-radius: 6px 6px 2px 2px;
  }
  .cardbox .lid::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 36px;
    height: 36px;
    transform: translate(-50%, -50%) rotate(45deg);
    border: 1.5px solid var(--gold);
    background: linear-gradient(135deg, var(--gold-bright), var(--gold-dim));
    box-shadow: 0 0 12px rgba(212, 175, 55, 0.5);
  }

  /* Stack of cards visible inside the box */
  .cardbox .stack {
    position: absolute;
    left: 50%;
    bottom: 95px;
    transform: translateX(-50%);
    width: 70px;
    height: 90px;
    pointer-events: none;
  }
  .cardbox .stack .layer {
    position: absolute;
    inset: 0;
    background: var(--ivory);
    border: 1px solid rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
  .cardbox .stack .layer:nth-child(1) { transform: translate(-6px, -2px) rotate(-3deg); }
  .cardbox .stack .layer:nth-child(2) { transform: translate(0, -6px) rotate(1deg); }
  .cardbox .stack .layer:nth-child(3) { transform: translate(6px, -2px) rotate(4deg); background: linear-gradient(135deg, var(--ivory), var(--ivory-dim)); }
  .cardbox .stack .layer:nth-child(3)::after {
    content: '♠';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    color: var(--ink);
  }

  /* ====== Card grid ====== */
  .grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 14px;
  }
  @media (max-width: 1023px) {
    .grid { grid-template-columns: repeat(4, 1fr); }
  }
  @media (max-width: 767px) {
    .grid { grid-template-columns: repeat(3, 1fr); gap: 10px; }
    .app { padding: 32px 18px 60px; }
    .header { flex-direction: column; align-items: flex-start; gap: 20px; }
    .stats { width: 100%; justify-content: space-between; gap: 16px; }
    .stat { text-align: left; }
  }

  /* ====== Card ====== */
  .card {
    position: relative;
    aspect-ratio: 2.5 / 3.5;
    background: var(--ivory);
    border-radius: 8px;
    box-shadow: var(--shadow-card);
    cursor: pointer;
    user-select: none;
    overflow: hidden;
    transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1),
                box-shadow 0.25s ease,
                filter 0.3s ease,
                opacity 0.3s ease;
    animation: cardDeal 0.5s cubic-bezier(0.22, 1, 0.36, 1) backwards;
    animation-delay: var(--deal-delay, 0s);
    border: 1px solid rgba(0, 0, 0, 0.15);
  }
  @keyframes cardDeal {
    from {
      opacity: 0;
      transform: translateY(20px) rotateY(90deg) scale(0.85);
    }
    to {
      transform: translateY(0) rotateY(0) scale(1);
    }
  }

  .card::before {
    content: '';
    position: absolute;
    inset: 3px;
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 6px;
    pointer-events: none;
  }

  .card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-card-up);
  }
  .card:active { transform: translateY(-2px) scale(0.98); }

  .card .corner {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1;
    font-family: 'Cinzel', serif;
    font-weight: 700;
  }
  .card .corner.tl {
    top: 6px;
    left: 7px;
  }
  .card .corner.br {
    bottom: 6px;
    right: 7px;
    transform: rotate(180deg);
  }
  .card .corner .rank {
    font-size: clamp(13px, 1.4vw, 17px);
    letter-spacing: -0.02em;
  }
  .card .corner .sym {
    font-size: clamp(11px, 1.2vw, 14px);
    margin-top: 1px;
  }

  .card .center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: clamp(32px, 4.5vw, 52px);
    line-height: 1;
    opacity: 0.92;
  }

  .card .center.joker {
    font-family: 'Cinzel', serif;
    font-weight: 700;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
  }
  .card .center.joker .star { font-size: clamp(28px, 4vw, 42px); }
  .card .center.joker .word {
    font-size: clamp(8px, 0.9vw, 11px);
    letter-spacing: 0.25em;
    margin-top: 2px;
  }

  .card .checkmark {
    position: absolute;
    top: 6px;
    right: 7px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--gold-bright), var(--gold));
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: scale(0.5);
    transition: opacity 0.2s ease, transform 0.2s ease;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    z-index: 2;
  }
  .card .checkmark::after {
    content: '';
    width: 8px;
    height: 5px;
    border-left: 2px solid var(--felt-deep);
    border-bottom: 2px solid var(--felt-deep);
    transform: rotate(-45deg) translate(1px, -1px);
  }

  /* Color variants */
  .card.black { color: var(--ink); }
  .card.red { color: var(--blood); }
  .card.gold { color: var(--gold-dim); }

  /* States */
  .card.checked {
    box-shadow: var(--shadow-card-up), 0 0 0 1px rgba(212, 175, 55, 0.4);
  }
  .card.checked .checkmark {
    opacity: 1;
    transform: scale(1);
  }
  .card.unchecked {
    filter: grayscale(0.85) brightness(0.55);
    opacity: 0.6;
  }
  .card.unchecked:hover {
    filter: grayscale(0.4) brightness(0.8);
    opacity: 0.85;
  }

  .card.flash {
    transform: translateY(-8px) scale(1.04) rotateY(8deg);
  }

  /* ====== Footer ====== */
  .footer {
    margin-top: 56px;
    padding-top: 24px;
    border-top: 1px solid rgba(201, 169, 97, 0.18);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 11px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--gold-dim);
  }
  .footer .dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--gold);
    margin: 0 8px;
    vertical-align: middle;
    box-shadow: 0 0 8px var(--gold);
  }

  /* Toast */
  .toast {
    position: fixed;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(10, 61, 44, 0.95);
    border: 1px solid var(--gold);
    color: var(--gold-soft);
    padding: 12px 24px;
    border-radius: 4px;
    font-size: 12px;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
    z-index: 100;
    backdrop-filter: blur(8px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  }
  .toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }

  @media (prefers-reduced-motion: reduce) {
    .card { animation: none; }
    * { transition-duration: 0.01ms !important; }
  }
