* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg-dark: #050014;
  --bg-mid: #10002b;
  --panel: rgba(12, 8, 30, 0.78);
  --panel-border: rgba(255, 255, 255, 0.14);
  --text: #ffffff;
  --muted: #c9c4ff;
  --cyan: #00f7ff;
  --blue: #2357ff;
  --pink: #ff0a78;
  --purple: #a100ff;
  --mobile-controls-height: 0px;
  --mobile-hud-height: 38px;
  --mobile-board-gap: 10px;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  background:
    radial-gradient(circle at 50% 0%, rgba(99, 0, 255, 0.35), transparent 38%),
    radial-gradient(circle at 90% 35%, rgba(0, 247, 255, 0.16), transparent 28%),
    radial-gradient(circle at 10% 80%, rgba(255, 10, 120, 0.14), transparent 34%),
    linear-gradient(145deg, var(--bg-mid), var(--bg-dark) 68%);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 24px;
  overflow-x: hidden;
  transition: background 0.45s ease;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.38;
  background:
    radial-gradient(circle at 18% 22%, rgba(255, 242, 0, 0.22), transparent 16%),
    radial-gradient(circle at 78% 24%, rgba(0, 247, 255, 0.22), transparent 18%),
    radial-gradient(circle at 62% 84%, rgba(255, 0, 76, 0.18), transparent 18%);
  filter: blur(8px);
  animation: colorFloat 8s ease-in-out infinite alternate;
}

body.theme-hot {
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 138, 20, 0.38), transparent 38%),
    radial-gradient(circle at 92% 28%, rgba(255, 0, 76, 0.22), transparent 28%),
    radial-gradient(circle at 12% 78%, rgba(255, 242, 0, 0.18), transparent 34%),
    linear-gradient(145deg, #2b0016, #08000f 68%);
}

body.theme-blast {
  background:
    radial-gradient(circle at 18% 18%, rgba(255, 242, 0, 0.35), transparent 26%),
    radial-gradient(circle at 84% 20%, rgba(0, 247, 255, 0.34), transparent 28%),
    radial-gradient(circle at 50% 92%, rgba(255, 0, 76, 0.28), transparent 34%),
    linear-gradient(145deg, #14003d, #050014 68%);
}

body.theme-danger {
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 0, 76, 0.46), transparent 38%),
    radial-gradient(circle at 92% 42%, rgba(255, 242, 0, 0.2), transparent 28%),
    radial-gradient(circle at 12% 78%, rgba(184, 0, 255, 0.22), transparent 34%),
    linear-gradient(145deg, #33000d, #080008 68%);
}

body.theme-danger::before {
  animation-duration: 1.4s;
  opacity: 0.56;
}

.game-shell {
  width: 100%;
  max-width: 1020px;
  display: grid;
  grid-template-columns: minmax(210px, 1fr) auto minmax(210px, 1fr);
  gap: 24px;
  align-items: start;
}

.mobile-hud {
  display: none;
}

.mobile-message {
  display: none;
}

.side-panel,
.board-panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  box-shadow:
    0 24px 70px rgba(0, 0, 0, 0.5),
    inset 0 0 28px rgba(255, 255, 255, 0.03);
  backdrop-filter: blur(16px);
  transition: border-color 0.35s ease, box-shadow 0.35s ease;
}

body.theme-blast .side-panel,
body.theme-blast .board-panel {
  border-color: rgba(255, 242, 0, 0.34);
  box-shadow:
    0 24px 80px rgba(255, 0, 76, 0.24),
    0 0 36px rgba(0, 247, 255, 0.18),
    inset 0 0 28px rgba(255, 255, 255, 0.05);
}

body.theme-danger .side-panel,
body.theme-danger .board-panel {
  border-color: rgba(255, 0, 76, 0.42);
  box-shadow:
    0 24px 80px rgba(255, 0, 76, 0.26),
    0 0 34px rgba(255, 242, 0, 0.14),
    inset 0 0 28px rgba(255, 0, 76, 0.08);
}

.side-panel {
  padding: 22px;
}

.board-panel {
  padding: 18px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--cyan), var(--purple), var(--pink));
  color: #fff;
  font-size: 30px;
  box-shadow: 0 0 24px rgba(0, 247, 255, 0.7);
  margin-bottom: 14px;
  animation: logoPulse 2.6s ease-in-out infinite;
}

@keyframes colorFloat {
  0% {
    transform: translate3d(-1.5%, -1%, 0) scale(1);
  }

  100% {
    transform: translate3d(1.5%, 1%, 0) scale(1.05);
  }
}

@keyframes logoPulse {
  0%,
  100% {
    transform: scale(1);
    filter: saturate(1);
  }

  50% {
    transform: scale(1.04);
    filter: saturate(1.5);
  }
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 4px;
  font-size: 31px;
  letter-spacing: 0.5px;
  text-shadow: 0 0 18px rgba(0, 247, 255, 0.8);
}

.subtitle {
  color: var(--muted);
  margin-bottom: 18px;
}

.stats-grid {
  display: grid;
  gap: 12px;
}

.stat-card {
  padding: 14px;
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 4px;
}

.stat-card strong {
  font-size: 26px;
  text-shadow: 0 0 14px rgba(255, 255, 255, 0.35);
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

button {
  border: 0;
  border-radius: 14px;
  padding: 13px 14px;
  color: #fff;
  font-weight: 800;
  cursor: pointer;
  background: linear-gradient(135deg, #00d5ff, #2754ff 58%, #8f00ff);
  box-shadow: 0 0 18px rgba(0, 247, 255, 0.25);
  transition: transform 0.16s ease, filter 0.16s ease, box-shadow 0.16s ease;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

button:hover {
  transform: translateY(-1px);
  filter: brightness(1.1);
  box-shadow: 0 0 24px rgba(0, 247, 255, 0.45);
}

button:active {
  transform: translateY(1px) scale(0.98);
}

.sound-btn {
  width: 100%;
  margin: 14px 0 18px;
  background: linear-gradient(135deg, #ff0a78, #a100ff, #2357ff);
}

.canvas-frame {
  position: relative;
  border-radius: 18px;
  padding: 8px;
  background:
    linear-gradient(135deg, rgba(0, 247, 255, 0.9), rgba(255, 10, 120, 0.75), rgba(35, 87, 255, 0.9));
  box-shadow:
    0 0 34px rgba(0, 247, 255, 0.22),
    0 0 62px rgba(161, 0, 255, 0.24);
}

#board,
#next {
  display: block;
  background: #080014;
  border-radius: 12px;
  touch-action: none;
}

#board {
  width: 300px;
  height: 600px;
}

#next {
  width: 150px;
  height: 150px;
  border: 2px solid rgba(0, 247, 255, 0.38);
  box-shadow: inset 0 0 30px rgba(0, 247, 255, 0.1), 0 0 22px rgba(0, 247, 255, 0.18);
}

.info-panel h2 {
  margin-bottom: 12px;
}

.help-box {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.help-box h3 {
  color: #fff;
  margin-bottom: 10px;
}

.help-box p {
  margin-bottom: 8px;
}

.message {
  display: none;
  margin-top: 14px;
  padding: 12px;
  border-radius: 14px;
  color: #fff5b8;
  background: rgba(255, 214, 10, 0.14);
  border: 1px solid rgba(255, 214, 10, 0.2);
}

.mobile-controls {
  display: none;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 16px;
}

.mobile-controls button {
  min-height: 54px;
  font-size: 18px;
}

@media (max-width: 850px) {
  html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    touch-action: none;
  }

  body {
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100dvh;
    min-height: 100dvh;
    padding: 0;
    overflow: hidden;
    position: fixed;
    inset: 0;
    touch-action: none;
    background: #050014;
  }

  body::before {
    display: none;
  }

  .game-shell {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    width: 100vw;
    height: 100dvh;
    max-width: 100%;
    overflow: hidden;
    padding: max(3px, env(safe-area-inset-top)) 0 0;
  }

  .brand-panel,
  .info-panel {
    display: none !important;
  }

  .mobile-hud {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    position: fixed;
    top: max(7px, env(safe-area-inset-top));
    left: 50%;
    transform: translateX(-50%);
    width: min(86vw, 348px);
    min-height: var(--mobile-hud-height);
    gap: 5px;
    padding: 5px;
    border-radius: 14px;
    background: rgba(5, 0, 20, 0.42);
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.32);
    backdrop-filter: blur(10px);
    pointer-events: none;
    z-index: 30;
  }

  .mobile-hud div {
    min-width: 0;
    padding: 4px 6px;
    border-radius: 10px;
    text-align: center;
    background: rgba(255, 255, 255, 0.07);
  }

  .mobile-hud span {
    display: block;
    color: var(--muted);
    font-size: 9px;
    line-height: 1;
    margin-bottom: 3px;
    text-transform: uppercase;
  }

  .mobile-hud strong {
    display: block;
    color: #fff;
    font-size: 15px;
    line-height: 1.05;
    text-shadow: 0 0 12px rgba(0, 247, 255, 0.75);
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .mobile-message {
    display: none;
    position: fixed;
    top: calc(max(7px, env(safe-area-inset-top)) + var(--mobile-hud-height) + 5px);
    left: 50%;
    transform: translateX(-50%);
    width: min(86vw, 348px);
    margin: 0;
    padding: 7px 10px;
    border-radius: 14px;
    text-align: center;
    color: #fff5b8;
    font-size: 13px;
    font-weight: 800;
    background: rgba(255, 214, 10, 0.14);
    border: 1px solid rgba(255, 214, 10, 0.2);
    backdrop-filter: blur(10px);
    z-index: 31;
  }

  .board-panel {
    display: grid;
    justify-items: center;
    align-content: center;
    grid-template-rows: auto auto;
    width: 100vw;
    height: 100dvh;
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .canvas-frame {
    max-width: 100%;
    padding: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }

  #board {
    height: min(calc(100vw * 2), calc(100dvh - var(--mobile-board-gap) - env(safe-area-inset-bottom)));
    width: auto;
    max-width: 100vw;
    aspect-ratio: 1 / 2;
    border-radius: 0;
  }

  .mobile-controls {
    display: none !important;
  }

  .mobile-controls button {
    width: 100%;
    height: 100%;
    min-height: 0;
    padding: 0;
    border-radius: 14px;
    font-size: 20px;
    background: rgba(0, 247, 255, 0.11);
    border: 1px solid rgba(255, 255, 255, 0.18);
    box-shadow:
      0 0 10px rgba(0, 247, 255, 0.1),
      inset 0 0 10px rgba(255, 255, 255, 0.06);
    backdrop-filter: blur(4px);
    opacity: 0.58;
    touch-action: none;
  }

  .mobile-controls button:active,
  .mobile-controls button.is-pressed {
    transform: scale(0.96);
    filter: brightness(1.35);
    opacity: 1;
    box-shadow:
      0 0 24px rgba(255, 255, 255, 0.34),
      inset 0 0 18px rgba(255, 255, 255, 0.14);
  }

  .control-left {
    grid-area: left;
  }

  .control-right {
    grid-area: right;
  }

  .control-rotate {
    grid-area: rotate;
    background: rgba(184, 0, 255, 0.12) !important;
  }

  .control-down {
    grid-area: down;
    background: rgba(0, 255, 87, 0.1) !important;
  }

  .control-drop {
    grid-area: drop;
    background: rgba(255, 10, 120, 0.16) !important;
    font-size: 14px;
    letter-spacing: 0.8px;
  }

  .control-pause {
    grid-area: pause;
    background: rgba(255, 242, 0, 0.1) !important;
    font-size: 20px;
  }
}

@media (max-width: 380px) {
  #board {
    height: min(calc(100vw * 2), calc(100dvh - var(--mobile-board-gap) - env(safe-area-inset-bottom)));
    width: auto;
    max-width: 100vw;
  }

  .mobile-controls button {
    font-size: 24px;
  }

  .control-drop {
    font-size: 13px !important;
  }
}
