:root {
  --bg: #07090d;
  --surface: #0d1219;
  --surface-2: #121a23;
  --line: #22303b;
  --text: #f3f7f8;
  --muted: #81909d;
  --cyan: #35e5ee;
  --violet: #8a70ff;
  --green: #42db8b;
  --amber: #f0b93c;
  --red: #ff5864;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body {
  background-color: var(--bg);
  background-image:
    linear-gradient(rgba(53, 229, 238, .025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(53, 229, 238, .025) 1px, transparent 1px);
  background-size: 28px 28px;
  letter-spacing: 0;
}
button, input { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  min-height: 62px; padding: 9px 14px;
  background: rgba(7, 9, 13, .91); border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}
.brand-lockup, .topbar-actions { display: flex; align-items: center; gap: 9px; }
.brand-lockup img { width: 38px; height: 38px; object-fit: cover; border: 1px solid #2c5561; border-radius: 50%; }
.brand-lockup strong, .brand-lockup span { display: block; }
.brand-lockup strong { font-size: 18px; line-height: 1.05; }
.brand-lockup span { margin-top: 3px; color: var(--cyan); font: 700 8px/1 monospace; }
.network-status { color: var(--green); font: 700 9px/1 monospace; }
.network-status i { display: inline-block; width: 6px; height: 6px; margin-right: 4px; background: var(--green); border-radius: 50%; box-shadow: 0 0 8px var(--green); }
.identity { display: grid; place-items: center; width: 34px; height: 34px; overflow: hidden; color: #071014; background: var(--cyan); border: 1px solid #83fbff; border-radius: 50%; font-weight: 800; }
.identity img { width: 100%; height: 100%; object-fit: cover; }

main { width: min(100%, 720px); margin: 0 auto; padding: 18px 14px 30px; }
.view { display: none; }
.view.active { display: block; animation: view-in .22s ease-out; }
@keyframes view-in { from { opacity: 0; transform: translateY(5px); } }
.section-heading, .list-heading, .deck-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.section-heading { margin-bottom: 15px; }
h1, h2, p { margin: 0; }
h1 { font-size: 27px; line-height: 1.1; }
h2 { font-size: 16px; }
.eyebrow, .deck-heading, .list-heading > span { color: var(--cyan); font: 700 10px/1.2 monospace; }
.eyebrow { margin-bottom: 5px; }
.icon-button { width: 39px; height: 39px; color: var(--cyan); background: var(--surface); border: 1px solid var(--line); border-radius: 7px; font-size: 23px; }
.icon-button:active { border-color: var(--cyan); }

.search-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 7px; margin-bottom: 17px; }
input { width: 100%; min-width: 0; height: 44px; padding: 0 13px; color: var(--text); background: #090e14; border: 1px solid var(--line); border-radius: 7px; outline: none; }
input::placeholder { color: #566572; }
input:focus { border-color: var(--cyan); box-shadow: 0 0 0 2px rgba(53, 229, 238, .12); }
.search-row button { min-width: 82px; padding: 0 14px; color: #031013; background: var(--cyan); border: 0; border-radius: 7px; font-weight: 800; }

.state-panel, .empty-state { padding: 18px; color: var(--muted); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; text-align: center; }
.state-panel.loading { display: flex; align-items: center; justify-content: center; gap: 11px; font: 700 11px/1 monospace; text-transform: uppercase; }
.state-panel.error, .empty-state.error { color: var(--red); border-color: rgba(255, 88, 100, .45); }
.scan-loader { width: 16px; height: 16px; border: 2px solid #26343d; border-top-color: var(--cyan); border-radius: 50%; animation: spin .75s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.portfolio-summary { display: grid; grid-template-columns: 1.5fr 1fr 1fr; margin-bottom: 20px; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; }
.portfolio-summary > div { min-width: 0; padding: 12px 10px; background: rgba(13, 18, 25, .92); border-left: 1px solid var(--line); }
.portfolio-summary > div:first-child { border-left: 0; }
.portfolio-summary span, .portfolio-summary strong { display: block; }
.portfolio-summary span { color: var(--muted); font: 700 9px/1 monospace; text-transform: uppercase; }
.portfolio-summary strong { margin-top: 6px; overflow: hidden; color: var(--cyan); font-size: 16px; text-overflow: ellipsis; white-space: nowrap; }
.deck-heading { margin: 0 2px 9px; }
.deck-heading small { color: var(--muted); font: 500 10px/1 monospace; }

.deck-module { width: min(100%, 430px); margin: 0 auto 22px; }
.gift-deck { width: 100%; aspect-ratio: 3 / 4.2; perspective: 1200px; outline: none; }
.gift-deck:focus-visible { box-shadow: 0 0 0 2px var(--cyan); }
.deck-inner { position: relative; width: 100%; height: 100%; transition: transform .62s cubic-bezier(.2, .75, .25, 1); transform-style: preserve-3d; }
.gift-deck.flipped .deck-inner { transform: rotateY(180deg); }
.deck-face { position: absolute; inset: 0; overflow: hidden; border: 1px solid #31515c; border-radius: 8px; background: #090d13; backface-visibility: hidden; }
.deck-face::before { content: ""; position: absolute; inset: 7px; z-index: 3; pointer-events: none; border: 1px solid rgba(53, 229, 238, .22); border-radius: 4px; }
.deck-face.mythic { border-color: #d8a533; box-shadow: 0 0 24px rgba(240, 185, 60, .13); }
.deck-face.epic { border-color: #765fda; box-shadow: 0 0 24px rgba(138, 112, 255, .13); }
.deck-face.rare { border-color: #2887b7; box-shadow: 0 0 24px rgba(53, 229, 238, .11); }
.deck-data { display: flex; flex-direction: column; padding: 22px 20px 18px; transform: rotateY(180deg); background-color: #0a0f15; background-image: linear-gradient(rgba(53, 229, 238, .025) 1px, transparent 1px), linear-gradient(90deg, rgba(53, 229, 238, .025) 1px, transparent 1px); background-size: 18px 18px; }
.card-corners { position: absolute; top: 18px; right: 18px; left: 18px; z-index: 5; display: flex; justify-content: space-between; color: rgba(240, 250, 252, .75); font: 700 9px/1 monospace; }
.asset-stage { position: absolute; inset: 0; display: grid; place-items: center; background: radial-gradient(circle at center, rgba(53, 229, 238, .16), transparent 45%); }
.asset-stage::after { content: ""; position: absolute; right: 0; bottom: 0; left: 0; height: 45%; background: linear-gradient(transparent, #090d13 88%); }
.asset-stage > img, .asset-animation { position: relative; z-index: 2; display: block; width: 82%; height: 66%; object-fit: contain; filter: saturate(1.08) drop-shadow(0 14px 24px rgba(0, 0, 0, .62)); animation: asset-float 4s ease-in-out infinite; }
.asset-animation img, .asset-animation canvas { width: 100% !important; height: 100% !important; object-fit: contain; }
.asset-animation.animation-failed source { display: none; }
.asset-ring { position: absolute; width: 66%; aspect-ratio: 1; border: 1px solid rgba(53, 229, 238, .38); transform: rotate(45deg); box-shadow: 0 0 35px rgba(53, 229, 238, .08) inset; }
.asset-ring::after { content: ""; position: absolute; inset: 12%; border: 1px dashed rgba(138, 112, 255, .5); }
@keyframes asset-float { 50% { transform: translateY(-7px); } }
.art-caption { position: absolute; right: 24px; bottom: 38px; left: 24px; z-index: 5; }
.art-caption h2 { margin-top: 8px; font-size: clamp(22px, 7vw, 32px); line-height: 1.02; }
.art-caption p { margin-top: 5px; color: var(--muted); font: 600 11px/1.2 monospace; text-transform: uppercase; }
.rarity-chip { display: inline-block; padding: 4px 7px; color: var(--cyan); background: rgba(7, 9, 13, .75); border: 1px solid currentColor; border-radius: 3px; font: 800 9px/1 monospace; }
.mythic .rarity-chip { color: var(--amber); }
.epic .rarity-chip { color: #a998ff; }
.flip-hint { position: absolute; right: 18px; bottom: 14px; z-index: 5; color: #57707b; font: 700 8px/1 monospace; }

.data-header { position: relative; z-index: 5; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.data-header span, .ability span { color: var(--cyan); font: 700 8px/1 monospace; }
.data-header h2 { margin-top: 5px; font-size: 20px; }
.data-header > strong { color: var(--muted); font: 700 12px/1 monospace; }
.core-score { position: relative; z-index: 5; display: grid; grid-template-columns: 1fr auto auto; align-items: end; gap: 7px; padding: 17px 0 14px; }
.core-score > span { align-self: center; color: var(--muted); font: 700 9px/1 monospace; }
.core-score strong { color: var(--cyan); font: 800 38px/.8 monospace; }
.core-score small { color: var(--muted); font: 700 10px/1 monospace; }
.score-dot { display: inline-block; width: 8px; height: 8px; margin-right: 6px; background: var(--muted); border-radius: 50%; box-shadow: 0 0 8px currentColor; }
.score-dot.good { background: var(--green); color: var(--green); }
.score-dot.watch { background: var(--amber); color: var(--amber); }
.score-dot.risk { background: var(--red); color: var(--red); }
.attribute-grid { position: relative; z-index: 5; display: grid; grid-template-columns: 1fr 1fr; overflow: hidden; border: 1px solid var(--line); border-radius: 6px; }
.attribute-grid > div { min-width: 0; min-height: 84px; padding: 10px; background: rgba(13, 18, 25, .88); border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.attribute-grid > div:nth-child(-n+2) { border-top: 0; }
.attribute-grid > div:nth-child(odd) { border-left: 0; }
.attribute-grid span, .attribute-grid strong, .attribute-grid small { display: block; }
.attribute-grid span { color: var(--muted); font: 700 8px/1 monospace; }
.attribute-grid strong { margin-top: 8px; overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.attribute-grid small { margin-top: 5px; color: var(--cyan); font: 700 9px/1 monospace; }
.ability { position: relative; z-index: 5; margin-top: 14px; padding: 11px 12px; background: rgba(53, 229, 238, .045); border-left: 2px solid var(--cyan); }
.ability p { margin-top: 6px; color: #b6c2c9; font-size: 11px; line-height: 1.35; }
.data-footer { position: relative; z-index: 5; display: flex; justify-content: space-between; gap: 8px; margin-top: auto; padding-top: 12px; color: #657782; font: 700 8px/1 monospace; }
.data-footer span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deck-controls { display: grid; grid-template-columns: 1fr 1fr; margin-top: 8px; overflow: hidden; border: 1px solid var(--line); border-radius: 6px; }
.deck-controls button { height: 40px; color: var(--muted); background: var(--surface); border: 0; border-left: 1px solid var(--line); font-size: 12px; font-weight: 700; }
.deck-controls button:first-child { border-left: 0; }
.deck-controls button.active { color: #041013; background: var(--cyan); }

.list-heading { margin: 24px 0 9px; }
.item-list, .collection-list { overflow: hidden; background: rgba(13, 18, 25, .86); border: 1px solid var(--line); border-radius: 8px; }
.gift-row, .collection-row { display: grid; align-items: center; gap: 10px; min-height: 61px; padding: 10px 11px; border-top: 1px solid var(--line); }
.gift-row:first-child, .collection-row:first-child { border-top: 0; }
.gift-row { grid-template-columns: 28px minmax(0, 1fr) auto; }
.rank, .collection-rank { color: #50616d; font: 700 10px/1 monospace; }
.row-main { min-width: 0; }
.row-main strong, .row-main span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-main strong { font-size: 13px; }
.row-main span { margin-top: 5px; color: var(--muted); font: 600 9px/1 monospace; }
.row-value { text-align: right; }
.row-value strong, .row-value span { display: block; }
.row-value strong { font-size: 12px; }
.row-value span { margin-top: 5px; color: var(--muted); font: 700 9px/1 monospace; }

.filter-field { display: block; margin-bottom: 12px; }
.counter { padding: 4px 7px; color: var(--cyan); border: 1px solid var(--line); border-radius: 5px; font: 700 10px/1 monospace; }
.collection-row { grid-template-columns: 22px 34px minmax(0, 1fr) auto; }
.collection-visual { display: grid; place-items: center; width: 32px; height: 32px; font-size: 21px; filter: drop-shadow(0 0 6px rgba(53, 229, 238, .18)); }
.collection-score { min-width: 38px; color: var(--cyan); font: 800 12px/1 monospace; text-align: right; }

.tabbar { position: fixed; right: 0; bottom: 0; left: 0; z-index: 30; display: grid; grid-template-columns: repeat(3, 1fr); padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); background: rgba(8, 11, 16, .95); border-top: 1px solid var(--line); backdrop-filter: blur(18px); }
.tab { display: grid; justify-items: center; gap: 3px; min-height: 52px; padding: 5px; color: #657581; background: transparent; border: 0; }
.tab span:first-child { font-size: 20px; line-height: 1; }
.tab span:last-child { font: 700 9px/1 monospace; }
.tab.active { color: var(--cyan); }
.tab.active span:first-child { text-shadow: 0 0 10px rgba(53, 229, 238, .62); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }

@media (max-width: 370px) {
  main { padding-right: 10px; padding-left: 10px; }
  .network-status { display: none; }
  .portfolio-summary { grid-template-columns: 1.4fr .8fr .8fr; }
  .portfolio-summary strong { font-size: 13px; }
  .deck-data { padding: 19px 16px 15px; }
  .attribute-grid > div { min-height: 76px; }
  .ability { margin-top: 10px; }
}

@media (min-width: 560px) {
  main { padding-top: 24px; }
  .gift-deck { aspect-ratio: 3 / 4; }
  .art-caption h2 { font-size: 32px; }
}

@media (min-width: 800px) {
  .app-shell { padding: 0 0 0 88px; }
  .topbar { min-height: 68px; padding-right: 24px; padding-left: 24px; }
  .brand-lockup img { width: 42px; height: 42px; }
  main { width: min(100%, 1160px); padding: 28px 30px 42px; }
  h1 { font-size: 31px; }
  .section-heading { margin-bottom: 19px; }
  .search-row { width: min(100%, 520px); }

  .tabbar {
    top: 0; right: auto; width: 88px; height: 100vh;
    grid-template-columns: 1fr; grid-template-rows: repeat(3, 72px);
    align-content: center; padding: 10px 7px;
    border-top: 0; border-right: 1px solid var(--line);
  }
  .tab { align-content: center; min-height: 68px; border-radius: 6px; }
  .tab.active { background: rgba(53, 229, 238, .06); }

  #portfolio-content:not([hidden]) {
    display: grid;
    grid-template-columns: minmax(330px, 430px) minmax(300px, 1fr);
    grid-template-rows: auto auto 1fr;
    gap: 0 24px;
    align-items: start;
  }
  #portfolio-content .portfolio-summary { grid-column: 1 / -1; }
  #portfolio-content .deck-heading { grid-column: 1; grid-row: 2; }
  #portfolio-content #portfolio-featured { grid-column: 1; grid-row: 3; }
  #portfolio-content .list-heading { grid-column: 2; grid-row: 2; margin-top: 0; }
  #portfolio-content .item-list { grid-column: 2; grid-row: 3; }
  #portfolio-content .deck-module { margin-bottom: 0; }

  #gift-view.active {
    display: grid;
    grid-template-columns: minmax(280px, 390px) minmax(360px, 430px);
    grid-template-rows: auto auto 1fr;
    gap: 0 34px;
    align-items: start;
    justify-content: center;
  }
  #gift-view .section-heading { grid-column: 1; grid-row: 1; }
  #gift-view .search-row { grid-column: 1; grid-row: 2; width: 100%; }
  #gift-view #gift-state { grid-column: 1; grid-row: 3; }
  #gift-view #gift-card { grid-column: 2; grid-row: 1 / 4; }
  #gift-view .deck-module { margin-bottom: 0; }

  #collections-view .filter-field { width: min(100%, 520px); }
  #collections-view .collection-list { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); }
  #collections-view .collection-row { min-height: 66px; background: rgba(13, 18, 25, .98); border-top: 0; }
}

@media (min-width: 1180px) {
  #portfolio-content:not([hidden]) { gap: 0 36px; }
  #gift-view.active { gap: 54px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
