:root {
  --bg: #0f1226;
  --panel: rgba(16, 20, 42, 0.82);
  --panel-strong: rgba(11, 15, 34, 0.95);
  --line: rgba(255, 255, 255, 0.12);
  --text: #f6f2e9;
  --muted: #c6c8de;
  --accent: #ffd84d;
  --fire: #ff6b35;
  --water: #4dc3ff;
  --earth: #8dd35f;
  --air: #ddd6ff;
  --danger: #ff5a7a;
  --success: #63f5aa;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

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

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

body {
  position: relative;
  overflow-x: hidden;
  background:
    radial-gradient(circle at top, rgba(77, 195, 255, 0.12), transparent 28%),
    radial-gradient(circle at bottom right, rgba(255, 107, 53, 0.18), transparent 30%),
    linear-gradient(160deg, #090b16 0%, #10152d 54%, #151024 100%);
  color: var(--text);
  font-family: "Outfit", system-ui, sans-serif;
}

.backdrop {
  position: fixed;
  inset: auto;
  pointer-events: none;
  border-radius: 999px;
  filter: blur(20px);
  opacity: 0.65;
}

.backdrop--one {
  width: 420px;
  height: 420px;
  top: -90px;
  right: -100px;
  background: radial-gradient(circle, rgba(255, 216, 77, 0.4), transparent 70%);
}

.backdrop--two {
  width: 360px;
  height: 360px;
  left: -120px;
  bottom: 10%;
  background: radial-gradient(circle, rgba(99, 245, 170, 0.18), transparent 70%);
}

.shell {
  width: min(1400px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 36px;
}

.hero {
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
  font-size: 0.82rem;
}

.hero h1 {
  margin: 0;
  font-family: "Bangers", cursive;
  font-size: clamp(3rem, 7vw, 6.5rem);
  line-height: 0.9;
  letter-spacing: 0.04em;
  color: #fff5c5;
  text-shadow: 0 6px 0 rgba(0, 0, 0, 0.22);
}

.subtitle {
  max-width: 760px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.15rem);
}

.game-frame {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 20px;
}

.hud,
.arena-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.hud {
  padding: 22px;
}

.brand-card,
.controls-card {
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 18px;
}

.brand-card__label {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 800;
}

.brand-card h2,
.controls-card h3 {
  margin: 0 0 8px;
}

.brand-card p,
.controls-card p {
  margin: 0;
  color: var(--muted);
}

.controls-card {
  margin-top: 18px;
}

.controls-card p + p {
  margin-top: 8px;
}

.element-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 18px 0;
}

.element-button,
.restart {
  appearance: none;
  border: 0;
  cursor: pointer;
  font: inherit;
}

.element-button {
  min-height: 88px;
  border-radius: 18px;
  padding: 14px;
  color: #fff;
  font-weight: 800;
  text-align: left;
  transition: transform 0.18s ease, box-shadow 0.18s ease, outline-color 0.18s ease;
  outline: 2px solid transparent;
}

.element-button span {
  display: block;
  margin-top: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  opacity: 0.88;
}

.element-button:hover,
.element-button:focus-visible {
  transform: translateY(-2px);
}

.element-button.active {
  outline-color: rgba(255, 255, 255, 0.8);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.12);
}

.element-button.fire { background: linear-gradient(135deg, #ff8f3f, #d93214); }
.element-button.water { background: linear-gradient(135deg, #5ee7ff, #2161ff); }
.element-button.earth { background: linear-gradient(135deg, #9ee44c, #458b28); }
.element-button.air { background: linear-gradient(135deg, #f7f0ff, #947cff); color: #21153b; }

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stat {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat strong {
  display: block;
  margin-top: 7px;
  font-size: 1.2rem;
}

.meters {
  margin-top: 18px;
}

.meters label {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.meter {
  width: 100%;
  height: 14px;
  margin-bottom: 14px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.meter div {
  height: 100%;
  width: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #ff8d8d, var(--danger));
}

.meter--power div {
  background: linear-gradient(90deg, #ffe685, #ffd84d);
}

.restart {
  width: 100%;
  margin-top: 18px;
  padding: 14px 16px;
  border-radius: 18px;
  background: #fff5c5;
  color: #231a06;
  font-weight: 800;
}

.arena-wrap {
  position: relative;
  padding: 18px;
}

.arena-overlay {
  position: absolute;
  inset: 66px 18px 58px;
  display: grid;
  place-items: center;
  gap: 8px;
  text-align: center;
  border-radius: 22px;
  background: rgba(7, 11, 23, 0.7);
  color: var(--text);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
  z-index: 2;
}

.arena-overlay.show {
  opacity: 1;
}

.arena-overlay__title {
  font-family: "Bangers", cursive;
  font-size: clamp(3rem, 8vw, 5rem);
  line-height: 0.9;
  color: #fff5c5;
  letter-spacing: 0.04em;
}

.arena-overlay__text {
  color: var(--muted);
  font-size: 1rem;
}

.arena-topbar,
.arena-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 4px 2px 14px;
}

#message-banner,
.streak,
#tip-line {
  color: var(--muted);
}

.streak strong {
  color: var(--accent);
}

canvas {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 22px;
  background:
    radial-gradient(circle at center, rgba(255, 255, 255, 0.03), transparent 45%),
    linear-gradient(180deg, #1a2044, #0d1124);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #fff;
  font-weight: 700;
}

/* ── Touch Controls ─────────────────────────────── */
.touch-controls {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}

.touch-joystick {
  position: absolute;
  left: 16px;
  bottom: 24px;
  pointer-events: auto;
  touch-action: none;
  text-align: center;
}

.touch-joystick--aim {
  left: auto;
  right: 16px;
}

.touch-joystick__base {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 255, 255, 0.18);
  display: grid;
  place-items: center;
  position: relative;
}

.touch-joystick__base--aim {
  border-color: rgba(255, 107, 53, 0.35);
  background: rgba(255, 107, 53, 0.06);
}

.touch-joystick__thumb {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(255, 216, 77, 0.5);
  border: 2px solid rgba(255, 216, 77, 0.7);
  position: absolute;
}

.touch-joystick__thumb--aim {
  background: rgba(255, 107, 53, 0.45);
  border-color: rgba(255, 107, 53, 0.65);
}

.touch-joystick__label {
  margin-top: 8px;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.35);
  pointer-events: none;
}

.touch-buttons-ev {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: auto;
  touch-action: none;
}

.touch-btn-ev {
  appearance: none;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  font: inherit;
  font-size: 0.6rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #fff;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

.touch-btn-ev:active {
  transform: scale(0.92);
}

.touch-btn-ev--burst {
  width: 68px;
  height: 68px;
  font-size: 0.65rem;
  background: rgba(255, 216, 77, 0.3);
  border-color: rgba(255, 216, 77, 0.45);
}

.touch-btn-ev--pause {
  width: 42px;
  height: 42px;
  font-size: 0.8rem;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  align-self: center;
}

/* ── Responsive ────────────────────────────────── */
@media (max-width: 1080px) {
  .game-frame {
    grid-template-columns: 1fr;
  }
}

/* ── Mobile-First Game Layout ──────────────────── */
@media (max-width: 767px) {
  .shell {
    width: 100%;
    padding: 0;
  }

  .hero {
    display: none;
  }

  .hud {
    padding: 0;
    background: transparent;
    border: 0;
    box-shadow: none;
    backdrop-filter: none;
    position: static;
    overflow: visible;
  }

  .hud > *:not(.element-picker) {
    display: none !important;
  }

  /* Element picker becomes full-screen modal */
  .element-picker {
    position: fixed;
    inset: 0;
    z-index: 25;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 10px;
    padding: 10px;
    margin: 0;
    background: rgba(9, 11, 22, 0.97);
  }

  .element-picker.hidden-mobile {
    display: none !important;
  }

  .element-button {
    min-height: auto;
    font-size: 1.5rem;
    font-weight: 800;
    border-radius: 20px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
  }

  .element-button span {
    font-size: 1rem;
    margin-top: 10px;
  }

  .game-frame {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .arena-wrap {
    padding: 0;
    border-radius: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
    backdrop-filter: none;
  }

  .arena-topbar,
  .arena-bottom {
    display: none;
  }

  .arena-overlay {
    inset: 0;
    border-radius: 0;
  }

  canvas {
    width: 100vw !important;
    height: calc(100vh - 140px) !important;
    height: calc(100dvh - 140px) !important;
    border-radius: 0;
    border: 0;
  }
}

/* Fallback for slightly larger phones */
@media (min-width: 768px) and (max-width: 1080px) {
  .arena-overlay {
    inset: 66px 18px 58px;
    border-radius: 22px;
  }
}

/* ── Touch Controls (viewport-responsive) ──────── */
@media (pointer: coarse) {
  .touch-controls {
    display: block;
  }

  .controls-card {
    display: none;
  }
}

@media (max-width: 767px) {
  .touch-joystick {
    left: 3vw;
    bottom: max(12px, env(safe-area-inset-bottom, 0px) + 8px);
  }

  .touch-joystick--aim {
    left: auto;
    right: 3vw;
    bottom: max(12px, env(safe-area-inset-bottom, 0px) + 8px);
  }

  .touch-joystick__base {
    width: min(120px, 28vw);
    height: min(120px, 28vw);
  }

  .touch-joystick__thumb {
    width: min(48px, 11vw);
    height: min(48px, 11vw);
  }

  .touch-buttons-ev {
    position: absolute;
    right: auto;
    left: 50%;
    transform: translateX(-50%);
    bottom: max(12px, env(safe-area-inset-bottom, 0px) + 8px);
    top: auto;
    flex-direction: row;
    gap: 10px;
  }

  .touch-btn-ev--burst {
    width: 58px;
    height: 58px;
    font-size: 0.6rem;
  }

  .touch-btn-ev--pause {
    width: 38px;
    height: 38px;
    font-size: 0.7rem;
  }

  .touch-joystick__label {
    font-size: 0.55rem;
  }
}
