/* ==========================================================================
   Sword Master — stylesheet

   Art direction: bright saturated palette, bold dark outlines, chunky rounded
   UI, playful sans (Fredoka). Every interactive surface has a hard dark border
   and an offset shadow, which is what gives the "sticker" look Poki-style
   games use — and it doubles as a strong focus/contrast affordance.

   Layout is mobile-first: a single column with the battle above the upgrade
   panel. From 900px the two sit side by side.
   ========================================================================== */

/* --------------------------------------------------------------- tokens */

:root {
  /* Backdrop */
  --sky-top: #5EC8F5;
  --sky-bottom: #8A63D2;
  --ground: #6BBF4A;
  --ground-dark: #4A9A2E;

  /* Ink — every outline in the game is this colour. */
  --ink: #1B2430;
  --ink-soft: rgba(27, 36, 48, 0.6);

  /* Surfaces */
  --surface: #FFFDF5;
  --surface-alt: #FFF2D0;
  --surface-sunken: #EFE3C4;

  /* Currencies */
  --coin: #FFD24A;
  --coin-dark: #B8801A;
  --gem: #4AC7FF;
  --gem-dark: #1B7FB0;

  /* Actions */
  --green: #4ADB5E;
  --green-dark: #2A9A38;
  --red: #FF5A5F;
  --red-dark: #C4262E;
  --purple: #B98CFF;
  --purple-dark: #6A32C8;
  --orange: #FF8A3D;

  /* Structure */
  --border: 3px solid var(--ink);
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 0 var(--ink);
  --shadow-lg: 0 6px 0 var(--ink);

  --font: 'Fredoka', 'Baloo 2', system-ui, -apple-system, 'Segoe UI', sans-serif;

  /* Safe-area insets, so the HUD clears an iPhone notch. */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ----------------------------------------------------------------- reset */

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

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font);
  font-weight: 600;
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-bottom) 100%);
  /* `user-select` IS inherited, so this one line covers the whole tree. */
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  /* Stops iOS from resizing text when the device is rotated. */
  -webkit-text-size-adjust: 100%;
}

/*
 * Kill double-tap-to-zoom on everything the player taps.
 *
 * `touch-action` is NOT an inherited property, so declaring it on `body` alone
 * does nothing for these elements — the browser keeps running its double-tap
 * gesture recogniser and a fast tap sequence zooms the page in and out. It has
 * to be set on the tap targets themselves.
 *
 * `manipulation` is deliberate rather than `none`: it disables the double-tap
 * zoom and the 300ms click delay while still allowing pinch-to-zoom, so players
 * who need to magnify the screen still can. `none` would take that away.
 */
#stage,
button,
.track-card,
.skin-card,
.perk-card,
.settings__row,
.modal {
  touch-action: manipulation;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

svg {
  display: block;
}

/* Honour the OS setting as well as the in-game toggle. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

body[data-reduced-motion='true'] * {
  animation-duration: 0.01ms !important;
}

/* ---------------------------------------------------------------- layout */

#shake-wrap {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  /* Promotes to its own layer so screen shake never triggers layout. */
  will-change: transform;
}

/* ------------------------------------------------------------------- HUD */

#hud {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(8px + var(--safe-top)) 10px 8px;
  background: rgba(27, 36, 48, 0.25);
  backdrop-filter: blur(6px);
  flex-shrink: 0;
  z-index: 5;
}

.hud__currencies {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.counter {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px 5px 6px;
  background: var(--surface);
  border: var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow);
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  font-weight: 700;
  will-change: transform;
}

.coin-icon,
.gem-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.coin-icon--large {
  width: 34px;
  height: 34px;
}

.hud__dps {
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 2px 0 var(--ink);
  white-space: nowrap;
}

.hud__buffs {
  display: flex;
  gap: 5px;
  margin-left: auto;
  overflow: hidden;
}

.buff-pill {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  background: var(--buff-colour, var(--coin));
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  text-shadow: 0 1px 0 var(--ink);
  white-space: nowrap;
  animation: buff-pulse 1.6s ease-in-out infinite;
}

.buff-pill em {
  font-style: normal;
  opacity: 0.85;
}

@keyframes buff-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.hud__menu {
  display: flex;
  gap: 6px;
  margin-left: auto;
}

.icon-btn {
  position: relative;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.icon-btn svg {
  width: 24px;
  height: 24px;
}

.icon-btn:active {
  transform: translateY(4px);
  box-shadow: 0 0 0 var(--ink);
}

/* A ready action gets a gentle bounce — the only motion in the HUD, so it
   reliably pulls the eye. */
.icon-btn[data-ready='true'] {
  animation: btn-bounce 1.4s ease-in-out infinite;
}

@keyframes btn-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  display: grid;
  place-items: center;
  background: var(--red);
  color: #fff;
  border: 2px solid var(--ink);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.badge:empty,
.badge[data-visible='false'] {
  display: none;
}

.badge--dot {
  min-width: 14px;
  width: 14px;
  height: 14px;
  padding: 0;
}

.badge--text {
  background: var(--gem);
  font-size: 9px;
  top: -7px;
  right: -10px;
}

/* ----------------------------------------------------------------- stage */

#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* The ground: a solid band with a lighter cap, drawn with gradients so
     there is no image to load. */
  background:
    linear-gradient(180deg, transparent 0%, transparent 72%,
      var(--ground) 72%, var(--ground) 76%,
      var(--ground-dark) 76%, var(--ground-dark) 100%);
  cursor: pointer;
  overflow: hidden;
}

/* Boss levels tint the arena red; goldens tint it gold. */
#stage[data-kind='boss']::before,
#stage[data-kind='golden']::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%,
    rgba(255, 74, 107, 0.28), transparent 62%);
  animation: arena-throb 1.8s ease-in-out infinite;
}

#stage[data-kind='golden']::before {
  background: radial-gradient(ellipse at 50% 45%,
    rgba(255, 210, 74, 0.4), transparent 62%);
}

@keyframes arena-throb {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

.stage__level {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding-top: 10px;
  z-index: 2;
}

#level-label {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.06em;
  text-shadow: 0 2px 0 var(--ink), 0 0 12px rgba(0, 0, 0, 0.3);
}

#level-label[data-boss='true'] {
  color: var(--coin);
  animation: boss-label 0.9s ease-in-out infinite;
}

@keyframes boss-label {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

.pips {
  display: flex;
  gap: 4px;
}

.pip {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  border: 2px solid var(--ink);
  transition: background 0.15s ease, transform 0.15s ease;
}

.pip--done {
  background: var(--coin);
  transform: scale(1.15);
}

.shard-count {
  font-size: 11px;
  color: var(--purple);
  text-shadow: 0 1px 0 var(--ink);
}

.shard-count[data-visible='false'] {
  display: none;
}

/* Boss / golden countdown */

.stage__timer {
  width: min(320px, 78%);
  margin-top: 8px;
  z-index: 2;
}

.stage__timer[data-visible='false'] {
  visibility: hidden;
}

.timer__track {
  height: 12px;
  background: var(--surface-sunken);
  border: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.timer__fill {
  height: 100%;
  background: var(--green);
  transform-origin: left center;
  transition: transform 0.1s linear;
}

.stage__timer[data-urgent='true'] .timer__fill {
  background: var(--red);
}

.timer__text {
  display: block;
  text-align: center;
  font-size: 12px;
  color: #fff;
  text-shadow: 0 2px 0 var(--ink);
  margin-top: 2px;
}

/* Arena: enemy on the right, weapon on the left, both above the ground line. */

.stage__arena {
  position: relative;
  flex: 1;
  width: 100%;
  min-height: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: clamp(4px, 4vw, 40px);
  padding-bottom: 14%;
  z-index: 2;
}

.enemy {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  order: 2;
}

.enemy__sprite {
  width: clamp(110px, 30vw, 190px);
  aspect-ratio: 1;
  animation: idle-bob 2.2s ease-in-out infinite;
  will-change: transform;
}

.enemy__sprite svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

@keyframes idle-bob {
  0%, 100% { transform: translateY(0) scale(1, 1); }
  50% { transform: translateY(-8px) scale(0.98, 1.02); }
}

.enemy-svg--boss {
  animation: boss-idle 1.4s ease-in-out infinite;
}

@keyframes boss-idle {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

.enemy-svg--golden {
  animation: golden-shimmer 0.8s ease-in-out infinite;
}

@keyframes golden-shimmer {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.35); }
}

.enemy__health {
  position: relative;
  width: clamp(120px, 32vw, 200px);
  height: 20px;
  background: var(--surface-sunken);
  border: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.enemy__health-fill {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, #FF7A7F, var(--red));
  transform-origin: left center;
  transition: transform 0.08s ease-out;
}

.enemy__health-text {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
  font-variant-numeric: tabular-nums;
}

.enemy__name {
  font-size: 12px;
  color: #fff;
  text-shadow: 0 2px 0 var(--ink);
}

/* The weapon. Rotated at rest so it reads as "held", and the swing animation
   in battle.js rotates around this same origin. */

.weapon {
  order: 1;
  width: clamp(80px, 22vw, 140px);
  aspect-ratio: 120 / 220;
  transform: rotate(-28deg);
  transform-origin: 50% 85%;
  will-change: transform;
  animation: weapon-idle 2.6s ease-in-out infinite;
}

.weapon svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

@keyframes weapon-idle {
  0%, 100% { transform: rotate(-28deg) translateY(0); }
  50% { transform: rotate(-24deg) translateY(-5px); }
}

/* The prismatic skin cycles hue rather than needing 15 more palettes. */
.weapon-svg--prismatic {
  animation: prismatic 3s linear infinite;
}

@keyframes prismatic {
  from { filter: hue-rotate(0deg); }
  to { filter: hue-rotate(360deg); }
}

/* Sits in normal flow between the arena and the combo meter rather than being
   absolutely positioned — at 375px an absolute hint collided with the enemy
   health bar, and flow layout cannot collide by construction. */
.tap-hint {
  margin-bottom: 6px;
  font-size: 13px;
  color: #fff;
  letter-spacing: 0.1em;
  text-shadow: 0 2px 0 var(--ink);
  animation: tap-hint 1.2s ease-in-out infinite;
  pointer-events: none;
  z-index: 2;
}

@keyframes tap-hint {
  0%, 100% { transform: translateY(0); opacity: 0.85; }
  50% { transform: translateY(-6px); opacity: 1; }
}

/* Combo meter */

.combo {
  width: min(340px, 84%);
  margin-bottom: 10px;
  z-index: 2;
  transition: opacity 0.2s ease;
  opacity: 0.55;
}

.combo[data-active='true'] {
  opacity: 1;
}

.combo__track {
  height: 10px;
  background: rgba(27, 36, 48, 0.35);
  border: 2px solid var(--ink);
  border-radius: 999px;
  overflow: hidden;
}

.combo__fill {
  height: 100%;
  background: linear-gradient(90deg, var(--gem), var(--coin));
  transform-origin: left center;
  transform: scaleX(0);
  transition: transform 0.1s ease-out;
}

.combo[data-hot='true'] .combo__fill {
  background: linear-gradient(90deg, var(--coin), var(--red));
}

.combo__value {
  display: block;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.05em;
  text-shadow: 0 2px 0 var(--ink);
  margin-top: 3px;
}

.combo[data-hot='true'] .combo__value {
  color: var(--coin);
  animation: combo-hot 0.5s ease-in-out infinite;
}

@keyframes combo-hot {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

/* Effects canvas — must never intercept a tap. */
#fx-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 3;
}

/* ---------------------------------------------------------------- panel */

#panel {
  flex-shrink: 0;
  max-height: 46dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 10px 10px calc(10px + var(--safe-bottom));
  background: var(--surface-alt);
  border-top: var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 4;
}

/* Weapon card */

.weapon-card {
  background: var(--surface);
  border: var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.weapon-card__current {
  display: flex;
  align-items: center;
  gap: 10px;
}

.weapon-card__art {
  width: 52px;
  height: 82px;
  flex-shrink: 0;
}

.weapon-card__art svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.weapon-card__meta {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.weapon-card__tier {
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
}

.weapon-card__name {
  font-size: 19px;
  font-weight: 700;
  line-height: 1.1;
}

.weapon-card__tagline {
  font-size: 11px;
  color: var(--ink-soft);
  font-weight: 500;
}

.weapon-card__damage {
  font-size: 12px;
  color: var(--red-dark);
  font-weight: 700;
}

.weapon-card__maxed {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px;
  text-align: center;
  background: var(--surface-alt);
  border: 2px dashed var(--ink-soft);
  border-radius: var(--radius-sm);
  font-size: 12px;
}

/* Buttons */

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 14px;
  border: var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  background: var(--surface-sunken);
  font-weight: 700;
  font-size: 14px;
  transition: transform 0.1s ease, box-shadow 0.1s ease, filter 0.15s ease;
}

.btn:active {
  transform: translateY(4px);
  box-shadow: 0 0 0 var(--ink);
}

.btn--large {
  padding: 14px 18px;
  font-size: 16px;
  width: 100%;
}

.btn--wide {
  width: 100%;
}

.btn--primary {
  background: var(--green);
  color: #fff;
  text-shadow: 0 2px 0 var(--green-dark);
}

.btn--danger {
  background: var(--red);
  color: #fff;
  text-shadow: 0 2px 0 var(--red-dark);
}

.btn--epic {
  background: linear-gradient(135deg, var(--purple), var(--gem));
  color: #fff;
  text-shadow: 0 2px 0 var(--purple-dark);
  animation: epic-glow 2s ease-in-out infinite;
}

@keyframes epic-glow {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.2); }
}

.btn--ghost {
  background: transparent;
  border: 2px solid var(--ink-soft);
  box-shadow: none;
  font-size: 13px;
  font-weight: 600;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  animation: none;
}

.btn[data-visible='false'] {
  display: none;
}

/* The evolve button: the single most important button in the game, so it is
   the loudest thing on screen when it is affordable. */

.btn--evolve {
  background: var(--surface-sunken);
  color: var(--ink-soft);
  justify-content: space-between;
  text-align: left;
  padding: 9px 12px;
}

.btn--evolve[data-affordable='true'] {
  background: linear-gradient(135deg, var(--coin), var(--orange));
  color: var(--ink);
  animation: evolve-ready 1.3s ease-in-out infinite;
}

@keyframes evolve-ready {
  0%, 100% { box-shadow: var(--shadow); }
  50% { box-shadow: 0 4px 0 var(--ink), 0 0 22px rgba(255, 210, 74, 0.9); }
}

.btn__preview {
  width: 30px;
  height: 48px;
  flex-shrink: 0;
}

.btn__preview svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.btn__body {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
  min-width: 0;
}

.btn__label {
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn__sub {
  font-size: 11px;
  font-weight: 500;
  opacity: 0.75;
}

.btn__cost {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

/* A depth-locked tier shows the level needed, not a price the player cannot
   act on yet. */
.lock-tag {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  white-space: nowrap;
  color: var(--ink-soft);
}

.btn--evolve[data-locked='true'] {
  animation: none;
  background: var(--surface-sunken);
}

/* Panel controls */

.panel__controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2px;
}

.panel__heading {
  font-size: 12px;
  letter-spacing: 0.12em;
  color: var(--ink-soft);
}

.buy-mode {
  display: flex;
  gap: 3px;
  background: var(--surface-sunken);
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 2px;
}

.buy-mode button {
  padding: 3px 11px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-soft);
  transition: background 0.12s ease, color 0.12s ease;
}

.buy-mode button[data-active='true'] {
  background: var(--ink);
  color: var(--surface);
}

/* Track cards */

.track-list {
  display: grid;
  gap: 6px;
}

.track-card {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  background: var(--surface);
  border: var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  text-align: left;
  transition: transform 0.1s ease, box-shadow 0.1s ease, filter 0.15s ease;
  will-change: transform;
}

.track-card:active {
  transform: translateY(4px);
  box-shadow: 0 0 0 var(--ink);
}

/* Unaffordable cards desaturate rather than disappear, so the player can
   still see what they are saving toward. */
.track-card[data-affordable='false'] {
  filter: saturate(0.35);
  opacity: 0.72;
}

.track-card[data-maxed='true'] {
  filter: none;
  opacity: 1;
  background: var(--surface-alt);
}

.track-card__icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  background: var(--accent);
  border: 2px solid var(--ink);
  border-radius: 9px;
  color: #fff;
  flex-shrink: 0;
}

.track-card__icon svg {
  width: 20px;
  height: 20px;
}

.track-card__body {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
  min-width: 0;
}

.track-card__head {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.track-card__name {
  font-size: 13px;
  font-weight: 700;
}

.track-card__level {
  font-size: 11px;
  color: var(--ink-soft);
}

.track-card__effect {
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.track-card__cost {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.track-card__cost em {
  font-style: normal;
  font-size: 10px;
  color: var(--ink-soft);
}

.track-card__maxed {
  color: var(--green-dark);
  font-size: 12px;
}

/* --------------------------------------------------------------- overlay */

#flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  z-index: 40;
}

#toasts {
  position: fixed;
  top: calc(60px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  pointer-events: none;
  z-index: 50;
  width: max-content;
  max-width: 92vw;
}

.toast {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 15px;
  background: var(--surface);
  border: var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow);
  max-width: 100%;
}

.toast__icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.toast__body {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.toast__title {
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
}

.toast__text {
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toast--gold { background: linear-gradient(135deg, #FFF3C4, var(--coin)); }
.toast--gem { background: linear-gradient(135deg, #D4F1FF, var(--gem)); }
.toast--epic {
  background: linear-gradient(135deg, var(--purple), var(--gem));
  color: #fff;
}
.toast--epic .toast__title { color: rgba(255, 255, 255, 0.8); }

/* ---------------------------------------------------------------- modals */

#modal-root {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(27, 36, 48, 0.65);
  backdrop-filter: blur(4px);
  z-index: 60;
}

#modal-root[data-open='true'] {
  display: flex;
}

.modal {
  width: min(460px, 100%);
  max-height: 86dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  background: var(--surface-alt);
  border-bottom: var(--border);
  flex-shrink: 0;
}

.modal--gold .modal__header { background: linear-gradient(135deg, #FFF3C4, var(--coin)); }
.modal--gem .modal__header { background: linear-gradient(135deg, #D4F1FF, var(--gem)); }
.modal--epic .modal__header {
  background: linear-gradient(135deg, var(--purple), var(--gem));
  color: #fff;
}

.modal__title {
  font-size: 18px;
  font-weight: 700;
  /* Let the title shrink before the balance does — the number is the thing the
     player opened the dialog to check. */
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal__header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Live gem balance in a modal header. Styled like the HUD counter so it reads
   as the same piece of information, not a new one. */
.gem-balance {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 11px 4px 6px;
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  will-change: transform;
}

.gem-balance .gem-icon {
  width: 18px;
  height: 18px;
}

.modal__close {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  font-size: 22px;
  line-height: 1;
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: 8px;
  flex-shrink: 0;
}

.modal__body {
  padding: 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Wheel */

.wheel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.wheel__stage {
  position: relative;
  width: min(280px, 72vw);
  aspect-ratio: 1;
}

.wheel__rotor {
  width: 100%;
  height: 100%;
  will-change: transform;
}

.wheel__face {
  width: 100%;
  height: 100%;
}

.wheel__label {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 700;
}

.wheel__sublabel {
  font-family: var(--font);
  font-size: 9px;
  font-weight: 600;
}

/* The pointer sits above the wheel and dips into it. */
.wheel__pointer {
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 13px solid transparent;
  border-right: 13px solid transparent;
  border-top: 26px solid var(--red);
  filter: drop-shadow(0 2px 0 var(--ink));
  z-index: 2;
}

.wheel__status {
  font-size: 13px;
  color: var(--ink-soft);
}

/* Daily */

.daily__intro {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-soft);
  text-align: center;
}

.daily__grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.daily__day {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 4px;
  background: var(--surface-alt);
  border: 2px solid var(--ink);
  border-radius: var(--radius-sm);
  position: relative;
  text-align: center;
}

.daily__day--grand {
  grid-column: span 4;
  background: linear-gradient(135deg, #FFF3C4, var(--coin));
}

.daily__day--available {
  background: linear-gradient(135deg, var(--green), #8AE89A);
  animation: btn-bounce 1.4s ease-in-out infinite;
}

.daily__day--claimed {
  opacity: 0.5;
}

.daily__label {
  font-size: 9px;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
}

.daily__icon svg {
  width: 26px;
  height: 26px;
}

.daily__reward {
  font-size: 10px;
  font-weight: 700;
  line-height: 1.15;
}

.daily__tick {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 30px;
  color: var(--green-dark);
}

.daily__wait {
  text-align: center;
  font-size: 13px;
  color: var(--ink-soft);
}

/* Achievements */

.achievements__count {
  text-align: center;
  font-size: 13px;
  color: var(--ink-soft);
}

.achievements__list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.achievement {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  background: var(--surface-alt);
  border: 2px solid var(--ink);
  border-radius: var(--radius-sm);
}

.achievement--done {
  background: linear-gradient(135deg, #D8F5DC, var(--green));
}

.achievement__info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.achievement__info strong { font-size: 13px; }
.achievement__info span { font-size: 11px; font-weight: 500; color: var(--ink-soft); }
.achievement__info small { font-size: 10px; color: var(--ink-soft); }

.achievement__bar {
  height: 6px;
  background: var(--surface-sunken);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 2px;
}

.achievement__fill {
  height: 100%;
  background: var(--gem);
  transform-origin: left center;
}

.achievement__reward {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.achievement__gems {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 13px;
  font-weight: 700;
}

.achievement__gems svg { width: 17px; height: 17px; }

.achievement__tick {
  font-size: 19px;
  color: var(--green-dark);
}

/* Shop */

/* The shop lays its own children out. Without this it is a plain block
   container, so the negative margin on .shop__note below has no flex gap to
   offset and drags the note up into the heading instead of just tightening it. */
.shop {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.shop__heading {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.shop__note {
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-soft);
  /* Pulls the note closer to the heading it belongs to, without colliding. */
  margin-top: -7px;
}

.shop__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 7px;
}

.skin-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 9px 5px;
  background: var(--surface-alt);
  border: 2px solid var(--ink);
  border-radius: var(--radius-sm);
  text-align: center;
}

.skin-card--equipped {
  background: linear-gradient(135deg, #D8F5DC, var(--green));
}

.skin-card__art {
  width: 34px;
  height: 54px;
}

.skin-card__art svg { width: 100%; height: 100%; overflow: visible; }

.skin-card__name { font-size: 12px; }
.skin-card__desc { font-size: 9px; font-weight: 500; color: var(--ink-soft); line-height: 1.2; }

.skin-card__action {
  display: flex;
  align-items: center;
  gap: 3px;
  margin-top: 3px;
  font-size: 11px;
  font-weight: 700;
}

.skin-card__action .gem-icon { width: 14px; height: 14px; }

.shop__perks {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.perk-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 11px;
  background: var(--surface-alt);
  border: 2px solid var(--ink);
  border-radius: var(--radius-sm);
  text-align: left;
}

.perk-card--owned { opacity: 0.6; }

.perk-card__body { display: flex; flex-direction: column; gap: 1px; }
.perk-card__body strong { font-size: 13px; }
.perk-card__body span { font-size: 11px; font-weight: 500; color: var(--ink-soft); }

.perk-card__cost {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.perk-card__cost .gem-icon { width: 16px; height: 16px; }

/* Settings */

.settings__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--surface-alt);
  border: 2px solid var(--ink);
  border-radius: var(--radius-sm);
  font-size: 14px;
  cursor: pointer;
}

.settings__row input {
  width: 22px;
  height: 22px;
  accent-color: var(--green-dark);
  cursor: pointer;
}

.settings__stats h3 {
  font-size: 14px;
  margin-bottom: 6px;
}

.settings__stats dl {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.settings__stats dl > div {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  padding: 3px 0;
  border-bottom: 1px dashed rgba(27, 36, 48, 0.18);
}

.settings__stats dt { font-weight: 500; color: var(--ink-soft); }
.settings__stats dd { font-weight: 700; font-variant-numeric: tabular-nums; }

/* Offline */

.offline {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
}

.offline__art { font-size: 48px; }

.offline__away { font-size: 14px; color: var(--ink-soft); font-weight: 500; }

.offline__amount {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 30px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.offline__capped { font-size: 11px; color: var(--ink-soft); }

/* Prestige */

.prestige { display: flex; flex-direction: column; gap: 12px; }

.prestige__intro { font-size: 13px; font-weight: 500; line-height: 1.45; }

.prestige__figures {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.prestige__figures > div {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 8px;
  background: linear-gradient(135deg, var(--purple), var(--gem));
  border: 2px solid var(--ink);
  border-radius: var(--radius-sm);
  color: #fff;
}

.prestige__figure { font-size: 24px; font-weight: 700; text-shadow: 0 2px 0 var(--purple-dark); }
.prestige__caption { font-size: 10px; letter-spacing: 0.06em; opacity: 0.9; }

.prestige__keeps {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 12px;
  font-weight: 500;
}

.prestige__blocked {
  text-align: center;
  font-size: 13px;
  color: var(--ink-soft);
}

/* ------------------------------------------------------------ responsive */

/* Narrow phones: drop the DPS readout so the HUD stays a single row. Wrapping
   to two rows steals a surprising amount of the play area on a 375px screen. */
@media (max-width: 430px) {
  .hud__dps { display: none; }
  #hud { gap: 6px; }
  .counter { padding: 4px 10px 4px 5px; font-size: 14px; }
  .icon-btn { width: 38px; height: 38px; }
  .icon-btn svg { width: 21px; height: 21px; }
  /* Tighten the dead space between the enemy and the combo meter. */
  .stage__arena { padding-bottom: 9%; }
}

/* Short viewports (landscape phones): shrink the arena rather than the panel,
   because the panel is where the game is actually played. */
@media (max-height: 620px) {
  .stage__arena { padding-bottom: 4%; }
  .enemy__sprite { width: clamp(80px, 18vw, 130px); }
  .weapon { width: clamp(60px, 14vw, 100px); }
  .tap-hint { display: none; }
  #panel { max-height: 52dvh; }
}

/* Two-column from tablet width: battle left, upgrades right. */
@media (min-width: 900px) {
  #shake-wrap {
    display: grid;
    grid-template-columns: 1fr minmax(360px, 420px);
    grid-template-rows: auto 1fr;
  }

  #hud { grid-column: 1 / -1; }

  #stage { grid-column: 1; grid-row: 2; }

  #panel {
    grid-column: 2;
    grid-row: 2;
    max-height: none;
    height: 100%;
    border-top: none;
    border-left: var(--border);
  }

  .enemy__sprite { width: clamp(150px, 18vw, 230px); }
  .weapon { width: clamp(110px, 13vw, 165px); }
  .weapon-card__name { font-size: 22px; }
  .track-card__name { font-size: 14px; }
}

/* Wide desktop: give the arena more breathing room. */
@media (min-width: 1300px) {
  .stage__arena { gap: 80px; }
  #toasts { top: calc(72px + var(--safe-top)); }
}
