* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  color: #f8fbff;
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background: #08224f;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

body::before {
  position: fixed;
  inset: -28px;
  z-index: -3;
  content: "";
  background-image: url("./concept/reference.png");
  background-position: center;
  background-size: cover;
  filter: blur(12px) saturate(1.14);
  transform: scale(1.04);
}

body::after {
  position: fixed;
  inset: 0;
  z-index: -2;
  content: "";
  background:
    radial-gradient(circle at 50% 12%, rgba(67, 166, 255, 0.35), transparent 30%),
    linear-gradient(180deg, rgba(6, 41, 101, 0.54), rgba(7, 36, 53, 0.62) 48%, rgba(15, 48, 38, 0.82));
}

button {
  font: inherit;
}

.game-shell {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: 100%;
  height: 100dvh;
  min-height: 440px;
  overflow: hidden;
}

.hud {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(132px, 1fr) auto minmax(160px, 1fr);
  gap: 14px;
  align-items: center;
  min-height: 68px;
  padding: 10px clamp(12px, 2.4vw, 28px);
  background:
    linear-gradient(180deg, rgba(3, 16, 42, 0.92), rgba(5, 24, 52, 0.62)),
    linear-gradient(90deg, rgba(255, 214, 93, 0.14), transparent 26%, transparent 74%, rgba(255, 214, 93, 0.12));
  border-bottom: 1px solid rgba(255, 234, 161, 0.24);
  box-shadow: 0 14px 36px rgba(2, 10, 26, 0.28);
}

.brand-block,
.stat,
.goal-chip,
.progress-mini {
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.34);
}

.brand-block {
  min-width: 0;
}

.brand-title {
  display: block;
  font-size: clamp(1rem, 1.8vw, 1.45rem);
  font-weight: 900;
  line-height: 1.05;
  letter-spacing: 0;
  color: #fff5c0;
}

.brand-subtitle {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  color: #abdcff;
  font-size: 0.76rem;
  font-weight: 750;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(78px, 1fr));
  gap: 8px;
  align-items: stretch;
  justify-self: center;
}

.stat {
  display: grid;
  gap: 2px;
  min-width: 78px;
  padding: 7px 10px 8px;
  text-align: center;
  background: rgba(4, 25, 56, 0.54);
  border: 1px solid rgba(146, 209, 255, 0.2);
  border-radius: 8px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.stat strong {
  overflow: hidden;
  color: #ffffff;
  font-size: 1rem;
  font-weight: 900;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stat span {
  color: #9ac4e7;
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  line-height: 1;
  text-transform: uppercase;
}

.hud-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.hud-button,
.primary-button,
.secondary-button {
  min-height: 36px;
  border: 0;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0;
  cursor: pointer;
}

.hud-button {
  padding: 0 12px;
  color: #e9f6ff;
  background: linear-gradient(180deg, rgba(40, 112, 183, 0.86), rgba(12, 58, 116, 0.9));
  border: 1px solid rgba(162, 218, 255, 0.26);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 8px 18px rgba(0, 0, 0, 0.24);
}

.hud-button:hover,
.hud-button:focus-visible {
  background: linear-gradient(180deg, rgba(61, 150, 226, 0.96), rgba(17, 79, 149, 0.94));
  outline: 2px solid rgba(255, 235, 153, 0.55);
  outline-offset: 2px;
}

.hud-button.is-active {
  color: #092039;
  background: linear-gradient(180deg, #ffe177, #e6a928);
  border-color: rgba(255, 246, 178, 0.7);
}

.stage-wrap {
  position: relative;
  min-height: 0;
  overflow: hidden;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
  touch-action: none;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: clamp(18px, 3.4vw, 32px);
  z-index: 4;
  max-width: min(520px, calc(100% - 32px));
  padding: 10px 16px;
  color: #fff6d0;
  font-size: 0.9rem;
  font-weight: 850;
  text-align: center;
  background: rgba(7, 28, 58, 0.82);
  border: 1px solid rgba(255, 224, 118, 0.42);
  border-radius: 8px;
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.32);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.goal-strip {
  z-index: 2;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  padding: 8px clamp(12px, 2.4vw, 28px);
  color: #e9f7ff;
  background: linear-gradient(180deg, rgba(7, 40, 56, 0.66), rgba(5, 28, 39, 0.9));
  border-top: 1px solid rgba(176, 230, 255, 0.2);
}

.goal-chip {
  display: flex;
  min-width: 0;
  gap: 10px;
  align-items: center;
  color: #ecf8ff;
  font-size: 0.86rem;
  font-weight: 780;
}

.goal-swatch {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  border: 2px solid rgba(255, 255, 255, 0.55);
  border-radius: 50%;
  background: #ffd95b;
  box-shadow: 0 0 16px currentColor;
}

.progress-mini {
  flex: 0 0 auto;
  color: #b5d8ff;
  font-size: 0.76rem;
  font-weight: 800;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    radial-gradient(circle at 50% 28%, rgba(48, 160, 224, 0.24), transparent 34%),
    rgba(3, 12, 27, 0.72);
  backdrop-filter: blur(8px);
}

.overlay[hidden] {
  display: none;
}

.overlay-panel {
  width: min(640px, 100%);
  max-height: min(82dvh, 680px);
  padding: clamp(20px, 3vw, 30px);
  overflow: auto;
  color: #edf8ff;
  background:
    linear-gradient(180deg, rgba(14, 63, 112, 0.96), rgba(11, 36, 72, 0.98)),
    radial-gradient(circle at 50% 0%, rgba(255, 219, 94, 0.2), transparent 42%);
  border: 1px solid rgba(255, 231, 152, 0.36);
  border-radius: 8px;
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.46), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.overlay-panel h1 {
  margin: 0 0 8px;
  color: #fff3b3;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  font-weight: 950;
  line-height: 1;
  letter-spacing: 0;
}

.overlay-panel p {
  margin: 0 0 16px;
  color: #cbe9ff;
  font-size: 0.98rem;
  font-weight: 650;
  line-height: 1.42;
}

.overlay-meta {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 16px 0;
}

.meta-card {
  min-width: 0;
  padding: 10px;
  text-align: center;
  background: rgba(4, 22, 48, 0.54);
  border: 1px solid rgba(165, 216, 255, 0.2);
  border-radius: 8px;
}

.meta-card strong {
  display: block;
  color: #ffffff;
  font-size: 1rem;
  font-weight: 900;
}

.meta-card span {
  color: #9bc9eb;
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
}

.level-map {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 8px;
  margin: 18px 0;
}

.world-row {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
  color: #fff1a9;
  font-size: 0.78rem;
  font-weight: 900;
}

.level-button {
  aspect-ratio: 1;
  min-width: 0;
  min-height: 34px;
  color: #e8f7ff;
  font-size: 0.76rem;
  font-weight: 900;
  background: rgba(9, 37, 78, 0.9);
  border: 1px solid rgba(151, 204, 255, 0.28);
  border-radius: 50%;
  cursor: pointer;
}

.level-button.complete {
  color: #102849;
  background: linear-gradient(180deg, #ffe57d, #e4a624);
  border-color: rgba(255, 247, 180, 0.85);
}

.level-button.current {
  border-color: #ffffff;
  box-shadow: 0 0 0 2px rgba(48, 160, 224, 0.72), 0 0 18px rgba(48, 160, 224, 0.7);
}

.level-button.locked {
  color: rgba(211, 229, 242, 0.45);
  background: rgba(6, 19, 40, 0.72);
  cursor: default;
}

.overlay-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 18px;
}

.primary-button,
.secondary-button {
  padding: 0 18px;
}

.primary-button {
  color: #12223b;
  background: linear-gradient(180deg, #fff08c, #e7aa24);
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.26), inset 0 1px 0 rgba(255, 255, 255, 0.56);
}

.secondary-button {
  color: #e7f7ff;
  background: rgba(11, 55, 102, 0.9);
  border: 1px solid rgba(172, 221, 255, 0.28);
}

.primary-button:hover,
.primary-button:focus-visible,
.secondary-button:hover,
.secondary-button:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.55);
  outline-offset: 2px;
}

@media (max-width: 800px) {
  .game-shell {
    min-height: 520px;
  }

  .hud {
    grid-template-columns: 1fr;
    gap: 8px;
    min-height: 116px;
    padding: 8px 10px;
  }

  .brand-block {
    display: flex;
    gap: 10px;
    align-items: baseline;
    justify-content: space-between;
  }

  .brand-title {
    font-size: 1rem;
  }

  .brand-subtitle {
    text-align: right;
  }

  .stats {
    width: 100%;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

  .stat strong {
    font-size: 0.92rem;
  }

  .stat span {
    font-size: 0.58rem;
  }

  .hud-actions {
    display: grid;
    width: 100%;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
  }

  .hud-button {
    min-height: 32px;
    padding: 0 6px;
    font-size: 0.7rem;
  }

  .goal-strip {
    min-height: 54px;
    padding: 8px 10px;
  }

  .goal-chip {
    font-size: 0.76rem;
  }

  .progress-mini {
    font-size: 0.68rem;
  }

  .overlay-meta {
    grid-template-columns: 1fr;
  }

  .level-map {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

@media (max-width: 430px) {
  .brand-subtitle {
    max-width: 150px;
  }

  .goal-strip {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .progress-mini {
    align-self: flex-end;
  }

  .overlay-panel {
    max-height: 88dvh;
  }
}

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