:root {
  font-family: ui-rounded, "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  color: #f8f5ff;
  background: #120b2b;
  --panel: #1c1240;
  --panel-2: #241854;
  --line: #4a3887;
  --cyan: #38e8ff;
  --pink: #ff5db1;
  --yellow: #ffd93d;
  --green: #5cff9d;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background:
    radial-gradient(circle at 12% 8%, rgba(139, 92, 246, .35), transparent 42%),
    radial-gradient(circle at 88% 12%, rgba(255, 93, 177, .25), transparent 38%),
    radial-gradient(circle at 50% 100%, rgba(56, 232, 255, .18), transparent 45%),
    #120b2b;
  min-height: 100dvh;
  overscroll-behavior: none;
  overflow-x: hidden;
}
main { min-height: 100dvh; }
button { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 3px solid var(--yellow);
  outline-offset: 2px;
}
.screen { display: none; }
.screen.active { display: flex; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.hidden { display: none !important; }

/* Title */
#screen-title {
  min-height: 100dvh;
  align-items: center;
  justify-content: center;
  padding: calc(18px + env(safe-area-inset-top)) 18px calc(18px + env(safe-area-inset-bottom));
  text-align: center;
}
.title-card {
  width: min(560px, 100%);
  background: rgba(28, 18, 64, .8);
  border: 2px solid var(--line);
  border-radius: 30px;
  padding: 18px 20px 24px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .45);
}
#title-art { display: block; width: 100%; height: auto; border-radius: 22px; margin-bottom: 6px; }
h1 {
  margin: 4px 0 6px;
  font-size: clamp(2.4rem, 9vw, 3.8rem);
  line-height: .95;
  letter-spacing: -.02em;
  background: linear-gradient(180deg, #fff 20%, var(--yellow) 75%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 0 rgba(0, 0, 0, .35));
}
.tagline { margin: 0 auto 18px; max-width: 40ch; color: #d6cdf6; font-size: .98rem; }
.big {
  font-size: 1.05rem;
  font-weight: 800;
  padding: 14px 26px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #fff 0%, var(--yellow) 60%);
  color: #2a1a00;
  cursor: pointer;
  box-shadow: 0 6px 0 #b8860b, 0 12px 24px rgba(0, 0, 0, .35);
  transition: transform .08s, box-shadow .08s;
}
.big:active { transform: translateY(4px); box-shadow: 0 2px 0 #b8860b; }
.big.ghost { background: transparent; color: #f8f5ff; border: 2px solid var(--line); box-shadow: none; }
.how-to { margin-top: 18px; text-align: left; color: #cfc6f0; font-size: .88rem; }
.how-to summary { cursor: pointer; color: var(--cyan); font-weight: 700; }
.how-to p { margin: 8px 0; }

/* Builder */
#screen-builder {
  flex-direction: column;
  gap: 12px;
  width: min(1200px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 12px calc(14px + env(safe-area-inset-bottom));
}
.build-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.badge {
  display: inline-block;
  padding: 6px 16px;
  border-radius: 999px;
  background: var(--yellow);
  color: #2a1a00;
  font-weight: 900;
  letter-spacing: .02em;
}
.name-label { display: flex; align-items: center; gap: 8px; font-size: .78rem; color: #c9bff0; }
.name-label input {
  font: inherit;
  font-weight: 700;
  color: #fff;
  background: #0e0822;
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
  width: 11em;
}
.build-layout {
  display: grid;
  min-width: 0;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 14px;
  flex: 1;
  min-height: 0;
}
.build-layout > * { min-width: 0; }
.preview-panel, .options-panel {
  background: rgba(28, 18, 64, .86);
  border: 2px solid var(--line);
  border-radius: 24px;
  padding: 12px;
}
.preview-panel { display: flex; flex-direction: column; gap: 10px; }
#preview { display: block; width: 100%; height: auto; max-height: 46vh; object-fit: contain; border-radius: 18px; background: #0d1730; }
.stats { display: flex; flex-direction: column; gap: 7px; }
.stat { display: grid; grid-template-columns: 52px 1fr 34px; gap: 8px; align-items: center; font-size: .74rem; color: #cfc6f0; }
.stat b { text-align: right; color: #fff; font-size: .78rem; }
.stat-bar { height: 10px; border-radius: 999px; background: #0d0820; overflow: hidden; border: 1px solid rgba(255, 255, 255, .08); }
.stat-bar > div { height: 100%; width: 50%; border-radius: inherit; transition: width .2s ease; }
#stat-hp { background: linear-gradient(90deg, #22c55e, #86efac); }
#stat-pow { background: linear-gradient(90deg, #ef4444, #fca5a5); }
#stat-spd { background: linear-gradient(90deg, #06b6d4, #67e8f9); }
.preview-actions { display: flex; gap: 8px; margin-top: auto; }
.small {
  flex: 1;
  padding: 10px;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 700;
  font-size: .8rem;
  background: var(--panel-2);
  border: 2px solid var(--line);
}
.small.ghost { background: transparent; }
.options-panel { display: flex; flex-direction: column; gap: 8px; min-height: 0; min-width: 0; overflow: hidden; }
.tabs { display: flex; gap: 6px; overflow-x: auto; max-width: 100%; padding-bottom: 4px; scrollbar-width: thin; }
.tab {
  flex: 0 0 auto;
  min-width: 64px;
  padding: 7px 9px;
  border-radius: 12px;
  border: 2px solid var(--line);
  background: #150e31;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  font-size: .68rem;
  font-weight: 700;
  color: #cfc6f0;
}
.tab .tab-icon { font-size: 1.15rem; line-height: 1.1; }
.tab[aria-selected="true"] { background: var(--yellow); border-color: var(--yellow); color: #2a1a00; }
.hint { margin: 0; font-size: .78rem; color: #b9addd; min-height: 1.2em; }
.options {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(78px, 1fr));
  gap: 8px;
  align-content: start;
  overflow-y: auto;
  padding: 2px;
  min-height: 0;
}
.option {
  min-height: 76px;
  padding: 8px 4px;
  border-radius: 14px;
  border: 2px solid transparent;
  background: #150e31;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.option .icon { font-size: 1.55rem; line-height: 1; }
.option .label { font-size: .67rem; color: #cfc6f0; line-height: 1.1; }
.option[aria-pressed="true"] { border-color: var(--cyan); background: #103349; box-shadow: 0 0 0 3px rgba(56, 232, 255, .15); }
.option[aria-pressed="true"] .label { color: #fff; font-weight: 700; }
.swatch { width: 32px; height: 32px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .55); box-shadow: inset 0 -6px 10px rgba(0, 0, 0, .3); }
.ready { align-self: center; margin-top: 2px; min-width: min(360px, 90%); }

@media (min-width: 761px) {
  .tabs { flex-wrap: wrap; overflow: visible; }
}

/* Handover */
#screen-handover { min-height: 100dvh; align-items: center; justify-content: center; padding: 20px; text-align: center; }
.handover-card {
  width: min(460px, 100%);
  background: rgba(28, 18, 64, .9);
  border: 2px solid var(--line);
  border-radius: 28px;
  padding: 28px 22px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .45);
}
.handover-card h2 { font-size: 1.9rem; margin: 14px 0 8px; }
.handover-card p { color: #cfc6f0; margin: 0 0 20px; }

/* Fight */
#screen-fight {
  flex-direction: column;
  gap: 6px;
  height: 100dvh;
  padding: calc(8px + env(safe-area-inset-top)) 8px calc(8px + env(safe-area-inset-bottom));
  overflow: hidden;
}
.hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  align-items: center;
  width: min(1100px, 100%);
  margin: 0 auto;
}
.hud-side { min-width: 0; }
.hud-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: .76rem; font-weight: 800; margin-bottom: 4px; }
.hud-top span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p1 .hud-top span:first-child { color: var(--cyan); }
.p2 .hud-top span:first-child { color: var(--pink); }
.bar { height: 11px; border-radius: 999px; background: #0b0719; overflow: hidden; border: 1px solid rgba(255, 255, 255, .09); }
.bar .fill { height: 100%; width: 100%; border-radius: inherit; transition: width .15s ease; }
.hp-bar .fill { background: linear-gradient(90deg, #22c55e, #86efac); }
.special-bar { height: 6px; margin-top: 4px; }
.p1 .special-bar .fill { background: linear-gradient(90deg, #0891b2, var(--cyan)); }
.p2 .special-bar .fill { background: linear-gradient(90deg, #be185d, var(--pink)); }
.timer {
  font-size: 1.35rem;
  font-weight: 900;
  color: var(--yellow);
  background: #0b0719;
  border: 1px solid rgba(255, 255, 255, .1);
  border-radius: 12px;
  padding: 4px 10px;
  min-width: 54px;
  text-align: center;
}
.timer.low { color: #ff6b6b; animation: pulse .5s infinite alternate; }
@keyframes pulse { to { transform: scale(1.12); } }
.arena-wrap { flex: 1; min-height: 0; width: 100%; display: flex; align-items: center; justify-content: center; }
#arena {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 1100px;
  border-radius: 20px;
  touch-action: none;
}
.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: min(1100px, 100%); margin: 0 auto; }
.control-side { padding: 5px 6px 7px; border-radius: 16px; background: rgba(28, 18, 64, .75); border: 2px solid var(--line); }
.control-side.p1 { border-color: rgba(56, 232, 255, .45); }
.control-side.p2 { border-color: rgba(255, 93, 177, .45); }
.control-name { display: block; text-align: center; font-size: .62rem; letter-spacing: .04em; color: #b9addd; margin-bottom: 4px; text-transform: uppercase; }
.buttons { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.fight-btn {
  min-height: 54px;
  border: 0;
  border-radius: 13px;
  padding: 6px 4px;
  font-weight: 900;
  font-size: .8rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  cursor: pointer;
  user-select: none;
  touch-action: none;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .25);
  transition: transform .06s;
}
.fight-btn small { font-size: .58rem; opacity: .65; font-weight: 700; }
.fight-btn:active { transform: translateY(2px); }
.fight-btn.attack { background: linear-gradient(180deg, #ff8a8a, #e11d48); color: #fff; }
.fight-btn.guard { background: linear-gradient(180deg, #93c5fd, #2563eb); color: #fff; }
.fight-btn.zap { background: linear-gradient(180deg, #d8b4fe, #7c3aed); color: #fff; }
.fight-btn.zap:disabled { opacity: .48; filter: grayscale(.4); cursor: not-allowed; }
.fight-btn.special { background: linear-gradient(180deg, #fef08a, #eab308); color: #3a2a00; }
.fight-btn.special:disabled { opacity: .38; filter: grayscale(.7); cursor: not-allowed; }
@media (max-width: 430px) {
  .fight-btn { font-size: .72rem; }
  .fight-btn small { font-size: .55rem; }
}
.fight-btn.ready-glow { animation: glow .5s infinite alternate; }
@keyframes glow { to { box-shadow: 0 0 18px 4px rgba(255, 217, 61, .75), inset 0 -4px 0 rgba(0, 0, 0, .25); } }
.result {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(7, 4, 18, .72);
  backdrop-filter: blur(6px);
}
.result-card {
  width: min(440px, 100%);
  padding: 28px 22px;
  border-radius: 28px;
  text-align: center;
  background: rgba(36, 24, 84, .98);
  border: 2px solid var(--line);
  box-shadow: 0 24px 70px rgba(0, 0, 0, .55);
}
.result-card h2 { margin: 0 0 8px; font-size: 2rem; color: var(--yellow); }
.result-card p { color: #d6cdf6; margin: 0 0 20px; }
.result-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.result-actions .big { font-size: .95rem; padding: 12px 20px; }

@media (max-width: 760px) {
  .build-layout { grid-template-columns: 1fr; }
  .preview-panel {
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(118px, .9fr);
    grid-template-areas: "preview stats" "actions actions";
    align-items: center;
    padding: 10px;
  }
  #preview { grid-area: preview; width: 100%; height: 30vh; max-height: 30vh; object-fit: contain; }
  .stats { grid-area: stats; }
  .preview-actions { grid-area: actions; }
  .options { max-height: 42vh; }
  .stat { font-size: .68rem; grid-template-columns: 44px 1fr 28px; gap: 6px; }
  .stat b { font-size: .72rem; }
  .ready {
    position: sticky;
    bottom: calc(8px + env(safe-area-inset-bottom));
    z-index: 5;
    width: 100%;
  }
}
@media (max-height: 560px) and (orientation: landscape) {
  #screen-title { padding: 8px; }
  .title-card { display: grid; grid-template-columns: 180px 1fr; align-items: center; gap: 10px 16px; width: min(720px, 100%); padding: 10px 16px; }
  #title-art { grid-row: span 3; margin: 0; }
  h1 { font-size: 2rem; margin: 0; }
  .tagline { margin: 0; font-size: .82rem; }
  .title-card .big { justify-self: start; padding: 10px 18px; font-size: .9rem; }
  .how-to { grid-column: 1 / -1; margin-top: 4px; font-size: .8rem; }
  .control-name { display: none; }
  .fight-btn { min-height: 44px; font-size: .74rem; }
  .fight-btn small { display: none; }
  .hud-top { font-size: .68rem; }
  .timer { font-size: 1rem; padding: 2px 8px; min-width: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
