* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0c0812;
  font-family: 'Segoe UI', system-ui, sans-serif;
  color: #f3ead6;
  user-select: none;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
}

#battle-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* ---------- top bar ---------- */

.topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: linear-gradient(to bottom, rgba(10, 6, 14, 0.85), rgba(10, 6, 14, 0));
  pointer-events: none;
}

.topbar__brand {
  display: flex;
  flex-direction: column;
}

.topbar__title {
  font-size: 20px;
  font-weight: 900;
  letter-spacing: 0.24em;
  background: linear-gradient(180deg, #ffe9b0, #c9973f);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 2px 12px rgba(240, 183, 87, 0.25);
}

.topbar__subtitle {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #b9a684;
}

.topbar__wave {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: #ffe9b0;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.8);
}

.topbar__controls {
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.chip {
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid rgba(240, 183, 87, 0.55);
  background: linear-gradient(180deg, rgba(44, 32, 18, 0.92), rgba(24, 16, 10, 0.92));
  color: #ffe9b0;
  font: 800 13px system-ui;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 233, 176, 0.25);
}

.chip.is-active {
  background: linear-gradient(180deg, #f0b757, #b07a24);
  color: #241505;
}

/* Icon-only chip (sound toggle): narrower padding, larger emoji. */
.chip--icon {
  padding: 8px 10px;
  font-size: 15px;
  min-width: 38px;
  text-align: center;
}

/* ---------- ult hint ---------- */

.ult-hint {
  position: absolute;
  left: 50%;
  bottom: 132px;
  transform: translateX(-50%);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: rgba(243, 234, 214, 0.72);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.9);
  pointer-events: none;
  transition: opacity 0.6s;
}

.ult-hint.is-hidden {
  opacity: 0;
}

/* ---------- portrait bar (the one input) ---------- */

.portraits {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  display: flex;
  gap: 14px;
  padding: 10px 18px 8px;
  border-radius: 18px;
  border: 1px solid rgba(240, 183, 87, 0.35);
  background: linear-gradient(180deg, rgba(26, 18, 30, 0.88), rgba(12, 8, 16, 0.92));
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 233, 176, 0.12);
}

.portrait {
  position: relative;
  width: 76px;
  border: none;
  background: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 0;
}

.portrait__ring {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  padding: 3px;
  background: conic-gradient(var(--energy-color, #f0b757) calc(var(--energy) * 1turn), rgba(255, 255, 255, 0.1) 0turn);
  transition: filter 0.2s;
}

.portrait__frame {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid var(--faction-color, #7a5c22);
  background: radial-gradient(circle at 50% 30%, #241a2e, #0e0a14);
}

.portrait__frame canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.portrait__hp {
  width: 62px;
  height: 5px;
  border-radius: 3px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.portrait__hp span {
  display: block;
  height: 100%;
  width: calc(var(--hp) * 100%);
  background: linear-gradient(90deg, #8fe3a2, #3f9c58);
  transition: width 0.25s;
}

.portrait__name {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #d8c9a6;
  white-space: nowrap;
}

.portrait.is-ready .portrait__ring {
  animation: ult-pulse 1.1s ease-in-out infinite;
  filter: drop-shadow(0 0 10px rgba(255, 233, 176, 0.8));
}

.portrait.is-dead {
  filter: grayscale(1) brightness(0.55);
}

.portrait.is-dead .portrait__ring {
  animation: none;
  filter: none;
}

@keyframes ult-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.07); }
}

/* ---------- result ---------- */

.result {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(6, 4, 10, 0.66);
  backdrop-filter: blur(3px);
}

.result__panel {
  min-width: 300px;
  padding: 30px 40px 28px;
  text-align: center;
  border-radius: 20px;
  border: 1px solid rgba(240, 183, 87, 0.5);
  background:
    radial-gradient(circle at 50% 0%, rgba(240, 183, 87, 0.14), transparent 60%),
    linear-gradient(180deg, #241a2e, #120c18);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.7), inset 0 1px 0 rgba(255, 233, 176, 0.2);
}

.result__title {
  font-size: 26px;
  font-weight: 900;
  letter-spacing: 0.04em;
  background: linear-gradient(180deg, #ffe9b0, #c9973f);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.result__stars {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 16px 0 10px;
  font-size: 34px;
}

.result__stars .star {
  color: #4a4038;
  transform: scale(0.6);
  opacity: 0;
}

.result__stars .star.is-earned {
  color: #ffd253;
  text-shadow: 0 0 16px rgba(255, 210, 83, 0.65);
  animation: star-pop 0.45s cubic-bezier(0.2, 1.6, 0.4, 1) forwards;
}

.result__stars .star.is-empty {
  opacity: 1;
  transform: scale(1);
}

@keyframes star-pop {
  from { transform: scale(0.3); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.result__sub {
  font-size: 13px;
  color: #b9a684;
  margin-bottom: 20px;
}

.result__button {
  padding: 12px 34px;
  border-radius: 999px;
  border: none;
  background: linear-gradient(180deg, #f0b757, #b07a24);
  color: #241505;
  font: 900 15px system-ui;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(240, 183, 87, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.result__button:hover {
  filter: brightness(1.08);
}

.loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: #0c0812;
  color: #b9a684;
  font-size: 15px;
  letter-spacing: 0.2em;
}

/* The hidden attribute must beat any display rule. */
.loading[hidden],
.result[hidden],
.screen[hidden],
.toast[hidden] {
  display: none;
}

/* ---------- overlay screens (map / roster) ---------- */

.screen {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: 0 16px 32px;
  background:
    radial-gradient(circle at 50% -10%, rgba(240, 183, 87, 0.08), transparent 55%),
    linear-gradient(180deg, #171021, #0c0812 65%);
}

.resourcebar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 4px 12px;
  margin-bottom: 6px;
  background: linear-gradient(180deg, rgba(12, 8, 18, 0.96) 70%, rgba(12, 8, 18, 0));
}

.resourcebar__brand {
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 0.24em;
  background: linear-gradient(180deg, #ffe9b0, #c9973f);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-right: auto;
}

.resource {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid rgba(240, 183, 87, 0.3);
  background: rgba(24, 16, 26, 0.85);
  font: 800 13px system-ui;
  color: #ffe9b0;
}

.resource__icon {
  opacity: 0.85;
}

.map-chapter h2 {
  margin: 18px 4px 10px;
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #b9a684;
}

.map-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.stage {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(240, 183, 87, 0.35);
  background: linear-gradient(180deg, rgba(44, 32, 52, 0.9), rgba(20, 14, 26, 0.95));
  color: #f3ead6;
  cursor: pointer;
  text-align: left;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 233, 176, 0.12);
  transition: transform 0.12s, border-color 0.12s;
}

.stage:hover {
  transform: translateY(-2px);
  border-color: rgba(240, 183, 87, 0.7);
}

.stage.is-locked {
  opacity: 0.38;
  cursor: default;
  filter: grayscale(0.7);
}

.stage.is-locked:hover {
  transform: none;
}

.stage__id {
  font: 900 16px system-ui;
  color: #ffe9b0;
}

.stage__stars {
  font-size: 13px;
  color: #ffd253;
}

.stage__stars .dim {
  color: #4a4038;
}

.stage__minde {
  font-size: 11px;
  font-weight: 700;
  color: #8fd8e8;
}

.stage__cost {
  font-size: 11px;
  font-weight: 800;
  color: #b9a684;
}

/* ---------- roster ---------- */

.roster-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
}

.hero-card {
  display: flex;
  gap: 10px;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid var(--faction-color, rgba(240, 183, 87, 0.4));
  background:
    radial-gradient(circle at 20% 0%, rgba(240, 183, 87, 0.1), transparent 60%),
    linear-gradient(180deg, rgba(40, 28, 48, 0.92), rgba(18, 12, 24, 0.96));
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 233, 176, 0.12);
}

.hero-card.is-locked {
  filter: saturate(0.35) brightness(0.8);
  border-color: rgba(150, 150, 160, 0.3);
}

.hero-card__art {
  width: 75px;
  height: 100px;
  flex: none;
  border-radius: 10px;
  background: radial-gradient(circle at 50% 20%, #2a1e36, #120c18);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.hero-card__body {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.hero-card__name {
  font: 900 14px system-ui;
  color: #ffe9b0;
}

.hero-card__meta {
  font: 700 11px system-ui;
  color: #b9a684;
}

.hero-card__button {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 12px;
  border-radius: 10px;
  border: none;
  background: linear-gradient(180deg, #f0b757, #b07a24);
  color: #241505;
  font: 900 12px system-ui;
  cursor: pointer;
}

.hero-card__button small {
  font: 700 10px system-ui;
  opacity: 0.85;
}

.hero-card__button:disabled {
  filter: grayscale(0.8) brightness(0.7);
  cursor: default;
}

.minde-bar {
  height: 7px;
  border-radius: 4px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(143, 216, 232, 0.35);
}

.minde-bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #8fd8e8, #4f9cb0);
}

/* ---------- toast + result loot ---------- */

.toast {
  position: absolute;
  left: 50%;
  top: 68px;
  transform: translateX(-50%);
  z-index: 5;
  padding: 10px 22px;
  border-radius: 999px;
  border: 1px solid rgba(240, 183, 87, 0.5);
  background: rgba(24, 16, 12, 0.94);
  color: #ffe9b0;
  font: 800 13px system-ui;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
}

.result__loot {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

.result__loot-row {
  font: 800 14px system-ui;
  color: #f3ead6;
}

/* ---------- team picker ---------- */

.picker__panel {
  max-width: min(560px, 94vw);
  max-height: 86vh;
  overflow-y: auto;
}

.picker__slots {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 14px 0 10px;
}

.picker-slot {
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  border-radius: 14px;
  border: 2px dashed rgba(240, 183, 87, 0.35);
  color: #8a7a5e;
  font: 800 10px system-ui;
  overflow: hidden;
}

.picker-slot.is-front {
  border-color: rgba(240, 183, 87, 0.7);
  box-shadow: inset 0 0 12px rgba(240, 183, 87, 0.15);
}

.picker__auras {
  display: flex;
  justify-content: center;
  gap: 8px;
  min-height: 26px;
  margin-bottom: 10px;
}

.aura-badge {
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--faction-color);
  color: var(--faction-color);
  font: 800 11px system-ui;
  background: rgba(12, 8, 16, 0.8);
}

.picker__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.picker-hero {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(24, 16, 26, 0.85);
  color: #d8c9a6;
  font: 700 12px system-ui;
  cursor: pointer;
  text-align: left;
}

.picker-hero.is-picked {
  border-color: var(--faction-color);
  background: rgba(240, 183, 87, 0.12);
  color: #ffe9b0;
}

.portrait-mini {
  border-radius: 10px;
  flex: none;
  background: radial-gradient(circle at 50% 30%, #241a2e, #0e0a14);
}

.picker__actions {
  display: flex;
  justify-content: center;
  gap: 12px;
}

.hero-card__stars {
  font-size: 13px;
  color: #ffd253;
  letter-spacing: 2px;
}

.hero-card__stars .dim {
  color: #4a4038;
}

.hero-card__button--promote {
  background: linear-gradient(180deg, #8fd8e8, #4f8ba0);
  color: #0a1c22;
}

.result__awakened {
  margin-top: 8px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid rgba(143, 216, 232, 0.6);
  background: rgba(143, 216, 232, 0.12);
  color: #bff2ea;
  font: 900 14px system-ui;
  animation: star-pop 0.5s cubic-bezier(0.2, 1.6, 0.4, 1);
}

@media (max-width: 560px) {
  .portraits { gap: 8px; padding: 8px 10px 6px; }
  .portrait { width: 60px; }
  .portrait__ring { width: 52px; height: 52px; }
  .portrait__hp { width: 50px; }
  .portrait__name { font-size: 9px; }
  .topbar__title { font-size: 16px; }
}
