:root {
  color-scheme: dark;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #080a0f;
  color: #f4f6fb;
}

@font-face {
  font-family: "Metal Mania";
  src: url("assets/fonts/MetalMania-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

html.telegram-webapp,
body.telegram-webapp {
  height: var(--tg-viewport-stable-height, 100dvh);
  min-height: var(--tg-viewport-stable-height, 100dvh);
}

body {
  position: relative;
  isolation: isolate;
  background:
    radial-gradient(circle at 50% 15%, #1d283c 0, transparent 38%),
    linear-gradient(160deg, #080a0f, #111722);
  user-select: none;
  touch-action: none;
}

body::before {
  content: "";
  position: fixed;
  z-index: -1;
  inset: -20%;
  background:
    radial-gradient(circle at 25% 30%, rgba(72, 94, 128, 0.12), transparent 28%),
    radial-gradient(circle at 76% 68%, rgba(43, 71, 91, 0.1), transparent 32%);
  animation: void-drift 16s ease-in-out infinite alternate;
}

body.theme-color {
  color-scheme: light;
  background:
    radial-gradient(circle at 16% 18%, rgba(226, 184, 164, 0.58), transparent 34%),
    radial-gradient(circle at 84% 74%, rgba(170, 207, 190, 0.54), transparent 38%),
    linear-gradient(155deg, #f8efdf, #e6d8ca 52%, #d1dfd7);
}

body.theme-color::before {
  background:
    radial-gradient(circle at 28% 28%, rgba(211, 176, 207, 0.3), transparent 30%),
    radial-gradient(circle at 70% 64%, rgba(238, 211, 163, 0.32), transparent 34%);
}

body.theme-color .panel {
  box-shadow: 0 24px 70px rgba(65, 48, 37, 0.28);
}

body.theme-color .game-header {
  color: #202632;
}

body.theme-color .game-header span,
body.theme-color .game-title,
body.theme-color #status {
  color: #4b5868;
}

body:not(.theme-color) .brand-title {
  font-family: "Metal Mania", "Times New Roman", serif;
  font-weight: 400;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #f2eee6;
  text-shadow: 0 1px 0 #000, 0 0 18px rgba(90, 18, 18, 0.5);
}

body:not(.theme-color) .eyebrow.brand-title {
  font-size: 20px;
  color: #e4dfd6;
}

body:not(.theme-color) .game-title.brand-title {
  font-size: 17px;
  color: #ece8e0;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

#app,
.screen {
  width: 100%;
  height: 100%;
}

.screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.screen--hidden {
  display: none;
}

.panel {
  width: min(100%, 380px);
  max-height: 100%;
  overflow: hidden;
  padding: clamp(20px, 5vh, 28px);
  border: 1px solid #3b4351;
  border-radius: 24px;
  background: rgba(15, 19, 27, 0.94);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
  text-align: center;
}

.eyebrow {
  margin: 0 0 8px;
  color: #aab4c8;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.24em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0 0 24px;
  font-size: clamp(26px, 7vw, 38px);
}

.menu-panel h1 {
  margin-bottom: clamp(20px, 5vh, 34px);
  color: #b8c2d4;
  font-size: clamp(17px, 4.5vw, 22px);
  font-weight: 500;
}

.menu-panel {
  position: relative;
}

.support-link {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid #485367;
  border-radius: 50%;
  background: #171d27;
  color: #dce4f0;
  text-decoration: none;
  transition: transform 120ms ease, background 120ms ease;
}

.support-link svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.support-link:hover {
  background: #253044;
}

.support-link:active {
  transform: scale(0.94);
}

.support-link:focus-visible {
  outline: 2px solid #78a8d0;
  outline-offset: 3px;
}

.menu-panel .eyebrow {
  margin-bottom: clamp(20px, 5vh, 34px);
}

.logo-mark {
  position: relative;
  width: 88px;
  height: 84px;
  margin: 0 auto 18px;
}

.cube-logo {
  perspective: 240px;
}

.cube-3d {
  position: absolute;
  width: 44px;
  height: 44px;
  top: 20px;
  left: 22px;
  transform-style: preserve-3d;
  animation: cube-tumble-x 7s linear infinite;
}

.cube-side {
  position: absolute;
  inset: 0;
  border: 1px solid #d5dbe3;
  background: #f4f6fb;
  box-shadow: inset 0 0 11px rgba(255, 255, 255, 0.18);
  backface-visibility: visible;
}

.cube-side::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  top: 14px;
  left: 14px;
  border: 1px solid #303a48;
  background: #05070b;
  box-shadow: inset 0 0 5px #000;
}

.cube-side--front {
  transform: translateZ(22px);
}

.cube-side--back {
  transform: rotateY(180deg) translateZ(22px);
}

.cube-side--right {
  transform: rotateY(90deg) translateZ(22px);
}

.cube-side--left {
  transform: rotateY(-90deg) translateZ(22px);
}

.cube-side--top {
  transform: rotateX(90deg) translateZ(22px);
}

.cube-side--bottom {
  transform: rotateX(-90deg) translateZ(22px);
}

body.theme-color .cube-side {
  background: #efe6d8;
  border-color: #cfc0ae;
}

.size-button,
.menu-button,
.primary-button,
.secondary-button {
  width: 100%;
  min-height: 64px;
  margin-top: 12px;
  border: 1px solid transparent;
  border-radius: 16px;
  background: #252c38;
  color: #e8edf5;
  transition: transform 120ms ease, filter 120ms ease;
}

.size-button:active,
.menu-button:active,
.primary-button:active,
.secondary-button:active {
  transform: scale(0.98);
}

.size-button {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.compact-button {
  min-height: 46px;
}

body.theme-color .size-button,
body.theme-color .menu-button,
body.theme-color .primary-button,
body.theme-color .secondary-button,
body.theme-color #menu-button {
  background: #efe6d8;
  color: #2c3340;
  border-color: #d7c8b6;
}

body.theme-color .support-link {
  background: #efe6d8;
  color: #2c3340;
  border-color: #d7c8b6;
}

body.theme-color .segmented-control {
  background: #e8ddd0;
  border-color: #d4c4b0;
}

body.theme-color .segmented-control button {
  color: #6a6358;
}

body.theme-color .segmented-control button[aria-pressed="true"] {
  background: #f7f1e8;
  color: #2c3340;
}

.wide-panel {
  width: min(100%, 560px);
}

.record-grid,
.leaderboards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.record-card,
.leaderboards article {
  border: 1px solid #343d4d;
  border-radius: 14px;
  background: #171d27;
}

.record-card {
  padding: 13px 8px;
}

.record-card span,
.record-card strong,
.record-card small {
  display: block;
}

.record-card span,
.record-card small {
  color: #95a0b3;
  font-size: 11px;
  text-transform: uppercase;
}

.record-card strong {
  margin: 3px 0;
  font-size: 25px;
}

.leaderboards {
  margin-top: 10px;
}

.leaderboards article {
  min-height: 120px;
  padding: 14px 10px;
}

.leaderboards h2 {
  margin: 0 0 14px;
  color: #c9d3e3;
  font-size: 13px;
}

.leaderboard-list {
  margin: 0;
  padding: 0;
  max-height: 132px;
  overflow-y: auto;
  list-style: none;
  color: #c5cedc;
  font-size: 11px;
  line-height: 1.45;
  text-align: left;
}

.leaderboard-list li {
  padding: 3px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.leaderboard-empty {
  color: #778399 !important;
}

.setting-row {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  margin: 8px 0;
  color: #aeb8ca;
  font-size: 13px;
  text-align: left;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 3px;
  padding: 3px;
  border: 1px solid #343d4d;
  border-radius: 11px;
  background: #10151d;
}

.segmented-control button {
  min-height: 34px;
  min-width: 0;
  padding: 0 4px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #8792a5;
  font-size: 11px;
}

.segmented-control button[aria-pressed="true"] {
  background: #354258;
  color: #fff;
}

.volume-row {
  grid-template-columns: 72px minmax(0, 1fr) 48px;
}

.volume-row span {
  grid-column: 1;
}

.volume-row input {
  grid-column: 2;
  width: 100%;
  min-width: 0;
  margin: 0;
  accent-color: #6697c2;
  touch-action: none;
}

.volume-row output {
  grid-column: 3;
  color: #e2e8f2;
  text-align: right;
}

#settings-screen {
  overflow: hidden;
}

#settings-screen .panel {
  width: min(100%, 380px);
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: clamp(16px, 3.2vh, 24px) clamp(18px, 4vw, 28px);
}

#settings-screen h1 {
  margin: 0 0 10px;
  font-size: clamp(22px, 5.5vh, 32px);
}

#settings-screen .eyebrow.brand-title {
  height: 28px;
  margin: 0 0 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

body:not(.theme-color) #settings-screen .eyebrow.brand-title {
  font-size: 16px;
  letter-spacing: 0.08em;
}

#settings-screen .panel > .compact-button {
  margin-top: 12px;
  flex-shrink: 0;
}

#game-screen {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
  max-width: min(100vw, calc(100vh / 1.6));
  margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom));
}

#game-screen.screen--hidden {
  display: none;
}

#game-screen.is-shaking {
  animation: screen-shake 420ms cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

.game-header {
  min-height: 48px;
  display: grid;
  grid-template-columns: 1fr auto 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 0 6px;
}

.score-box span,
.score-box strong,
.record-box span,
.record-box strong {
  display: block;
}

.game-header span {
  color: #929cad;
  font-size: 11px;
  text-transform: uppercase;
}

#score {
  font-size: 22px;
}

.record-box {
  text-align: right;
}

.record-box strong {
  font-size: 18px;
}

.game-title {
  color: #b9c4d8;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.14em;
}

#menu-button {
  justify-self: end;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: #252c38;
  color: #e8edf5;
  font-size: 12px;
}

#canvas-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
}

#game-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#blast-flash {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle at 50% 42%, rgba(255, 248, 230, 0.92), rgba(255, 170, 70, 0.28) 42%, transparent 72%);
}

#blast-flash.is-on {
  animation: blast-flash 260ms ease-out;
}

@keyframes blast-flash {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

#status {
  min-height: 20px;
  margin: 0;
  color: #a5afc1;
  font-size: 12px;
  text-align: center;
}

.combo-popup {
  position: absolute;
  z-index: 5;
  top: 43%;
  left: 50%;
  pointer-events: none;
  color: #fff;
  font-size: clamp(30px, 9vw, 58px);
  font-weight: 950;
  letter-spacing: -0.04em;
  opacity: 0;
  text-shadow: 0 4px 22px rgba(0, 0, 0, 0.75);
  transform: translate(-50%, -50%) scale(0.65);
  white-space: nowrap;
}

.combo-popup.is-active {
  animation: combo-pop 900ms ease-out;
}

.bomb-dock {
  position: absolute;
  z-index: 4;
  top: 52px;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 5px 10px;
  border: 1px solid #697589;
  border-radius: 18px;
  background: rgba(9, 12, 18, 0.92);
  color: #e8edf5;
  font-size: 11px;
  transform: translateX(-50%);
  touch-action: none;
  cursor: grab;
}

body.theme-color .bomb-dock {
  background: rgba(239, 230, 216, 0.94);
  border-color: #d7c8b6;
  color: #2c3340;
}

.bomb-dock.screen--hidden {
  display: none;
}

.bomb-dock.is-arriving {
  animation: bomb-arrive 800ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.bomb-icon {
  position: relative;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #8d99aa, #202631 58%, #090b0f);
  box-shadow: 0 0 13px rgba(190, 214, 244, 0.36);
}

.bomb-icon::after {
  content: "";
  position: absolute;
  width: 8px;
  height: 5px;
  top: -4px;
  right: -1px;
  border-top: 2px solid #d4a65c;
  border-radius: 50%;
  transform: rotate(28deg);
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: rgba(2, 4, 8, 0.82);
  backdrop-filter: blur(8px);
}

.overlay.screen--hidden {
  display: none;
}

.overlay .panel p:not(.eyebrow) {
  color: #bbc4d4;
}

.new-record {
  color: #fff !important;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.primary-button {
  background: #346f9d;
}

.secondary-button {
  min-height: 50px;
  border-color: #3f4859;
  background: transparent;
}

@keyframes combo-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.55);
  }
  18% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.12);
  }
  48% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -68%) scale(0.94);
  }
}

@keyframes screen-shake {
  0%,
  100% { transform: translate3d(0, 0, 0); }
  16% { transform: translate3d(-3px, 1px, 0); }
  32% { transform: translate3d(3px, -1px, 0); }
  48% { transform: translate3d(-2px, -1px, 0); }
  64% { transform: translate3d(2px, 1px, 0); }
  80% { transform: translate3d(-1px, 0, 0); }
}

@keyframes bomb-arrive {
  0% {
    opacity: 0;
    transform: translate(-50%, 140px) scale(1.6);
  }
  65% {
    opacity: 1;
    transform: translate(-50%, -5px) scale(0.95);
  }
  100% {
    transform: translate(-50%, 0) scale(1);
  }
}

@keyframes void-drift {
  0% { transform: translate3d(-2%, -1%, 0) scale(1); }
  100% { transform: translate3d(3%, 2%, 0) scale(1.08); }
}

@keyframes cube-tumble-x {
  0% { transform: rotateY(-28deg) rotateX(-18deg); }
  100% { transform: rotateY(-28deg) rotateX(342deg); }
}

@media (max-height: 560px) {
  .panel {
    padding: 16px 22px;
  }

  .logo-mark {
    height: 64px;
    margin-bottom: 4px;
    transform: scale(0.78);
  }

  .menu-button,
  .size-button {
    min-height: 48px;
  }

  .game-header {
    min-height: 36px;
  }

  #status {
    display: none;
  }
}

@media (max-width: 390px) {
  .game-title {
    font-size: 9px;
    letter-spacing: 0.08em;
  }

  body:not(.theme-color) .game-title.brand-title {
    font-size: 14px;
    letter-spacing: 0.04em;
  }

  .game-header {
    gap: 5px;
  }

  #menu-button {
    padding: 0 9px;
  }
}
