:root {
  color-scheme: dark;
  --ink: #fff8dd;
  --muted: #c9f3e8;
  --night: #17122d;
  --panel: rgba(25, 24, 55, 0.84);
  --panel-strong: rgba(39, 35, 78, 0.96);
  --gold: #ffe45e;
  --moss: #83f071;
  --teal: #31e6d5;
  --rose: #ff4f9a;
  --violet: #b875ff;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
}

body {
  background:
    radial-gradient(circle at 24% 20%, rgba(255, 79, 154, 0.22), transparent 20rem),
    radial-gradient(circle at 58% 36%, rgba(49, 230, 213, 0.24), transparent 21rem),
    radial-gradient(circle at 82% 8%, rgba(255, 228, 94, 0.2), transparent 24rem),
    linear-gradient(145deg, #17122d 0%, #12364d 44%, #24123d 100%);
  color: var(--ink);
  touch-action: manipulation;
}

button {
  border: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(330px, 1fr) auto;
  gap: 0.75rem;
  min-height: 100dvh;
  padding: max(0.9rem, env(safe-area-inset-top)) 0.9rem max(0.9rem, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: 980px;
  width: 100%;
  margin: 0 auto;
}

.eyebrow,
.label {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.35rem, 6vw, 2.4rem);
  line-height: 1;
}

h2 {
  font-size: 1rem;
}

.round-pill {
  min-width: 6.9rem;
  padding: 0.64rem 0.78rem;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.1);
  font-size: 0.82rem;
  font-weight: 900;
  text-align: center;
}

.battle-wrap {
  position: relative;
  display: grid;
  place-items: center;
  max-width: 980px;
  width: 100%;
  min-height: 48dvh;
  margin: 0 auto;
  isolation: isolate;
}

.scene-glow {
  position: absolute;
  width: min(88vw, 640px);
  aspect-ratio: 1.7;
  border-radius: 50%;
  background:
    radial-gradient(circle, rgba(49, 230, 213, 0.3), transparent 60%),
    radial-gradient(circle at 65% 35%, rgba(255, 79, 154, 0.22), transparent 34%),
    radial-gradient(circle at 35% 58%, rgba(255, 228, 94, 0.2), transparent 34%);
  filter: blur(18px);
  transform: translateY(10%);
  z-index: -1;
}

.board {
  --tile-w: clamp(54px, 10vw, 92px);
  --tile-h: calc(var(--tile-w) * 0.56);
  position: relative;
  width: calc(var(--tile-w) * 8.1);
  height: calc(var(--tile-w) * 5.7);
  margin: 0 auto;
}

.board::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 63%;
  width: 74%;
  height: 42%;
  transform: translate(-50%, -50%);
  border: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle at 42% 45%, rgba(49, 230, 213, 0.26), transparent 42%),
    radial-gradient(circle at 62% 52%, rgba(255, 79, 154, 0.18), transparent 48%),
    radial-gradient(circle at 50% 55%, rgba(7, 8, 28, 0.68), transparent 72%);
  filter: blur(10px);
  box-shadow:
    0 24px 46px rgba(0, 0, 0, 0.34),
    0 0 44px rgba(49, 230, 213, 0.16);
  z-index: 0;
  pointer-events: none;
}

.tile {
  position: absolute;
  width: var(--tile-w);
  height: var(--tile-w);
  transform: translate(-50%, -50%) rotate(45deg) scaleY(0.56);
  border: 2px solid rgba(246, 238, 190, 0.5);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.26), transparent 43%),
    linear-gradient(45deg, #43b985, #2f8ac2);
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.16),
    0 10px 0 #133a63,
    0 20px 24px rgba(0, 0, 0, 0.38);
  transition:
    filter 160ms ease,
    transform 160ms ease,
    background 160ms ease;
}

.tile::after {
  content: "";
  position: absolute;
  inset: 17%;
  border: 1px dashed rgba(255, 255, 255, 0.23);
  border-radius: 5px;
}

.tile.blocked {
  border-color: rgba(255, 255, 255, 0.28);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.13), transparent 44%),
    linear-gradient(45deg, #4d3b6d, #24324d);
  filter: saturate(0.82) brightness(0.82);
}

.tile.bonus {
  border-color: rgba(255, 229, 139, 0.82);
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 228, 94, 0.42), transparent 34%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.24), transparent 42%),
    linear-gradient(45deg, #d99a3e, #2bb9ae);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.12),
    0 10px 0 #6b3919,
    0 0 24px rgba(255, 228, 94, 0.32),
    0 20px 22px rgba(0, 0, 0, 0.42);
}

.tile.reachable {
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 228, 94, 0.28), transparent 36%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.24), transparent 44%),
    linear-gradient(45deg, #83d957, #18bfb8);
  border-color: rgba(255, 238, 112, 0.82);
  filter: saturate(1.18) brightness(1.04);
}

.tile.attackable {
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 79, 154, 0.42), transparent 38%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.22), transparent 44%),
    linear-gradient(45deg, #e85370, #6849d9);
  border-color: rgba(255, 139, 190, 0.86);
}

.tile.selected {
  filter: drop-shadow(0 0 16px rgba(255, 228, 94, 0.9)) brightness(1.22);
}

.unit {
  position: absolute;
  width: calc(var(--tile-w) * 0.86);
  height: calc(var(--tile-w) * 1.18);
  transform: translate(-50%, -92%);
  z-index: 5;
  pointer-events: none;
  transition:
    left 240ms ease,
    top 240ms ease,
    transform 160ms ease;
}

.unit.hit {
  animation: hit 360ms ease;
}

.shadow {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 70%;
  height: 14%;
  transform: translateX(-50%);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.34);
  filter: blur(2px);
}

.body,
.head,
.hat,
.weapon,
.spark {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.hero .body {
  bottom: 14%;
  width: 42%;
  height: 46%;
  border-radius: 44% 44% 30% 30%;
  background: linear-gradient(160deg, #ffe45e, #23d6bc 50%, #2073e8);
  box-shadow: inset -8px -8px rgba(0, 0, 0, 0.14);
}

.hero .head {
  bottom: 55%;
  width: 34%;
  height: 28%;
  border-radius: 50%;
  background: #f2b98b;
}

.hero .hat {
  bottom: 74%;
  width: 58%;
  height: 28%;
  border-radius: 60% 60% 24% 24%;
  background: linear-gradient(135deg, #ffe45e, #83f071 48%, #31e6d5);
  clip-path: polygon(7% 68%, 30% 12%, 75% 14%, 97% 68%, 67% 86%, 30% 83%);
}

.hero .weapon {
  bottom: 33%;
  width: 9%;
  height: 58%;
  border-radius: 999px;
  background: linear-gradient(#fff7b8, #ff8f3d);
  transform: translateX(170%) rotate(23deg);
  transform-origin: bottom;
}

.enemy .body {
  bottom: 14%;
  width: 48%;
  height: 48%;
  border-radius: 50% 50% 36% 36%;
  background: linear-gradient(160deg, #ff7bbd, #8f5cff 52%, #3b1f82);
  box-shadow: inset -10px -9px rgba(0, 0, 0, 0.2);
}

.enemy .head {
  bottom: 57%;
  width: 38%;
  height: 30%;
  border-radius: 50%;
  background: #9d73ff;
}

.enemy .hat {
  bottom: 79%;
  width: 68%;
  height: 24%;
  border-radius: 999px 999px 30% 30%;
  background: linear-gradient(135deg, #ff4f9a, #7b4dff);
}

.enemy .spark {
  bottom: 82%;
  width: 16%;
  height: 16%;
  border-radius: 50%;
  background: var(--rose);
  box-shadow: 0 0 18px var(--rose);
  animation: pulse 1.2s ease-in-out infinite;
}

.damage {
  position: absolute;
  z-index: 20;
  min-width: 2.2rem;
  padding: 0.25rem 0.45rem;
  border-radius: 999px;
  background: #ffe45e;
  color: #261633;
  font-weight: 950;
  text-align: center;
  transform: translate(-50%, -140%);
  animation: floatDamage 760ms ease forwards;
  pointer-events: none;
}

.hud {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.7rem;
  max-width: 980px;
  width: 100%;
  margin: 0 auto;
}

.unit-panel,
.guide-panel,
.actions {
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: var(--panel);
  box-shadow:
    0 18px 45px rgba(0, 0, 0, 0.24),
    0 0 28px rgba(49, 230, 213, 0.08),
    inset 0 1px rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(18px);
}

.unit-panel {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.75rem;
  min-height: 4.25rem;
  padding: 0.7rem;
  border-radius: 8px;
}

.avatar {
  width: 2.85rem;
  height: 2.85rem;
  border-radius: 8px;
  background:
    radial-gradient(circle at 48% 35%, #f2b98b 0 18%, transparent 19%),
    radial-gradient(circle at 50% 50%, #31e6d5 0 40%, #2073e8 41% 70%, transparent 71%),
    linear-gradient(135deg, #ffe45e, #31e6d5);
  box-shadow: inset 0 -10px rgba(0, 0, 0, 0.18);
}

.enemy-avatar {
  background:
    radial-gradient(circle at 49% 32%, #9d73ff 0 18%, transparent 19%),
    radial-gradient(circle at 50% 53%, #8f5cff 0 42%, #3b1f82 43% 70%, transparent 71%),
    linear-gradient(135deg, #ff4f9a, #7b4dff);
}

.bar {
  overflow: hidden;
  width: 100%;
  height: 0.7rem;
  margin-top: 0.36rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
}

.bar span {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--moss), var(--gold));
  transition: width 220ms ease;
}

.enemy-bar span {
  background: linear-gradient(90deg, #ff4f9a, #ffe45e);
}

.guide-panel {
  padding: 0.85rem;
  border-radius: 8px;
}

.guide-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
}

.guide-panel p {
  margin: 0.5rem 0 0;
  color: #eafbf6;
  font-size: 0.91rem;
  line-height: 1.35;
}

.icon-button {
  display: grid;
  place-items: center;
  flex: 0 0 2.35rem;
  width: 2.35rem;
  height: 2.35rem;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gold), var(--teal));
  color: #17122d;
  font-weight: 950;
  box-shadow: 0 8px 22px rgba(49, 230, 213, 0.32);
}

.guide-meter {
  overflow: hidden;
  height: 0.34rem;
  margin-top: 0.75rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
}

.guide-meter span {
  display: block;
  width: 68%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--rose), var(--violet), var(--gold));
  animation: think 2.8s ease-in-out infinite;
}

.actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  padding: 0.5rem;
  border-radius: 8px;
}

.actions button {
  min-height: 3rem;
  border-radius: 7px;
  background: var(--panel-strong);
  font-weight: 900;
  box-shadow:
    inset 0 1px rgba(255, 255, 255, 0.1),
    0 0 18px rgba(184, 117, 255, 0.08);
}

.actions button:not(:disabled):hover {
  background: linear-gradient(135deg, rgba(255, 79, 154, 0.28), rgba(49, 230, 213, 0.2));
}

.actions button:active {
  transform: translateY(1px);
}

.tile:active {
  transform: translate(-50%, -50%) rotate(45deg) scaleY(0.52);
}

.actions button:disabled {
  color: rgba(247, 243, 223, 0.42);
  cursor: not-allowed;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  z-index: 50;
  max-width: min(92vw, 28rem);
  padding: 0.8rem 1rem;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 999px;
  background: rgba(25, 24, 55, 0.94);
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 800;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 1rem);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@keyframes pulse {
  50% {
    transform: translateX(-50%) scale(1.18);
  }
}

@keyframes hit {
  25% {
    transform: translate(-50%, -92%) rotate(-7deg) scale(1.05);
  }
  60% {
    transform: translate(-50%, -92%) rotate(6deg) scale(0.98);
  }
}

@keyframes floatDamage {
  to {
    opacity: 0;
    transform: translate(-50%, -230%);
  }
}

@keyframes think {
  50% {
    width: 100%;
    filter: hue-rotate(35deg);
  }
}

@media (min-width: 760px) {
  .app-shell {
    grid-template-rows: auto 1fr auto;
    padding-inline: 1.6rem;
  }

  .battle-wrap {
    min-height: 55dvh;
  }

  .board {
    --tile-w: clamp(66px, 5.1vw, 88px);
  }

  .hud {
    grid-template-columns: 1fr 1fr;
    align-items: stretch;
  }

  .guide-panel {
    grid-column: 1 / -1;
  }

  .actions {
    grid-column: 1 / -1;
  }
}

@media (max-width: 380px) {
  .board {
    --tile-w: 17.1vw;
  }

  .actions button {
    font-size: 0.82rem;
  }
}
