:root {
  color-scheme: dark;
  --bg: #0f1020;
  --panel: #1a1b28;
  --panel-2: #212233;
  --line: #2f3148;
  --accent: #6842ff;
  --accent-hi: #8c6dff;
  --text: #fff;
  --muted: #aaadbe;
  --secondary: #2a2b3d;
  --gold: #ffc53d;
  font-family:
    "Nunito", ui-rounded, "SF Pro Rounded", system-ui, -apple-system,
    "Segoe UI", sans-serif;
}
* {
  box-sizing: border-box;
}
html,
body {
  width: 100%;
  min-width: 0;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}
body {
  padding: 12px;
  overflow-x: hidden;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
button {
  font: inherit;
  color: inherit;
}
:focus-visible {
  outline: 3px solid #b9a8ff;
  outline-offset: 2px;
}

/* ---------- layout ---------- */
.tg {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas:
    "brand"
    "hud"
    "stage"
    "actions"
    "help";
  gap: 10px;
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
}
.tg-brand {
  grid-area: brand;
}
.tg-hud {
  grid-area: hud;
}
.tg-stage {
  grid-area: stage;
}
.tg-actions {
  grid-area: actions;
}
.tg-help {
  grid-area: help;
}



/* ---------- brand ---------- */
.tg-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.tg-logo {
  width: 40px;
  height: 40px;
  flex: none;
  filter: drop-shadow(0 3px 6px rgb(0 0 0 / 0.45));
}
.tg-brand-text {
  min-width: 0;
}
.tg-brand h1 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 900;
  line-height: 1.05;
  letter-spacing: -0.01em;
  background: linear-gradient(180deg, #fff 30%, #c9bcff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tg-brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  line-height: 1.25;
}

/* ---------- HUD chips ---------- */
.tg-hud {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}
.chip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  min-height: 40px;
  padding: 6px 10px;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.07),
    0 4px 10px rgb(0 0 0 / 0.25);
}
.chip svg {
  width: 20px;
  height: 20px;
  flex: none;
  filter: drop-shadow(0 1px 1px rgb(0 0 0 / 0.4));
}
.chip-label {
  display: none;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.chip strong {
  font-size: 1.08rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  white-space: nowrap;
}
.chip-gold strong {
  color: #ffd45e;
}
.chip-lives strong {
  color: #ff8fa3;
}
.chip.bump {
  animation: chip-bump 0.35s ease;
}
.chip.shake {
  animation: shake 0.4s ease;
}
@keyframes chip-bump {
  40% {
    transform: scale(1.12);
  }
}
@keyframes shake {
  20%,
  60% {
    transform: translateX(-6px);
  }
  40%,
  80% {
    transform: translateX(6px);
  }
}

/* ---------- stage ---------- */
.tg-stage {
  position: relative;
  min-width: 0;
  border-radius: 20px;
  overflow: hidden;
  background: #274a2a;
  box-shadow:
    0 0 0 3px #2a2b3d,
    0 0 0 5px #151625,
    0 16px 40px rgb(0 0 0 / 0.5);
}
#board {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
  touch-action: manipulation;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
#board:focus-visible {
  outline: none;
}
.tg-stage:has(#board:focus-visible) {
  box-shadow:
    0 0 0 3px #b9a8ff,
    0 0 0 5px #151625,
    0 16px 40px rgb(0 0 0 / 0.5);
}

.tg-banner {
  position: absolute;
  left: 50%;
  top: 12px;
  padding: 8px 20px;
  border-radius: 999px;
  background: linear-gradient(180deg, #7b5cff, #5230e6);
  box-shadow:
    inset 0 2px 0 rgb(255 255 255 / 0.25),
    0 8px 20px rgb(0 0 0 / 0.4);
  font-weight: 900;
  font-size: clamp(0.95rem, 2.6vw, 1.3rem);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -20px) scale(0.8);
  transition:
    opacity 0.25s ease,
    transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.tg-banner.show {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}
.tg-banner.boss {
  background: linear-gradient(180deg, #ff5a6e, #c21d3b);
}
.tg-banner.gold {
  background: linear-gradient(180deg, #ffd45e, #e69500);
  color: #4a2a00;
}

/* ---------- popover ---------- */
.tg-pop {
  position: absolute;
  z-index: 5;
  width: 212px;
  padding: 10px;
  border-radius: 18px;
  background: linear-gradient(180deg, #2a2b40, #1c1d2c);
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.1),
    0 0 0 2px rgb(140 109 255 / 0.55),
    0 14px 30px rgb(0 0 0 / 0.55);
  transform-origin: 50% 100%;
  animation: pop-in 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.tg-pop.below {
  transform-origin: 50% 0;
}
.tg-pop[hidden] {
  display: none;
}
.tg-pop.shake {
  animation: shake 0.4s ease;
}
@keyframes pop-in {
  from {
    opacity: 0;
    transform: scale(0.7);
  }
}
.pop-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.pop-head img {
  width: 36px;
  height: 36px;
  flex: none;
}
.pop-title {
  flex: 1;
  min-width: 0;
}
.pop-title strong {
  display: block;
  font-size: 0.95rem;
  font-weight: 900;
  line-height: 1.1;
}
.pop-title span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}
.pop-close {
  width: 40px;
  height: 40px;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: var(--secondary);
  cursor: pointer;
  font-size: 1.1rem;
  font-weight: 900;
}
.pop-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}
.build-btn {
  display: grid;
  justify-items: center;
  gap: 1px;
  min-height: 76px;
  padding: 4px 4px 6px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(180deg, #34355a, #262740);
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.1),
    0 3px 0 #15162a;
  cursor: pointer;
  transition: transform 0.12s ease;
}
.build-btn:hover,
.build-btn:focus-visible {
  background: linear-gradient(180deg, #43447a, #2f3056);
}
.build-btn:active {
  transform: translateY(2px);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.1);
}
.build-btn img {
  width: 42px;
  height: 42px;
}
.build-btn .b-name {
  font-size: 0.75rem;
  font-weight: 900;
}
.cost {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  color: #ffd45e;
  font-size: 0.78rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}
.cost::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff2b8, #ffb81f 55%, #b36b00);
}
.poor {
  filter: saturate(0.3);
  opacity: 0.6;
}
.poor .cost {
  color: #ff8fa3;
}
.pop-desc {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.3;
}
.pop-stats {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}
.pop-stats span {
  flex: 1;
  padding: 3px 4px;
  border-radius: 8px;
  background: rgb(0 0 0 / 0.25);
  text-align: center;
  font-size: 0.68rem;
  font-weight: 800;
  color: var(--muted);
}
.pop-stats b {
  display: block;
  color: #fff;
  font-size: 0.82rem;
}
.pop-row {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 6px;
  margin-bottom: 8px;
}
.act-btn {
  display: grid;
  justify-items: center;
  align-content: center;
  min-height: 48px;
  padding: 4px;
  border: 0;
  border-radius: 14px;
  cursor: pointer;
  font-weight: 900;
  font-size: 0.82rem;
  line-height: 1.1;
}
.act-up {
  background: linear-gradient(180deg, #8c6dff, #5a36f0);
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.3),
    0 3px 0 #3a1fb0;
}
.act-up .cost {
  color: #fff3c4;
}
.act-up:disabled {
  background: var(--secondary);
  box-shadow: none;
  color: var(--muted);
  cursor: default;
}
.act-sell {
  background: linear-gradient(180deg, #3a3b55, #2a2b3d);
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.1),
    0 3px 0 #15162a;
}
.act-sell .cost {
  color: #8dffb0;
}
.act-btn:active:not(:disabled) {
  transform: translateY(2px);
}
.pop-target-label {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.seg {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 3px;
  padding: 3px;
  border-radius: 12px;
  background: rgb(0 0 0 / 0.3);
}
.seg button {
  min-height: 40px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.74rem;
  font-weight: 900;
}
.seg button[aria-pressed="true"] {
  background: linear-gradient(180deg, #7b5cff, #5230e6);
  color: #fff;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.25);
}

/* ---------- actions ---------- */
.tg-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 0;
}
.tg-tools {
  display: flex;
  gap: 8px;
}
.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 20px;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 900;
  font-size: 1rem;
  transition:
    transform 0.12s ease,
    filter 0.12s ease;
}
.pill:active:not(:disabled) {
  transform: translateY(2px) scale(0.98);
}
.pill-primary {
  background: linear-gradient(180deg, #8c6dff, #6842ff 55%, #5230e6);
  box-shadow:
    inset 0 2px 0 rgb(255 255 255 / 0.3),
    0 4px 0 #3a1fb0,
    0 8px 18px rgb(104 66 255 / 0.4);
}
.pill-primary:hover:not(:disabled) {
  filter: brightness(1.08);
}
.pill-primary:disabled {
  background: linear-gradient(180deg, #33344d, #2a2b3d);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.06);
  color: var(--muted);
  cursor: default;
}
.pill-secondary {
  background: linear-gradient(180deg, #34354d, #2a2b3d);
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.1),
    0 3px 0 #15162a;
}
.pill-secondary:hover {
  filter: brightness(1.15);
}
.pill-secondary[aria-pressed="true"] {
  background: linear-gradient(180deg, #ffd45e, #f0a500);
  color: #4a2a00;
  box-shadow:
    inset 0 2px 0 rgb(255 255 255 / 0.4),
    0 3px 0 #a86a00;
}
.icon-btn {
  width: 48px;
  padding: 0;
  flex: none;
}
.wave-btn {
  position: relative;
  flex: 1;
  min-width: 0;
  flex-direction: column;
  gap: 0;
  overflow: hidden;
  padding: 4px 14px 8px;
}
.wave-main {
  font-size: 1rem;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.wave-sub {
  font-size: 0.74rem;
  color: #fff3c4;
  line-height: 1.1;
}
.wave-sub:empty {
  display: none;
}
.wave-bar {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 5px;
  height: 4px;
  border-radius: 4px;
  background: rgb(0 0 0 / 0.25);
  overflow: hidden;
  opacity: 0;
}
.wave-bar span {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: inherit;
  background: #ffd45e;
  transform-origin: 0 50%;
}
.wave-btn.timer .wave-bar {
  opacity: 1;
}
.wave-btn.ready:not(:disabled) {
  animation: ready-pulse 1.4s ease-in-out infinite;
}
@keyframes ready-pulse {
  50% {
    box-shadow:
      inset 0 2px 0 rgb(255 255 255 / 0.3),
      0 4px 0 #3a1fb0,
      0 0 0 6px rgb(140 109 255 / 0.3),
      0 8px 24px rgb(104 66 255 / 0.6);
  }
}

.tg-help {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.45;
}
.tg-help span {
  display: block;
}
.help-keys {
  display: none;
  margin-top: 4px;
}
@media (hover: hover) and (pointer: fine) {
  .help-keys {
    display: block;
  }
}
kbd {
  display: inline-block;
  padding: 0 5px;
  border-radius: 5px;
  background: var(--secondary);
  box-shadow: 0 2px 0 #15162a;
  color: #fff;
  font: inherit;
  font-size: 0.72rem;
  font-weight: 900;
}

/* ---------- overlay ---------- */
.tg-overlay {
  position: absolute;
  inset: -4px;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 12px;
  border-radius: 22px;
  background: radial-gradient(ellipse at 50% 40%, rgb(30 24 70 / 0.72), rgb(10 10 24 / 0.9));
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  overflow-y: auto;
}
.tg-overlay[hidden] {
  display: none;
}
.tg-card {
  width: min(560px, 100%);
  padding: 22px 20px 20px;
  border-radius: 26px;
  background: linear-gradient(180deg, #25264a, #1a1b28);
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.1),
    0 0 0 2px rgb(140 109 255 / 0.35),
    0 24px 60px rgb(0 0 0 / 0.6);
  text-align: center;
  animation: card-in 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.92);
  }
}
.tg-card h2 {
  margin: 4px 0 6px;
  font-size: clamp(1.6rem, 5vw, 2.3rem);
  font-weight: 900;
  line-height: 1.05;
  background: linear-gradient(180deg, #fff 35%, #c9bcff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tg-card p {
  margin: 0 auto 14px;
  max-width: 400px;
  color: var(--muted);
  font-weight: 700;
  line-height: 1.4;
}
.card-art {
  display: block;
  width: min(260px, 70%);
  height: auto;
  margin: 0 auto;
  filter: drop-shadow(0 10px 18px rgb(0 0 0 / 0.5));
}
.card-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}
.pill-big {
  min-height: 56px;
  min-width: 170px;
  font-size: 1.2rem;
}
.map-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 6px 0 14px;
}
.map-card {
  display: grid;
  gap: 4px;
  padding: 8px 8px 10px;
  border: 0;
  border-radius: 18px;
  background: linear-gradient(180deg, #34355a, #262740);
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.1),
    0 4px 0 #15162a;
  cursor: pointer;
  text-align: center;
  transition: transform 0.15s ease;
}
.map-card:hover,
.map-card:focus-visible {
  transform: translateY(-3px);
  background: linear-gradient(180deg, #44457a, #2f3056);
}
.map-card canvas {
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
  border-radius: 12px;
  box-shadow: 0 3px 8px rgb(0 0 0 / 0.4);
}
.map-card strong {
  font-size: 0.95rem;
  font-weight: 900;
}
.map-meta {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}
.diff-Easy {
  color: #7dffa8;
}
.diff-Medium {
  color: #ffd45e;
}
.diff-Hard {
  color: #ff8fa3;
}
.stars {
  display: flex;
  justify-content: center;
  gap: 2px;
}
.stars svg {
  width: 20px;
  height: 20px;
}
.stars-big {
  gap: 8px;
  margin: 4px 0 10px;
}
.stars-big svg {
  width: 56px;
  height: 56px;
  animation: star-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.stars-big svg:nth-child(2) {
  animation-delay: 0.18s;
  transform: translateY(-10px);
}
.stars-big svg:nth-child(3) {
  animation-delay: 0.36s;
}
@keyframes star-pop {
  from {
    opacity: 0;
    transform: scale(0.2) rotate(-40deg);
  }
}
.results {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 0 0 16px;
}
.results div {
  min-width: 78px;
  padding: 6px 10px;
  border-radius: 14px;
  background: rgb(0 0 0 / 0.25);
}
.results span {
  display: block;
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.results strong {
  font-size: 1.2rem;
  font-weight: 900;
}

@media (max-width: 560px) {
  .map-list {
    grid-template-columns: minmax(0, 1fr);
  }
  .map-card {
    grid-template-columns: 96px minmax(0, 1fr);
    align-items: center;
    text-align: left;
    column-gap: 10px;
  }
  .map-card canvas {
    grid-row: span 3;
  }
  .map-card .stars {
    justify-content: flex-start;
  }
  .tg-card {
    padding: 16px 12px;
  }
  .help-keys {
    display: none !important;
  }
  .tg-pop {
    width: 196px;
    padding: 8px;
  }
  .pill-big {
    min-width: 140px;
  }
}
@media (max-width: 380px) {
  body {
    padding: 8px;
  }
  .tg-brand h1 {
    font-size: 1.2rem;
  }
  .pill {
    padding: 0 12px;
  }
  .tg-tools {
    gap: 6px;
  }
  .icon-btn {
    width: 44px;
    padding: 0;
  }
}

@media (min-width: 820px) {
  .tg {
    max-width: 940px;
    grid-template-columns: minmax(0, 1fr) 184px;
    grid-template-rows: auto auto auto 1fr;
    grid-template-areas:
      "stage brand"
      "stage hud"
      "stage actions"
      "stage help";
    align-items: start;
    column-gap: 12px;
  }
  .tg-hud {
    grid-template-columns: minmax(0, 1fr);
  }
  .chip {
    justify-content: flex-start;
    padding: 8px 14px;
  }
  .chip strong {
    margin-left: auto;
    font-size: 1.2rem;
  }
  .chip-label {
    display: inline;
  }
  .tg-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .tg-tools {
    justify-content: space-between;
  }
  .tg-tools .icon-btn {
    flex: 1;
  }
  .wave-btn {
    min-height: 64px;
  }
  .tg-help .help-keys {
    display: block;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
