*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #071018;
  --panel: #0f1c28;
  --cream: #e8eef8;
  --gold: #fbbf24;
  --hp: #ef4444;
  --xp: #38bdf8;
  --green: #22c55e;
}

html,
body {
  height: 100%;
  background: var(--bg);
  color: var(--cream);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(ellipse 70% 40% at 50% -5%, rgba(124, 58, 237, 0.2), transparent 55%),
    radial-gradient(ellipse 50% 35% at 80% 80%, rgba(56, 189, 248, 0.08), transparent 50%),
    var(--bg);
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: max(0.5rem, env(safe-area-inset-top)) 0.9rem 0.4rem;
  flex-shrink: 0;
}

.home-link {
  color: #7dd3fc;
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0.06em;
}

.logo {
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.logo span {
  color: #c4b5fd;
}

.version {
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  opacity: 0.45;
  color: #86efac;
}

.screen {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem 1rem;
}

.screen[hidden] {
  display: none !important;
}

.screen h2 {
  font-size: clamp(1.4rem, 4vw, 1.85rem);
  font-weight: 800;
  color: #e9d5ff;
  margin-bottom: 0.35rem;
}

.sub,
.hint-select {
  font-size: 0.9rem;
  opacity: 0.55;
  margin-bottom: 1.25rem;
}

.char-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: center;
  max-width: 40rem;
}

.char-card {
  width: min(16rem, 90vw);
  padding: 1.1rem 1rem 1.2rem;
  border-radius: 1rem;
  border: 1px solid rgba(148, 180, 255, 0.2);
  background: linear-gradient(165deg, rgba(18, 28, 48, 0.95), rgba(10, 14, 23, 0.98));
  color: inherit;
  font: inherit;
  cursor: pointer;
  text-align: center;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.char-card:hover,
.char-card:focus-visible {
  transform: translateY(-3px);
  border-color: rgba(167, 139, 250, 0.55);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  outline: none;
}

.char-preview {
  width: 4.2rem;
  height: 4.2rem;
  margin: 0 auto 0.75rem;
  position: relative;
  display: grid;
  place-items: center;
}

.squipy-preview {
  border-radius: 0.65rem;
  background: linear-gradient(160deg, #c4b5fd, #7c3aed 55%, #5b21b6);
  border: 2px solid rgba(255, 255, 255, 0.75);
  box-shadow: 0 0 16px rgba(167, 139, 250, 0.5);
}

.tri-preview {
  background: transparent;
}

.tri-shape {
  width: 0;
  height: 0;
  border-left: 2rem solid transparent;
  border-right: 2rem solid transparent;
  border-bottom: 3.4rem solid #3df0ff;
  filter: drop-shadow(0 0 10px rgba(61, 240, 255, 0.55));
}

.face {
  position: absolute;
  width: 1.6rem;
  height: 1rem;
}

.squipy-preview .face {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -45%);
}

.tri-face {
  top: 55%;
  left: 50%;
  transform: translate(-50%, -20%);
}

.face .eye {
  position: absolute;
  top: 0;
  width: 0.28rem;
  height: 0.28rem;
  background: #0f172a;
  border-radius: 50%;
}

.face .eye:first-child {
  left: 0.15rem;
}
.face .eye:nth-child(2) {
  right: 0.15rem;
}

.face .mouth {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 0.6rem;
  height: 0.22rem;
  border-bottom: 2.5px solid #0f172a;
  border-radius: 0 0 50% 50%;
  transform: translateX(-50%);
}

.char-card h3 {
  font-size: 1.2rem;
  font-weight: 800;
  margin-bottom: 0.35rem;
}

.weapon {
  font-size: 0.85rem;
  margin-bottom: 0.35rem;
  color: #fde68a;
}

.desc {
  font-size: 0.8rem;
  line-height: 1.4;
  opacity: 0.6;
}

/* Game screen */
.game-screen {
  justify-content: flex-start;
  padding-top: 0.25rem;
  gap: 0.4rem;
}

.hud {
  width: min(960px, 100%);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.hud-left {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 12rem;
  flex: 1;
}

.hud-right {
  display: flex;
  gap: 0.85rem;
}

.lbl,
.sl {
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.5;
  font-weight: 650;
}

.hp-wrap,
.xp-wrap {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.hp-bar,
.xp-bar {
  flex: 1;
  height: 0.7rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

.hp-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #ef4444, #f87171);
  border-radius: inherit;
  transition: width 0.12s ease;
}

.xp-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #0ea5e9, #38bdf8);
  border-radius: inherit;
  transition: width 0.15s ease;
}

.hp-text {
  font-size: 0.78rem;
  font-weight: 700;
  min-width: 2rem;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  min-width: 3.2rem;
}

.stat span:last-child {
  font-weight: 750;
  font-size: 1rem;
}

.stage-wrap {
  position: relative;
  width: min(960px, 100%);
  max-height: min(540px, calc(calc(100vh - var(--rg-bar)) - 10rem));
}

#game {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  max-height: min(540px, calc(calc(100vh - var(--rg-bar)) - 10rem));
  border-radius: 0.75rem;
  border: 3px solid #1e3a2f;
  box-shadow:
    inset 0 0 0 2px rgba(201, 162, 39, 0.35),
    0 12px 36px rgba(0, 0, 0, 0.45);
  background: #0d3d28;
  display: block;
  touch-action: none;
}

/* Virtual stick — always available; larger on phones */
.joy-pad {
  position: absolute;
  left: 0.65rem;
  bottom: 0.65rem;
  width: 6.5rem;
  height: 6.5rem;
  border-radius: 50%;
  background: rgba(8, 16, 24, 0.35);
  border: 2px solid rgba(255, 255, 255, 0.18);
  box-shadow: inset 0 0 18px rgba(0, 0, 0, 0.35);
  touch-action: none;
  z-index: 5;
  display: grid;
  place-items: center;
  opacity: 0.55;
  transition: opacity 0.15s ease;
}

.joy-pad:active,
.joy-pad.dragging {
  opacity: 0.9;
}

.joy-knob {
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #c4b5fd, #7c3aed 65%, #5b21b6);
  border: 2px solid rgba(255, 255, 255, 0.55);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  pointer-events: none;
  transform: translate(0, 0);
  will-change: transform;
}

.hint {
  font-size: 0.68rem;
  opacity: 0.4;
  text-align: center;
  margin-top: 0.35rem;
  padding-bottom: max(0.25rem, env(safe-area-inset-bottom));
}

/* Modals */
.modal {
  position: fixed;
  inset: var(--rg-bar) 0 0 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(5, 10, 16, 0.72);
  backdrop-filter: blur(4px);
}

.modal[hidden] {
  display: none !important;
}

.modal-card {
  width: min(26rem, 100%);
  padding: 1.25rem 1.15rem 1.35rem;
  border-radius: 1rem;
  border: 1px solid rgba(167, 139, 250, 0.35);
  background: linear-gradient(165deg, #161b2e, #0c101c);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  text-align: center;
}

.modal-card h2 {
  font-size: 1.45rem;
  color: #fde68a;
  margin-bottom: 0.25rem;
}

.modal-sub {
  font-size: 0.88rem;
  opacity: 0.6;
  margin-bottom: 1rem;
}

.upgrade-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.upgrade-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  width: 100%;
  padding: 0.75rem 0.9rem;
  border-radius: 0.65rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
  color: inherit;
  font: inherit;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.12s ease, background 0.12s ease;
}

.upgrade-btn:hover,
.upgrade-btn:focus-visible,
.upgrade-btn.selected {
  border-color: rgba(125, 211, 252, 0.65);
  background: rgba(56, 189, 248, 0.14);
  outline: none;
  box-shadow: 0 0 0 1px rgba(125, 211, 252, 0.25);
}

.upgrade-btn.selected {
  border-color: rgba(251, 191, 36, 0.7);
  background: rgba(251, 191, 36, 0.12);
  box-shadow: 0 0 0 1px rgba(251, 191, 36, 0.35);
}

.upgrade-btn strong {
  font-size: 0.95rem;
  color: #e0f2fe;
}

.upgrade-btn span {
  font-size: 0.78rem;
  opacity: 0.6;
  line-height: 1.35;
}

.over-score {
  font-size: 1.1rem;
  margin-bottom: 1rem;
}

.over-score strong {
  color: #fde68a;
  font-size: 1.4rem;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

.btn {
  min-width: 7rem;
  padding: 0.65rem 1rem;
  border-radius: 0.5rem;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.08);
  color: inherit;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.btn.primary {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  border-color: transparent;
  color: #1c1917;
}

.btn.ghost {
  background: transparent;
}

@media (max-width: 560px) {
  .top-bar {
    padding: max(0.35rem, env(safe-area-inset-top)) 0.55rem 0.25rem;
  }

  .logo {
    font-size: 0.82rem;
  }

  .hud {
    flex-direction: row;
    flex-wrap: wrap;
    width: 100%;
    gap: 0.35rem 0.5rem;
    padding: 0 0.15rem;
  }

  .hud-left {
    min-width: 0;
    flex: 1 1 55%;
  }

  .hud-right {
    width: auto;
    flex: 1 1 auto;
    justify-content: flex-end;
    gap: 0.55rem;
  }

  .stat {
    align-items: flex-end;
    min-width: 2.6rem;
  }

  .stat span:last-child {
    font-size: 0.88rem;
  }

  /* Fill phone: canvas grows; stick docks under play area */
  .screen.game-screen {
    flex: 1;
    min-height: 0;
    width: 100%;
    padding: 0.2rem 0.35rem 0;
    gap: 0.3rem;
    justify-content: flex-start;
  }

  .stage-wrap {
    position: relative;
    flex: 1 1 auto;
    width: 100%;
    max-width: none;
    max-height: none;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    /* room for fixed stick at bottom */
    margin-bottom: 0;
    padding-bottom: 0;
  }

  #game {
    width: 100%;
    height: auto;
    max-height: calc(calc(100dvh - var(--rg-bar)) - 7.5rem - 6.5rem);
    /* prefer filling width on tall phones */
    aspect-ratio: 16 / 9;
    border-radius: 0.55rem;
    border-width: 2px;
  }

  /* Stick fixed at bottom center of the phone screen */
  .joy-pad {
    position: fixed;
    left: 50%;
    right: auto;
    bottom: max(0.85rem, env(safe-area-inset-bottom));
    top: auto;
    transform: translateX(-50%);
    width: 7.75rem;
    height: 7.75rem;
    opacity: 0.82;
    z-index: 20;
    background: rgba(8, 16, 24, 0.55);
    border-color: rgba(196, 181, 253, 0.45);
  }

  .joy-knob {
    width: 3.1rem;
    height: 3.1rem;
  }

  .hint {
    display: none;
  }

  .modal {
    padding: 0.65rem;
    align-items: flex-end;
  }

  .modal-card {
    width: 100%;
    max-height: min(80vh, 32rem);
    overflow: auto;
  }
}

/* Desktop: keep stick subtle so keys stay primary */
@media (hover: hover) and (pointer: fine) {
  .joy-pad {
    opacity: 0.28;
  }

  .joy-pad:hover,
  .joy-pad:active {
    opacity: 0.75;
  }
}
