* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

:root {
  --bg: #05060d;
  --panel: #0d1122;
  --line: #1d2442;
  --text: #e8ecff;
  --muted: #8a93b8;
  --hud-min: 170px;   /* portrait: minimum HUD height above the play area */
  --hud-side: 260px;  /* landscape: minimum HUD width beside the play area */
  /* Side of the square play area. vh fallback first, dvh where supported. */
  --s: min(100vw, calc(100vh - var(--hud-min)));
  --s: min(100vw, calc(100dvh - var(--hud-min)));
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#stage {
  flex: none;
  width: var(--s);
  height: var(--s);
  position: relative;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
}

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

#hud {
  width: var(--s);
  flex: 1 1 auto;
  min-height: var(--hud-min);
  max-height: 440px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: hidden;
  font-size: 12px;
}

@media (orientation: landscape) {
  :root {
    --s: min(100vh, calc(100vw - var(--hud-side)));
    --s: min(100dvh, calc(100vw - var(--hud-side)));
  }
  #app { flex-direction: row; }
  #hud {
    order: 2;
    height: var(--s);
    max-height: none;
    width: min(380px, calc(100vw - var(--s)));
    min-width: var(--hud-side);
    flex: none;
    padding: 14px;
    gap: 10px;
    font-size: 13px;
  }
  .powers { flex-direction: column; }
}

.hud-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.label, .section-label, .bar-label {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1.2px;
  font-size: 10px;
  font-weight: 700;
}

.score {
  font-size: 30px;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.score span { font-size: 16px; color: var(--muted); margin-left: 2px; }
.best { color: var(--muted); font-size: 11px; margin-top: 2px; }
.best span { color: var(--text); font-weight: 700; }

.hud-buttons { display: flex; gap: 6px; }
.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}
.icon-btn.off { color: var(--muted); text-decoration: line-through; }

.bars { display: flex; flex-direction: column; gap: 4px; }
.bar-row {
  display: grid;
  grid-template-columns: 52px 1fr 30px;
  align-items: center;
  gap: 6px;
  transition: opacity 0.2s;
}
.bar {
  height: 8px;
  border-radius: 4px;
  background: var(--line);
  overflow: hidden;
}
.fill { height: 100%; width: 100%; transition: width 0.15s linear; }
.bar-val { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 4px;
}
.chip {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 6px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.chip span { color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: 0.8px; }
.chip b { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.powers {
  display: flex;
  gap: 10px;
  min-height: 0;
  flex: 1 1 auto;
}
.power-col {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow: hidden;
}
.active-powers, .queue { display: flex; flex-direction: column; gap: 4px; }
.queue { flex-direction: row; flex-wrap: wrap; }

.power {
  display: flex;
  gap: 6px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--c);
  border-radius: 6px;
  padding: 3px 6px;
}
.glyph {
  color: var(--c);
  font-weight: 800;
  min-width: 20px;
  text-align: center;
}
.power-body { flex: 1; min-width: 0; }
.power-name {
  font-weight: 700;
  display: flex;
  justify-content: space-between;
  gap: 6px;
  white-space: nowrap;
}
.power-name em { font-style: normal; color: var(--muted); font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.power-bar { height: 3px; background: var(--line); border-radius: 2px; margin-top: 3px; overflow: hidden; }
.power-bar div { height: 100%; background: var(--c); }

.qchip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 2px 8px 2px 4px;
  font-size: 11px;
  white-space: nowrap;
}
.empty { color: var(--muted); font-style: italic; font-size: 11px; }

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

#overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(3, 4, 10, 0.72);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 10;
  cursor: pointer;
  padding: 20px;
}
#overlay.show { display: flex; }

.panel {
  max-width: 440px;
  width: 100%;
  text-align: center;
  background: rgba(13, 17, 34, 0.92);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 15px;
  line-height: 1.45;
}
.panel h1 {
  font-size: 44px;
  font-weight: 900;
  letter-spacing: 4px;
  background: linear-gradient(90deg, #ff5fa8, #ffa040, #58f08a);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
#ovBody { display: flex; flex-direction: column; gap: 10px; }

/* ---------------------------------------------------------------- logo
   "POG" in a pink → orange → green gradient, "2" white, bigger, tilted, in a different font.
   Mirrored on the share card by drawLogo() in js/share.js. */
.panel h1.logo-title {
  background: none;
  color: inherit;
  letter-spacing: 0;
  font-size: clamp(56px, 16vw, 76px);
  font-weight: 400;
  margin: 4px 0 2px;
}
.logo {
  display: inline-flex;
  align-items: center;
  gap: 0.14em;
  line-height: 1;
  white-space: nowrap;
}
.logo-pog {
  font-family: "Luckiest Guy", "Arial Black", Impact, sans-serif;
  letter-spacing: 0.04em;
  padding-top: 0.1em;
  background: linear-gradient(90deg, #ff5fa8 0%, #ff5fa8 18%, #ffa040 50%, #58f08a 82%, #58f08a 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-stroke: 0.045em #1a1033;
  paint-order: stroke fill;
  filter: drop-shadow(0 0.07em 0 #1a1033);
}
.logo-2 {
  display: inline-block;
  font-family: "Bungee", "Arial Black", Impact, sans-serif;
  font-size: 1.4em;
  color: #ffffff;
  -webkit-text-stroke: 0.035em #1a1033;
  paint-order: stroke fill;
  text-shadow: 0 0.06em 0 #1a1033, 0 0 0.3em rgba(255, 255, 255, 0.45);
  transform: rotate(-8deg) translateY(-0.04em);
  animation: logo-bob 2.6s ease-in-out infinite;
}
@keyframes logo-bob {
  50% { transform: rotate(-3deg) translateY(-0.1em) scale(1.04); }
}
@media (prefers-reduced-motion: reduce) {
  .logo-2 { animation: none; }
}
.muted { color: var(--muted); font-size: 13px; }
.legend { display: inline-flex; align-items: center; gap: 4px; margin: 0 6px; white-space: nowrap; }
.legend i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.powers-legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 4px; font-size: 13px; }
.powers-legend b { margin-right: 2px; }
.final { font-size: 56px; font-weight: 900; line-height: 1; }
.final span { font-size: 24px; color: var(--muted); }
.new-best { color: #ffe066; }
.cta {
  margin-top: 4px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: #58f08a;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.45; } }

/* Game-over / share screen */
#overlay.over { cursor: default; }
#overlay.over .cta { display: none; }
#overlay.over .panel { gap: 8px; padding: 18px; }
#overlay.over h1 { font-size: 30px; }
#overlay.over .final { font-size: 48px; }
.share-img {
  display: block;
  margin: 2px auto;
  width: auto;
  max-width: 100%;
  height: min(42vh, 400px);
  height: min(42dvh, 400px);
  aspect-ratio: 1080 / 1350;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #05060d;
  opacity: 0;
  transition: opacity 0.25s;
}
.share-img.ready { opacity: 1; }
.final-actions { display: flex; gap: 10px; justify-content: center; }
.btn {
  flex: 1 1 0;
  max-width: 180px;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  cursor: pointer;
}
.btn.primary { background: #58f08a; border-color: #58f08a; color: #05200f; }
.btn:disabled { opacity: 0.5; cursor: wait; }
