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

:root {
  --bg: #12100e;
  --bg-deep: #0a0908;
  --panel: #1c1814;
  --panel-2: #241f19;
  --border: #3a3228;
  --border-soft: #2a241c;
  --green: #8bff4a;
  --green-dim: #3d8f1f;
  --green-glow: rgba(139, 255, 74, 0.35);
  --orange: #ff7a2e;
  --orange-dim: #c45a18;
  --orange-glow: rgba(255, 122, 46, 0.4);
  --text: #f0e6d8;
  --muted: #8a7e6e;
  --danger: #ff4444;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --nav-h: 64px;
  --font-display: 'Rubik Mono One', 'Press Start 2P', monospace;
  --font-arcade: 'Press Start 2P', monospace;
  --font-body: 'Manrope', system-ui, -apple-system, sans-serif;
}

html, body {
  height: 100%;
  background: var(--bg-deep);
  color: var(--text);
  font-family: var(--font-body);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

body {
  display: flex;
  justify-content: center;
  align-items: stretch;
}

#app {
  width: 100%;
  max-width: 420px;
  height: 100dvh;
  background:
    radial-gradient(ellipse 120% 50% at 50% -10%, rgba(255, 122, 46, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse 80% 40% at 50% 100%, rgba(139, 255, 74, 0.04) 0%, transparent 40%),
    var(--bg);
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── HUD ── */
.hud {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 8px;
  padding: calc(12px + var(--safe-t)) 12px 10px;
  z-index: 20;
  flex-shrink: 0;
}

.hud-cell {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  position: relative;
  overflow: hidden;
}

.hud-cell::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.03) 0%, transparent 40%);
  pointer-events: none;
}

.coins-cell {
  border-color: rgba(139, 255, 74, 0.35);
  box-shadow: 0 0 16px rgba(139, 255, 74, 0.08), inset 0 0 20px rgba(139, 255, 74, 0.03);
}

.hud-label {
  font-family: var(--font-body);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 3px;
}

.coins-cell .hud-label {
  color: var(--green-dim);
}

.hud-value {
  font-family: var(--font-display);
  font-size: 15px;
  color: var(--green);
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  text-shadow: 0 0 12px var(--green-glow);
  line-height: 1.2;
}

.hud-mini {
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  margin-top: 2px;
}

.bar-wrap {
  width: 100%;
  height: 6px;
  background: var(--bg-deep);
  border-radius: 3px;
  margin-top: 4px;
  overflow: hidden;
  border: 1px solid var(--border-soft);
}

.bar {
  height: 100%;
  width: 100%;
  transform-origin: left center;
  transition: transform 0.12s linear;
  border-radius: 2px;
}

.hp-bar {
  background: linear-gradient(90deg, #c45a18, var(--orange));
  box-shadow: 0 0 8px var(--orange-glow);
}

.energy-bar {
  background: linear-gradient(90deg, var(--green-dim), var(--green));
  box-shadow: 0 0 8px var(--green-glow);
}

/* ── Screens ── */
.screen {
  display: none;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 4px 14px;
  padding-bottom: calc(var(--nav-h) + var(--safe-b) + 16px);
  -webkit-overflow-scrolling: touch;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

.screen-title {
  font-family: var(--font-display);
  font-size: 16px;
  color: var(--text);
  margin: 12px 0 8px;
  text-align: center;
  letter-spacing: 0.04em;
}

.screen-sub {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 16px;
}

/* ── Arena ── */
.arena {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 0;
}

.hamster-wrap {
  position: relative;
  width: min(68vw, 240px);
  height: min(68vw, 240px);
  cursor: pointer;
  touch-action: manipulation;
}

/* Spotlight ring under hamster */
.hamster-wrap::before {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -6%;
  transform: translateX(-50%);
  width: 78%;
  height: 18%;
  background: radial-gradient(ellipse, rgba(255, 122, 46, 0.25) 0%, transparent 70%);
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
}

.hamster-wrap::after {
  content: '';
  position: absolute;
  inset: -8%;
  border-radius: 50%;
  border: 2px solid rgba(255, 122, 46, 0.12);
  box-shadow:
    0 0 0 8px rgba(255, 122, 46, 0.04),
    inset 0 0 30px rgba(0, 0, 0, 0.3);
  pointer-events: none;
  z-index: 0;
}

.hamster-svg {
  width: 100%;
  height: 100%;
  position: relative;
  z-index: 1;
  filter: drop-shadow(0 12px 20px rgba(0, 0, 0, 0.55));
  transition: transform 0.07s cubic-bezier(0.2, 0.8, 0.3, 1);
  transform-origin: center 75%;
}

.hamster-wrap.squash .hamster-svg {
  transform: scaleX(1.1) scaleY(0.9);
}

.hamster-wrap.hit .hamster-svg {
  filter: drop-shadow(0 12px 20px rgba(0, 0, 0, 0.55)) brightness(1.25) saturate(1.15);
}

.hamster-wrap.ko .hamster-svg {
  transform: rotate(-14deg) translateY(8px) scale(0.96);
  filter: grayscale(0.5) brightness(0.65) drop-shadow(0 8px 12px rgba(0, 0, 0, 0.4));
}

.hamster-wrap.ko::after {
  border-color: rgba(255, 68, 68, 0.25);
  box-shadow: 0 0 0 8px rgba(255, 68, 68, 0.06);
}

.tap-hint {
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--muted);
  margin-top: 20px;
  text-transform: uppercase;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.85; }
}

.stats-row {
  display: flex;
  gap: 24px;
  margin-top: 16px;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.stats-row b {
  color: var(--green);
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 400;
  margin-left: 4px;
}

.ko-banner {
  position: absolute;
  top: 4%;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-display);
  font-size: 13px;
  color: var(--orange);
  background: rgba(18, 14, 10, 0.92);
  border: 1.5px solid var(--orange);
  border-radius: 8px;
  padding: 10px 16px;
  z-index: 5;
  letter-spacing: 0.06em;
  box-shadow: 0 0 24px var(--orange-glow);
  animation: ko-pulse 0.5s ease infinite alternate;
  white-space: nowrap;
}

.ko-banner.hidden { display: none; }

@keyframes ko-pulse {
  from { box-shadow: 0 0 16px var(--orange-glow); }
  to { box-shadow: 0 0 28px rgba(255, 122, 46, 0.55); }
}

/* ── Particles ── */
.particles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
  z-index: 10;
}

.particle {
  position: absolute;
  font-family: var(--font-display);
  font-size: 15px;
  color: var(--green);
  text-shadow: 0 0 10px var(--green-glow);
  pointer-events: none;
  animation: float-up 0.85s cubic-bezier(0.2, 0.7, 0.3, 1) forwards;
  white-space: nowrap;
  z-index: 10;
}

.particle.crit {
  color: var(--orange);
  font-size: 17px;
  text-shadow: 0 0 14px var(--orange-glow);
}

@keyframes float-up {
  0% { opacity: 1; transform: translate(-50%, 0) scale(0.9); }
  20% { opacity: 1; transform: translate(-50%, -16px) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -72px) scale(1.05); }
}

/* ── Shake ── */
#app.shake {
  animation: shake 0.32s ease-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-5px); }
  30% { transform: translateX(5px); }
  45% { transform: translateX(-3px); }
  60% { transform: translateX(3px); }
  75% { transform: translateX(-1px); }
}

/* ── Upgrades ── */
.upgrades-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.upgrade-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 12px 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
  box-shadow: 0 2px 0 var(--bg-deep);
}

.upgrade-card:active {
  transform: scale(0.985);
}

.upgrade-card.affordable {
  border-color: rgba(139, 255, 74, 0.4);
  background: linear-gradient(135deg, var(--panel) 0%, rgba(61, 143, 31, 0.08) 100%);
}

.upgrade-card.maxed {
  opacity: 0.5;
}

.upg-icon {
  width: 44px;
  height: 44px;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.upgrade-card.affordable .upg-icon {
  border-color: rgba(139, 255, 74, 0.3);
  box-shadow: 0 0 12px rgba(139, 255, 74, 0.1);
}

.upg-info {
  flex: 1;
  min-width: 0;
}

.upg-name {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 2px;
}

.upg-desc {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 3px;
  line-height: 1.3;
}

.upg-lvl {
  font-size: 11px;
  font-weight: 600;
  color: var(--green-dim);
  letter-spacing: 0.02em;
}

.upg-buy {
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 700;
  background: var(--orange);
  color: #1a1008;
  border: none;
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  box-shadow: 0 3px 0 var(--orange-dim);
  transition: transform 0.08s, box-shadow 0.08s;
  min-width: 72px;
  text-align: center;
}

.upg-buy:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--orange-dim);
}

.upg-buy:disabled {
  background: var(--border-soft);
  color: var(--muted);
  box-shadow: 0 2px 0 #1a1612;
  cursor: not-allowed;
}

/* ── Profile ── */
.profile-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 16px;
  margin-bottom: 20px;
}

.profile-name {
  font-family: var(--font-display);
  font-size: 16px;
  color: var(--green);
  margin-bottom: 14px;
  text-shadow: 0 0 16px var(--green-glow);
}

.profile-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-soft);
  color: var(--muted);
}

.profile-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.profile-row b {
  color: var(--text);
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 400;
}

.lb-title {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}

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

.lb-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
}

.lb-row.me {
  border-color: rgba(139, 255, 74, 0.4);
  background: linear-gradient(90deg, rgba(61, 143, 31, 0.12), var(--panel));
}

.lb-rank {
  font-family: var(--font-display);
  font-size: 12px;
  color: var(--orange);
  width: 32px;
  flex-shrink: 0;
}

.lb-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.lb-coins {
  font-family: var(--font-display);
  font-size: 12px;
  color: var(--green);
  flex-shrink: 0;
}

/* ── Bottom nav ── */
.bottom-nav {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: rgba(10, 9, 8, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-soft);
  display: flex;
  z-index: 30;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 4px;
  transition: color 0.15s;
  position: relative;
}

.nav-btn.active {
  color: var(--green);
}

.nav-btn.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 28px;
  height: 2px;
  background: var(--green);
  border-radius: 0 0 2px 2px;
  box-shadow: 0 0 10px var(--green-glow);
}

.nav-icon {
  font-size: 20px;
  line-height: 1;
  transition: transform 0.15s;
}

.nav-btn.active .nav-icon {
  transform: scale(1.08);
}

/* ── Toast ── */
.toast {
  position: fixed;
  top: calc(18% + var(--safe-t));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(18, 16, 14, 0.95);
  border: 1px solid var(--green);
  border-radius: 10px;
  color: var(--green);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 700;
  padding: 12px 20px;
  z-index: 100;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), 0 0 20px var(--green-glow);
  max-width: 85%;
  text-align: center;
  backdrop-filter: blur(8px);
}

.toast.hidden { display: none; }

.toast.error {
  border-color: var(--danger);
  color: var(--danger);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), 0 0 16px rgba(255, 68, 68, 0.3);
}

/* ── Withdraw ── */
.withdraw-block {
  margin-bottom: 20px;
}

.withdraw-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
}

.withdraw-card.hidden { display: none; }

.withdraw-hint {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.4;
  margin-bottom: 12px;
}

.withdraw-hint b { color: var(--orange); }

.withdraw-hint.muted { color: var(--muted); opacity: 0.8; }

.withdraw-progress-wrap {
  height: 8px;
  background: var(--bg-deep);
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--border-soft);
  margin-bottom: 8px;
}

.withdraw-progress {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--orange-dim), var(--orange));
  border-radius: 3px;
  transition: width 0.3s ease;
}

.withdraw-prog-text {
  font-family: var(--font-display);
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 14px;
  text-align: center;
}

.withdraw-btn {
  width: 100%;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 700;
  background: var(--orange);
  color: #1a1008;
  border: none;
  border-radius: 10px;
  padding: 14px 16px;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--orange-dim);
}

.withdraw-btn:disabled {
  background: var(--border-soft);
  color: var(--muted);
  box-shadow: 0 2px 0 #1a1612;
  cursor: not-allowed;
}

.withdraw-btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--orange-dim);
}

.withdraw-btn-go {
  margin-top: 8px;
}

.withdraw-btn-cancel {
  width: 100%;
  margin-top: 8px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 10px;
  padding: 12px;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
  margin-top: 10px;
}

.field-input {
  width: 100%;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  outline: none;
}

.field-input:focus {
  border-color: var(--orange);
}

.withdraw-done-title {
  font-family: var(--font-display);
  font-size: 14px;
  color: var(--green);
  margin-bottom: 8px;
  text-shadow: 0 0 12px var(--green-glow);
}

/* small screens */
@media (max-width: 360px) {
  .hud {
    gap: 6px;
    padding-left: 10px;
    padding-right: 10px;
  }
  .hud-value {
    font-size: 13px;
  }
  .hamster-wrap {
    width: min(64vw, 200px);
    height: min(64vw, 200px);
  }
  .upg-buy {
    min-width: 64px;
    padding: 9px 10px;
    font-size: 11px;
  }
}

/* ── Skins ── */
.skins-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.skin-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.skin-card.active {
  border-color: rgba(139, 255, 74, 0.5);
  box-shadow: 0 0 16px rgba(139, 255, 74, 0.12);
}

.skin-emoji {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  flex-shrink: 0;
}

.skin-info { flex: 1; min-width: 0; }
.skin-name {
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 2px;
}
.skin-desc {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.35;
}
.skin-btn {
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 700;
  border: none;
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  white-space: nowrap;
  background: var(--orange);
  color: #1a1008;
  box-shadow: 0 3px 0 var(--orange-dim);
  flex-shrink: 0;
}
.skin-btn:disabled {
  background: var(--border-soft);
  color: var(--muted);
  box-shadow: none;
  cursor: default;
}
.skin-btn.equip {
  background: var(--green);
  box-shadow: 0 3px 0 var(--green-dim);
  color: #0a1405;
}
.skin-btn.active-label {
  background: transparent;
  color: var(--green);
  box-shadow: none;
  border: 1px solid var(--green-dim);
}

.skin-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  z-index: 4;
  font-size: 22px;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5));
}
.skin-badge.hidden { display: none; }

/* Visual skins on beaver */
.hamster-wrap.skin-newyear .hamster-svg {
  filter: drop-shadow(0 12px 20px rgba(0,0,0,0.55)) saturate(1.2) hue-rotate(-15deg) brightness(1.05);
}
.hamster-wrap.skin-gold .hamster-svg {
  filter: drop-shadow(0 0 18px rgba(255, 200, 60, 0.55)) sepia(0.55) saturate(1.8) brightness(1.15);
}
.hamster-wrap.skin-cyber .hamster-svg {
  filter: drop-shadow(0 0 16px rgba(80, 220, 255, 0.5)) hue-rotate(160deg) saturate(1.4) brightness(1.1);
}
