/* Duelist Kingdom — dark stone & gold */
:root {
  --bg: #0d0a07;
  --stone: #1a1510;
  --stone-2: #241d16;
  --stone-3: #30271d;
  --line: #3d3224;
  --gold: #d4af37;
  --gold-2: #f3d77a;
  --gold-3: #8a6a1c;
  --sand: #c9b48a;
  --text: #ece2cc;
  --muted: #9d907a;
  --danger: #d1604c;
  --ok: #7cb27f;
  --radius: 10px;
  --card-ratio: 421 / 614;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  --font-title: 'Cinzel', 'Trajan Pro', Georgia, serif;
  --font-deco: 'Cinzel Decorative', 'Cinzel', Georgia, serif;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color-scheme: dark;
}

/* A display:grid/flex rule would otherwise win over the [hidden] attribute (modals!). */
[hidden] { display: none !important; }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font: 15px/1.5 var(--font);
  color: var(--text);
  background:
    radial-gradient(1100px 520px at 50% -12%, rgba(212, 175, 55, .13), transparent 60%),
    radial-gradient(700px 480px at 105% 105%, rgba(140, 70, 20, .16), transparent 60%),
    radial-gradient(600px 400px at -10% 60%, rgba(90, 60, 30, .14), transparent 60%),
    linear-gradient(180deg, #110d09, var(--bg));
  background-attachment: fixed;
}
body.modal-open { overflow: hidden; }
a { color: var(--gold-2); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
code { font-family: ui-monospace, 'Cascadia Code', Consolas, monospace; background: var(--stone-3); padding: 1px 6px; border-radius: 5px; font-size: .9em; color: var(--gold-2); }
h1, h2, h3, h4 { font-family: var(--font-title); letter-spacing: .02em; margin: 0 0 .4em; line-height: 1.2; }
h1 { font-size: clamp(1.6rem, 3.5vw, 2.3rem); color: var(--gold-2); text-shadow: 0 2px 18px rgba(212, 175, 55, .25); }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.gold { color: var(--gold-2); }
.warn { color: #e7b35a; }
:focus-visible { outline: 2px solid var(--gold-2); outline-offset: 2px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 18px;
  padding: 10px max(16px, env(safe-area-inset-left));
  background: linear-gradient(180deg, rgba(24, 19, 14, .97), rgba(16, 12, 9, .95));
  border-bottom: 1px solid var(--line);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .4);
  backdrop-filter: blur(6px);
}
.topbar::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: -5px; height: 4px;
  background: repeating-linear-gradient(90deg, var(--gold-3) 0 10px, transparent 10px 14px, var(--gold) 14px 18px, transparent 18px 22px);
  opacity: .5;
}
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-deco); font-size: 1.15rem; color: var(--gold-2); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  padding: 7px 12px; border-radius: 8px; color: var(--sand); font-family: var(--font-title); font-weight: 700; font-size: .92rem; white-space: nowrap;
}
.nav a:hover { background: var(--stone-2); text-decoration: none; }
.nav a.active { color: #1b1305; background: linear-gradient(180deg, var(--gold-2), var(--gold)); }
.top-right { display: flex; align-items: center; gap: 10px; }
.pack-pill {
  display: inline-flex; align-items: center; gap: 7px; padding: 5px 12px 5px 8px; border-radius: 999px;
  border: 1px solid var(--gold-3); background: var(--stone-2); color: var(--gold-2); font-weight: 700;
}
.pack-pill:hover { text-decoration: none; border-color: var(--gold); }
.pack-pill-icon { width: 14px; height: 19px; border-radius: 2px; background: linear-gradient(135deg, var(--gold-2), var(--gold-3)); box-shadow: 0 0 8px rgba(243, 215, 122, .5); }

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: 8px 12px; padding-bottom: 6px; }
  .brand span { font-size: 1rem; }
  .nav { order: 3; flex-basis: 100%; }
  .top-right { margin-left: auto; }
  #me-name { display: none; }
}

/* ---------- Layout ---------- */
.view { padding: 0 16px 60px; }
.page { max-width: 1180px; margin: 0 auto; padding-top: 26px; }
.page-wide { max-width: 1500px; }
.page-head { margin-bottom: 20px; }
.page-head.with-actions { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.lead { margin: 0; color: var(--sand); font-style: italic; }
.section-title { font-size: 1.25rem; color: var(--gold); margin-top: 30px; }
.loading, .empty { max-width: 700px; margin: 60px auto; text-align: center; color: var(--muted); font-style: italic; }
.loading::before { content: ''; display: block; width: 34px; height: 48px; margin: 0 auto 14px; border-radius: 4px; background: linear-gradient(135deg, var(--gold-2), var(--gold-3)); animation: spin-card 1.2s ease-in-out infinite; }
@keyframes spin-card { 50% { transform: rotateY(180deg); } }
.panel { background: linear-gradient(180deg, var(--stone-2), var(--stone)); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.panel .section-title { margin-top: 0; }

/* ---------- Controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--stone-3), var(--stone-2)); color: var(--text);
  font: 700 .95rem var(--font-title); letter-spacing: .02em; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: transform .08s, border-color .15s, filter .15s;
}
.btn:hover { border-color: var(--gold-3); text-decoration: none; filter: brightness(1.1); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.btn-gold { background: linear-gradient(180deg, var(--gold-2), var(--gold) 55%, var(--gold-3)); color: #1d1405; border-color: #6f5414; text-shadow: 0 1px 0 rgba(255, 255, 255, .3); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 5px 10px; font-size: .82rem; }
.btn-block { width: 100%; }
.icon-btn { width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--line); background: var(--stone-3); color: var(--text); cursor: pointer; font-weight: 700; flex: none; }
.icon-btn:hover { border-color: var(--gold-3); color: var(--gold-2); }
.input {
  min-width: 0; padding: 8px 11px; border-radius: 8px; border: 1px solid var(--line);
  background: #120e0a; color: var(--text); font: inherit;
}
.input:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(212, 175, 55, .18); }
select.input { padding-right: 28px; max-width: 100%; text-overflow: ellipsis; }
.input-qty { width: 70px; }
.input-search { flex: 1 1 220px; }
.input-code { text-transform: uppercase; letter-spacing: .08em; font-family: ui-monospace, Consolas, monospace; }
.check { display: inline-flex; align-items: center; gap: 4px; color: var(--sand); font-size: .9rem; white-space: nowrap; }
.chip { display: inline-block; padding: 2px 9px; border-radius: 999px; background: var(--stone-3); border: 1px solid var(--line); font-size: .8rem; margin-right: 6px; }
.chip-gold { border-color: var(--gold-3); color: var(--gold-2); }
.chip-small { font-size: .7rem; padding: 0 6px; margin-left: 6px; vertical-align: middle; }
.badge { font-size: .72rem; padding: 2px 8px; border-radius: 999px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.badge-ok { background: rgba(124, 178, 127, .15); color: var(--ok); border: 1px solid rgba(124, 178, 127, .4); }
.badge-draft { background: rgba(231, 179, 90, .12); color: #e7b35a; border: 1px solid rgba(231, 179, 90, .4); }
.set-code { display: inline-block; padding: 1px 7px; border-radius: 5px; background: #120e0a; border: 1px solid var(--gold-3); color: var(--gold-2); font: 700 .75rem ui-monospace, Consolas, monospace; }
.tabs { display: flex; gap: 4px; padding: 4px; background: #120e0a; border-radius: 10px; border: 1px solid var(--line); }
.tabs:empty { display: none; }
.tab { flex: 1; padding: 8px 10px; border: 0; border-radius: 7px; background: transparent; color: var(--sand); font: 700 .9rem var(--font-title); cursor: pointer; }
.tab.active { background: var(--stone-3); color: var(--gold-2); box-shadow: inset 0 0 0 1px var(--gold-3); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 16px 0; }
.filters .input { flex: 0 1 auto; }
.filters .input-search { flex: 1 1 220px; }
.inline-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
ul.plain { padding-left: 18px; margin: 0; }
ul.plain li { margin: 4px 0; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 30px 0; }
.login-card {
  width: min(420px, 100%); padding: 30px 26px; text-align: center; border-radius: 16px;
  background: linear-gradient(180deg, rgba(36, 29, 22, .96), rgba(22, 17, 12, .96));
  border: 1px solid var(--gold-3); box-shadow: 0 0 0 4px rgba(212, 175, 55, .07), 0 25px 60px rgba(0, 0, 0, .6);
}
.login-logo { filter: drop-shadow(0 0 18px rgba(243, 215, 122, .45)); }
.login-title { font-family: var(--font-deco); margin: 6px 0 0; }
.login-sub { color: var(--sand); margin: 0 0 12px; font-size: .9rem; }
.login-intro { color: var(--muted); font-style: italic; font-size: .92rem; }
.login-form { display: grid; gap: 12px; text-align: left; margin-top: 10px; }
.field { display: grid; gap: 4px; }
.field > span { font-size: .8rem; color: var(--sand); text-transform: uppercase; letter-spacing: .08em; }
.form-error { color: var(--danger); min-height: 1.2em; margin: 0; font-size: .9rem; }
.login-foot { margin-top: 18px; font-size: .8rem; text-align: center; }

/* ---------- Cards ---------- */
.card {
  position: relative; aspect-ratio: var(--card-ratio); border-radius: 4.5% / 3.1%; overflow: hidden;
  background: #1a130c; box-shadow: 0 4px 14px rgba(0, 0, 0, .5); cursor: pointer; container-type: inline-size;
  transition: transform .15s ease, box-shadow .15s ease;
}
.card-img { display: block; width: 100%; height: 100%; object-fit: cover; user-select: none; }
.card-grid .card:hover, .history-cards .card:hover { transform: translateY(-3px) scale(1.02); box-shadow: 0 10px 24px rgba(0, 0, 0, .6), 0 0 0 1px var(--gold-3); }
.card.missing { filter: grayscale(1) brightness(.45); }
.card.missing:hover { filter: grayscale(.6) brightness(.7); }
.card-qty {
  position: absolute; right: 4%; bottom: 3%; padding: 1px 7px; border-radius: 999px;
  background: rgba(10, 8, 5, .88); border: 1px solid var(--gold); color: var(--gold-2); font-weight: 800; font-size: .78rem;
}
.badge-new {
  position: absolute; top: 12.5%; left: -2px; padding: 2px 9px 2px 7px; z-index: 3;
  background: linear-gradient(180deg, #ff6a3d, #c4271a); color: #fff; font: 900 .72rem var(--font-title); letter-spacing: .08em;
  border-radius: 0 6px 6px 0; box-shadow: 0 2px 8px rgba(0, 0, 0, .6); animation: pop .4s .25s both;
}
@keyframes pop { from { transform: scale(0); } 70% { transform: scale(1.25); } }

/* CSS fallback card (missing image) */
.fcard {
  --frame: #c9a24a; --frame-2: #8c6a22;
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 2cqw; padding: 5cqw 5cqw 4cqw;
  background: linear-gradient(160deg, var(--frame), var(--frame-2)); color: #1a120a; font-family: var(--font-title);
  border: 1.6cqw solid #1b140c; border-radius: inherit;
}
.f-normal { --frame: #d8b76a; --frame-2: #a17f35; }
.f-effect { --frame: #d0773a; --frame-2: #8e4416; }
.f-ritual { --frame: #6d8fd1; --frame-2: #34508e; }
.f-fusion { --frame: #9a6ac2; --frame-2: #5b3584; }
.f-spell { --frame: #2ba08d; --frame-2: #13625a; }
.f-trap { --frame: #c04a8d; --frame-2: #7a2457; }
.fc-name { display: flex; justify-content: space-between; align-items: center; gap: 2cqw; padding: 1.5cqw 3cqw; background: rgba(255, 248, 230, .82); border: .6cqw solid rgba(0, 0, 0, .45); font-weight: 900; font-size: 7cqw; line-height: 1.1; }
.fc-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fc-attr { flex: none; width: 10cqw; height: 10cqw; display: grid; place-items: center; border-radius: 50%; background: #1b140c; color: var(--gold-2); font-size: 6cqw; }
.fc-stars { text-align: right; color: #b8240c; font-size: 6cqw; line-height: 1; letter-spacing: -.5cqw; text-shadow: 0 0 2px #ffd36b; min-height: 6cqw; }
.fc-kind { color: #1a120a; font-size: 5.2cqw; text-shadow: none; letter-spacing: 0; font-weight: 700; }
.fc-art { flex: 1; display: grid; place-items: center; border: .8cqw solid rgba(0, 0, 0, .55); background: radial-gradient(circle at 50% 40%, rgba(255, 255, 255, .25), rgba(0, 0, 0, .35)), linear-gradient(135deg, #3a2b1a, #120c07); color: var(--gold-2); font-size: 26cqw; text-shadow: 0 0 6cqw rgba(243, 215, 122, .6); }
.fc-text { background: rgba(255, 248, 230, .85); border: .6cqw solid rgba(0, 0, 0, .4); padding: 2cqw 3cqw; font: 4.6cqw/1.25 Georgia, serif; height: 26cqw; overflow: hidden; }
.fc-stats { text-align: right; font-weight: 900; font-size: 5.4cqw; }

/* Holo (Super = artwork foil, Ultra = stronger + gold, Secret = full-card rainbow) */
.holo { --mx: 50%; --my: 50%; --rx: 0deg; --ry: 0deg; transform: perspective(900px) rotateX(var(--rx)) rotateY(var(--ry)); transition: transform .25s ease; }
.holo-layer { position: absolute; pointer-events: none; z-index: 2; mix-blend-mode: color-dodge; background-size: 300% 300%; animation: holo-shift 5s ease-in-out infinite alternate; }
@keyframes holo-shift { from { background-position: 0% 30%; } to { background-position: 100% 70%; } }
.holo::after {
  content: ''; position: absolute; inset: 0; z-index: 2; pointer-events: none; mix-blend-mode: overlay;
  background: radial-gradient(circle at var(--mx) var(--my), rgba(255, 255, 255, .55), transparent 45%); opacity: 0; transition: opacity .2s;
}
.holo:hover::after { opacity: 1; }
.holo-super .holo-layer {
  inset: 18.1% 11.9% 29.6% 11.9%; opacity: .8;
  background-image:
    linear-gradient(115deg, rgba(255, 70, 170, .18), rgba(80, 230, 255, .18), rgba(255, 240, 90, .18)),
    linear-gradient(115deg, transparent 10%, rgba(255, 70, 170, .6) 28%, rgba(80, 230, 255, .6) 42%, rgba(255, 240, 90, .6) 56%, rgba(120, 255, 140, .5) 70%, transparent 88%);
}
.holo-ultra { box-shadow: 0 0 0 1px rgba(243, 215, 122, .5), 0 0 22px rgba(243, 215, 122, .35), 0 6px 18px rgba(0, 0, 0, .55); }
.holo-ultra .holo-layer {
  inset: 0; opacity: .5;
  background-image:
    linear-gradient(180deg, rgba(255, 215, 90, .9) 0 4%, transparent 4% 12.5%, transparent 12.5%),
    linear-gradient(115deg, transparent 15%, rgba(255, 70, 170, .6) 30%, rgba(80, 230, 255, .6) 42%, rgba(255, 240, 90, .6) 54%, rgba(120, 255, 140, .5) 66%, transparent 82%);
}
.holo-secret { box-shadow: 0 0 0 1px rgba(255, 255, 255, .5), 0 0 26px rgba(180, 140, 255, .45), 0 6px 18px rgba(0, 0, 0, .55); }
.holo-secret .holo-layer {
  inset: 0; opacity: .6;
  background-image:
    repeating-linear-gradient(45deg, rgba(255, 0, 120, .35) 0 2px, rgba(0, 220, 255, .35) 2px 4px, rgba(255, 255, 0, .35) 4px 6px, rgba(0, 255, 120, .3) 6px 8px),
    linear-gradient(120deg, transparent 20%, rgba(255, 255, 255, .7) 45%, transparent 70%);
}
@media (prefers-reduced-motion: reduce) {
  .holo-layer, .flip, .badge-new { animation: none !important; }
  .flip-inner { transition: none !important; }
}

/* Card back */
.card-back {
  position: relative; width: 100%; height: 100%; border-radius: 4.5% / 3.1%;
  background:
    radial-gradient(ellipse 60% 70% at 50% 50%, transparent 58%, rgba(0, 0, 0, .55) 60%, transparent 63%),
    repeating-radial-gradient(circle at 50% 50%, #5a3415 0 6px, #3e220c 6px 12px),
    #3e220c;
  border: 5px solid #2a160a; box-shadow: inset 0 0 0 2px #7b4d1d, inset 0 0 30px rgba(0, 0, 0, .7), 0 6px 16px rgba(0, 0, 0, .6);
  display: grid; place-items: center;
}
.cb-oval {
  width: 62%; height: 74%; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(from 0deg, #2b1405, #9b5a1a, #2b1405, #c27a26, #2b1405, #9b5a1a, #2b1405);
  box-shadow: 0 0 0 3px #1a0c04, 0 0 18px rgba(255, 170, 60, .35), inset 0 0 24px rgba(0, 0, 0, .8);
}
.cb-eye {
  width: 70%; aspect-ratio: 2 / 1.3;
  background: center / contain no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 64'%3E%3Cpath d='M5 26C25 4 75 4 95 26 75 46 25 46 5 26Z' fill='%23140a03' stroke='%23f3d77a' stroke-width='4'/%3E%3Ccircle cx='50' cy='26' r='11' fill='%23f3d77a'/%3E%3Cpath d='M44 38c-2 10-8 16-16 20M52 38l8 22' stroke='%23f3d77a' stroke-width='4' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  filter: drop-shadow(0 0 6px rgba(243, 215, 122, .7));
}

/* ---------- Packs ---------- */
.pack-status { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; padding: 14px 18px; margin-bottom: 20px; border-radius: var(--radius); background: linear-gradient(90deg, rgba(212, 175, 55, .14), rgba(212, 175, 55, .02)); border: 1px solid var(--gold-3); }
.pack-count { font-family: var(--font-title); font-size: 1.2rem; color: var(--sand); }
.pack-count strong { font-size: 2.2rem; color: var(--gold-2); margin-right: 2px; }
.booster-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.booster {
  display: flex; flex-direction: column; gap: 8px; padding: 10px; border-radius: var(--radius); cursor: pointer; text-align: left; color: var(--text);
  background: linear-gradient(180deg, var(--stone-2), var(--stone)); border: 1px solid var(--line); font: inherit; transition: transform .15s, border-color .15s, box-shadow .15s;
}
.booster:hover { transform: translateY(-4px) rotate(-.6deg); border-color: var(--gold); box-shadow: 0 12px 26px rgba(0, 0, 0, .55), 0 0 18px rgba(212, 175, 55, .2); }
.booster-art { width: 100%; height: 170px; object-fit: contain; filter: drop-shadow(0 6px 10px rgba(0, 0, 0, .6)); }
.booster-fallback {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center; padding: 10px;
  border-radius: 6px; background: linear-gradient(160deg, #5b4413, #2a1d08 55%, #6d5218); border: 2px solid var(--gold-3); color: var(--gold-2);
}
.booster-fallback span { font: 900 2rem var(--font-deco); }
.booster-fallback small { font-family: var(--font-title); font-size: .75rem; color: var(--sand); }
.booster-meta { display: grid; gap: 2px; }
.booster-name { font-family: var(--font-title); font-weight: 700; font-size: .9rem; line-height: 1.25; }
.history { margin-top: 10px; }
.history-row { display: grid; grid-template-columns: auto minmax(140px, 220px) 1fr; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.history-cards { display: grid; grid-template-columns: repeat(9, minmax(0, 52px)); gap: 5px; }
.history-cards .badge-new { font-size: .5rem; padding: 1px 4px; }
@media (max-width: 760px) {
  .history-row { grid-template-columns: auto 1fr; }
  .history-cards { grid-column: 1 / -1; grid-template-columns: repeat(9, minmax(0, 1fr)); }
  .booster-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
  .booster-art { height: 140px; }
}

/* Opening ceremony */
.opening {
  position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: 18px 12px max(18px, env(safe-area-inset-bottom)); overflow-y: auto;
  background: radial-gradient(circle at 50% 35%, #2e220b, #060503 70%);
  animation: fade-in .25s ease both;
}
@keyframes fade-in { from { opacity: 0; } }
.opening-title { font-family: var(--font-title); font-size: 1.1rem; color: var(--sand); }
.opening-stage { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; width: 100%; }
.opening-hint { color: var(--muted); font-style: italic; animation: blink 1.6s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .4; } }
.sealed-pack { position: relative; border: 0; background: none; cursor: pointer; padding: 0; animation: float 2.6s ease-in-out infinite; }
.sealed-art { width: min(260px, 60vw); height: auto; max-height: 52vh; object-fit: contain; filter: drop-shadow(0 18px 30px rgba(0, 0, 0, .8)) drop-shadow(0 0 30px rgba(243, 215, 122, .25)); }
.sealed-pack .booster-fallback { width: min(240px, 60vw); aspect-ratio: 5 / 8; }
.sealed-pack:hover { animation: wiggle .5s ease-in-out infinite; }
.tear-line { position: absolute; left: 6%; right: 6%; top: 14%; height: 2px; background: linear-gradient(90deg, transparent, #fff, transparent); opacity: 0; }
.sealed-pack.torn { animation: tear .45s ease-in forwards; }
.sealed-pack.torn .tear-line { animation: flash-line .3s ease-out forwards; }
@keyframes float { 50% { transform: translateY(-10px); } }
@keyframes wiggle { 25% { transform: rotate(-3deg); } 75% { transform: rotate(3deg); } }
@keyframes tear { 30% { transform: scale(1.08) rotate(-2deg); } 100% { transform: scale(1.3) translateY(-30px); opacity: 0; filter: brightness(3); } }
@keyframes flash-line { to { opacity: 1; box-shadow: 0 0 20px 6px #fff; } }

.pack-cards { --cw: min(160px, 17vw); display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; max-width: 1000px; }
.flip { width: var(--cw); aspect-ratio: var(--card-ratio); perspective: 1100px; cursor: pointer; animation: deal .55s cubic-bezier(.2, .8, .2, 1) both; animation-delay: calc(var(--i) * 75ms); }
@keyframes deal { from { opacity: 0; transform: translateY(-45vh) rotate(-10deg) scale(.5); } }
.flip-inner { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform .65s cubic-bezier(.3, 1.35, .5, 1); }
.flip:hover:not(.flipped) .flip-inner { transform: translateY(-6px) rotateZ(-1.5deg); }
.flip.flipped .flip-inner { transform: rotateY(180deg); }
.flip-back, .flip-front { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.flip-front { transform: rotateY(180deg); }
.flip-front .card { width: 100%; height: 100%; }
.rare-slot:not(.flipped) .card-back { box-shadow: inset 0 0 0 2px #7b4d1d, inset 0 0 30px rgba(0, 0, 0, .7), 0 0 22px rgba(243, 215, 122, .5); animation: rare-pulse 1.4s ease-in-out infinite; }
@keyframes rare-pulse { 50% { box-shadow: inset 0 0 0 2px #7b4d1d, inset 0 0 30px rgba(0, 0, 0, .7), 0 0 34px rgba(243, 215, 122, .85); } }
.flip.flash .flip-front::before {
  content: ''; position: absolute; inset: -30%; z-index: 5; pointer-events: none; border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 245, 200, .95), rgba(243, 215, 122, .4) 40%, transparent 70%);
  animation: burst .9s .25s ease-out both;
}
.flip.flash-ScR .flip-front::before { background: radial-gradient(circle, #fff, rgba(190, 150, 255, .6) 40%, transparent 70%); }
@keyframes burst { from { transform: scale(.2); opacity: 1; } to { transform: scale(1.6); opacity: 0; } }
.rarity-tag { position: absolute; left: 50%; bottom: -24px; transform: translateX(-50%); white-space: nowrap; font: 700 .72rem var(--font-title); color: var(--muted); }
.rarity-tag.r-SR, .rarity-tag.r-UR, .rarity-tag.r-UtR, .rarity-tag.r-ScR, .rarity.r-SR, .rarity.r-UR, .rarity.r-UtR, .rarity.r-ScR { color: var(--gold-2); text-shadow: 0 0 8px rgba(243, 215, 122, .5); }
.rarity-tag.r-ScR, .rarity.r-ScR { color: #d8c4ff; text-shadow: 0 0 8px rgba(200, 160, 255, .7); }
.pack-cards .flip { margin-bottom: 22px; }
.opening-footer { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 10px; min-height: 44px; }
.opening-summary { width: 100%; text-align: center; font-family: var(--font-title); font-size: 1.05rem; }
@media (max-width: 760px) {
  .pack-cards { --cw: calc((100vw - 64px) / 3); gap: 10px; }
}

/* ---------- Starter ---------- */
.starter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.starter {
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 16px; text-align: center; cursor: pointer; color: var(--text); font: inherit;
  background: linear-gradient(180deg, var(--stone-2), var(--stone)); border: 1px solid var(--line); border-radius: 14px; transition: transform .15s, border-color .15s;
}
.starter:hover { transform: translateY(-4px); border-color: var(--gold); box-shadow: 0 0 26px rgba(212, 175, 55, .2); }
.starter h3 { color: var(--gold-2); margin: 4px 0 0; }
.starter p { margin: 0; font-size: .9rem; }
.starter-img { height: 150px; width: auto; max-width: 100%; object-fit: contain; }
.starter-img.booster-fallback { width: 110px; }
.starter-cards { display: grid; grid-template-columns: repeat(3, 64px); gap: 6px; }
.starter-count { font-family: var(--font-title); color: var(--gold); font-weight: 700; }

/* ---------- Collection ---------- */
.progress-box { padding: 14px 16px; border-radius: var(--radius); background: var(--stone); border: 1px solid var(--line); }
.progress-label { margin-bottom: 8px; }
.progress-label strong { color: var(--gold-2); font-size: 1.15rem; }
.progress { height: 12px; border-radius: 999px; background: #0c0906; border: 1px solid var(--line); overflow: hidden; margin-bottom: 6px; }
.progress-bar { height: 100%; background: linear-gradient(90deg, var(--gold-3), var(--gold), var(--gold-2)); box-shadow: 0 0 12px rgba(243, 215, 122, .5); transition: width .6s; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 12px; }
.card-grid-sm { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
@media (max-width: 520px) { .card-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; } .card-grid-sm { grid-template-columns: repeat(4, 1fr); gap: 6px; } }
.sentinel { height: 1px; }

/* ---------- Modal / card sheet ---------- */
.modal { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: 16px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(4, 3, 2, .8); backdrop-filter: blur(3px); animation: fade-in .2s both; }
.modal-box {
  position: relative; width: min(940px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; padding: 22px;
  background: linear-gradient(180deg, var(--stone-2), var(--stone)); border: 1px solid var(--gold-3); border-radius: 14px; box-shadow: 0 30px 80px rgba(0, 0, 0, .7);
  animation: rise .25s ease both;
}
@keyframes rise { from { opacity: 0; transform: translateY(20px) scale(.98); } }
.modal-close { position: absolute; top: 8px; right: 10px; z-index: 3; width: 36px; height: 36px; border: 0; border-radius: 50%; background: var(--stone-3); color: var(--text); font-size: 1.4rem; cursor: pointer; }
.modal-close:hover { color: var(--gold-2); }
.card-modal { display: grid; grid-template-columns: minmax(0, 320px) 1fr; gap: 24px; }
.cm-art .card { width: 100%; cursor: default; }
.cm-name { color: var(--gold-2); font-size: 1.5rem; padding-right: 30px; }
.cm-type { color: var(--sand); margin-bottom: 10px; font-family: var(--font-title); }
.cm-stats { margin-bottom: 10px; }
.cm-desc { white-space: pre-line; background: rgba(0, 0, 0, .25); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font-family: Georgia, serif; }
.cm-section { margin-top: 14px; }
.cm-section h4 { color: var(--gold); font-size: .9rem; text-transform: uppercase; letter-spacing: .08em; margin-bottom: 6px; }
.cm-prints { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; font-size: .9rem; }
.cm-prints li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.cm-prints .rarity { color: var(--muted); font-size: .85em; }
.cm-prints .rarity::before { content: "· "; }
.cm-alts { display: flex; gap: 6px; flex-wrap: wrap; }
.cm-alt { width: 50px; padding: 0; border: 1px solid var(--line); border-radius: 4px; background: none; cursor: pointer; overflow: hidden; }
.cm-alt:hover { border-color: var(--gold); }
.cm-alt img { display: block; }
.cm-owned-count { font-family: var(--font-title); font-size: 1.1rem; color: var(--gold-2); }
.cm-passcode { margin-top: 12px; font-size: .8rem; }
.gift-form { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 10px; padding: 10px; border-radius: 8px; border: 1px dashed var(--gold-3); }
@media (max-width: 680px) {
  .modal { padding: 0; place-items: end center; }
  .modal-box { max-height: 94vh; border-radius: 14px 14px 0 0; padding: 18px 14px; }
  .card-modal { grid-template-columns: 1fr; }
  .cm-art { width: min(260px, 70vw); margin: 0 auto; }
}

/* <dialog> confirm / prompt */
.dialog { width: min(440px, calc(100vw - 32px)); padding: 22px; color: var(--text); background: linear-gradient(180deg, var(--stone-2), var(--stone)); border: 1px solid var(--gold-3); border-radius: 14px; box-shadow: 0 30px 80px rgba(0, 0, 0, .7); }
.dialog::backdrop { background: rgba(4, 3, 2, .75); }
.dialog h3 { color: var(--gold-2); }
.dialog p { color: var(--sand); white-space: pre-line; word-break: break-word; }
.dialog .input { width: 100%; margin-bottom: 8px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }

/* Toasts */
.toasts { position: fixed; z-index: 300; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%); display: grid; gap: 8px; width: min(440px, calc(100vw - 32px)); pointer-events: none; }
.toast { padding: 11px 16px; border-radius: 10px; background: #1e1811; border: 1px solid var(--gold-3); box-shadow: var(--shadow); animation: rise .25s both; transition: opacity .4s, transform .4s; }
.toast-ok { border-color: rgba(124, 178, 127, .6); }
.toast-error { border-color: rgba(209, 96, 76, .7); }
.toast.out { opacity: 0; transform: translateY(10px); }

/* ---------- Decks ---------- */
.deck-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.deck-tile { padding: 14px 16px; border-radius: var(--radius); background: linear-gradient(180deg, var(--stone-2), var(--stone)); border: 1px solid var(--line); display: grid; gap: 8px; }
.deck-tile-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.deck-name { font: 700 1.1rem var(--font-title); color: var(--gold-2); }
.deck-counts { display: flex; gap: 12px; flex-wrap: wrap; font-size: .9rem; }
.deck-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 430px); gap: 18px; align-items: start; }
.editor-tabs { display: none; margin-bottom: 12px; }
.editor-pool .filters { margin-top: 0; }
.editor-deck { position: sticky; top: 76px; max-height: calc(100vh - 90px); overflow-y: auto; padding: 14px; border-radius: var(--radius); background: linear-gradient(180deg, var(--stone-2), var(--stone)); border: 1px solid var(--line); }
.deck-title-input { width: 100%; font: 700 1.15rem var(--font-title); color: var(--gold-2); }
.editor-actions { display: flex; align-items: center; gap: 8px; margin: 10px 0; flex-wrap: wrap; }
.save-state { margin-right: auto; font-size: .85rem; }
.counters { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.counter { padding: 6px 8px; border-radius: 8px; background: #120e0a; border: 1px solid var(--line); text-align: center; }
.counter strong { display: block; font: 900 1.3rem var(--font-title); color: var(--gold-2); }
.counter span { font-size: .7rem; color: var(--muted); }
.counter.bad { border-color: rgba(209, 96, 76, .6); }
.counter.bad strong { color: var(--danger); }
.deck-errors { margin: 10px 0; font-size: .85rem; }
.deck-errors ul { margin: 0; padding: 8px 10px 8px 26px; border-radius: 8px; background: rgba(209, 96, 76, .08); border: 1px solid rgba(209, 96, 76, .35); color: #f0b3a6; }
.deck-ok { padding: 8px 10px; border-radius: 8px; background: rgba(124, 178, 127, .1); border: 1px solid rgba(124, 178, 127, .4); color: var(--ok); }
.zone { margin-top: 14px; }
.zone h3 { font-size: 1rem; color: var(--gold); border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.zone h4 { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin: 8px 0 4px; font-family: var(--font); }
.deck-row { display: flex; align-items: center; gap: 4px; padding: 2px 2px 2px 0; border-left: 4px solid var(--frame, var(--line)); border-radius: 4px; margin-bottom: 3px; background: rgba(0, 0, 0, .2); }
.deck-row.f-normal { --frame: #d8b76a; } .deck-row.f-effect { --frame: #d0773a; } .deck-row.f-ritual { --frame: #6d8fd1; }
.deck-row.f-fusion { --frame: #9a6ac2; } .deck-row.f-spell { --frame: #2ba08d; } .deck-row.f-trap { --frame: #c04a8d; }
.deck-row-name { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; background: none; border: 0; color: var(--text); font: inherit; font-size: .88rem; text-align: left; cursor: pointer; padding: 2px 4px; }
.deck-row-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deck-row-name:hover span { color: var(--gold-2); }
.deck-row-name img { width: 26px; border-radius: 2px; flex: none; }
.deck-row-name .dot { width: 26px; height: 38px; border-radius: 2px; background: var(--frame); flex: none; }
.deck-row-qty { font-weight: 800; color: var(--gold-2); min-width: 26px; text-align: right; margin-right: 4px; }
.pool-card { position: relative; }
.pool-card .avail { position: absolute; right: 3px; bottom: 3px; padding: 0 6px; border-radius: 999px; background: rgba(10, 8, 5, .88); border: 1px solid var(--gold-3); color: var(--gold-2); font-size: .7rem; font-weight: 800; pointer-events: none; }
.pool-card.exhausted .card { filter: grayscale(.8) brightness(.5); }
.info-btn { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--gold-3); background: rgba(10, 8, 5, .85); color: var(--gold-2); font: italic 700 .8rem Georgia, serif; cursor: pointer; opacity: .85; }
.side-toggle { display: none; }
@media (max-width: 900px) {
  .editor { grid-template-columns: minmax(0, 1fr); }
  .editor-tabs { display: flex; position: sticky; top: 92px; z-index: 10; }
  .editor[data-tab='cards'] .editor-deck, .editor[data-tab='deck'] .editor-pool { display: none; }
  .editor-deck { position: static; max-height: none; }
  .side-toggle { display: inline-flex; }
  .hint-desktop { display: none; }
}

/* ---------- Duel ---------- */
.steps { list-style: none; padding: 0; margin: 0; display: grid; gap: 14px; }
.step { display: grid; grid-template-columns: 48px 1fr; gap: 14px; padding: 16px; border-radius: var(--radius); background: linear-gradient(180deg, var(--stone-2), var(--stone)); border: 1px solid var(--line); }
.step-num { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; font: 900 1.3rem var(--font-title); color: #1d1405; background: linear-gradient(180deg, var(--gold-2), var(--gold-3)); box-shadow: 0 0 16px rgba(212, 175, 55, .35); }
.step h3 { color: var(--gold-2); }
.step p { margin: 0 0 10px; }
.duel-decks { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--line); }
.table { width: 100%; border-collapse: collapse; background: var(--stone); }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font: 700 .78rem var(--font-title); text-transform: uppercase; letter-spacing: .06em; color: var(--gold); background: #15110c; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table tr.me td { background: rgba(212, 175, 55, .07); }
.table tbody tr:last-child td { border-bottom: 0; }
.table-compact th, .table-compact td { padding: 6px 8px; font-size: .88rem; }
@media (max-width: 640px) { .hide-sm { display: none; } .table th, .table td { padding: 8px; } }
.gift-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.gift-list li { padding: 8px 12px; border-radius: 8px; background: var(--stone); border: 1px solid var(--line); }

/* ---------- Admin ---------- */
.admin-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 16px; }
.admin-grid .table-wrap { margin-top: 12px; max-height: 340px; overflow-y: auto; }
.code-list { display: flex; flex-wrap: wrap; gap: 6px; }
.code { font: 700 .9rem ui-monospace, Consolas, monospace; padding: 6px 10px; border-radius: 6px; border: 1px dashed var(--gold); background: #120e0a; color: var(--gold-2); cursor: pointer; }
.new-codes { margin-top: 10px; }
@media (max-width: 860px) { .admin-grid { grid-template-columns: 1fr; } }
