:root {
  --bg-top: #0d1020;
  --bg-bottom: #04050d;
  --panel: rgba(12, 16, 34, 0.72);
  --panel-border: rgba(255, 255, 255, 0.12);
  --text-main: #f5f7ff;
  --text-muted: rgba(245, 247, 255, 0.68);
  --accent: #ff8a5b;
  --accent-strong: #ffd166;
  --accent-cool: #52e5c7;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "Space Grotesk", sans-serif;
  color: var(--text-main);
  background:
    radial-gradient(circle at top, rgba(255, 138, 91, 0.18), transparent 30%),
    radial-gradient(circle at 20% 80%, rgba(82, 229, 199, 0.14), transparent 24%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  overflow: hidden;
  touch-action: manipulation;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: auto;
  border-radius: 999px;
  filter: blur(14px);
  opacity: 0.55;
  pointer-events: none;
}

body::before {
  width: 10rem;
  height: 10rem;
  top: 8%;
  left: -3rem;
  background: rgba(255, 209, 102, 0.18);
}

body::after {
  width: 14rem;
  height: 14rem;
  right: -5rem;
  bottom: 6%;
  background: rgba(82, 229, 199, 0.14);
}

.app-shell {
  min-height: 100vh;
  padding: max(1rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom));
}

.game-frame {
  position: relative;
  width: min(100%, 980px);
  margin: 0 auto;
}

.hud {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.9rem;
}

.hud--hidden {
  display: none;
}

.brand__eyebrow,
.panel__eyebrow,
.stat-label,
.panel__hint {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.7rem;
}

.brand h1,
.panel h2 {
  margin: 0;
  line-height: 0.96;
}

.brand h1 {
  font-size: clamp(2rem, 7vw, 3.7rem);
}

.brand__eyebrow {
  display: block;
  color: var(--accent-cool);
  margin-bottom: 0.35rem;
}

.stats {
  display: flex;
  gap: 0.75rem;
}

.stat-card {
  min-width: 4.8rem;
  padding: 0.8rem 0.9rem;
  border: 1px solid var(--panel-border);
  border-radius: 1rem;
  background: rgba(255, 255, 255, 0.07);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
}

.stat-card--difficulty strong {
  font-size: clamp(1rem, 4vw, 1.3rem);
}

.stat-label {
  display: block;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.stat-card strong {
  font-size: clamp(1.15rem, 5vw, 1.7rem);
}

.play-area {
  position: relative;
  min-height: min(72vh, 760px);
  border-radius: 1.8rem;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.02)),
    linear-gradient(180deg, rgba(8, 10, 22, 0.78), rgba(8, 10, 22, 0.92));
  box-shadow: var(--shadow);
}

.screen {
  display: none;
  min-height: inherit;
}

.screen--active {
  display: grid;
}

.panel--screen {
  width: min(100%, 32rem);
  margin: auto;
}

#gameScreen {
  position: relative;
  min-height: inherit;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: min(72vh, 760px);
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(5, 6, 16, 0.36);
  opacity: 0;
  visibility: hidden;
  transition: opacity 180ms ease, visibility 180ms ease;
}

.overlay--active {
  opacity: 1;
  visibility: visible;
}

.panel {
  width: min(100%, 25rem);
  padding: 1.4rem;
  border-radius: 1.4rem;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.panel__eyebrow {
  margin: 0 0 0.5rem;
  color: var(--accent-cool);
}

.panel h2 {
  font-size: clamp(1.8rem, 7vw, 3.2rem);
  margin-bottom: 0.8rem;
}

.panel__text {
  margin: 0 0 0.8rem;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1.5;
}

.how-to-play {
  display: grid;
  gap: 0.9rem;
  margin-top: 1rem;
  padding: 0.9rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 1.15rem;
  background: rgba(255, 255, 255, 0.04);
}

.demo-card {
  border-radius: 1rem;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.03)),
    rgba(7, 9, 18, 0.84);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 0.8rem;
}

.demo-card__label,
.demo-card__caption {
  margin: 0;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.demo-card__label {
  margin-bottom: 0.55rem;
  color: rgba(245, 247, 255, 0.72);
}

.demo-card__caption {
  margin-top: 0.6rem;
  color: #9cf0dd;
}

.demo-card__scene {
  position: relative;
  height: 7rem;
  border-radius: 0.9rem;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 20%, rgba(255, 209, 102, 0.1), transparent 26%),
    linear-gradient(180deg, rgba(19, 24, 52, 0.9), rgba(7, 9, 16, 0.98));
}

.demo-path {
  position: absolute;
  background: linear-gradient(135deg, rgba(82, 229, 199, 0.95), rgba(82, 229, 199, 0.45));
  box-shadow: 0 10px 24px rgba(82, 229, 199, 0.18);
}

.demo-path--horizontal {
  left: 12%;
  top: 56%;
  width: 50%;
  height: 0.85rem;
  border-radius: 999px;
}

.demo-path--vertical {
  left: 56%;
  top: 22%;
  width: 0.85rem;
  height: 42%;
  border-radius: 999px;
}

.demo-turn-cue {
  position: absolute;
  left: calc(56% - 1.2rem);
  top: 34%;
  padding: 0.22rem 0.45rem;
  border-radius: 999px;
  background: rgba(255, 209, 102, 0.18);
  border: 1px solid rgba(255, 209, 102, 0.45);
  color: #ffe6b1;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0;
  animation: cuePulse 3.2s ease-in-out infinite;
}

.demo-runner {
  position: absolute;
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-strong), var(--accent));
  box-shadow: 0 0 0 0.4rem rgba(255, 138, 91, 0.12), 0 0.4rem 1rem rgba(255, 138, 91, 0.32);
  animation: demoRunFlow 3.2s cubic-bezier(0.42, 0, 0.2, 1) infinite;
}

.demo-success-badge {
  position: absolute;
  right: 0.75rem;
  top: 0.75rem;
  padding: 0.24rem 0.5rem;
  border-radius: 999px;
  background: rgba(82, 229, 199, 0.16);
  border: 1px solid rgba(82, 229, 199, 0.4);
  color: #b9fff1;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0;
  transform: translateY(0.25rem) scale(0.96);
  animation: demoSuccessReveal 3.2s ease-in-out infinite;
}

.how-to-play__title {
  margin: 0;
  color: var(--text-main);
  font-size: 0.95rem;
  font-weight: 700;
}

.how-to-play__list {
  margin: 0.45rem 0 0;
  padding-left: 1rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.how-to-play__list li + li {
  margin-top: 0.26rem;
}

.panel__actions {
  display: flex;
  margin-top: 1.1rem;
}

.panel__actions--split {
  gap: 0.7rem;
}

.difficulty-picker {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.65rem;
  margin-top: 1.15rem;
}

.difficulty-option {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.12);
  cursor: pointer;
  border-radius: 1rem;
  padding: 0.8rem 0.65rem;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  font: inherit;
  font-weight: 700;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease, box-shadow 140ms ease;
}

.difficulty-option:hover,
.difficulty-option:focus-visible {
  transform: translateY(-1px);
  border-color: rgba(255, 209, 102, 0.45);
}

.difficulty-option--active {
  background: linear-gradient(180deg, rgba(255, 209, 102, 0.2), rgba(255, 138, 91, 0.16));
  border-color: rgba(255, 209, 102, 0.5);
  box-shadow: 0 12px 28px rgba(255, 138, 91, 0.18);
}

.primary-button {
  appearance: none;
  border: 0;
  cursor: pointer;
  width: 100%;
  padding: 0.95rem 1.1rem;
  border-radius: 999px;
  font: inherit;
  font-weight: 700;
  color: #08101f;
  background: linear-gradient(135deg, var(--accent-strong), var(--accent));
  box-shadow: 0 14px 40px rgba(255, 138, 91, 0.35);
  transition: transform 140ms ease, box-shadow 140ms ease, filter 140ms ease;
}

.primary-button:hover,
.primary-button:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 18px 46px rgba(255, 138, 91, 0.42);
  filter: saturate(1.05);
}

.secondary-button {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.14);
  cursor: pointer;
  width: 100%;
  padding: 0.95rem 1.1rem;
  border-radius: 999px;
  font: inherit;
  font-weight: 700;
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(12px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.secondary-button:hover,
.secondary-button:focus-visible {
  transform: translateY(-1px);
  border-color: rgba(82, 229, 199, 0.42);
  background: rgba(255, 255, 255, 0.1);
}

.panel__hint {
  margin: 0.9rem 0 0;
  color: rgba(245, 247, 255, 0.56);
}

@keyframes demoRunFlow {
  0% {
    transform: translate(1.2rem, 3.55rem);
  }
  30% {
    transform: translate(7rem, 3.55rem);
  }
  42% {
    transform: translate(8.2rem, 3.55rem);
  }
  72% {
    transform: translate(8.2rem, 1rem);
  }
  100% {
    transform: translate(8.2rem, 1rem);
  }
}

@keyframes cuePulse {
  0% {
    transform: scale(0.96);
    opacity: 0;
  }
  24% {
    transform: scale(0.96);
    opacity: 0;
  }
  38% {
    transform: scale(1);
    opacity: 1;
  }
  54% {
    transform: scale(1.05);
    opacity: 0;
  }
  100% {
    transform: scale(1.05);
    opacity: 0;
  }
}

@keyframes demoSuccessReveal {
  0%,
  62% {
    opacity: 0;
    transform: translateY(0.25rem) scale(0.96);
  }
  76%,
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 720px) {
  .hud {
    flex-direction: column;
  }

  .stats {
    width: 100%;
  }

  .stat-card {
    flex: 1;
  }

  .play-area,
  #gameScreen,
  #gameCanvas {
    min-height: 68vh;
    height: 68vh;
  }

  .panel__actions--split {
    flex-direction: column;
  }
}

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

.game-footer {
  margin-top: 1.5rem;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  opacity: 0.7;
}

.game-footer a {
  color: var(--accent-cool);
  text-decoration: none;
}

.game-footer a:hover {
  text-decoration: underline;
}
