:root {
  color-scheme: dark;
  --bg: #070b1d;
  --panel: rgba(11, 24, 56, 0.72);
  --panel-strong: rgba(17, 42, 92, 0.9);
  --line: rgba(127, 219, 255, 0.38);
  --text: #f7fbff;
  --muted: #9db3d7;
  --cyan: #37d8ff;
  --gold: #ffd35a;
  --pink: #ff6ea8;
  --green: #76df4e;
  --danger: #ff5a66;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.36);
}

* {
  box-sizing: border-box;
}

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

body {
  overflow-x: hidden;
  background:
    radial-gradient(circle at 20% 8%, rgba(55, 216, 255, 0.22), transparent 24%),
    radial-gradient(circle at 80% 88%, rgba(255, 110, 168, 0.18), transparent 28%),
    linear-gradient(180deg, #050714, var(--bg) 55%, #03040b);
  color: var(--text);
  font-family: "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  touch-action: manipulation;
  user-select: none;
}

button {
  font: inherit;
}

.app {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(100vw, 520px);
  min-height: 100svh;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
  gap: 12px;
}

.topbar,
.hud,
.controls {
  flex: 0 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 46px;
}

.brand {
  font-weight: 900;
  font-size: 1.55rem;
  letter-spacing: 0;
  text-shadow: 0 0 22px rgba(55, 216, 255, 0.65);
}

.icon-btn,
.control-btn,
.primary-btn,
.secondary-btn,
.difficulty-btn {
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: var(--text);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.icon-btn {
  min-width: 76px;
  min-height: 40px;
  border-radius: 10px;
  background: rgba(18, 42, 92, 0.78);
  font-size: 0.72rem;
  font-weight: 800;
}

.icon-btn.off {
  color: var(--muted);
  background: rgba(24, 27, 42, 0.78);
}

.hud {
  display: grid;
  grid-template-columns: 1fr 1.05fr 1.18fr;
  gap: 8px;
}

.hud-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 74px;
  padding: 10px 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: inset 0 0 22px rgba(55, 216, 255, 0.08);
}

.hud-card span {
  color: var(--muted);
  font-size: 0.67rem;
  font-weight: 800;
}

.hud-card strong {
  margin-top: 4px;
  font-size: clamp(1.15rem, 7vw, 2.35rem);
  line-height: 1;
  letter-spacing: 0;
}

.hud-main {
  border-color: rgba(55, 216, 255, 0.75);
  box-shadow: 0 0 24px rgba(55, 216, 255, 0.25);
}

.board-wrap {
  position: relative;
  flex: 1 1 auto;
  display: grid;
  align-items: start;
  min-height: 0;
}

#gameCanvas {
  display: block;
  width: 100%;
  aspect-ratio: 6 / 7;
  max-height: calc(100svh - 238px);
  border-radius: 18px;
  border: 1px solid rgba(127, 219, 255, 0.36);
  background: rgba(4, 12, 28, 0.72);
  box-shadow: var(--shadow), 0 0 34px rgba(55, 216, 255, 0.18);
  touch-action: none;
}

.combo-toast {
  position: absolute;
  top: 10px;
  right: 12px;
  min-height: 34px;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(255, 177, 72, 0.18);
  color: #ffe39a;
  font-weight: 900;
  pointer-events: none;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 180ms ease, transform 180ms ease;
  text-shadow: 0 0 12px rgba(255, 211, 90, 0.75);
}

.combo-toast.show {
  opacity: 1;
  transform: translateY(0);
}

.play-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 34px;
  padding: 7px 12px;
  border: 1px solid rgba(127, 219, 255, 0.22);
  border-radius: 999px;
  background: rgba(7, 18, 42, 0.72);
  color: #d8e8ff;
  font-size: 0.82rem;
  font-weight: 800;
}

.play-hint span {
  color: var(--gold);
}

.play-hint strong {
  font-weight: 900;
}

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

.control-btn {
  min-height: 62px;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(39, 182, 206, 0.82), rgba(24, 88, 150, 0.82));
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.28);
  font-size: 0.76rem;
  font-weight: 800;
}

.control-btn:nth-child(2) {
  background: linear-gradient(180deg, rgba(55, 206, 172, 0.82), rgba(17, 111, 118, 0.82));
}

.control-btn:nth-child(3) {
  background: linear-gradient(180deg, rgba(172, 104, 255, 0.84), rgba(89, 58, 168, 0.84));
}

.btn-icon {
  display: block;
  font-size: 1.55rem;
  line-height: 1;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(3, 5, 14, 0.78);
  backdrop-filter: blur(12px);
}

.title-overlay {
  overflow: hidden;
}

.title-constellation {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.title-constellation::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle at 16% 21%, rgba(255, 255, 255, 0.8) 0 1px, transparent 2px),
    radial-gradient(circle at 72% 14%, rgba(127, 219, 255, 0.85) 0 1px, transparent 2px),
    radial-gradient(circle at 88% 70%, rgba(255, 211, 90, 0.78) 0 1px, transparent 2px),
    radial-gradient(circle at 32% 76%, rgba(255, 110, 168, 0.72) 0 1px, transparent 2px);
  opacity: 0.85;
  animation: shimmer 4.8s ease-in-out infinite;
}

.mini-tile {
  position: absolute;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  opacity: 0.8;
  box-shadow: 0 0 20px currentColor;
  animation: floatTile 5.8s ease-in-out infinite;
}

.mini-tile.red {
  left: 14%;
  top: 18%;
  color: #ff5a66;
  background: linear-gradient(180deg, #ff8a91, #b51c32);
}

.mini-tile.blue {
  right: 16%;
  top: 22%;
  color: #37d8ff;
  background: linear-gradient(180deg, #67e2ff, #0874c7);
  animation-delay: -1.4s;
}

.mini-tile.green {
  left: 18%;
  bottom: 22%;
  color: #76df4e;
  background: linear-gradient(180deg, #9dff72, #299923);
  animation-delay: -2.2s;
}

.mini-tile.yellow {
  right: 18%;
  bottom: 19%;
  color: #ffd35a;
  background: linear-gradient(180deg, #ffe776, #c7850c);
  animation-delay: -3.1s;
}

.mini-tile.violet {
  left: 48%;
  top: 12%;
  color: #a56cff;
  background: linear-gradient(180deg, #c796ff, #5732b8);
  animation-delay: -4.4s;
}

.light-line {
  position: absolute;
  height: 2px;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, rgba(55, 216, 255, 0.68), transparent);
  transform-origin: center;
  opacity: 0.62;
  animation: linePulse 3.6s ease-in-out infinite;
}

.line-a {
  left: 18%;
  top: 30%;
  width: 64%;
  transform: rotate(8deg);
}

.line-b {
  left: 20%;
  bottom: 28%;
  width: 58%;
  transform: rotate(-10deg);
  animation-delay: -1.8s;
}

.hidden {
  display: none;
}

.panel {
  width: min(100%, 420px);
  padding: 22px;
  border: 1px solid rgba(127, 219, 255, 0.28);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(13, 30, 70, 0.94), rgba(7, 13, 31, 0.94));
  box-shadow: var(--shadow), 0 0 42px rgba(118, 92, 255, 0.18);
  text-align: center;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--cyan);
  font-size: 0.74rem;
  font-weight: 900;
}

h1,
h2,
.lead {
  margin-left: 0;
  margin-right: 0;
}

h1,
h2 {
  margin-top: 0;
  margin-bottom: 10px;
  font-size: clamp(2rem, 11vw, 3.2rem);
  line-height: 1.05;
  letter-spacing: 0;
  text-shadow: 0 0 26px rgba(55, 216, 255, 0.5);
}

h2 {
  font-size: clamp(1.75rem, 9vw, 2.55rem);
}

.lead {
  margin-top: 0;
  margin-bottom: 18px;
  color: #cfe1ff;
  line-height: 1.65;
}

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

.difficulty-btn,
.primary-btn,
.secondary-btn {
  min-height: 48px;
  border-radius: 13px;
  font-weight: 900;
}

.difficulty-btn {
  background: rgba(255, 255, 255, 0.08);
  color: #cfe1ff;
}

.difficulty-btn.active {
  border-color: rgba(55, 216, 255, 0.85);
  background: rgba(55, 216, 255, 0.18);
  color: var(--text);
}

.primary-btn {
  width: 100%;
  background: linear-gradient(180deg, #37d8ff, #2677ff);
  box-shadow: 0 12px 30px rgba(38, 119, 255, 0.32);
}

.secondary-btn {
  background: rgba(255, 255, 255, 0.08);
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 16px 0;
}

.result-stats div {
  padding: 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.08);
}

.result-stats span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.result-stats strong {
  display: block;
  margin-top: 4px;
  font-size: 1.55rem;
}

.result-actions {
  display: grid;
  gap: 10px;
}

@media (max-width: 380px) {
  .app {
    padding-left: 10px;
    padding-right: 10px;
    gap: 9px;
  }

  .hud {
    gap: 6px;
  }

  .hud-card {
    min-height: 64px;
    border-radius: 12px;
  }

  .control-btn {
    min-height: 56px;
  }
}

@keyframes floatTile {
  0%,
  100% {
    transform: translateY(0) rotate(-4deg);
  }
  50% {
    transform: translateY(-12px) rotate(5deg);
  }
}

@keyframes linePulse {
  0%,
  100% {
    opacity: 0.28;
  }
  50% {
    opacity: 0.78;
  }
}

@keyframes shimmer {
  0%,
  100% {
    opacity: 0.48;
  }
  50% {
    opacity: 0.9;
  }
}
