:root {
  --paper: #f8f7fc;
  --surface: #fff;
  --ink: #201936;
  --muted: #615872;
  --line: #e6e0f0;
  --violet: #5c3bdd;
  --violet-dark: #4828ba;
  --violet-soft: #eee8ff;
  --accent-line: #dfd4fd;
  --night: #141024;
  background: radial-gradient(ellipse at 50% 0%, #e8dfff, transparent 64%), #eeedf5;
  color: var(--ink);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #181425;
  --surface: #231d33;
  --ink: #f4efff;
  --muted: #c0b6d2;
  --line: #40364f;
  --violet: #7652f0;
  --violet-dark: #d2beff;
  --violet-soft: #382956;
  --accent-line: #554274;
  background: radial-gradient(ellipse at 50% 0%, #302345, transparent 64%), #100d1a;
}

body {
  max-width: 540px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 0 70px #3020541a;
}

.icon-library { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon {
  display: block;
  width: 22px;
  height: 22px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linecap: round;
  stroke-linejoin: round;
}

body > header {
  padding: calc(12px + env(safe-area-inset-top)) 20px 12px;
  background: var(--paper);
  border-color: var(--line);
}
.header-brand {
  gap: 10px;
  color: var(--ink);
  font-size: 22px;
  font-weight: 820;
  letter-spacing: -.055em;
}
.header-brand img { display: block; box-shadow: 0 4px 12px #5c3bdd35; border-radius: 11px; }
.point-chip {
  gap: 5px;
  padding: 6px 10px;
  background: #fff3d9;
  border: 1px solid #f4dfb4;
  color: #69400b;
  font-variant-numeric: tabular-nums;
}
.point-chip .icon { width: 16px; height: 16px; }
.point-label { font-size: 11px; font-weight: 650; }

.app-heading { padding: 24px 20px 16px; }
.in-capture .app-heading { display: none; }
.app-heading .eyebrow { color: var(--violet-dark); }
#screen-title {
  position: static;
  width: auto;
  height: auto;
  margin: 4px 0 0;
  clip-path: none;
  white-space: normal;
  font-size: clamp(25px, 7vw, 34px);
  line-height: 1.2;
}
#collection, #market, #battle, #settings { padding: 0 20px 28px; background: transparent; }
.library-toolbar:not(:has(button:not([hidden]))) { display: none; }

#collection .collection-hero {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  padding: 142px 22px 23px;
  margin: 0;
  border: 1px solid #4c3583;
  border-radius: 25px;
  background:
    radial-gradient(ellipse at 78% 14%, #7050bb 0%, transparent 57%),
    linear-gradient(145deg, #302052, #211735 74%);
  color: white;
  box-shadow: 0 10px 28px #39246d22;
}
.collection-hero::before {
  position: absolute;
  inset: 0;
  z-index: -1;
  content: "";
  background-image: linear-gradient(#f1dcff17 1px, transparent 1px), linear-gradient(90deg,#f1dcff17 1px,transparent 1px);
  background-size: 22px 22px;
  mask-image: linear-gradient(145deg, black, transparent 75%);
}
.hero-kicker { color: #dfd2ff; font: 700 10px ui-monospace, monospace; letter-spacing: .16em; }
.collection-hero h2 { margin: 4px 0 0; font-size: clamp(24px, 6.7vw, 32px); line-height: 1.2; letter-spacing: -.04em; }
.collection-hero p { margin: 9px 0 20px; max-width: 34ch; color: #e5dbf8; font-size: 14px; }
#collection .collection-hero.has-cards {
  padding: 18px 110px 17px 20px;
  margin-bottom: 14px;
  min-height: 104px;
}
.collection-hero.has-cards h2 { font-size: clamp(19px, 5vw, 24px); }
.collection-hero.has-cards p { margin: 5px 0 0; font-size: 12px; }
.collection-hero.has-cards .hero-kicker { display: none; }
.collection-hero.has-cards .hero-art { top: -6px; right: 5px; transform: scale(.73); transform-origin: right center; }
.hero-art { position: absolute; top: 13px; right: 14px; width: 172px; height: 118px; pointer-events: none; }
.hero-art span {
  position: absolute;
  top: 11px;
  left: 31px;
  width: 71px;
  height: 97px;
  border: 1px solid #d5beffb8;
  border-radius: 12px;
  background: linear-gradient(150deg,#a585e991,#5f439860);
  transform: rotate(-18deg);
}
.hero-art span:nth-child(2) {
  display: grid;
  place-items: center;
  top: 9px;
  left: 68px;
  color: #fff3df;
  background: radial-gradient(ellipse at 30% 20%,#b392ff,#7651ce 55%,#452985);
  border-color: #e9daff;
  box-shadow: inset 0 0 0 5px #f4ddff22, 0 8px 20px #1b0c4a80;
  transform: rotate(15deg);
}
.hero-art span .icon { width: 34px; height: 34px; fill: currentColor; stroke-width: 1; }
.hero-art > .icon { position: absolute; top: 11px; right: 0; width: 16px; height: 16px; color: #ffdfab; }
#start-collection, #export {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 13px;
  font-weight: 750;
}
#start-collection { padding-inline: 12px; background: #f5efff; color: #382278; }
#start-collection .icon, #export .icon { width: 18px; height: 18px; }
#start-collection .action-arrow { margin-left: 4px; }

.app-nav {
  align-items: end;
  padding: 7px 8px calc(9px + env(safe-area-inset-bottom));
  border-color: var(--line);
  background: var(--surface);
  box-shadow: 0 -5px 20px #39246d0b;
}
.app-nav button { color: var(--muted); gap: 4px; min-height: 55px; }
.app-nav .nav-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 30px;
  border-radius: 10px;
}
.app-nav button[aria-current=page] { color: var(--violet-dark); }
.app-nav button[aria-current=page] .nav-icon { background: var(--violet-soft); }
.app-nav .capture-tab { color: var(--violet-dark); margin-top: -22px; }
.app-nav .capture-tab .nav-icon {
  width: 59px;
  height: 51px;
  border: 2px solid var(--surface);
  border-radius: 17px;
  color: #fff;
  background: linear-gradient(145deg,#785aff,#522bcf);
  box-shadow: 0 5px 14px #5c3bdd58;
}
.app-nav .capture-tab svg { width: 25px; height: 25px; padding: 0; border: 0; border-radius: 0; background: none; color: inherit; box-shadow: none; }

.feature-preview, .settings-panel {
  border: 1px solid var(--line);
  border-radius: 19px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 4px 15px #30205408;
}
.feature-preview { display: grid; justify-items: start; gap: 10px; }
.feature-preview p { margin: 0; color: var(--muted); }
.feature-icon { display: grid; place-items: center; width: 43px; height: 43px; border-radius: 13px; background: var(--violet-soft); color: var(--violet-dark); }
.settings-panel { margin-top: 12px; }
#wallet-identity { margin: 0 0 10px; font-weight: 700; }
#wallet-note, #wallet-identity, #invite-status, #library-selection { color: var(--muted); }
#app-theme, #language, #invite-code, #invite-input { border-color: var(--line); background: var(--paper); }
#settings label { color: var(--ink); }
label[for="app-theme"] { margin-top: 16px; }
.settings-panel button, .library-toolbar button:not(.delete-action) {
  border-color: var(--accent-line);
  background: var(--violet-soft);
  color: var(--violet-dark);
  font-weight: 650;
}
.library-card { border-radius: 15px; background: var(--surface); border-color: var(--line); padding: 6px; }
.library-card-title { color: var(--ink); font-weight: 650; padding: 0 3px 2px; }
.library-card[aria-pressed=true] { border-color: var(--violet); background: var(--violet-soft); }
.library-card[aria-pressed=true]::after { background: var(--violet); }

#capture:not([hidden]), .capture-top, #library-viewer { background: var(--night); }
.capture-top { padding: calc(5px + env(safe-area-inset-top)) 14px 5px; }
.capture-title { display: flex; align-items: center; gap: 8px; }
.capture-top strong { font-size: 14px; letter-spacing: .04em; }
#capture .stage { background: radial-gradient(ellipse at 50% 35%, #49336d, #211832 65%, var(--night)); }
#capture .stage::after { border-color: #d1bcff33; }
#capture-actions { background: linear-gradient(transparent, #141024 46%); }
#capture-actions button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
#capture-actions .icon { width: 18px; height: 18px; }
.import-icon { transform: rotate(180deg); }
#capture-actions #camera-action { background: #f4edff; color: #382278; border-color: #f4edff; }
#capture-actions .upload { background: #28203e; color: #f0e8ff; border-color: #68578b; }
#capture-actions #discard-pack { background: #28203e; border-color: #68578b; }
#reveal, #export { background: var(--violet); border-color: var(--violet); color: white; box-shadow: none; }
.pack-emblem img { display: block; margin-inline: auto; border-radius: 15px; box-shadow: 0 0 21px #d5beff55; }
.pack-wrap strong { letter-spacing: -.04em; }
#card-details { background: var(--surface); border-color: var(--line); color: var(--ink); }
#card-details::backdrop, #library-viewer::backdrop { background: #151022b8; }
.stats div { background: var(--violet-soft); }
.stats dt, .ability { color: var(--muted); }
.viewer-top button, #card-details form button, #capture-close, #card-info {
  display: grid;
  place-items: center;
  min-width: 44px;
  padding: 0;
  border-radius: 12px;
}
.viewer-top button { background: #28203e; border-color: #68578b; }
#card-details form button { background: var(--violet-soft); border-color: var(--line); }

:root[data-theme="dark"] .point-chip { background: #3c2a1a; border-color: #644a30; color: #ffe0a3; }
:root[data-theme="dark"] .delete-action { background: #3c2332; border-color: #694052; color: #ffc4cc; }

button:hover { filter: none; }
@media (hover: hover) {
  .app-nav button:hover .nav-icon, .library-card:hover { background-color: var(--violet-soft); }
  .collection-hero button:hover { background: #e7dcff; }
  #reveal:not(:disabled):hover, #export:hover { background: #4828ba; }
}
button:focus-visible, input:focus-visible, select:focus-visible, #card:focus-visible { outline: 2px solid #8b6bf5; outline-offset: 2px; }
@media (max-width: 360px) {
  body > header, .app-heading, #collection, #market, #battle, #settings { padding-inline: 14px; }
  .app-nav { grid-template-columns: repeat(2,minmax(0,1fr)) 62px repeat(2,minmax(0,1fr)); }
  .app-nav button { font-size: 11px; }
}
