/* ---------- shared ---------- */
:root {
  --silver: linear-gradient(135deg, #ffffff 0%, #7b869a 14%, #f4f8ff 30%, #4f5a6e 48%, #ffffff 64%, #8793a8 82%, #eef3fb 100%);
  --gold: linear-gradient(135deg, #fff3a8, #d29a00 50%, #fff3a8);
  --holo: linear-gradient(115deg, #6fe3ff, #b79bff, #7dffd0, #ffb8f0, #6fe3ff);
  --void: conic-gradient(from var(--a, 0deg), #1a0838, #8a4dff, #19c3ff, #3a0a6e, #ff4de0, #1a0838);
  --glitch: linear-gradient(90deg, #19f0ff 0 33%, #ff2bd0 33% 66%, #19f0ff 66%);
  --prism: conic-gradient(from var(--a, 0deg), #ff5d5d, #ffd34d, #5ee6a0, #5ad1ff, #9b7bff, #ff7ad9, #ff5d5d);
}
@property --a { syntax: '<angle>'; initial-value: 0deg; inherits: false; }

.fx-canvas { position: fixed; inset: 0; z-index: 70; width: 100%; height: 100%; pointer-events: none; }
.screen-flash { position: fixed; inset: 0; z-index: 65; pointer-events: none; animation: flash-out .4s ease-out forwards; }
@keyframes flash-out { from { opacity: var(--flash, .4); } to { opacity: 0; } }
.app-shell.is-shaking { animation: shake .36s cubic-bezier(.36, .07, .19, .97); }
@keyframes shake {
  10%, 90% { transform: translate(calc(var(--shake) * -.2), 0); }
  20%, 80% { transform: translate(calc(var(--shake) * .4), calc(var(--shake) * .2)); }
  30%, 50%, 70% { transform: translate(calc(var(--shake) * -.8), calc(var(--shake) * -.3)); }
  40%, 60% { transform: translate(var(--shake), calc(var(--shake) * .3)); }
}
.float-text { position: fixed; z-index: 66; font-weight: 800; pointer-events: none; text-shadow: 0 1px 0 #fff; transform: translate(-50%, 0); animation: float-up 1s ease-out forwards; }
@keyframes float-up { 0% { opacity: 0; transform: translate(-50%, 10px) scale(.6); } 15% { opacity: 1; transform: translate(-50%, 0) scale(1.15); } 100% { opacity: 0; transform: translate(-50%, -46px) scale(1); } }

/* ---------- profiles ---------- */
.profile-bar { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.profile-bar select { min-width: 0; max-width: 60%; padding: 6px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: inherit; font: inherit; font-weight: 600; }

/* ---------- landing hub & settings ---------- */
.hub { display: grid; margin-top: 26px; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.hub-button { display: grid; padding: 14px 6px 12px; justify-items: center; gap: 2px; border: 1px solid var(--line); border-radius: 14px; background: #fff; cursor: pointer; transition: transform .14s ease, border-color .14s ease; }
.hub-button:hover { border-color: var(--green); transform: translateY(-2px); }
.hub-icon { font-size: 26px; }
.hub-name { font-size: 13px; font-weight: 600; }
.hub-detail { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.settings { margin-top: 26px; color: var(--muted); font-size: 12px; }
.settings summary { cursor: pointer; }
.settings-body { display: grid; padding-top: 12px; gap: 10px; }
.settings-row { display: flex; flex-wrap: wrap; gap: 8px; }
.settings-note { margin: 0; font-size: 12px; line-height: 1.4; }
.settings textarea { width: 100%; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; font: 11px ui-monospace, monospace; resize: vertical; }
.small-button { padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px; background: #fff; cursor: pointer; font-size: 12px; }
.small-button:hover { border-color: var(--green); }
.small-button.primary { color: #fff; border-color: var(--green); background: var(--green); font-weight: 600; }
.small-button.danger { color: #b6614d; }

/* ---------- HUD: combo + pack meter ---------- */
.hud { display: grid; width: min(100%, 340px); margin: 26px auto 0; justify-items: center; gap: 8px; }
.combo { display: flex; align-items: baseline; gap: 6px; color: var(--muted); }
.combo-count { color: var(--ink); font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; transition: transform .15s; }
.combo-label { font-size: 12px; }
.combo-pips { display: flex; margin-left: 6px; gap: 4px; align-self: center; }
.combo-pips i { display: grid; width: 17px; height: 17px; place-items: center; border-radius: 50%; background: var(--line); color: var(--muted); font-size: 8px; font-style: normal; font-weight: 700; transition: background .2s, transform .2s; }
.combo-pips i::before { content: attr(data-step); }
.combo-pips i.is-lit { color: #fff; background: #ff9d2e; transform: scale(1.15); box-shadow: 0 0 8px #ff9d2e; }
.combo:not([data-level="0"]) .combo-count { color: #e07a12; }
.combo[data-level="2"] .combo-count, .combo[data-level="3"] .combo-count, .combo[data-level="4"] .combo-count { font-size: 26px; text-shadow: 0 0 12px #ffb84d88; }
.combo[data-level="4"] .combo-count { background: var(--prism); -webkit-background-clip: text; background-clip: text; color: transparent; animation: spin-a 2s linear infinite; }
@keyframes spin-a { to { --a: 360deg; } }
.meter { width: 100%; height: 9px; overflow: hidden; border-radius: 99px; background: var(--line); --pack: #9aa095; }
.meter-fill { height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--pack), color-mix(in srgb, var(--pack), #fff 40%)); transition: width .35s cubic-bezier(.2, 1.2, .4, 1), background .3s; }
.meter-label { margin: 0; color: var(--muted); font-size: 12px; }
.meter-label b { font-weight: 700; }

.combo-banner { position: fixed; z-index: 64; top: 26%; left: 0; right: 0; display: grid; justify-items: center; pointer-events: none; animation: banner 1.3s cubic-bezier(.2, 1.3, .4, 1) forwards; }
.combo-banner b { font-size: clamp(38px, 12vw, 64px); font-weight: 900; letter-spacing: -1px; background: linear-gradient(180deg, #fff27a, #ff8a1f); -webkit-background-clip: text; background-clip: text; color: transparent; filter: drop-shadow(0 3px 0 #b34a00) drop-shadow(0 0 14px #ffb84d); }
.combo-banner.level-3 b, .combo-banner.level-4 b { background: var(--prism); -webkit-background-clip: text; background-clip: text; filter: drop-shadow(0 3px 0 #3b1f66) drop-shadow(0 0 16px #ff7ad9); }
.combo-banner span { color: var(--ink); font-weight: 700; font-size: 15px; text-shadow: 0 1px 0 #fff; }
@keyframes banner { 0% { opacity: 0; transform: scale(.3) rotate(-6deg); } 20% { opacity: 1; transform: scale(1.12) rotate(2deg); } 35% { transform: scale(1) rotate(0); } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(-30px) scale(1.05); } }

/* ---------- pack reveal (non-blocking, sits on top) ---------- */
.reveal-layer { position: fixed; z-index: 60; top: 0; left: 0; right: 0; height: var(--reveal-fx-bottom, auto); display: flex; flex-direction: column; align-items: center; padding: max(14px, env(safe-area-inset-top)) 22px 0; overflow-y: clip; pointer-events: none; }
body:has(.app-shell.has-overlay) .fx-canvas,
body:has(.app-shell.has-overlay) .screen-flash {
  clip-path: inset(0 0 calc(100% - var(--reveal-fx-bottom, 200px)) 0);
}
.reveal { position: relative; width: min(100%, 440px); height: 202px; perspective: 700px; pointer-events: auto; touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; animation: reveal-in .24s cubic-bezier(.2, 1.5, .4, 1); }
.reveal.is-out { animation: reveal-out .16s ease-in forwards; }
@keyframes reveal-in { from { opacity: 0; transform: translateY(-50px) scale(.7); } to { opacity: 1; transform: none; } }
@keyframes reveal-out { to { opacity: 0; transform: translateY(-30px) scale(.9); } }
.reveal-pack { position: absolute; inset: 0 0 auto; height: 118px; display: grid; place-items: center; border-radius: 16px; font-size: 16px; color: #fff; background: linear-gradient(135deg, var(--pack), color-mix(in srgb, var(--pack), #fff 45%) 50%, var(--pack)); background-size: 200% 200%; box-shadow: 0 0 0 3px #fff, 0 6px 26px var(--pack); font-weight: 800; letter-spacing: 1.5px; text-transform: uppercase; text-shadow: 0 1px 4px #0006; animation: wobble .3s ease-in-out infinite alternate, sheen 1s linear infinite; transition: transform .16s ease-in, opacity .16s; backface-visibility: hidden; }
.tier-3 .reveal-pack, .tier-4 .reveal-pack { animation-duration: .18s, .7s; box-shadow: 0 0 0 3px #fff, 0 0 40px 6px var(--pack); }
@keyframes wobble { from { transform: rotate(-2.5deg) scale(1); } to { transform: rotate(2.5deg) scale(1.04); } }
@keyframes sheen { to { background-position: 200% 0; } }
.reveal-face { position: absolute; inset: 0; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: 118px 76px; justify-items: center; align-content: start; gap: 8px; opacity: 0; transform: rotateY(90deg) scale(.9); transition: transform .3s cubic-bezier(.2, 1.6, .4, 1) .1s, opacity .1s .1s; }
.reveal-face .card.wide { width: 100%; min-width: 0; height: 118px; grid-template-columns: 38% minmax(0, 1fr); }
.reveal-face .card.wide .card-name { overflow-wrap: anywhere; font-size: clamp(15px, 4vw, 19px); }
.reveal.is-flipped .reveal-pack { opacity: 0; transform: rotateY(-90deg) scale(1.15); pointer-events: none; }
.reveal.is-flipped .reveal-face { opacity: 1; transform: none; }

.toast-ach { height: auto; }
.ach-toast { display: flex; padding: 12px 14px; align-items: center; gap: 12px; border-radius: 14px; background: linear-gradient(135deg, #fff9d6, #ffe9a0); box-shadow: 0 0 0 2px #fff, 0 8px 30px #ffb84daa; animation: pop .4s cubic-bezier(.2, 1.6, .4, 1); }
.ach-toast .ach-icon { font-size: 30px; }
.ach-text { display: grid; flex: 1; }
.ach-text small { color: #a8740b; font-size: 10px; font-weight: 800; letter-spacing: 1.4px; }
.ach-text b { font-size: 16px; }
.ach-reward { padding: 4px 10px; border-radius: 99px; color: #fff; background: var(--pack); font-size: 12px; font-weight: 800; }
@keyframes pop { from { transform: scale(.6); } to { transform: none; } }

/* charge-up + shatter for Holo/Prisme reveals */
.reveal-dim { position: fixed; z-index: 59; inset: 0; pointer-events: none; opacity: 0; background: radial-gradient(circle at 50% 12%, #0000 0, #00000070 75%); transition: opacity .35s; }
.reveal-dim.on { opacity: 1; }
.reveal.is-charging .reveal-pack { animation: charge .09s linear infinite alternate, sheen .4s linear infinite; box-shadow: 0 0 0 3px #fff, 0 0 60px 14px var(--pack); }
@keyframes charge { from { transform: translate(-3px, 1px) rotate(-2deg) scale(1.03); } to { transform: translate(3px, -1px) rotate(2deg) scale(1.08); } }
.shard { position: absolute; inset: 0; pointer-events: none; border-radius: 16px; background: linear-gradient(135deg, var(--pack), #fff 50%, var(--pack)); animation: shard .75s cubic-bezier(.2, .7, .3, 1) forwards; }
@keyframes shard { to { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)) scale(.6); opacity: 0; } }

/* ---------- cards ---------- */
.card { --frame: #dcded5; position: relative; display: grid; padding: 3px; border-radius: 13px; background: var(--frame); background-size: 300% 300%; color: var(--ink); text-align: left; box-shadow: 0 2px 6px #0000001a; }
.card::before { content: ''; position: absolute; inset: 3px; border-radius: 10px; background: #fff; }
.card > * { position: relative; }
.card.ed-1 { --frame: var(--silver); box-shadow: 0 0 0 1.5px #4f5a6e, 0 0 14px 2px #b9cdf5, 0 3px 8px #0003, inset 0 0 0 1px #fff; }
/* a static four-point star on the corner of the flag */
.card.ed-1 .card-frame::after { content: ''; position: absolute; top: -9px; right: -9px; width: 26px; height: 26px; pointer-events: none; z-index: 3;
  background: radial-gradient(circle, #fff 0 12%, transparent 14%), linear-gradient(#0000 44%, #fff 50%, #0000 56%), linear-gradient(90deg, #0000 44%, #fff 50%, #0000 56%);
  clip-path: polygon(50% 0, 58% 42%, 100% 50%, 58% 58%, 50% 100%, 42% 58%, 0 50%, 42% 42%); filter: drop-shadow(0 0 3px #fff); }
.sheet-card .card.ed-1 .card-frame::after, .reveal-face .card.ed-1 .card-frame::after, .preview-card .card.ed-1 .card-frame::after, .merge-card .card.ed-1 .card-frame::after, .merge-result .card.ed-1 .card-frame::after { animation: twinkle 1.2s ease-in-out infinite alternate; }
/* Silver: a bright glint sweeps across the flag while the card is in focus. */
.sheet-card .card.ed-1 .card-shine, .reveal-face .card.ed-1 .card-shine, .preview-card .card.ed-1 .card-shine, .map-card .card.ed-1 .card-shine, .merge-card .card.ed-1 .card-shine, .merge-result .card.ed-1 .card-shine {
  background: linear-gradient(105deg, transparent 38%, #ffffffd0 50%, transparent 62%); background-size: 260% 100%; animation: sweep 3s ease-in-out infinite; }
.card.ed-2 { --frame: var(--gold); box-shadow: 0 0 12px #f5c93a88; }
.card.ed-3 { --frame: var(--holo); box-shadow: 0 0 14px #6fe3ff88; }
.card.ed-4 { --frame: var(--prism); }
.card.ed-5 { --frame: var(--void); box-shadow: 0 0 16px #8a4dffaa; }
.card.ed-6 { --frame: var(--glitch); box-shadow: -3px 0 10px #19f0ff99, 3px 0 10px #ff2bd099; }
@keyframes holo { to { background-position: 300% 0; } }
.card-frame { position: relative; border-radius: 8px; aspect-ratio: 4 / 3; background: #eee; }
.flag-stack { position: absolute; inset: 0; overflow: hidden; border-radius: 8px; isolation: isolate; }
.card-flag { display: block; width: 100%; height: 100%; object-fit: cover; }
.card-shine { position: absolute; inset: 0; pointer-events: none; border-radius: 8px; }

/* Gull and up (.fx): the flag breaks out of its frame. */
.card.fx { --par: 0; }
.card.ed-2 { --pop: 1.1; --rot: -.8deg; }
.card.ed-3 { --pop: 1.14; --rot: -1deg; --par: 3; }
.card.ed-4 { --pop: 1.18; --rot: -1.2deg; --par: 5; }
.card.ed-5 { --pop: 1.18; --rot: -1deg; --par: 6; }
.card.ed-6 { --pop: 1.16; --rot: -.6deg; --par: 4; }
.card.fx .card-frame { background: transparent; }
.card.big.fx .card-frame { margin: 16px 14px 4px; }
.card.wide.fx .card-frame { margin: 10px 0 6px 8px; }
.card.tile.fx .card-frame { margin: 6px 5px 4px; }
.card.fx .flag-stack {
  overflow: visible; transform-origin: 50% 100%;
  transform: translate(calc(var(--tx, 0) * var(--par) * 1px), calc(var(--ty, 0) * var(--par) * 1px)) scale(var(--pop)) rotate(var(--rot));
}
/* The shadow is a static box-shadow, not a filter. */
.card.fx .flag-stack::before { content: ''; position: absolute; inset: 0; z-index: -1; border-radius: 6px; box-shadow: 0 6px 7px #0000005c; }
.card.fx .card-flag { border-radius: 6px; }

/* Live foil: a shader canvas (foil-gl.js), 140% of the flag so effects spill past the edge. Hidden until it has drawn once. */
.fx-gl { position: absolute; left: -20%; top: -20%; width: 140%; height: 140%; z-index: 1; visibility: hidden; pointer-events: none; }
.gl-live > .fx-gl { visibility: visible; }
.gl-live > .card-flag, .gl-live ~ .card-shine, .gl-live > .card-shine { visibility: hidden; }
.flag-stack.gl-live .card-shine { display: none; }
.card.is-shiny .fx-gl { filter: saturate(1.25) brightness(1.05); }

/* Gull: a slow glint. */
.card.ed-2 .card-shine { background: linear-gradient(105deg, transparent 38%, #ffffffaa 50%, transparent 62%); background-size: 260% 100%; animation: sweep 2.8s ease-in-out infinite; }
@keyframes sweep { from { background-position: 130% 0; } to { background-position: -130% 0; } }

/* Holo + Prisme: foil that follows tilt. */
.card.ed-3 .card-shine, .card.ed-4 .card-shine {
  mix-blend-mode: soft-light;
  background:
    linear-gradient(calc(105deg + var(--tx, 0) * 40deg), transparent 10%, #ff5d5d99 26%, #ffd34d99 38%, #5ee6a099 50%, #5ad1ff99 62%, #b79bff99 74%, transparent 90%) 0 0 / 220% 220%;
  background-position: calc(50% + var(--tx, 0) * 50%) calc(50% + var(--ty, 0) * 50%);
}
/* Prisme: glowing rim and twinkling sparks past the edge. */
/* (the old red/cyan fringing filter was dropped: it forced a repaint of every strip on each tilt update) */
.card.ed-4 { box-shadow: 0 0 14px #ff7ad988, 0 0 30px #5ad1ff44; }
.sheet-card .card.ed-4, .reveal-face .card.ed-4, .preview-card .card.ed-4, .merge-card .card.ed-4, .merge-result .card.ed-4 { animation: spin-a 2.5s linear infinite, prism-glow 1.8s ease-in-out infinite alternate; }
.sheet-card .card.ed-5, .reveal-face .card.ed-5, .preview-card .card.ed-5, .merge-card .card.ed-5, .merge-result .card.ed-5 { animation: spin-a 6s linear infinite; }
@keyframes prism-glow { from { box-shadow: 0 0 14px #ff7ad988, 0 0 30px #5ad1ff44; } to { box-shadow: 0 0 26px #ffd34dcc, 0 0 50px #9b7bff77; } }
.card.ed-4::after { content: ''; position: absolute; inset: -9px; pointer-events: none; z-index: 3; background:
  radial-gradient(circle at 4% 18%, #fff 0 2px, transparent 3px), radial-gradient(circle at 97% 30%, #9fe8ff 0 2.5px, transparent 4px),
  radial-gradient(circle at 88% 92%, #fff 0 2px, transparent 3px), radial-gradient(circle at 12% 88%, #ffc6f1 0 2.5px, transparent 4px),
  radial-gradient(circle at 50% -1%, #fff6b0 0 2px, transparent 3px);
  animation: twinkle 1.1s ease-in-out infinite alternate; }

/* Shiny: glitter */
.card.is-shiny .card-shine { background: linear-gradient(105deg, transparent 38%, #ffffffaa 50%, transparent 62%); background-size: 260% 100%; animation: sweep 2.6s ease-in-out infinite; }
.card.is-shiny.ed-3 .card-shine, .card.is-shiny.ed-4 .card-shine { animation: none; }
.card.is-shiny .card-frame::after { content: ''; position: absolute; inset: 0; pointer-events: none; z-index: 2; background:
  radial-gradient(circle at 18% 28%, #fff 0 1.5px, transparent 2.5px), radial-gradient(circle at 76% 22%, #fff 0 1.5px, transparent 2.5px),
  radial-gradient(circle at 62% 74%, #fff 0 1.5px, transparent 2.5px), radial-gradient(circle at 28% 80%, #fff 0 1.5px, transparent 2.5px);
  animation: twinkle 1.4s ease-in-out infinite alternate; }
.card.is-shiny .card-flag { filter: saturate(1.3) brightness(1.06); }
@keyframes twinkle { from { opacity: .15; transform: scale(.96); } to { opacity: 1; transform: scale(1.04); } }
.card-meta { display: grid; gap: 1px; }
.card-name { font-size: 13px; line-height: 1.2; }
.card-edition, .card-rarity, .card-extra { color: var(--muted); font-size: 11px; line-height: 1.25; }
.card-rarity { color: var(--rc); }
.card-rarity small { color: var(--muted); font-size: 10px; }
.card-extra { color: var(--green); font-weight: 600; }
.card-badge { position: absolute; top: 6px; right: 6px; padding: 1px 6px; border-radius: 99px; color: #fff; background: #e0441b; font-size: 10px; font-weight: 800; box-shadow: 0 1px 4px #0004; }

.card.wide { grid-template-columns: 160px 1fr; height: 118px; align-items: center; gap: 12px; padding: 3px 12px 3px 3px; }
.card.wide .card-frame { align-self: stretch; aspect-ratio: auto; }
.card.wide .card-name { font-size: 19px; }
.card.wide .card-edition, .card.wide .card-rarity, .card.wide .card-extra { font-size: 12px; }
.card.wide .card-badge { top: 5px; right: 8px; }
.card.tile { padding: 3px 3px 5px; gap: 4px; }
.card.tile .card-meta { padding: 0 4px; }
.card.tile .card-badge { top: 7px; right: 7px; }
.card.big { width: min(320px, 86vw); padding: 4px 4px 12px; gap: 8px; }
.card.big .card-meta { padding: 0 10px; text-align: center; }
.card.big .card-name { font-size: 22px; }
.card.big .card-edition, .card.big .card-rarity { font-size: 13px; }
.card.unowned { opacity: .55; }
.card.unowned .card-flag { filter: grayscale(1) opacity(.35); }
.card.tile .flag-stack { border-radius: 8px; }
.card.unowned .card-name { color: var(--muted); font-weight: 500; }

/* ---------- sub views ---------- */
.view { width: min(100%, 720px); align-self: start; padding-bottom: 40px; }
.view-header { position: sticky; z-index: 5; top: 0; display: flex; min-height: 48px; align-items: center; gap: 12px; background: var(--paper); }
.view-header h2 { flex: 1; margin: 0; font-size: 20px; letter-spacing: -.5px; }
.view-count { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.toolbar { display: grid; margin: 4px 0 14px; gap: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 6px 11px; border: 1px solid var(--line); border-radius: 99px; background: #fff; cursor: pointer; font-size: 12px; }
.chip small { color: var(--muted); }
.chip.is-active { color: #fff; border-color: var(--green); background: var(--green); }
.chip.is-active small { color: #dfeadb; }
.chip[disabled] { opacity: .45; cursor: default; }
.chip.merge-all:not([disabled]) { border-color: #a65cf0; color: #7a2fd0; font-weight: 700; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.tile-wrap { min-width: 0; padding: 0; border: 0; background: none; cursor: pointer; text-align: left; transition: transform .12s; }
.tile-wrap .card, .tile-wrap .card-meta { min-width: 0; }
.tile-wrap .card-name { overflow-wrap: anywhere; }
.tile-wrap:active { transform: scale(.96); }

.sheet-backdrop { position: fixed; z-index: 80; inset: 0; display: grid; place-items: end center; background: #1b1f1acc; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.sheet { position: relative; display: grid; width: min(100%, 460px); max-height: 92vh; padding: 28px 20px calc(20px + env(safe-area-inset-bottom)); overflow: auto; justify-items: center; gap: 10px; border-radius: 22px 22px 0 0; background: var(--paper); animation: sheet-up .25s cubic-bezier(.2, 1.2, .4, 1); }
@keyframes sheet-up { from { transform: translateY(60px); opacity: 0; } }
.sheet-close { position: absolute; top: 8px; right: 10px; width: 36px; height: 36px; border: 0; border-radius: 50%; background: transparent; cursor: pointer; font-size: 26px; color: var(--muted); }
.sheet-card { touch-action: pan-y; }
.sheet-location { display: flex; width: min(100%, 300px); align-items: center; gap: 14px; }
.sheet-location > div { display: grid; gap: 4px; }
.sheet-location b { font-size: 16px; }
.sheet-location span { color: var(--muted); font-size: 12px; }
.country-globe { position: relative; display: block; width: 76px; aspect-ratio: 1; flex: 0 0 auto; opacity: 0; transform: scale(.72) rotate(-12deg); transition: opacity .35s ease, transform .55s cubic-bezier(.2, 1.4, .4, 1); }
.country-globe.is-ready { opacity: 1; transform: scale(1) rotate(0); }
.country-globe svg { display: block; width: 100%; height: 100%; overflow: visible; filter: drop-shadow(0 4px 5px #264a4338); }
.globe-ocean { fill: #a8d3c5; stroke: #f5fff8; stroke-width: 1.2; }
.globe-country { fill: #6da993; stroke: #e2f2e8; stroke-width: .65; vector-effect: non-scaling-stroke; }
.globe-country.is-target { fill: #e9853f; stroke: #fff3cb; stroke-width: 1.05; }
.globe-dot { fill: #528b7b; stroke: #d9eee4; stroke-width: .4; vector-effect: non-scaling-stroke; }
.globe-dot.is-target { fill: #e76e36; stroke: #fff; stroke-width: .8; }
.globe-latitude, .globe-longitude { fill: none; stroke: #f5fff8; stroke-width: .65; opacity: .48; }
.globe-shade { fill: url(#globe-shade); pointer-events: none; }
.globe-rim { fill: none; stroke: #fff; stroke-width: 1; opacity: .8; }
.sheet-card.pop { animation: card-pop .5s cubic-bezier(.2, 1.8, .4, 1); }
@keyframes card-pop { 0% { transform: scale(.4) rotate(-8deg); } 100% { transform: none; } }
.sheet-sub { margin: 0; color: var(--muted); font-size: 13px; }
.stacks { width: 100%; margin: 6px 0 0; padding: 0; list-style: none; }
.stacks li { display: flex; padding: 9px 0; align-items: center; gap: 10px; border-top: 1px solid var(--line); }
.stack-name { flex: 1; font-weight: 600; }
.stack-count { color: var(--muted); font-variant-numeric: tabular-nums; }

/* map */
.map-wrap { overflow: hidden; border-radius: 14px; background: #e6eeec; cursor: grab; }
.map-wrap svg { display: block; width: 100%; height: auto; max-height: 62vh; touch-action: none; }
.map-wrap.is-dragging, .map-wrap.is-dragging .country { cursor: grabbing; }
.map-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.map-controls input { flex: 1 1 180px; min-width: 0; padding: 8px 11px; border: 1px solid var(--line); border-radius: 999px; background: #fff; color: var(--ink); font: inherit; font-size: 13px; }
.sea { fill: #e6eeec; }
.country { stroke: #fbfaf5; stroke-width: calc(.5px * var(--stroke, 1)); cursor: grab; transition: fill .3s; }
.country.c-none { fill: #d3d6cb; }
.country.c-0 { fill: #8cc09a; }
.country.c-1 { fill: url(#silver); stroke: #7889a2; }
.country.c-2 { fill: url(#gold); stroke: #a97819; }
.country.c-3 { fill: url(#holo); }
.country.c-4 { fill: url(#prism); }
.country.c-5 { fill: #4a2a9a; }
.country.c-6 { fill: #ff2bd0; }
.country.shiny { stroke: #fff; stroke-width: 1.3; filter: drop-shadow(0 0 2px #ffe680); }
.country.is-selected { stroke: var(--ink); stroke-width: 1.6; }
.marker .hit { fill: transparent; }
.dot { stroke: #6b6f66; stroke-width: .6; }
.map-hint { margin: 10px 0; color: var(--muted); font-size: 13px; }
.map-info { min-height: 92px; margin-top: 12px; }
.map-card .card.wide { width: min(100%, 360px); margin: 0 auto; }
.legend { display: flex; flex-wrap: wrap; margin: 12px 0 0; padding: 0; gap: 4px 12px; list-style: none; color: var(--muted); font-size: 11px; }
.swatch { display: inline-block; width: 12px; height: 12px; margin-right: 5px; border-radius: 3px; vertical-align: -2px; }
.swatch.c-none { background: #d3d6cb; } .swatch.c-0 { background: #8cc09a; } .swatch.c-1 { background: linear-gradient(135deg, #71819b, #d4deec 24%, #899ab4 45%, #f1f5fc 58%, #9aa9c0 76%, #66758d); } .swatch.c-2 { background: linear-gradient(135deg, #c58a0d, #ffe27a 24%, #d89b0a 45%, #fff2b5 58%, #e5b83c 76%, #b87b0b); }
.swatch.c-3 { background: var(--holo); } .swatch.c-4 { background: var(--prism); } .swatch.c-5 { background: #4a2a9a; } .swatch.c-6 { background: #ff2bd0; }

/* achievements */
.ach-group { margin-bottom: 10px; border: 1px solid var(--line); border-radius: 14px; background: #fff; }
.ach-group summary { display: flex; padding: 14px; justify-content: space-between; cursor: pointer; font-weight: 700; }
.ach-group ul { margin: 0; padding: 0 12px 6px; list-style: none; }
.ach { display: flex; padding: 10px 2px; align-items: center; gap: 12px; border-top: 1px solid var(--line); }
.ach .ach-icon { font-size: 24px; filter: grayscale(1) opacity(.5); }
.ach.is-done .ach-icon { filter: none; }
.ach-body { display: grid; flex: 1; gap: 2px; min-width: 0; }
.ach-body small { color: var(--muted); font-size: 11px; line-height: 1.3; }
.ach-bar { height: 5px; margin-top: 4px; overflow: hidden; border-radius: 99px; background: var(--line); }
.ach-bar i { display: block; height: 100%; background: var(--green); }
.ach.is-done .ach-bar i { background: #f0a020; }
.ach-side { display: grid; justify-items: end; font-size: 12px; font-variant-numeric: tabular-nums; }
.ach-side small { color: var(--muted); font-size: 10px; }
.ach.is-done .ach-side { color: #c07d00; font-weight: 800; }

@media (prefers-reduced-motion: reduce) {
  .reveal.is-charging .reveal-pack, .card.ed-4::after, .card-shine,
  .reveal-pack, .card, .card-shine, .card-frame::after, .combo-count { animation: none !important; }
  .combo-banner { animation-duration: 1.6s; }
}

@media (max-width: 520px) {
  .reveal { width: min(100%, 380px); height: 114px; }
  .reveal-layer { padding-right: max(12px, env(safe-area-inset-right)); padding-left: max(12px, env(safe-area-inset-left)); }
  .reveal-pack { height: 100px; }
  .reveal-face {
    grid-template-columns: minmax(0, 1fr) 56px;
    grid-template-rows: 100px;
    align-items: center;
    gap: 8px;
  }
  .reveal-face .card.wide { height: 100px; }
  .reveal-face .country-globe { width: 56px; }
}

@media (max-height: 650px) and (min-width: 521px) {
  .reveal { height: 154px; }
  .reveal-pack { height: 100px; }
  .reveal-face { grid-template-rows: 100px 48px; gap: 4px; }
  .reveal-face .country-globe { width: 48px; }
  .card.wide { grid-template-columns: 136px 1fr; height: 100px; }
  .reveal-face .card.wide { height: 100px; }
}

/* On wider screens, put the locator globe beside the full-height flag card. This
   keeps the reveal compact vertically without shrinking the animated flag. */
@media (min-width: 521px) {
  .reveal { width: min(100%, 520px); height: 142px; }
  .reveal-face {
    grid-template-columns: minmax(0, 1fr) 76px;
    grid-template-rows: 118px;
    align-content: center;
    align-items: center;
    gap: 10px;
  }
  .reveal-face .country-globe { width: 76px; }
}
@media (max-height: 650px) and (min-width: 521px) {
  .reveal { height: 104px; }
  .reveal-pack { height: 84px; }
  .reveal-face { grid-template-columns: minmax(0, 1fr) 44px; grid-template-rows: 84px; gap: 8px; }
  .reveal-face .card.wide { height: 84px; }
  .reveal-face .country-globe { width: 44px; }
}
@media (max-height: 620px) and (orientation: portrait) and (max-width: 520px) {
  .reveal { height: 80px; }
  .reveal-pack { height: 68px; }
  .reveal-face { grid-template-columns: minmax(0, 1fr) 40px; grid-template-rows: 68px; gap: 6px; }
  .reveal-face .card.wide { height: 68px; }
  .reveal-face .country-globe { width: 40px; }
}
@media (max-height: 700px) and (min-height: 621px) and (orientation: portrait) and (max-width: 520px) {
  .reveal { height: 100px; }
  .reveal-pack { height: 88px; }
  .reveal-face { grid-template-columns: minmax(0, 1fr) 48px; grid-template-rows: 88px; gap: 6px; }
  .reveal-face .card.wide { height: 88px; }
  .reveal-face .country-globe { width: 48px; }
}
@media (orientation: landscape) {
  .has-keypad .reveal-layer { right: min(44vw, 340px); padding-right: 8px; padding-left: 8px; }
}

/* ---------- merge animation ---------- */
.merge-stage { position: fixed; z-index: 90; inset: 0; display: grid; place-items: center; overflow: hidden; background: radial-gradient(circle at 50% 45%, #303c5af2 0, #121522f5 42%, #07080cfb 100%); touch-action: manipulation; animation: fade .15s; }
.merge-stage.is-out { opacity: 0; transition: opacity .18s; }
.merge-core { position: absolute; top: 50%; left: 50%; width: 40px; aspect-ratio: 1; border-radius: 50%; background: #fff; opacity: 0; transform: translate(-50%, -50%) scale(.1); }
.merge-stage.is-fused .merge-core { animation: merge-bloom .9s cubic-bezier(.16, .8, .2, 1) forwards; }
@keyframes merge-bloom {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.1); box-shadow: 0 0 0 0 #fff, 0 0 0 0 #8b76ff; }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.2); box-shadow: 0 0 0 18px #ffffff35, 0 0 70px 30px #9880ffcc; }
  55% { opacity: .8; transform: translate(-50%, -50%) scale(18); box-shadow: 0 0 0 25px #ffffff00, 0 0 90px 45px #9880ff00; }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(24); }
}
.merge-card { position: absolute; top: 50%; left: 50%; width: 112px; filter: drop-shadow(0 8px 20px #0008); animation: swirl .75s cubic-bezier(.5, 0, .7, .4) forwards; }
.merge-stage.is-fast .merge-card { animation-duration: .48s; }
.merge-stage.is-fast .merge-result { animation-duration: .48s; }
.merge-stage.is-fast .merge-label { animation-duration: .3s; }
@keyframes swirl {
  0% { opacity: 0; transform: translate(-50%, -50%) rotate(var(--a)) translateY(-170px) rotate(calc(var(--a) * -1)) scale(.72); }
  12% { opacity: 1; }
  72% { opacity: 1; }
  100% { opacity: .2; transform: translate(-50%, -50%) rotate(calc(var(--a) + 300deg)) translateY(0) rotate(calc((var(--a) + 300deg) * -1)) scale(.12); }
}
.merge-stage.is-fused .merge-card { display: none; }
.merge-result { position: relative; z-index: 1; display: grid; justify-items: center; gap: 12px; animation: merge-card-reveal .72s cubic-bezier(.15, 1.5, .35, 1) both; }
.merge-result .card.big { filter: drop-shadow(0 14px 28px #0009); }
@keyframes merge-card-reveal {
  0% { opacity: 0; transform: translateY(35px) scale(.15) rotate(-18deg); filter: blur(12px) brightness(3); }
  45% { opacity: 1; transform: translateY(-10px) scale(1.12) rotate(5deg); filter: blur(0) brightness(1.6); }
  70% { transform: translateY(4px) scale(.96) rotate(-2deg); filter: brightness(1.2); }
  100% { opacity: 1; transform: none; filter: none; }
}
.merge-label { margin: 0; color: #fff; font-size: 26px; font-weight: 900; text-shadow: 0 2px 12px #000a; animation: merge-label-in .45s .2s cubic-bezier(.2, 1.5, .4, 1) both; }
@keyframes merge-label-in { from { opacity: 0; transform: translateY(12px) scale(.75); } to { opacity: 1; transform: none; } }
body:has(.merge-stage) .fx-canvas { z-index: 95; }
body:has(.merge-stage) .screen-flash { z-index: 96; }
@media (prefers-reduced-motion: reduce) {
  .merge-card, .merge-result, .merge-label, .merge-stage.is-fused .merge-core { animation-duration: .01ms !important; }
}

/* While a card is open, freeze everything behind it. Dozens of foil tiles animating under the
   sheet (plus the 64 waving strips of the big card) overload phone GPUs: columns drop out and flicker. */
body:has(.sheet-backdrop) .app-shell *,
body:has(.sheet-backdrop) .app-shell *::before,
body:has(.sheet-backdrop) .app-shell *::after { animation-play-state: paused !important; }

/* ---------- settings preview ---------- */
.preview-controls { display: grid; margin-bottom: 12px; grid-template-columns: 1fr 1fr; gap: 10px; }
.preview-controls label { display: grid; gap: 4px; color: var(--muted); font-size: 12px; }
.preview-controls label.check { display: flex; align-items: center; gap: 8px; }
.preview-controls select { width: 100%; min-width: 0; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; font-size: 14px; }
.preview-actions { margin-bottom: 18px; }
.preview-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 26px 18px; }
.preview-cell { display: grid; justify-items: center; gap: 12px; }
.preview-card .card.big { width: min(240px, 70vw); }
.preview-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
