:root {
  --bg0: #0b1020;
  --bg1: #141a2e;
  --ink: #eef1ff;
  --muted: #9aa3c7;
  --line: rgba(255,255,255,0.12);
  --gold: #f5c542;
  --warrior: #e07a3a;
  --mage: #8b5cf6;
  --ok: #34d399;
  --bad: #f87171;
  --hp: #22c55e;
  --hp-low: #ef4444;
  --monster: #f97316;
  --card: rgba(20, 26, 46, 0.92);
  --radius: 18px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, #2a1f55 0%, transparent 55%),
    radial-gradient(ellipse 50% 40% at 100% 100%, #1a3a2a 0%, transparent 45%),
    linear-gradient(180deg, var(--bg0), var(--bg1));
  min-height: 100vh;
  line-height: 1.45;
}

a { color: var(--gold); }
button, .btn {
  font: inherit;
  cursor: pointer;
  border: 0;
  border-radius: 999px;
  min-height: 44px;
  padding: 0.55rem 1.15rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.btn-primary {
  background: linear-gradient(135deg, var(--gold), #f59e0b);
  color: #1a1205;
}
.btn-ghost {
  background: rgba(255,255,255,0.08);
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn-warrior {
  background: linear-gradient(135deg, #c2410c, var(--warrior));
  color: #fff;
  width: 100%;
}
.btn-mage {
  background: linear-gradient(135deg, #6d28d9, var(--mage));
  color: #fff;
  width: 100%;
}

.app {
  width: min(920px, calc(100% - 1.25rem));
  margin: 0 auto;
  padding: 1rem 0 2rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  color: inherit;
}
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: #1e1b4b; display: grid; place-items: center;
  border: 1px solid rgba(245,197,66,0.45);
}
.brand-mark span {
  width: 14px; height: 14px; border-radius: 50%; background: var(--gold);
}
.brand strong { display: block; font-size: 0.98rem; }
.brand em { font-style: normal; color: var(--muted); font-size: 0.78rem; }

.screen { display: none; }
.screen.active { display: block; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem 1.25rem 1.35rem;
  box-shadow: 0 18px 50px rgba(0,0,0,0.35);
  backdrop-filter: blur(8px);
}

.hero h1 {
  margin: 0 0 0.35rem;
  font-size: clamp(1.6rem, 4vw, 2.15rem);
  letter-spacing: -0.02em;
}
.hero p { margin: 0 0 1.1rem; color: var(--muted); max-width: 36rem; }

.theme-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem 0.85rem;
  margin: 0 0 1rem;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,0.04);
}
.theme-row label {
  color: var(--ink);
  font-size: 0.95rem;
}
.theme-row select {
  flex: 1 1 220px;
  min-height: 44px;
  padding: 0.45rem 0.75rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #0f1528;
  color: var(--ink);
  font: inherit;
  font-weight: 600;
}
.theme-row select:focus {
  outline: 2px solid rgba(245,197,66,0.55);
  outline-offset: 2px;
}

.class-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
  margin-bottom: 1rem;
}
@media (max-width: 640px) {
  .class-grid { grid-template-columns: 1fr; }
}
.class-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1rem;
  background: rgba(255,255,255,0.03);
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  min-height: 180px;
}
.class-card .art {
  width: min(160px, 42vw);
  height: auto;
  aspect-ratio: 1;
  object-fit: contain;
  object-position: center bottom;
  border-radius: 14px;
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--line);
  display: block;
  margin: 0 auto;
}
.class-card h2 { margin: 0; font-size: 1.2rem; }
.class-card p { margin: 0; color: var(--muted); font-size: 0.92rem; flex: 1; }

.howto ol { margin: 0.4rem 0 1rem; padding-left: 1.2rem; color: var(--muted); }
.howto li { margin: 0.3rem 0; }

.hud {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
  margin-bottom: 0.75rem;
}
@media (max-width: 640px) {
  .hud { grid-template-columns: 1fr; }
}
.hud-panel {
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.7rem 0.85rem;
}
.hud-panel-player {
  background:
    linear-gradient(180deg, rgba(8,10,18,0.5), rgba(8,10,18,0.7)),
    url("../assets/ui-hp-frame.png") left 8px center / auto 92% no-repeat,
    rgba(0,0,0,0.35);
  border-color: rgba(180,120,60,0.4);
  padding-left: 0.95rem;
}
.level-chip {
  display: inline-flex;
  align-items: flex-start;
  justify-content: center;
  width: 64px;
  height: 64px;
  margin: -0.4rem 0.1rem;
  background: url("../assets/ui-level-chip.png") center / contain no-repeat;
  color: var(--gold);
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: 0.02em;
  text-shadow: 0 1px 2px rgba(0,0,0,0.9);
  line-height: 1;
  padding-top: 0.7rem;
  box-sizing: border-box;
  vertical-align: middle;
}
.level-chip #hud-level { color: inherit; }
.hud-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 0.75rem;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 0.45rem;
}
.hud-meta strong { color: var(--ink); font-weight: 700; }
.bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}
.bar {
  height: 12px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  overflow: hidden;
  border: 1px solid var(--line);
}
.bar.chip-bar {
  height: 18px;
  border-radius: 6px;
  border: 2px solid rgba(160,110,50,0.55);
  background: #1a120c url("../assets/ui-hp-bar.png") center / cover no-repeat;
  background-blend-mode: luminosity;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.55);
  overflow: hidden;
}
.bar > span {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: inherit;
  transition: width 0.18s ease;
}
.bar.chip-bar > span {
  border-radius: 3px;
}
#player-hp-fill { background: linear-gradient(90deg, #16a34a, var(--hp)); }
#player-hp-fill.low { background: linear-gradient(90deg, #b91c1c, var(--hp-low)); }
#monster-hp-fill { background: linear-gradient(90deg, #ea580c, var(--monster)); }
#monster-hp-fill.low { background: linear-gradient(90deg, #9a3412, #ef4444); }


.arena {
  position: relative;
  border-radius: 16px;
  border: 1px solid var(--line);
  background-color: #0a0e1c;
  background-image:
    linear-gradient(180deg, rgba(10,14,28,0.2), rgba(10,14,28,0.55)),
    url("../assets/arena-dark.png");
  background-size: cover;
  background-position: center;
  min-height: 280px;
  margin-bottom: 0.85rem;
  overflow: hidden;
}
.arena.class-warrior { box-shadow: inset 0 0 0 1px rgba(224,122,58,0.25); }
.arena.class-mage { box-shadow: inset 0 0 0 1px rgba(139,92,246,0.28); }
.arena.shake { animation: shake 0.35s ease; }

.fighters {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: end;
  padding: 0.6rem 0.8rem 0.4rem;
  z-index: 2;
  pointer-events: none;
}
.fighter {
  display: flex;
  align-items: flex-end;
  min-height: 0;
}
.fighter.hero { justify-content: flex-start; }
.fighter.monster { justify-content: flex-end; }
.fighter img {
  max-height: 220px;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  object-position: bottom center;
  filter: drop-shadow(0 10px 16px rgba(0,0,0,0.55));
  transform-origin: bottom center;
}
.fighter.monster.boss img {
  filter: drop-shadow(0 0 16px rgba(245,197,66,0.5)) drop-shadow(0 10px 16px rgba(0,0,0,0.55));
}
.fighter.hurt { animation: hurt 0.28s ease; }
.fighter.die { animation: die 0.5s ease forwards; }
.fighter.enter { animation: enter 0.45s ease; }
.fighter.attack { animation: hero-attack 0.28s ease; }

.fx-burst {
  position: absolute;
  left: 50%;
  top: 42%;
  width: min(300px, 58%);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  opacity: 0;
  pointer-events: none;
  z-index: 3;
  mix-blend-mode: screen;
}
.fx-burst.show-slash {
  background-image: url("../assets/fx-slash.png");
  animation: fx-pop 0.38s ease;
  opacity: 1;
}
.fx-burst.show-spell {
  background-image: url("../assets/fx-spell.png");
  animation: fx-pop 0.38s ease;
  opacity: 1;
}

.combat-flash {
  position: absolute;
  top: 0.75rem;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  opacity: 0;
  pointer-events: none;
  font-weight: 800;
  letter-spacing: 0.02em;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: rgba(0,0,0,0.55);
  border: 1px solid var(--line);
  transition: opacity 0.15s ease, transform 0.15s ease;
  white-space: nowrap;
  z-index: 4;
}
.combat-flash.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.combat-flash.hit { color: var(--ok); }
.combat-flash.miss { color: var(--bad); }
.combat-flash.win, .combat-flash.level { color: var(--gold); }

.prompt { text-align: center; margin-bottom: 0.65rem; }
.word-frame {
  border: none;
  border-radius: 10px;
  padding: 1rem 1.35rem 1.1rem;
  min-height: 96px;
  background:
    linear-gradient(180deg, rgba(6,8,14,0.55), rgba(6,8,14,0.62)),
    url("../assets/ui-word-frame.png") center / 100% 100% no-repeat;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}
.prompt .label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 0.35rem;
}
#word-display {
  font-family: var(--mono);
  font-size: clamp(1.55rem, 5vw, 2.25rem);
  font-weight: 700;
  letter-spacing: 0.08em;
  min-height: 1.35em;
  word-break: break-all;
}
#word-display span.ok { color: var(--ok); }
#word-display span.bad { color: var(--bad); text-decoration: underline; }
#word-display span.next {
  color: #fff;
  border-bottom: 3px solid var(--gold);
  padding-bottom: 1px;
}
#word-display span.pending { color: rgba(238,241,255,0.42); }

.timer {
  height: 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  overflow: hidden;
  border: 1px solid var(--line);
  margin: 0.65rem 0 0.85rem;
}
#timer-fill {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #38bdf8, #a78bfa);
  transition: width 0.05s linear;
}
#timer-fill.urgent { background: linear-gradient(90deg, #f59e0b, #ef4444); }

#type-input {
  width: 100%;
  min-height: 52px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,0.35);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 1.25rem;
  letter-spacing: 0.06em;
  padding: 0.7rem 0.9rem;
  outline: none;
}
#type-input:focus {
  border-color: rgba(245,197,66,0.65);
  box-shadow: 0 0 0 3px rgba(245,197,66,0.18);
}

.hint {
  margin: 0.55rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
}

.over-stats {
  list-style: none;
  padding: 0;
  margin: 0.75rem 0 1.1rem;
  color: var(--muted);
}
.over-stats li { margin: 0.35rem 0; }
.over-stats strong { color: var(--ink); }

.foot-note {
  margin-top: 0.9rem;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
@keyframes hurt {
  0% { filter: brightness(1); }
  40% { filter: brightness(2.2); transform: translateX(8px) scale(var(--s, 1)); }
  100% { filter: brightness(1); }
}
@keyframes die {
  to { opacity: 0; transform: scale(0.4) translateY(30px); }
}
@keyframes enter {
  from { opacity: 0; transform: scale(0.5) translateY(24px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes hero-attack {
  0% { transform: translateX(0); }
  40% { transform: translateX(12px); }
  100% { transform: translateX(0); }
}
@keyframes fx-pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.55); }
  35% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.12); }
}

@media (max-width: 640px) {
  .arena { min-height: 210px; }
  .fighter img { max-height: 150px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
