* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #d8cdbc;
  color: #2c2c2c;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

#game-root,
#game {
  width: 100%;
  height: 100%;
}

#game-root::before,
#game-root::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

#game-root::before {
  background:
    radial-gradient(circle at 42% 22%, rgba(81, 207, 102, 0.08), transparent 26%),
    radial-gradient(circle at 72% 68%, rgba(255, 217, 61, 0.08), transparent 30%),
    radial-gradient(circle at 50% 50%, transparent 64%, rgba(44, 44, 44, 0.08) 100%);
  mix-blend-mode: normal;
}

#game-root::after {
  opacity: 0.08;
  background-image: linear-gradient(135deg, rgba(44, 44, 44, 0.06) 0 2px, transparent 2px 18px);
  background-size: 36px 36px;
}

#game {
  display: block;
  touch-action: none;
}

#hud {
  position: fixed;
  top: 14px;
  left: 14px;
  right: 14px;
  z-index: 3;
  pointer-events: none;
}

.hud-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand {
  min-width: 0;
  max-width: 42vw;
  padding: 8px 10px;
  border: 3px solid #2c2c2c;
  border-radius: 12px;
  background: #fffbf2;
  box-shadow: 4px 4px 0 #2c2c2c;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat {
  min-width: 68px;
  padding: 7px 9px;
  border: 3px solid #2c2c2c;
  border-radius: 12px;
  background: #fffbf2;
  box-shadow: 4px 4px 0 #2c2c2c;
}

.stat span {
  display: block;
  color: #237804;
  font-size: 10px;
  font-weight: 800;
}

.stat strong {
  display: block;
  font-size: 16px;
  line-height: 1.05;
}

.bars {
  width: min(560px, calc(100vw - 28px));
  margin-top: 10px;
}

.bar {
  width: 100%;
  height: 10px;
  margin-bottom: 7px;
  border: 3px solid #2c2c2c;
  border-radius: 12px;
  background: #fffbf2;
  box-shadow: 3px 3px 0 #2c2c2c;
}

.bar i {
  display: block;
  width: 100%;
  height: 100%;
  transform-origin: left center;
  transform: scaleX(1);
}

.health i {
  background: #fa5252;
}

.xp i {
  background: #52c41a;
}

#skill-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: min(560px, calc(100vw - 28px));
  margin-top: 10px;
}

.skill-icon {
  position: relative;
  width: 54px;
  height: 54px;
  border: 3px solid #2c2c2c;
  border-radius: 14px;
  background: #fffbf2;
  box-shadow: 4px 4px 0 #2c2c2c;
  overflow: hidden;
}

.skill-icon.locked {
  opacity: 0.42;
}

.skill-icon::before {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 9px;
  background: color-mix(in srgb, var(--skill-color) 18%, transparent);
}

.skill-icon .cooldown {
  position: absolute;
  inset: auto 0 0;
  height: 0%;
  background: color-mix(in srgb, var(--skill-color) 34%, transparent);
  transition: height 80ms linear;
}

.skill-icon .glyph {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 24px;
  font-weight: 900;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.72);
}

.skill-icon .level {
  position: absolute;
  right: 4px;
  bottom: 3px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border: 2px solid #2c2c2c;
  border-radius: 9px;
  background: #ffd93d;
  font-size: 11px;
  font-weight: 900;
  line-height: 14px;
  text-align: center;
}

#upgrade-panel {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  place-content: center;
  gap: 18px;
  padding: 18px;
  background: rgba(216, 205, 188, 0.9);
  backdrop-filter: blur(8px);
}

#upgrade-panel.hidden {
  display: none;
}

#upgrade-panel h1 {
  margin: 0;
  font-size: clamp(24px, 4vw, 42px);
  text-align: center;
}

#upgrade-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(168px, 240px));
  gap: 12px;
}

.upgrade {
  position: relative;
  min-height: 164px;
  padding: 14px;
  border: 3px solid #2c2c2c;
  border-radius: 16px;
  background: #fffbf2;
  color: #2c2c2c;
  box-shadow: 4px 4px 0 #2c2c2c;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  transform: translateY(0) scale(1);
  transition:
    transform 140ms ease,
    background 140ms ease;
}

.upgrade:hover,
.upgrade:focus-visible {
  outline: 3px solid #52c41a;
  outline-offset: 3px;
  transform: translateY(-4px) scale(1.02);
}

.upgrade.selected {
  animation: upgrade-pop 320ms ease both;
}

.upgrade.not-selected {
  opacity: 0.35;
  transform: scale(0.96);
}

.upgrade b {
  display: block;
  margin-bottom: 8px;
  font-size: 19px;
}

.upgrade span {
  display: block;
  color: #646464;
  font-size: 14px;
  line-height: 1.45;
}

.upgrade-glow {
  position: absolute;
  inset: -18px;
  background: radial-gradient(circle at 24% 18%, color-mix(in srgb, var(--upgrade-color) 46%, transparent), transparent 38%);
  opacity: 0.8;
  pointer-events: none;
}

.upgrade-top {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.upgrade-icon {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border: 3px solid #2c2c2c;
  border-radius: 16px;
  background: color-mix(in srgb, var(--upgrade-color) 68%, #ffffff);
  box-shadow: 4px 4px 0 #2c2c2c;
  color: #2c2c2c;
  font-size: 28px;
  font-weight: 900;
}

.upgrade-level {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 7px;
  border: 2px solid #2c2c2c;
  border-radius: 999px;
  background: #ffffff;
  font-size: 12px;
  font-weight: 900;
}

.upgrade-level b {
  display: inline;
  margin: 0;
  color: var(--upgrade-color);
  font-size: 14px;
}

.upgrade-preview {
  position: relative;
  display: flex;
  gap: 5px;
  margin-top: 12px;
}

.upgrade-preview i {
  display: block;
  width: 28px;
  height: 8px;
  border-radius: 999px;
  background: var(--upgrade-color);
  animation: preview-pulse 900ms ease-in-out infinite;
}

.upgrade-preview i:nth-child(2) {
  animation-delay: 120ms;
}

.upgrade-preview i:nth-child(3) {
  animation-delay: 240ms;
}

@keyframes preview-pulse {
  0%,
  100% {
    transform: scaleX(0.72);
    opacity: 0.45;
  }
  50% {
    transform: scaleX(1.35);
    opacity: 1;
  }
}

@keyframes upgrade-pop {
  0% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.12) rotate(-1deg);
    background: color-mix(in srgb, var(--upgrade-color) 24%, #ffffff);
  }
  100% {
    transform: scale(0.94);
    opacity: 0;
  }
}

#mobile-stick {
  position: fixed;
  left: 18px;
  bottom: 18px;
  z-index: 4;
  display: none;
  width: 116px;
  height: 116px;
  border: 3px solid #2c2c2c;
  border-radius: 50%;
  background: rgba(255, 251, 242, 0.78);
  box-shadow: 4px 4px 0 #2c2c2c;
  touch-action: none;
}

#stick-knob {
  position: absolute;
  left: 39px;
  top: 39px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #4dabf7;
  border: 3px solid #2c2c2c;
}

#toast {
  position: fixed;
  left: 14px;
  bottom: 14px;
  z-index: 3;
  max-width: min(320px, calc(100vw - 28px));
  padding: 9px 11px;
  border: 3px solid #2c2c2c;
  border-radius: 12px;
  background: #fffbf2;
  color: #2c2c2c;
  box-shadow: 4px 4px 0 #2c2c2c;
  font-size: 13px;
  pointer-events: none;
}

#start-screen,
#death-screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-content: center;
  padding: 18px;
  background: rgba(216, 205, 188, 0.96);
  backdrop-filter: blur(6px);
}

#start-screen.hidden,
#death-screen.hidden {
  display: none;
}

.screen-box {
  width: min(460px, 100%);
  padding: 32px 28px;
  border: 4px solid #2c2c2c;
  border-radius: 20px;
  background: #fffbf2;
  box-shadow: 6px 6px 0 #2c2c2c;
  text-align: center;
}

.screen-brand {
  margin-bottom: 10px;
  font-size: clamp(28px, 6vw, 46px);
  font-weight: 900;
  letter-spacing: -0.5px;
  line-height: 1.1;
}

.screen-sub {
  margin: 0 0 22px;
  color: #646464;
  font-size: 15px;
}

.screen-controls {
  display: grid;
  gap: 8px;
  margin-bottom: 26px;
  text-align: left;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 2px solid #2c2c2c;
  border-radius: 10px;
  background: #fffbf2;
  box-shadow: 3px 3px 0 #2c2c2c;
  font-size: 13px;
}

.key {
  min-width: 52px;
  padding: 3px 8px;
  border: 2px solid #2c2c2c;
  border-radius: 6px;
  background: #d8cdbc;
  font-size: 11px;
  font-weight: 800;
  text-align: center;
}

#start-btn,
#restart-btn,
#portal-btn {
  display: block;
  width: 100%;
  padding: 14px;
  border: 3px solid #2c2c2c;
  border-radius: 14px;
  background: #52c41a;
  color: #fffbf2;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.5px;
  box-shadow: 4px 4px 0 #2c2c2c;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

#start-btn:hover,
#restart-btn:hover {
  transform: translateY(-3px);
  box-shadow: 6px 6px 0 #2c2c2c;
}

#start-btn:active,
#restart-btn:active {
  transform: translateY(1px);
  box-shadow: 2px 2px 0 #2c2c2c;
}

#portal-btn {
  margin-top: 10px;
  background: #845ef7;
}

.countdown {
  margin-top: 18px;
  font-size: 72px;
  font-weight: 900;
  color: #2c2c2c;
  animation: count-pop 0.6s ease both;
}

.countdown.hidden {
  display: none;
}

@keyframes count-pop {
  0% { transform: scale(1.8); opacity: 0; }
  50% { transform: scale(0.9); }
  100% { transform: scale(1); opacity: 1; }
}

.screen-title {
  margin-bottom: 20px;
  font-size: clamp(28px, 5vw, 42px);
  font-weight: 900;
  color: #fa5252;
  letter-spacing: 1px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 26px;
}

.stat-item {
  padding: 12px 8px;
  border: 3px solid #2c2c2c;
  border-radius: 12px;
  background: #fffbf2;
  box-shadow: 3px 3px 0 #2c2c2c;
}

.stat-label {
  display: block;
  color: #237804;
  font-size: 10px;
  font-weight: 800;
}

.stat-item strong {
  display: block;
  font-size: 22px;
  font-weight: 900;
}

.death-actions {
  display: grid;
  gap: 8px;
}

@media (pointer: coarse) {
  #mobile-stick {
    display: block;
  }

  #toast {
    left: 152px;
    right: 14px;
    max-width: none;
  }
}

@media (max-width: 680px) {
  .hud-row {
    gap: 6px;
  }

  .brand {
    max-width: 34vw;
    font-size: 12px;
  }

  .stat {
    min-width: 54px;
    padding: 6px 7px;
  }

  .stat strong {
    font-size: 14px;
  }

  #upgrade-options {
    grid-template-columns: 1fr;
    width: min(420px, calc(100vw - 36px));
  }

  .upgrade {
    min-height: 112px;
  }
}
