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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #070b14;
  color: #f4f7ff;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  overscroll-behavior: none;
}

body {
  display: block;
  min-height: 100dvh;
  min-height: 100svh;
  padding: 0;
}

.app {
  width: 100%;
  height: 100dvh;
  height: 100svh;
  max-width: none;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
}

.hud {
  display: flex;
  justify-content: space-between;
  flex-shrink: 0;
  margin-bottom: 0;
  padding: 10px 16px 8px;
  font-size: 15px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #9aa6c3;
}

.hud strong {
  color: #fff;
  font-size: 20px;
  margin-left: 6px;
}

.playfield {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #070b14;
}

.frame {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
}

.stage {
  position: relative;
  overflow: hidden;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  background: #10182a;
}

.frame.is-letterboxed {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  border-radius: 18px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
  overflow: hidden;
  background: #070b14;
}

.frame.is-letterboxed .stage {
  flex: none;
}

canvas {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  touch-action: none;
}

.star-bar {
  position: absolute;
  left: 16px;
  right: 16px;
  top: 56px;
  z-index: 4;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(7, 11, 20, 0.72);
  border: 1px solid #ffe27a;
  pointer-events: none;
}

.star-bar span {
  display: block;
  margin-bottom: 6px;
  color: #ffe27a;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.star-bar-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #2a3553;
}

.star-bar-fill {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #ffe27a, #ff8a1f);
  transition: width 0.08s linear;
}

.star-bar.low {
  border-color: #ff6b4a;
}

.star-bar.low span,
.star-bar.low .star-bar-fill {
  background: linear-gradient(90deg, #ffb347, #ff4d4d);
}

.star-bar.low span {
  background: none;
  color: #ffb347;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  background: rgba(7, 11, 20, 0.42);
  padding: 12px;
  pointer-events: auto;
}

.panel {
  display: flex;
  flex-direction: column;
  width: min(520px, 100%);
  max-height: 100%;
  overflow: hidden;
  padding: 20px 16px 16px;
  border-radius: 18px;
  background: #151d31;
  border: 1px solid #2a3553;
  text-align: center;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.panel::-webkit-scrollbar {
  display: none;
}

.panel.hidden,
.hidden {
  display: none !important;
}

.eyebrow {
  color: #7dd6c8;
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.panel h1 {
  font-size: 28px;
  margin-bottom: 10px;
}

.intro,
.panel p {
  color: #c5cde0;
  line-height: 1.45;
}

.intro {
  margin-bottom: 16px;
}

.heroes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  flex: 1 1 auto;
  min-height: 0;
  margin-bottom: 14px;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.heroes::-webkit-scrollbar {
  display: none;
}

.hero-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 10px 6px 12px;
  border-radius: 14px;
  border: 2px solid #2a3553;
  background: #10182a;
  color: #f4f7ff;
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
}

.hero-card span {
  line-height: 1.15;
  min-height: 2.3em;
}

.hero-card:hover:not(:disabled) {
  border-color: #4c5d86;
}

.hero-card.selected {
  border-color: #3dd6c6;
  box-shadow: 0 0 0 3px rgba(61, 214, 198, 0.22);
}

.hero-card.locked {
  opacity: 0.55;
  cursor: not-allowed;
}

.hero-card.locked img {
  filter: grayscale(1) brightness(0.7);
}

.hero-preview-img {
  width: 52px;
  height: 68px;
  object-fit: contain;
  display: block;
}

.chest {
  width: 150px;
  height: 124px;
  margin: 10px auto 8px;
  position: relative;
  background: transparent;
  border: 0;
  padding: 0;
  border-radius: 0;
}

.chest:hover:not(:disabled) {
  background: transparent;
  transform: translateY(-2px);
}

.chest-lid,
.chest-body,
.chest-lock {
  position: absolute;
  box-sizing: border-box;
}

.chest-lid {
  left: 12px;
  right: 12px;
  top: 10px;
  height: 44px;
  background: linear-gradient(#f0c43a, #c48a12);
  border: 3px solid #6b4310;
  border-radius: 14px 14px 5px 5px;
  transform-origin: bottom center;
  transition: transform 0.45s ease;
  z-index: 2;
}

.chest.open .chest-lid {
  transform: translateY(-16px) rotate(-12deg);
}

.chest-body {
  left: 10px;
  right: 10px;
  bottom: 10px;
  height: 64px;
  background: linear-gradient(#e0ad20, #8f6910);
  border: 3px solid #6b4310;
  border-radius: 6px 6px 16px 16px;
}

.chest-lock {
  left: 50%;
  bottom: 38px;
  width: 24px;
  height: 28px;
  margin-left: -12px;
  background: #ffe27a;
  border: 3px solid #6b4310;
  border-radius: 6px;
  z-index: 3;
}

.chest-reward {
  display: grid;
  justify-items: center;
  gap: 8px;
  margin: 8px 0 14px;
}

.chest-reward img {
  width: 88px;
  height: 110px;
  object-fit: contain;
  background: transparent;
  border: 0;
}

.chest-reward img:not([src]) {
  display: none;
}

.chest-reward strong {
  color: #ffe27a;
  font-size: 18px;
}

.hint {
  margin-bottom: 14px;
  font-size: 13px;
}

.help-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  text-align: left;
  color: #c5cde0;
  line-height: 1.55;
  margin: 0 8px 16px;
  padding-left: 20px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.help-list::-webkit-scrollbar {
  display: none;
}

.help-list li {
  margin-bottom: 8px;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 12px 28px;
  background: #3dd6c6;
  color: #07201c;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: #63eadb;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.actions {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  gap: 10px;
  margin-top: 8px;
}

.hint {
  flex-shrink: 0;
}

.secondary {
  background: transparent;
  color: #c5cde0;
  border: 1px solid #3a4666;
}

.secondary:hover:not(:disabled) {
  background: #1d2740;
}

.corner-btn {
  position: absolute;
  top: 12px;
  z-index: 5;
  padding: 8px 16px;
  font-size: 14px;
}

.menu-btn {
  left: 12px;
}

.pause-btn {
  right: 12px;
}

.corner-btn.hidden {
  display: none;
}

.level-list {
  display: grid;
  flex: 1 1 auto;
  min-height: 0;
  gap: 8px;
  margin-bottom: 16px;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.level-list::-webkit-scrollbar {
  display: none;
}

.level-btn {
  width: 100%;
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #10182a;
  color: #f4f7ff;
  border: 2px solid #2a3553;
  font-size: 15px;
}

.level-btn:hover:not(:disabled) {
  background: #1d2740;
  border-color: #3dd6c6;
}

.level-btn:disabled {
  opacity: 0.45;
}

.level-btn .meta {
  color: #9aa6c3;
  font-size: 12px;
  font-weight: 600;
}

@media (min-width: 768px) {
  .hud {
    font-size: 18px;
    padding: 12px 24px 10px;
  }

  .hud strong {
    font-size: 26px;
  }

  .heroes {
    grid-template-columns: repeat(4, 1fr);
  }

  .panel {
    width: min(640px, 94%);
  }

  .corner-btn {
    padding: 10px 20px;
    font-size: 16px;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .hud {
    padding: 6px 12px;
    font-size: 13px;
  }

  .hud strong {
    font-size: 16px;
  }

  .heroes {
    min-height: 72px;
  }

  .panel h1 {
    font-size: 22px;
  }
}
