:root {
  color-scheme: dark;
  --ink: #080b0f;
  --panel: #11161b;
  --panel-2: #171d22;
  --gold: #d7aa56;
  --gold-soft: #8e6c34;
  --ivory: #f4ead5;
  --muted: #8f9aa2;
  --green: #5fc78a;
  --red: #d36b62;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--ink);
  color: var(--ivory);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button { font: inherit; }

button, .item-card { touch-action: manipulation; }

.app-shell.boot-pending { visibility: hidden; }

.boot-screen {
  position: fixed;
  z-index: 100;
  inset: 0;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 420px);
  align-content: center;
  justify-content: center;
  padding: calc(28px + var(--safe-top)) 30px calc(28px + var(--safe-bottom));
  overflow: hidden;
  text-align: center;
  background:
    radial-gradient(circle at 50% 43%, rgba(190, 126, 45, .20), transparent 25%),
    radial-gradient(circle at 50% 115%, rgba(64, 102, 116, .25), transparent 44%),
    repeating-linear-gradient(0deg, transparent 0 39px, rgba(166, 194, 206, .025) 40px),
    repeating-linear-gradient(90deg, transparent 0 39px, rgba(166, 194, 206, .025) 40px),
    #080b0f;
  opacity: 1;
  transition: opacity .42s ease, visibility .42s ease;
}

.boot-screen::before,
.boot-screen::after {
  content: "";
  position: absolute;
  pointer-events: none;
  border: 1px solid rgba(215, 170, 86, .25);
  border-radius: 28px;
}
.boot-screen::before { inset: 13px; }
.boot-screen::after { inset: 19px; border-color: rgba(255, 224, 165, .06); }
.boot-screen.complete { opacity: 0; visibility: hidden; }

.boot-crest {
  width: 106px;
  height: 118px;
  margin: 0 auto 18px;
  display: grid;
  place-items: center;
  clip-path: polygon(50% 0, 93% 15%, 88% 72%, 50% 100%, 12% 72%, 7% 15%);
  background: linear-gradient(145deg, #c99748, #563817 48%, #17120d 80%);
  filter: drop-shadow(0 14px 24px #000c);
  animation: crest-float 2.4s ease-in-out infinite;
}
.boot-crest::before {
  content: "";
  position: absolute;
  width: 90px;
  height: 100px;
  clip-path: inherit;
  background: radial-gradient(circle at 50% 28%, #5d4525, #171511 58%, #080a0c);
}
.boot-crest span { position: relative; z-index: 1; color: #f2cd7b; font: 800 56px/1 Georgia, serif; text-shadow: 0 2px #27190a, 0 0 18px #d69b3c55; }
@keyframes crest-float { 50% { transform: translateY(-4px); filter: drop-shadow(0 18px 28px #000d); } }

.boot-eyebrow { color: var(--gold); font-size: 10px; font-weight: 900; letter-spacing: .32em; }
.boot-screen h1 { margin: 7px 0 8px; color: #f4e6ca; font: 700 clamp(23px, 7vw, 32px)/1.1 Georgia, serif; }
.boot-status { min-height: 18px; margin: 0 0 18px; color: #aeb8bd; font-size: 12px; }
.boot-track { height: 10px; padding: 2px; overflow: hidden; border: 1px solid #74552c; border-radius: 999px; background: #06080a; box-shadow: inset 0 2px 5px #000, 0 0 18px #bd813322; }
.boot-track span { display: block; width: 0%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #885722, #e2b75f 64%, #ffe4a3); box-shadow: 0 0 12px #e0a54599; transition: width .18s ease-out; }
.boot-numbers { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; margin-top: 8px; color: #77858d; font-size: 10px; }
.boot-numbers strong { color: #edcf91; font: 700 14px/1 Georgia, serif; }
.boot-retry { justify-self: center; margin-top: 20px; padding: 10px 18px; border: 1px solid #9a7138; border-radius: 10px; color: #f4dfb7; background: linear-gradient(#3b2918, #17120d); }

.app-shell {
  width: min(100%, 1040px);
  height: 100dvh;
  margin: 0 auto;
  padding-top: var(--safe-top);
  display: grid;
  grid-template-rows: 64px minmax(390px, 55%) 1fr;
  background:
    radial-gradient(circle at 50% 23%, rgba(141, 93, 34, .18), transparent 32%),
    linear-gradient(180deg, #0e1217 0%, #080b0f 100%);
  border-inline: 1px solid rgba(215, 170, 86, .12);
}

.topbar {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(215, 170, 86, .25);
  background: rgba(7, 10, 13, .86);
  backdrop-filter: blur(18px);
  z-index: 4;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid #9a7138;
  border-radius: 12px 12px 16px 16px;
  color: #f3cc76;
  font: 800 23px/1 Georgia, serif;
  background: linear-gradient(145deg, #3d2b16, #12100d 68%);
  box-shadow: inset 0 0 0 2px #17120b, 0 4px 14px #0009;
}

.brand-copy { min-width: 0; flex: 1; }
.brand-copy h1 { margin: 0; font: 700 18px/1 Georgia, serif; letter-spacing: .02em; }
.brand-copy h1 span { color: var(--gold); font-size: 12px; }
.fighter-meta { margin-top: 2px; color: #8999a5; font-size: 8.5px; font-weight: 700; }
.eyebrow, .caption-label { color: var(--gold); font-size: 9px; font-weight: 800; letter-spacing: .16em; }

.round-button,
.quiet-button {
  border: 1px solid rgba(215, 170, 86, .38);
  color: var(--ivory);
  background: linear-gradient(180deg, #25231e, #141619);
  box-shadow: inset 0 1px rgba(255,255,255,.06), 0 3px 8px #0006;
}

.round-button {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: 50%;
  font-size: 18px;
}

.round-button.active { color: #ffdc87; border-color: #d4a34d; box-shadow: 0 0 15px #c58b3844, inset 0 1px #fff2; }
.round-button:active, .quiet-button:active, .appearance-chip:active, .category-tab:active, .item-card:active { transform: scale(.96); }

.hero-panel {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border-bottom: 1px solid rgba(215, 170, 86, .28);
  background:
    linear-gradient(rgba(29, 42, 50, .72), rgba(10, 14, 17, .86)),
    repeating-linear-gradient(0deg, transparent 0 39px, rgba(161, 195, 210, .055) 40px),
    repeating-linear-gradient(90deg, transparent 0 39px, rgba(161, 195, 210, .055) 40px),
    #17232c;
}

.hero-panel::before,
.hero-panel::after {
  content: "";
  position: absolute;
  z-index: 1;
  pointer-events: none;
  inset: 6px;
  border: 1px solid rgba(198, 146, 65, .32);
  border-radius: 18px;
}

.hero-panel::after { inset: 10px; border-color: rgba(255, 219, 144, .08); }
.hero-glow { position: absolute; left: 25%; right: 25%; bottom: -22%; height: 62%; background: radial-gradient(ellipse, rgba(202, 142, 57, .24), transparent 68%); filter: blur(14px); }

.category-tabs::-webkit-scrollbar { display: none; }

.fighter-stage {
  position: absolute;
  inset: 10px 0 94px;
  z-index: 2;
  display: grid;
  place-items: center;
  pointer-events: none;
}

#fighterCanvas {
  display: block;
  width: 92%;
  height: 92%;
  object-fit: contain;
  filter: drop-shadow(0 12px 13px rgba(0, 0, 0, .78));
  transform-origin: 50% 86%;
  animation: duelion-breathe 2.2s ease-in-out infinite;
}

@keyframes duelion-breathe {
  0%, 100% { transform: translateY(-12px) scale(1); }
  50% { transform: translateY(-13.8px) scale(1.0025); }
}

.stage-loader {
  position: absolute;
  left: 50%;
  bottom: 5px;
  translate: -50% 0;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 9px;
  border: 1px solid #8a6533;
  border-radius: 999px;
  background: #0c1115dd;
  color: #d9c7a5;
  font-size: 10px;
  opacity: 0;
  transition: opacity .15s ease;
}
.stage-loader.visible { opacity: 1; }
.stage-loader span { width: 7px; height: 7px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 8px var(--gold); animation: pulse .8s ease-in-out infinite alternate; }
@keyframes pulse { to { opacity: .35; transform: scale(.7); } }

.fighter-caption {
  position: absolute;
  z-index: 3;
  left: 19px;
  right: 19px;
  bottom: 51px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
}
.fighter-caption strong { display: block; max-width: 230px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 700 15px/1.2 Georgia, serif; }
.quiet-button { border-radius: 9px; padding: 7px 11px; color: #d8c9ac; font-size: 11px; }

.quick-stats {
  position: absolute;
  z-index: 3;
  left: 16px;
  right: 16px;
  bottom: 8px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}
.quick-stat { min-width: 0; padding: 5px 8px; border: 1px solid rgba(215,170,86,.23); border-radius: 8px; background: rgba(8, 12, 15, .82); }
.quick-stat span { display: block; color: #86939b; font-size: 8px; letter-spacing: .08em; }
.quick-stat strong { display: block; margin-top: 1px; color: #f4e4c4; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.inventory-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: 45px 48px 1fr;
  background: linear-gradient(180deg, #11161b, #090c0f);
}
.inventory-heading { display: flex; align-items: center; justify-content: space-between; padding: 7px 14px 3px; }
.inventory-heading strong { display: block; font: 700 15px/1.15 Georgia, serif; }
.item-count { min-width: 29px; padding: 4px 7px; border-radius: 999px; color: #c3ad86; background: #1f211e; border: 1px solid #4f432e; text-align: center; font-size: 11px; }

.category-tabs { display: flex; gap: 7px; overflow-x: auto; padding: 5px 12px 8px; scrollbar-width: none; }
.category-tab { flex: 0 0 auto; min-width: 64px; height: 34px; padding: 0 12px; border: 1px solid #3d3b33; border-radius: 10px; color: #929ca3; background: linear-gradient(180deg, #1a2024, #101417); font-size: 11px; font-weight: 700; transition: .15s ease; }
.category-tab.selected { color: #ffe2a0; border-color: #b17c36; background: linear-gradient(180deg, #44301a, #21170e); box-shadow: inset 0 1px #f3c66c22, 0 0 12px #9e6c2b22; }

.item-grid {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-auto-rows: 102px;
  align-content: start;
  gap: 8px;
  padding: 7px 12px calc(18px + var(--safe-bottom));
}

.item-card {
  position: relative;
  min-width: 0;
  width: 100%;
  height: 100%;
  padding: 5px;
  border: 1px solid #353b3d;
  border-radius: 12px;
  color: #d9d9d1;
  background: radial-gradient(circle at 50% 32%, #2a3032, #111519 72%);
  box-shadow: inset 0 1px rgba(255,255,255,.035), 0 3px 10px #0005;
  overflow: hidden;
  transition: transform .1s ease, border-color .15s ease, background .15s ease;
}
.item-card[data-rarity="uncommon"] { border-color: #40644c; }
.item-card[data-rarity="rare"] { border-color: #3b5f83; }
.item-card[data-rarity="epic"] { border-color: #775085; }
.item-card[data-rarity="legendary"] { border-color: #9b6b2e; }
.item-card.equipped { border-color: #5ac184; background: radial-gradient(circle at 50% 32%, #264536, #111a17 72%); box-shadow: 0 0 0 1px #193626, 0 0 14px #2e9f5a33; }
.item-card img { width: 100%; height: calc(100% - 25px); object-fit: contain; filter: drop-shadow(0 4px 4px #0009); }
.item-card .item-name { display: block; height: 23px; overflow: hidden; color: #cfd4d2; font-size: 9px; line-height: 11px; text-align: center; }
.item-card .level { position: absolute; top: 5px; left: 5px; min-width: 19px; padding: 2px 4px; border-radius: 6px; background: #080b0ddd; color: #d7bd87; font-size: 8px; font-weight: 800; }
.item-card .check { position: absolute; top: 5px; right: 5px; display: none; width: 18px; height: 18px; place-items: center; border-radius: 50%; background: #308454; color: white; font-size: 11px; }
.item-card.equipped .check { display: grid; }

.sheet { position: fixed; z-index: 20; inset: 0; pointer-events: none; visibility: hidden; }
.sheet.open { pointer-events: auto; visibility: visible; }
.sheet-backdrop { position: absolute; inset: 0; width: 100%; border: 0; background: rgba(0,0,0,.63); opacity: 0; transition: opacity .2s ease; }
.sheet.open .sheet-backdrop { opacity: 1; }
.sheet-card { position: absolute; left: 50%; bottom: 0; width: min(100%, 560px); max-height: min(72dvh, 650px); padding: 8px 18px calc(18px + var(--safe-bottom)); border: 1px solid #806034; border-bottom: 0; border-radius: 22px 22px 0 0; background: linear-gradient(180deg, #1b2023, #0c1013); box-shadow: 0 -15px 45px #000b; transform: translate(-50%, 104%); transition: transform .24s cubic-bezier(.22,.8,.24,1); overflow-y: auto; }
.sheet.open .sheet-card { transform: translate(-50%, 0); }
.sheet-handle { width: 42px; height: 4px; margin: 0 auto 9px; border-radius: 99px; background: #7d735f; }
.sheet-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-header h2 { margin: 2px 0 0; font: 700 22px Georgia, serif; }
.stats-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat-row { display: flex; justify-content: space-between; gap: 8px; padding: 10px 11px; border: 1px solid #343a3b; border-radius: 10px; background: #111619; font-size: 12px; }
.stat-row span { color: #9da5a8; }
.stat-row strong { color: #f1d699; text-align: right; }

.item-toast { position: fixed; z-index: 30; left: 50%; bottom: calc(14px + var(--safe-bottom)); width: max-content; max-width: calc(100% - 28px); padding: 9px 13px; border: 1px solid #876635; border-radius: 999px; background: rgba(9,13,16,.95); color: #f0dfbd; font-size: 11px; box-shadow: 0 7px 25px #000b; opacity: 0; transform: translate(-50%, 10px); pointer-events: none; transition: .18s ease; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 760px) {
  .app-shell { grid-template-columns: 54% 46%; grid-template-rows: 64px 1fr; }
  .topbar { grid-column: 1 / -1; padding-inline: 18px; }
  .hero-panel { border-bottom: 0; border-right: 1px solid rgba(215,170,86,.28); }
  .inventory-panel { grid-template-rows: 55px 52px 1fr; }
  .item-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); padding: 9px 14px 20px; }
  .fighter-stage { inset: 12px 0 96px; }
  .fighter-caption { bottom: 56px; }
  .quick-stats { bottom: 12px; }
}

@media (max-height: 720px) and (max-width: 759px) {
  .app-shell { grid-template-rows: 58px minmax(315px, 50%) 1fr; }
  .topbar { padding-block: 6px; }
  .fighter-stage { inset-block: 7px 86px; }
  .fighter-caption { bottom: 48px; }
  .quick-stats { bottom: 5px; }
}

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