:root {
  --bg: #09111f;
  --bg-accent: #13243e;
  --panel: rgba(10, 20, 36, 0.84);
  --panel-border: rgba(140, 188, 255, 0.16);
  --text: #edf4ff;
  --muted: #9bb0ce;
  --primary: #79e0b5;
  --primary-deep: #1d7f66;
  --danger: #ff8e8e;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Space Grotesk", "Noto Sans SC", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(73, 167, 255, 0.18), transparent 28%),
    radial-gradient(circle at bottom left, rgba(121, 224, 181, 0.12), transparent 30%),
    linear-gradient(135deg, #040814 0%, #09111f 50%, #07101b 100%);
  transition: background 280ms ease;
}

body[data-skin="ember"] {
  background:
    radial-gradient(circle at top right, rgba(255, 153, 110, 0.2), transparent 30%),
    radial-gradient(circle at bottom left, rgba(245, 124, 74, 0.14), transparent 32%),
    linear-gradient(135deg, #140905 0%, #24110b 56%, #1b0a07 100%);
}

body[data-skin="ocean"] {
  background:
    radial-gradient(circle at top, rgba(87, 220, 255, 0.2), transparent 32%),
    radial-gradient(circle at bottom right, rgba(82, 143, 255, 0.14), transparent 28%),
    linear-gradient(135deg, #06111a 0%, #0b2338 55%, #07172c 100%);
}

body.impact::before {
  content: "";
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.12);
  pointer-events: none;
  animation: impactFlash 240ms ease;
  z-index: 20;
}

@keyframes impactFlash {
  from {
    opacity: 0.95;
  }
  to {
    opacity: 0;
  }
}

button {
  appearance: none;
  border: 0;
  border-radius: 16px;
  padding: 0.85rem 1rem;
  font: inherit;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease;
}

button:hover,
button:active {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.12);
}

button.primary {
  color: #04120d;
  background: linear-gradient(135deg, var(--primary), #b5ffdc);
  font-weight: 700;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.page-shell {
  width: min(1180px, calc(100vw - 24px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.hero {
  padding: 24px 8px 28px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--primary);
  letter-spacing: 0.22em;
  font-size: 0.78rem;
}

.hero h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 4.5rem);
  line-height: 0.95;
}

.hero-copy {
  width: min(620px, 100%);
  margin: 14px 0 0;
  color: var(--muted);
  line-height: 1.65;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(210px, 250px) minmax(280px, 420px) minmax(210px, 250px);
  gap: 18px;
  align-items: start;
}

.panel {
  position: relative;
  border: 1px solid var(--panel-border);
  border-radius: 28px;
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.panel-side {
  padding: 18px;
}

.config-card {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
  padding: 14px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.04);
}

.config-card label {
  display: grid;
  gap: 8px;
}

.config-card span {
  color: var(--muted);
  font-size: 0.92rem;
}

.config-card select {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 12px 14px;
  font: inherit;
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.stat-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.04);
}

.stat-card span,
.mini-header,
.tips span {
  color: var(--muted);
  font-size: 0.92rem;
}

.stat-card strong {
  font-size: 1.5rem;
}

.board-panel {
  padding: 14px;
}

.board-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  margin-bottom: 12px;
  padding: 6px 6px 2px;
}

.board-head strong {
  display: block;
  margin-top: 4px;
  font-size: 1rem;
}

.board-head p {
  max-width: 220px;
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
  text-align: right;
}

.mobile-hud {
  display: none;
}

.mobile-hud-info {
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

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

.focus-strip {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 0 0 8px;
}

.focus-chip {
  padding: 6px 10px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.76rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(140, 188, 255, 0.1);
}

.game-badges {
  display: flex;
  gap: 8px;
  margin: 0 0 8px;
  flex-wrap: wrap;
}

.game-badge {
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  color: #061510;
  background: linear-gradient(135deg, rgba(121, 224, 181, 0.96), rgba(181, 255, 220, 0.92));
}

.game-badge.muted {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.game-badges:empty {
  display: none;
}

.tutorial-card {
  display: none;
  gap: 10px;
  margin: 0 0 10px;
  padding: 14px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(18, 32, 52, 0.92), rgba(8, 18, 31, 0.94));
  border: 1px solid rgba(121, 224, 181, 0.18);
}

.tutorial-card.is-visible {
  display: grid;
}

.tutorial-card strong {
  font-size: 1rem;
}

.tutorial-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.tutorial-points {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tutorial-points span {
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 0.74rem;
  color: #dff7ea;
  background: rgba(121, 224, 181, 0.12);
}

.item-guide {
  display: none;
  margin: 0 0 6px;
  padding: 6px 8px;
  border-radius: 12px;
  color: #d9ecff;
  font-size: 0.78rem;
  line-height: 1.35;
  background: rgba(18, 33, 54, 0.72);
  border: 1px solid rgba(121, 224, 181, 0.18);
}

#gameCanvas,
#holdCanvas,
#nextCanvas {
  display: block;
  width: 100%;
  border-radius: 22px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px),
    linear-gradient(180deg, rgba(7, 19, 33, 0.96), rgba(11, 25, 44, 0.98));
  background-size: 10% 5%, 10% 5%, auto;
}

.overlay {
  position: absolute;
  inset: 14px;
  display: grid;
  place-items: center;
  border-radius: 22px;
  background: rgba(3, 8, 16, 0.68);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
}

.overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.overlay-card {
  width: min(86%, 320px);
  padding: 22px 20px;
  border-radius: 22px;
  text-align: center;
  background: rgba(9, 17, 31, 0.9);
  border: 1px solid rgba(121, 224, 181, 0.24);
}

.overlay-kicker {
  margin: 0 0 8px;
  color: var(--primary);
  letter-spacing: 0.2em;
  font-size: 0.78rem;
}

.overlay-card h2 {
  margin: 0;
  font-size: 1.4rem;
}

.overlay-card p {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.overlay-summary {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  text-align: left;
}

.overlay-summary-item {
  padding: 9px 11px;
  border-radius: 14px;
  font-size: 0.85rem;
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.overlay-summary-item strong {
  color: #dff7ea;
}

.overlay-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 14px;
}

.mini-board-wrap {
  margin-top: 16px;
  padding: 14px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.04);
}

.controls {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.tips {
  display: grid;
  gap: 14px;
  margin-top: 16px;
  padding: 14px;
}

.tips.compact {
  margin-top: 12px;
  padding: 12px;
}

.tips p {
  margin: 6px 0 0;
  color: var(--text);
  line-height: 1.55;
}

.leaderboard-wrap {
  min-height: 180px;
}

.challenge-wrap {
  min-height: 148px;
}

.challenge-card {
  display: grid;
  gap: 8px;
  margin-top: 10px;
  padding: 12px;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(23, 39, 64, 0.86), rgba(9, 19, 33, 0.94));
  border: 1px solid rgba(121, 224, 181, 0.14);
}

.challenge-card strong {
  font-size: 1rem;
}

.challenge-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.challenge-progress {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--text);
  font-size: 0.86rem;
}

.leaderboard-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.leaderboard-item {
  display: grid;
  grid-template-columns: 26px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  font-size: 0.92rem;
}

.leaderboard-item strong {
  font-size: 1rem;
}

.touch-panel {
  display: none;
  margin-top: 18px;
  padding: 0;
  border: 0;
  background: transparent;
  backdrop-filter: none;
  align-items: end;
  justify-content: space-between;
  gap: 0;
}

.touch-layout {
  display: none;
  align-items: end;
  justify-content: space-between;
  width: 100%;
  gap: 0;
}

.touch-panel[data-layout="split"] .split-layout {
  display: flex;
}

.touch-panel[data-layout="wheel"] .wheel-layout {
  display: flex;
}

.touch-cluster {
  display: grid;
  gap: 8px;
}

.touch-center {
  display: grid;
  gap: 6px;
  min-width: 96px;
}

.touch-btn {
  min-height: 44px;
  border-radius: 14px;
  padding: 0.7rem 0.8rem;
  font-size: 0.98rem;
  background: rgba(10, 20, 36, 0.58);
  border: 1px solid rgba(140, 188, 255, 0.12);
  backdrop-filter: blur(8px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
}

.touch-btn.is-pressing {
  transform: scale(0.96);
  filter: brightness(1.15);
}

.touch-btn.circle {
  width: 54px;
  height: 54px;
  min-height: 54px;
  border-radius: 999px;
  font-weight: 700;
}

.touch-btn.drop {
  min-height: 50px;
  font-weight: 700;
}

.wheel-layout {
  align-items: center;
}

.wheel-wrap {
  position: relative;
  width: 150px;
  height: 150px;
}

.wheel-wrap .touch-btn {
  position: absolute;
}

.wheel-up {
  left: 48px;
  top: 0;
}

.wheel-left {
  left: 0;
  top: 48px;
}

.wheel-right {
  right: 0;
  top: 48px;
}

.wheel-down {
  left: 48px;
  bottom: 0;
}

.wheel-center {
  left: 48px;
  top: 48px;
  width: 54px;
  height: 54px;
  min-height: 54px;
}

@media (max-width: 980px) {
  .game-layout {
    grid-template-columns: 1fr;
  }

  .panel-side {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .stat-card,
  .mini-board-wrap,
  .controls,
  .tips {
    margin: 0;
  }
}

@media (max-width: 720px) {
  .page-shell {
    width: min(100vw - 16px, 100%);
    padding-top: 18px;
  }

  .hero {
    padding-top: 8px;
  }

  .panel-side {
    grid-template-columns: 1fr;
  }

  body.mobile-playing .touch-panel {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: max(8px, env(safe-area-inset-bottom));
    z-index: 30;
    pointer-events: none;
  }

  body.mobile-playing .touch-panel .touch-btn {
    pointer-events: auto;
  }

  body.mobile-playing .touch-panel .split-layout {
    position: relative;
    min-height: 108px;
  }

  body.mobile-playing .touch-panel .left-cluster {
    position: fixed;
    left: 8px;
    bottom: calc(max(8px, env(safe-area-inset-bottom)) + 6px);
  }

  body.mobile-playing .touch-panel .right-cluster {
    position: fixed;
    right: 8px;
    bottom: calc(max(8px, env(safe-area-inset-bottom)) + 6px);
  }

  body.mobile-playing .touch-panel .touch-center {
    position: fixed;
    left: 50%;
    bottom: calc(max(8px, env(safe-area-inset-bottom)) + 2px);
    transform: translateX(-50%);
    min-width: 96px;
  }

  body.mobile-playing .touch-panel .wheel-layout {
    position: relative;
    min-height: 154px;
  }

  body.mobile-playing .touch-panel .wheel-wrap {
    position: fixed;
    left: 8px;
    bottom: calc(max(8px, env(safe-area-inset-bottom)) + 2px);
  }

  .board-head {
    flex-direction: column;
    align-items: start;
  }

  .board-head p {
    max-width: none;
    text-align: left;
  }

  #gameCanvas {
    touch-action: none;
  }

  body.mobile-playing {
    overflow: hidden;
  }

  body.mobile-playing .hero,
  body.mobile-playing .game-layout > aside {
    display: none;
  }

  body.mobile-playing .page-shell {
    width: 100vw;
    min-height: 100dvh;
    padding: 0;
  }

  body.mobile-playing .game-layout {
    display: block;
  }

  body.mobile-playing .board-panel {
    min-height: 100dvh;
    padding: 8px 6px 126px;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    backdrop-filter: none;
  }

  body.mobile-playing .board-head {
    margin-bottom: 4px;
    padding: 0 2px;
  }

  body.mobile-playing .board-head p {
    display: none;
  }

  body.mobile-playing .mobile-hud {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin: 0 0 6px;
    padding: 6px 8px;
    border-radius: 14px;
    background: rgba(7, 14, 26, 0.78);
    border: 1px solid rgba(140, 188, 255, 0.12);
  }

  body.mobile-playing .item-guide {
    display: block;
  }

  body.mobile-playing .focus-strip {
    margin: 0 0 6px;
    gap: 6px;
  }

  body.mobile-playing .focus-chip {
    font-size: 0.7rem;
    padding: 5px 8px;
  }

  body.mobile-playing .game-badges {
    margin: 0 0 6px;
  }

  body.mobile-playing .game-badge {
    padding: 5px 9px;
    font-size: 0.72rem;
  }

  body.mobile-playing .tutorial-card {
    margin: 0 0 8px;
    padding: 10px;
    border-radius: 14px;
  }

  body.mobile-playing .mobile-hud-actions button {
    min-height: 28px;
    padding: 0.3rem 0.52rem;
    border-radius: 12px;
    font-size: 0.74rem;
  }

  body.mobile-playing #gameCanvas {
    width: min(calc(100vw - 12px), calc((100dvh - 214px) / 2));
    max-height: calc(100dvh - 214px);
    margin: 0 auto;
  }
}

@media (max-width: 560px) {
  .touch-btn.circle {
    width: 50px;
    height: 50px;
    min-height: 50px;
  }

  .touch-center {
    min-width: 90px;
  }

  .wheel-wrap {
    width: 138px;
    height: 138px;
  }

  .wheel-up,
  .wheel-down {
    left: 44px;
  }

  .wheel-left,
  .wheel-right {
    top: 44px;
  }

  .wheel-center {
    left: 44px;
    top: 44px;
    width: 50px;
    height: 50px;
    min-height: 50px;
  }

  body.mobile-playing .board-panel {
    padding-bottom: 116px;
  }

  body.mobile-playing #gameCanvas {
    width: min(calc(100vw - 8px), calc((100dvh - 192px) / 2));
    max-height: calc(100dvh - 192px);
  }

  body.mobile-playing .mobile-hud {
    padding: 5px 7px;
  }

  body.mobile-playing .mobile-hud-info {
    font-size: 0.76rem;
  }

  body.mobile-playing .item-guide {
    font-size: 0.72rem;
    padding: 5px 7px;
  }

  body.mobile-playing .touch-panel .left-cluster,
  body.mobile-playing .touch-panel .right-cluster {
    bottom: calc(max(6px, env(safe-area-inset-bottom)) + 4px);
  }

  body.mobile-playing .touch-panel .touch-center {
    bottom: max(4px, env(safe-area-inset-bottom));
    min-width: 90px;
  }

  body.mobile-playing .touch-panel .wheel-wrap {
    left: 6px;
    bottom: max(4px, env(safe-area-inset-bottom));
  }

}
