/* Card Studio — charcoal + gold. Fraunces display / Inter body / JetBrains data
   (system fallbacks; no CDN). */
/* Bundled pixel font (SIL OFL — license in fonts/) */
@font-face {
  font-family: "Press Start 2P";
  src: url("../fonts/press-start-2p.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}

:root {
  --bg: #141414; --panel: #1c1c1c; --panel2: #232323; --line: #2e2e2e;
  --ink: #efece4; --ink-dim: #9a958a;
  --gold: #d9a72a; --gold-hi: #ecc459; --gold-lo: #a87d1c;
  --danger: #d05545;
  --disp: "Fraunces", Georgia, "Times New Roman", serif;
  --body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --foil: linear-gradient(120deg, var(--gold-lo), var(--gold-hi) 38%, #f7e9b8 50%, var(--gold-hi) 62%, var(--gold-lo));
  --tabbar-h: calc(58px + env(safe-area-inset-bottom));
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--body);
  font-size: 16px; overscroll-behavior: none; touch-action: pan-y;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, select, textarea { font: inherit; font-size: 16px; color: var(--ink); }
h1 { font-family: var(--disp); font-weight: 600; font-size: 26px; margin: 0 0 10px; letter-spacing: .01em; }
[hidden] { display: none !important; }
.btn, .chip, .tab, .tb-btn, .opt-row, .swatch, .rarity-chip, .card-tile, .asset-tile, .collection-row, .layer-row {
  transition: transform .12s ease, background-color .15s ease, color .15s ease, border-color .15s ease, opacity .15s ease;
}
.btn:active, .tb-btn:not(:disabled):active, .chip:active, .opt-row:active,
.card-tile:active, .asset-tile:active, .collection-row:active { transform: scale(.97); }
.tb-btn:disabled { opacity: .35; }
.card-stage, .motion-mode, .tool-stage { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }

/* ---------- chrome ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center;
  justify-content: space-between; padding: calc(8px + env(safe-area-inset-top)) 14px 8px;
  background: rgba(20,20,20,.92); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { font-family: var(--disp); font-size: 18px; display: flex; align-items: center; gap: 9px; }
.brand-mark {
  width: 15px; height: 21px; border-radius: 3px;
  background: var(--foil); background-size: 300% 100%;
  animation: foilslide 5s ease-in-out infinite;
}
@keyframes foilslide { 0%,100% { background-position: 0% 0; } 50% { background-position: 100% 0; } }
.topbar-actions { display: flex; gap: 8px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex;
  background: rgba(20,20,20,.94); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; min-height: 54px; color: var(--ink-dim);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  padding-top: 6px;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab-label { font-size: 10px; letter-spacing: .06em; text-transform: uppercase; font-weight: 600; }
.tab.active { color: var(--gold-hi); }

.view { padding: 16px 14px calc(var(--tabbar-h) + 16px); max-width: 1100px; margin: 0 auto; }
.view-head { margin-bottom: 14px; }
.empty { text-align: center; color: var(--ink-dim); padding: 56px 20px; }
.empty p { margin: 4px 0; } .empty .sub { font-size: 14px; }
.empty .btn { margin-top: 18px; }

/* ---------- buttons / chips / controls ---------- */
.btn {
  min-height: 44px; padding: 0 18px; border-radius: 10px; font-weight: 600;
  background: var(--panel2); border: 1px solid var(--line); display: inline-flex;
  align-items: center; justify-content: center; gap: 8px;
}
.btn.gold { background: var(--foil); background-size: 200% 100%; color: #1a1305; border-color: var(--gold-lo); }
.btn.gold:active { background-position: 100% 0; }
.btn.ghost { background: none; }
.btn.danger { color: var(--danger); border-color: #4a2a26; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 8px; }
.btn:focus-visible, .chip:focus-visible, .tab:focus-visible { outline: 2px solid var(--gold-hi); outline-offset: 2px; }

.chip {
  min-height: 36px; padding: 0 14px; border-radius: 999px; font-size: 14px;
  background: var(--panel); border: 1px solid var(--line); color: var(--ink-dim);
}
.chip.active { color: #1a1305; background: var(--gold); border-color: var(--gold-lo); font-weight: 600; }
.filter-row { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.filter-row::-webkit-scrollbar { display: none; }

.ctl { display: block; font-size: 13px; color: var(--ink-dim); margin: 12px 0; }
.ctl input[type=range] { width: 100%; margin-top: 6px; accent-color: var(--gold); }
.ctl.row { display: flex; align-items: center; gap: 10px; }
.ctl.row input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--gold); }
.field { margin: 12px 0; }
.field label { display: block; font-size: 13px; color: var(--ink-dim); margin-bottom: 6px; }
.field input[type=text], .field select, .field textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 10px;
  background: var(--panel2); border: 1px solid var(--line);
}
.field textarea { min-height: 72px; resize: vertical; }
.field input[type=color] { width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel2); padding: 4px; }
.field-row { display: flex; gap: 10px; align-items: end; }
.field-row .field { flex: 1; }
.seg { display: flex; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; min-height: 40px; font-size: 14px; color: var(--ink-dim); }
.seg button.active { background: var(--gold); color: #1a1305; font-weight: 600; }

/* ---------- card grid ---------- */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px; }
.card-tile { text-align: left; }
.card-tile .thumb {
  aspect-ratio: 5/7; width: 100%; border-radius: 10px; background: var(--panel);
  border: 1px solid var(--line); overflow: hidden; display: block;
}
.card-tile .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-tile .name { font-size: 14px; margin-top: 7px; }
.card-tile .meta { font-family: var(--mono); font-size: 11px; color: var(--ink-dim); margin-top: 2px; }

/* ---------- asset grid ---------- */
.asset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 12px; }
.asset-tile { text-align: center; }
.asset-tile .thumb {
  aspect-ratio: 1; width: 100%; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel) repeating-conic-gradient(#1f1f1f 0 25%, #262626 0 50%) 0 0/16px 16px;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.asset-tile .thumb img { max-width: 86%; max-height: 86%; object-fit: contain; }
.asset-tile .name { font-size: 12px; margin-top: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- collections ---------- */
.collection-list { display: flex; flex-direction: column; gap: 10px; }
.collection-row {
  display: flex; align-items: center; gap: 12px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px; padding: 14px; text-align: left; width: 100%;
}
.collection-row .col-name { font-family: var(--disp); font-size: 17px; }
.collection-row .col-count { font-family: var(--mono); font-size: 12px; color: var(--ink-dim); margin-left: auto; }

/* ---------- editor ---------- */
#view-editor { padding: 10px 0 0; max-width: none; height: calc(100dvh - var(--topbar-h, 57px)); display: flex; flex-direction: column; overflow: hidden; }
.editor-wrap { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.stage-outer { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 8px; overflow: hidden; touch-action: none; }
.card-stage { position: relative; width: 750px; height: 1050px; transform-origin: center; flex: none; }
.snap-line { position: absolute; background: var(--gold-hi); opacity: .9; z-index: 900; pointer-events: none; box-shadow: 0 0 8px rgba(236,196,89,.8); }
.snap-line.v { left: 50%; top: -40px; bottom: -40px; width: 3px; margin-left: -1.5px; }
.snap-line.h { top: 50%; left: -40px; right: -40px; height: 3px; margin-top: -1.5px; }

/* inline text editing */
.layer-text.editing {
  outline: 2px solid var(--gold-hi); outline-offset: 4px; cursor: text;
  caret-color: var(--gold-hi); user-select: text; -webkit-user-select: text;
  min-height: 1em;
}
.layer-text.editing:focus { outline-style: solid; }
.inline-bar {
  position: fixed; top: calc(var(--topbar-h, 57px) + 10px); left: 50%; transform: translateX(-50%);
  z-index: 28; display: flex; gap: 8px; padding: 6px; border-radius: 999px;
  background: rgba(28,28,28,.92); border: 1px solid var(--line); backdrop-filter: blur(10px);
  box-shadow: 0 8px 30px rgba(0,0,0,.5);
}
.inline-bar .btn.small { border-radius: 999px; }
.card-surface {
  position: absolute; inset: 0; border-radius: 34px; overflow: hidden;
  background: #0d0d0d; box-shadow: 0 18px 60px rgba(0,0,0,.6);
}
.layer { position: absolute; transform-origin: center; }
.layer:not(.layer-text) { overflow: hidden; }
.layer img { width: 100%; height: 100%; display: block; pointer-events: none; -webkit-user-drag: none; border-radius: inherit; }
.layer.contain img { object-fit: contain; } .layer.cover img { object-fit: cover; }
.layer-text { display: flex; pointer-events: none; white-space: pre-wrap; word-break: break-word; }

.sel-box { position: absolute; border: 2px dashed var(--gold-hi); pointer-events: none; z-index: 999; }
.sel-handle, .sel-rotate {
  position: absolute; width: 34px; height: 34px; border-radius: 50%;
  background: var(--gold); border: 3px solid #141414; pointer-events: auto; touch-action: none;
}
.sel-handle[data-h=nw] { top: -17px; left: -17px; } .sel-handle[data-h=ne] { top: -17px; right: -17px; }
.sel-handle[data-h=sw] { bottom: -17px; left: -17px; } .sel-handle[data-h=se] { bottom: -17px; right: -17px; }
.sel-rotate { top: -58px; left: 50%; margin-left: -17px; background: var(--panel2); border-color: var(--gold); }

.editor-toolbar {
  display: flex; gap: 8px; padding: 10px 12px calc(10px + var(--tabbar-h));
  overflow-x: auto; scrollbar-width: none; border-top: 1px solid var(--line); background: var(--bg);
}
.editor-toolbar::-webkit-scrollbar { display: none; }
.tb-btn {
  flex: none; min-height: 44px; padding: 0 16px; border-radius: 10px; font-weight: 600;
  font-size: 14px; background: var(--panel2); border: 1px solid var(--line);
}
.tb-btn.gold { background: var(--foil); background-size: 200% 100%; color: #1a1305; border-color: var(--gold-lo); }

/* ---------- inspector (selected layer panel) ---------- */
.inspector {
  position: fixed; left: 0; right: 0; bottom: var(--tabbar-h); z-index: 25;
  background: var(--panel); border-top: 1px solid var(--line);
  border-radius: 16px 16px 0 0; max-height: 46dvh;
  display: flex; flex-direction: column;
  padding: 12px 0 0; box-shadow: 0 -10px 40px rgba(0,0,0,.45);
}
.insp-head { padding: 0 16px; flex: none; }
.insp-scroll { overflow-y: auto; flex: 1; min-height: 0; padding: 0 16px 10px; }
.insp-foot {
  flex: none; display: flex; gap: 10px; padding: 10px 16px 12px;
  border-top: 1px solid var(--line); background: var(--panel);
}
.insp-foot .btn { flex: 1; }
@media (min-width: 760px) {
  .inspector { left: auto; width: 380px; top: 57px; bottom: 0; max-height: none; border-radius: 0; border-left: 1px solid var(--line); }
}

.insp-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.insp-title { font-family: var(--disp); font-size: 16px; }
.rot-row { display: flex; gap: 8px; flex-wrap: wrap; }
.inspector .sheet-actions { flex-wrap: wrap; }
.inspector .sheet-actions .btn { flex: 1 1 auto; }

/* draft recovery banner */
.resume-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%;
  margin: 0 0 14px; padding: 14px; border-radius: 12px; text-align: left;
  background: linear-gradient(120deg, rgba(217,167,42,.14), rgba(217,167,42,.05));
  border: 1px solid var(--gold-lo);
}
.resume-label { font-weight: 600; color: var(--gold-hi); }
.resume-name { font-family: var(--mono); font-size: 12px; color: var(--ink-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- energy icons ---------- */
.energy-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 14px; padding: 6px 0; }
.energy-tile { text-align: center; }
.energy-tile .name { display: block; font-size: 12px; margin-top: 6px; color: var(--ink-dim); }
.energy-circle {
  display: flex; align-items: center; justify-content: center;
  width: 64px; height: 64px; border-radius: 50%; margin: 0 auto;
  box-shadow: 0 5px 12px rgba(0,0,0,.4);
}
.energy-circle svg { width: 58%; height: 58%; }
.energy-swatch-row { display: flex; gap: 10px; flex-wrap: wrap; margin: 8px 0; }
.energy-swatch {
  display: flex; align-items: center; justify-content: center;
  width: 46px; height: 46px; border-radius: 50%; border: 2px solid transparent;
}
.energy-swatch.active { border-color: var(--gold-hi); box-shadow: 0 0 0 2px rgba(236,196,89,.35); }
.energy-swatch svg { width: 58%; height: 58%; }

/* ---------- sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 40; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; background: var(--panel);
  border-top: 1px solid var(--line); border-radius: 18px 18px 0 0;
  max-height: 82dvh; display: flex; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom); animation: sheetup .22s ease;
}
@keyframes sheetup { from { transform: translateY(40px); opacity: 0; } }
.sheet-grab { width: 42px; height: 5px; border-radius: 3px; background: var(--line); margin: 10px auto 4px; flex: none; }
.sheet-body { overflow-y: auto; padding: 8px 16px 0; }
.sheet-body > *:last-child { margin-bottom: 18px; }
.sheet-body > .sheet-actions:last-child {
  position: sticky; bottom: 0; margin-bottom: 0;
  background: linear-gradient(transparent, var(--panel) 32%);
  padding: 14px 0 16px; margin-top: 14px;
}
.sheet-title { font-family: var(--disp); font-size: 20px; margin: 6px 0 4px; }
.sheet-sub { color: var(--ink-dim); font-size: 13px; margin: 0 0 12px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 16px; }
.sheet-actions .btn { flex: 1; }
.opt-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.opt-row {
  display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 8px 12px;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; text-align: left; width: 100%;
}
.opt-row .opt-label { flex: 1; } .opt-row .opt-note { font-size: 12px; color: var(--ink-dim); }

/* layers panel rows */
.layer-row { display: flex; align-items: center; gap: 8px; min-height: 52px; padding: 6px 10px;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; }
.layer-row.sel { border-color: var(--gold); }
.layer-row .lr-name { flex: 1; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
.layer-row .lr-kind { font-family: var(--mono); font-size: 10px; color: var(--ink-dim); text-transform: uppercase; }
.layer-row .btn.small { min-width: 44px; }

/* swatches */
.swatch-row { display: flex; gap: 10px; flex-wrap: wrap; margin: 8px 0; }
.swatch { width: 44px; height: 44px; border-radius: 10px; border: 2px solid var(--line); }
.swatch.active { border-color: var(--gold-hi); }

/* rarity chips */
.rarity-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.rarity-chip { min-height: 40px; padding: 0 14px; border-radius: 999px; font-size: 13px; font-weight: 600;
  border: 1px solid var(--line); background: var(--panel2); color: var(--ink-dim); }
.rarity-chip.active { color: #14100a; background: var(--foil); background-size: 200% 100%; border-color: var(--gold-lo); }

/* ---------- motion mode ---------- */
.motion-mode { position: fixed; inset: 0; z-index: 60; background: radial-gradient(120% 100% at 50% 0%, #1d1d1d, #0a0a0a 70%);
  display: flex; align-items: center; justify-content: center; }
.motion-scene { perspective: 1200px; }
.motion-card { position: relative; width: min(78vw, 46dvh * .7143); aspect-ratio: 5/7;
  transform-style: preserve-3d; will-change: transform; border-radius: 4.5% / 3.2%;
  box-shadow: 0 30px 80px rgba(0,0,0,.75); }
.motion-card-inner { position: absolute; inset: 0; border-radius: inherit; overflow: hidden; }
.motion-card-inner .card-stage { transform-origin: top left; }
.motion-specular { position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: radial-gradient(60% 45% at var(--sx,50%) var(--sy,35%), rgba(255,255,255,.34), rgba(255,255,255,0) 60%);
  mix-blend-mode: overlay; }
.motion-close { position: absolute; top: calc(14px + env(safe-area-inset-top)); right: 16px;
  min-height: 44px; padding: 0 18px; border-radius: 10px; background: rgba(35,35,35,.8);
  border: 1px solid var(--line); font-weight: 600; z-index: 2; }
.motion-manual { position: absolute; top: calc(14px + env(safe-area-inset-top)); left: 16px;
  min-height: 44px; padding: 0 18px; border-radius: 10px; background: rgba(35,35,35,.8);
  border: 1px solid var(--line); font-weight: 600; z-index: 2; color: var(--ink-dim); }
.motion-manual.active { color: #1a1305; background: var(--foil); background-size: 200% 100%; border-color: var(--gold-lo); }
.motion-scene { touch-action: none; cursor: grab; }
.motion-scene:active { cursor: grabbing; }
.motion-enable { position: absolute; bottom: calc(30px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); }

/* ---------- tool modals (crop / wand) ---------- */
.tool-modal { position: fixed; inset: 0; z-index: 55; background: var(--bg); display: flex; flex-direction: column; }
.tool-head { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px; border-bottom: 1px solid var(--line); }
.tool-title { font-family: var(--disp); font-size: 18px; }
.tool-hint { color: var(--ink-dim); font-size: 13px; margin: 10px 16px 0; }
.tool-stage { flex: 1; min-height: 0; position: relative; display: flex; align-items: center; justify-content: center;
  overflow: hidden; margin: 12px; border-radius: 12px; background: var(--panel); touch-action: none; }
.tool-stage.checker { background: var(--panel) repeating-conic-gradient(#1f1f1f 0 25%, #2a2a2a 0 50%) 0 0/18px 18px; }
.tool-stage canvas { max-width: 100%; max-height: 100%; display: block; }
.tool-controls { padding: 4px 16px calc(16px + env(safe-area-inset-bottom)); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.tool-controls .ctl { flex: 1 1 100%; margin: 4px 0; }
.crop-rect { position: absolute; border: 2px solid var(--gold-hi); box-shadow: 0 0 0 4000px rgba(0,0,0,.55); touch-action: none; }
.crop-h { position: absolute; width: 34px; height: 34px; border-radius: 50%; background: var(--gold); border: 3px solid #141414; touch-action: none; }
.crop-h[data-c=nw] { top: -17px; left: -17px; } .crop-h[data-c=ne] { top: -17px; right: -17px; }
.crop-h[data-c=sw] { bottom: -17px; left: -17px; } .crop-h[data-c=se] { bottom: -17px; right: -17px; }

/* ---------- foil pack ---------- */
.pack-body { position: absolute; inset: 0; border-radius: 26px; overflow: hidden;
  box-shadow: inset 0 0 60px rgba(0,0,0,.25); }
.pack-ridges { position: absolute; inset: 0; opacity: .5; pointer-events: none;
  background: repeating-linear-gradient(90deg, rgba(255,255,255,.13) 0 2px, rgba(0,0,0,.12) 2px 4px, transparent 4px 13px); }
.pack-gloss { position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(115deg, transparent 28%, rgba(255,255,255,.34) 44%, rgba(255,255,255,.06) 52%, transparent 66%); }
.pack-crimp { position: absolute; left: 0; right: 0; height: 56px; pointer-events: none;
  background: rgba(0,0,0,.22); }
.pack-crimp::after { content: ""; position: absolute; inset: 0;
  background: repeating-linear-gradient(90deg, rgba(255,255,255,.16) 0 4px, rgba(0,0,0,.28) 4px 8px); }
.pack-crimp.top { top: 0; border-bottom: 2px dashed rgba(0,0,0,.35); }
.pack-crimp.bottom { bottom: 0; border-top: 2px dashed rgba(0,0,0,.35); }
.pack-content { position: absolute; inset: 56px 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 18px; padding: 30px 44px; text-align: center; }
.pack-eyebrow { font-family: var(--mono); font-size: 20px; letter-spacing: .34em;
  text-transform: uppercase; color: rgba(0,0,0,.55); }
.pack-art { width: 78%; aspect-ratio: 1; display: flex; align-items: center; justify-content: center; }
.pack-art img { max-width: 100%; max-height: 100%; object-fit: contain;
  filter: drop-shadow(0 14px 24px rgba(0,0,0,.45)); }
.pack-burst { width: 300px; height: 300px; border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, rgba(255,255,255,.75), rgba(255,255,255,.12) 55%, transparent 72%); }
.pack-name { font-family: var(--disp); font-weight: 700; font-size: 66px; line-height: 1.05;
  color: rgba(20,16,5,.88); text-shadow: 0 2px 0 rgba(255,255,255,.25); word-break: break-word; }
.pack-count { font-family: var(--mono); font-size: 22px; color: rgba(0,0,0,.55); }
.pack-preview { display: flex; justify-content: center; margin: 8px 0 14px; }
.pack-preview .pack-scaler { transform-origin: top left; }

/* ---------- pack opening ceremony ---------- */
.pack-open { position: fixed; inset: 0; z-index: 62;
  background: radial-gradient(120% 100% at 50% 0%, #1d1d1d, #090909 72%);
  display: flex; align-items: center; justify-content: center; }
.po-scene { position: relative; width: 100%; height: 100%; display: flex;
  align-items: center; justify-content: center; touch-action: none; overflow: hidden; }
.po-hint { position: absolute; top: calc(20px + env(safe-area-inset-top)); left: 0; right: 0;
  text-align: center; color: var(--ink-dim); font-size: 14px; letter-spacing: .04em; z-index: 3; pointer-events: none; }
.po-foot { position: absolute; bottom: calc(26px + env(safe-area-inset-bottom)); left: 0; right: 0;
  display: flex; gap: 12px; justify-content: center; z-index: 3; }
.po-pack { position: relative; filter: drop-shadow(0 26px 60px rgba(0,0,0,.7)); }
.po-pack .po-scaler, .po-card .po-scaler { transform-origin: top left; position: absolute; left: 0; top: 0; }
.po-pack.wobble { animation: po-wobble 3.2s ease-in-out infinite; }
@keyframes po-wobble {
  0%, 100% { transform: rotate(-1.6deg) translateY(0); }
  50% { transform: rotate(1.6deg) translateY(-10px); }
}
.po-piece { position: absolute; inset: 0; }
.po-piece.strip { animation: po-strip .8s ease-in forwards; }
@keyframes po-strip {
  0% { transform: translate(0,0) rotate(0); opacity: 1; }
  100% { transform: translate(-46%, -160%) rotate(-24deg); opacity: 0; }
}
.po-piece.rest { animation: po-drop .8s ease-in .18s forwards; }
@keyframes po-drop {
  0% { transform: translateY(0) rotate(0); opacity: 1; }
  100% { transform: translateY(130%) rotate(7deg); opacity: 0; }
}
.po-card { position: absolute; filter: drop-shadow(0 22px 50px rgba(0,0,0,.65));
  transition: transform .34s ease, opacity .34s ease; }
.po-card.out { transform: translateX(-130%) rotate(-16deg) !important; opacity: 0; }
.po-card.final-pop { animation: po-pop .55s cubic-bezier(.2,1.4,.4,1) forwards; }
@keyframes po-pop { 0% { scale: 1; } 55% { scale: 1.09; } 100% { scale: 1.045; } }
.po-burst { position: absolute; width: 140vmin; height: 140vmin; border-radius: 50%;
  background: radial-gradient(circle, rgba(236,196,89,.4), rgba(236,196,89,.12) 38%, transparent 62%);
  animation: po-burst 1s ease-out forwards; pointer-events: none; }
@keyframes po-burst { 0% { transform: scale(.2); opacity: 0; } 35% { opacity: 1; } 100% { transform: scale(1); opacity: .8; } }
@media (prefers-reduced-motion: reduce) {
  .po-pack.wobble, .po-card.final-pop, .po-burst { animation: none; }
}

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 18px); transform: translateX(-50%);
  background: var(--panel2); border: 1px solid var(--gold-lo); color: var(--ink); padding: 10px 18px;
  border-radius: 999px; font-size: 14px; z-index: 70; box-shadow: 0 8px 30px rgba(0,0,0,.5); }

@media (prefers-reduced-motion: reduce) {
  .brand-mark, .btn.gold, .rarity-chip.active { animation: none !important; }
  .sheet { animation: none; }
}
@media (min-width: 760px) {
  .editor-wrap { flex-direction: row; }
  .editor-toolbar { flex-direction: column; border-top: 0; border-left: 1px solid var(--line); overflow: visible; }
}
