:root {
  --bg: #040915;
  --panel: rgba(8, 18, 40, 0.8);
  --panel-strong: rgba(6, 12, 28, 0.94);
  --line: rgba(118, 173, 255, 0.2);
  --text: #eef6ff;
  --muted: #98add2;
  --cyan: #58e4ff;
  --blue: #4f7bff;
  --coral: #ff6d8d;
  --gold: #ffd66a;
  --shadow: 0 24px 70px rgba(2, 10, 28, 0.45);
  --cube-size: clamp(13rem, 38vw, 23rem);
  --cubie-gap: clamp(0.22rem, 0.55vw, 0.36rem);
  --cubie-size: calc((var(--cube-size) - (var(--cubie-gap) * 2)) / 3);
  --cubie-offset: calc(var(--cubie-size) + var(--cubie-gap));
  --cubie-depth: calc(var(--cubie-size) / 2);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--text);
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background:
    radial-gradient(circle at top, rgba(75, 122, 255, 0.16), transparent 34%),
    radial-gradient(circle at 18% 20%, rgba(88, 228, 255, 0.18), transparent 22%),
    linear-gradient(180deg, #071122, #02050d 70%);
}

body {
  overflow-x: hidden;
}

button {
  font: inherit;
}

.app-shell {
  position: relative;
  min-height: 100vh;
  padding: 2rem;
  isolation: isolate;
}

.background-grid,
.glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.background-grid {
  opacity: 0.26;
  background-image:
    linear-gradient(rgba(126, 178, 255, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(126, 178, 255, 0.08) 1px, transparent 1px);
  background-size: 2rem 2rem;
  mask-image: radial-gradient(circle at center, black 34%, transparent 84%);
}

.glow {
  filter: blur(72px);
  opacity: 0.45;
}

.glow-a {
  background: radial-gradient(circle, rgba(88, 228, 255, 0.32), transparent 60%);
  transform: translate(-8%, -18%);
}

.glow-b {
  background: radial-gradient(circle, rgba(79, 123, 255, 0.28), transparent 58%);
  transform: translate(58%, 20%);
}

.topbar,
.dashboard {
  position: relative;
  z-index: 1;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 1.75rem;
}

.eyebrow,
.panel-topline,
.hint-label,
.section-title {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--cyan);
  font-size: 0.74rem;
}

h1,
h2 {
  margin: 0;
  font-weight: 800;
  letter-spacing: 0.04em;
}

h1 {
  max-width: 12ch;
  font-size: clamp(2.8rem, 7vw, 5rem);
  line-height: 0.96;
  text-shadow: 0 0 24px rgba(88, 228, 255, 0.18);
}

.subtitle {
  max-width: 44rem;
  margin: 0.8rem 0 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.65;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
  gap: 0.75rem;
}

.primary-button,
.ghost-button,
.move-button,
.difficulty-button,
.utility-button {
  border: 1px solid rgba(118, 173, 255, 0.28);
  border-radius: 999px;
  color: var(--text);
  background: linear-gradient(180deg, rgba(21, 34, 66, 0.94), rgba(7, 12, 26, 0.94));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 12px 24px rgba(1, 10, 28, 0.28);
  cursor: pointer;
  transition:
    transform 180ms ease,
    border-color 180ms ease,
    box-shadow 180ms ease,
    background 180ms ease;
}

.primary-button,
.ghost-button,
.utility-button {
  padding: 0.92rem 1.25rem;
}

.primary-button:hover,
.ghost-button:hover,
.move-button:hover,
.difficulty-button:hover,
.utility-button:hover,
.primary-button:focus-visible,
.ghost-button:focus-visible,
.move-button:focus-visible,
.difficulty-button:focus-visible,
.utility-button:focus-visible {
  transform: translateY(-2px);
  border-color: rgba(88, 228, 255, 0.7);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 16px 32px rgba(88, 228, 255, 0.14);
  outline: none;
}

.primary-button {
  background: linear-gradient(135deg, rgba(88, 228, 255, 0.22), rgba(79, 123, 255, 0.22));
}

.panel {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 1.6rem;
  background:
    linear-gradient(180deg, rgba(9, 18, 41, 0.84), rgba(6, 10, 22, 0.76));
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.panel::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(135deg, rgba(88, 228, 255, 0.08), transparent 35%, rgba(255, 109, 141, 0.05));
}

.dashboard {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(19rem, 0.88fr);
  gap: 1.25rem;
  align-items: start;
}

.stage-panel,
.control-panel,
.help-card {
  padding: 1.2rem;
}

.panel-topline {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.8rem;
  margin-bottom: 1rem;
}

.stat-card {
  padding: 1rem;
  border: 1px solid rgba(109, 163, 255, 0.18);
  border-radius: 1.1rem;
  background: rgba(8, 16, 36, 0.48);
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.stat-card strong {
  display: block;
  margin-top: 0.4rem;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: 0.05em;
}

.stage-frame {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 35rem;
  padding: 1.2rem;
  border-radius: 1.4rem;
  border: 1px solid rgba(97, 149, 255, 0.24);
  background:
    radial-gradient(circle at center, rgba(88, 228, 255, 0.12), transparent 38%),
    linear-gradient(180deg, rgba(9, 18, 43, 0.98), rgba(6, 10, 18, 0.94));
  cursor: grab;
  touch-action: none;
  transition: box-shadow 180ms ease, transform 180ms ease;
}

.stage-frame:active {
  cursor: grabbing;
}

.stage-frame.move-pulse {
  box-shadow:
    inset 0 0 0 1px rgba(88, 228, 255, 0.16),
    0 0 0 1px rgba(88, 228, 255, 0.08),
    0 26px 70px rgba(8, 18, 44, 0.48);
}

.scanline {
  position: absolute;
  inset: 0;
  opacity: 0.46;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent 12%, transparent 88%, rgba(255, 255, 255, 0.03));
}

.cube-scene {
  position: relative;
  width: min(100%, 38rem);
  height: min(78vw, 38rem);
  display: grid;
  place-items: center;
  perspective: 1400px;
  perspective-origin: 50% 42%;
  user-select: none;
}

.rubik-cube {
  position: relative;
  width: var(--cube-size);
  height: var(--cube-size);
  transform-style: preserve-3d;
  will-change: transform;
}

.cube-core {
  position: absolute;
  top: 50%;
  left: 50%;
  width: calc(var(--cube-size) * 0.78);
  height: calc(var(--cube-size) * 0.78);
  border-radius: 1.2rem;
  background:
    radial-gradient(circle at 30% 30%, rgba(72, 88, 122, 0.35), rgba(14, 18, 29, 0.96) 66%);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.05),
    inset 0 0 28px rgba(0, 0, 0, 0.42),
    0 0 40px rgba(0, 0, 0, 0.28);
  transform: translate(-50%, -50%) translateZ(0);
}

.cubie {
  position: absolute;
  top: 50%;
  left: 50%;
  width: var(--cubie-size);
  height: var(--cubie-size);
  margin-top: calc(var(--cubie-size) / -2);
  margin-left: calc(var(--cubie-size) / -2);
  transform-style: preserve-3d;
  will-change: transform;
}

.cubie-face,
.cubie-sticker {
  backface-visibility: hidden;
}

.cubie-face {
  position: absolute;
  inset: 0;
  border-radius: 0.42rem;
  border: 1px solid rgba(255, 255, 255, 0.05);
  background:
    linear-gradient(180deg, rgba(24, 28, 42, 0.96), rgba(5, 8, 16, 0.98));
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.04),
    inset 0 0 14px rgba(255, 255, 255, 0.02);
}

.cubie-face--front { transform: translateZ(var(--cubie-depth)); }
.cubie-face--back { transform: rotateY(180deg) translateZ(var(--cubie-depth)); }
.cubie-face--right { transform: rotateY(90deg) translateZ(var(--cubie-depth)); }
.cubie-face--left { transform: rotateY(-90deg) translateZ(var(--cubie-depth)); }
.cubie-face--up { transform: rotateX(90deg) translateZ(var(--cubie-depth)); }
.cubie-face--down { transform: rotateX(-90deg) translateZ(var(--cubie-depth)); }

.cubie-sticker {
  position: absolute;
  inset: 10%;
  border-radius: 0.32rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background:
    linear-gradient(145deg, rgba(28, 33, 52, 0.96), rgba(8, 10, 18, 0.96));
  box-shadow:
    inset 0 0 10px rgba(255, 255, 255, 0.14),
    0 3px 7px rgba(0, 0, 0, 0.22);
  transition:
    background 180ms ease,
    box-shadow 180ms ease,
    opacity 180ms ease;
}

.cubie-sticker[data-color="white"] {
  background: linear-gradient(145deg, #ffffff, #cfdcff);
}

.cubie-sticker[data-color="yellow"] {
  background: linear-gradient(145deg, #ffeb94, #f5ac20);
}

.cubie-sticker[data-color="orange"] {
  background: linear-gradient(145deg, #ffbc7b, #ff7637);
}

.cubie-sticker[data-color="red"] {
  background: linear-gradient(145deg, #ff91a8, #ff365d);
}

.cubie-sticker[data-color="green"] {
  background: linear-gradient(145deg, #91f1b2, #19c66d);
}

.cubie-sticker[data-color="blue"] {
  background: linear-gradient(145deg, #91c7ff, #356cff);
}

.cubie-sticker[data-color="none"] {
  opacity: 0.15;
  box-shadow: none;
}

.cube-shadow {
  position: absolute;
  width: min(22rem, 60vw);
  height: min(6rem, 18vw);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(88, 228, 255, 0.3), rgba(6, 10, 18, 0.02) 70%);
  transform: translateY(calc(var(--cube-size) * 0.56));
  filter: blur(20px);
}

.hint-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
  margin-top: 1rem;
}

.hint-strip > div,
.tips-card {
  padding: 1rem;
  border: 1px solid rgba(109, 163, 255, 0.18);
  border-radius: 1rem;
  background: rgba(8, 16, 36, 0.42);
}

.hint-strip p,
.tips-card p {
  margin: 0.5rem 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.control-panel {
  display: grid;
  gap: 1rem;
}

.difficulty-choices,
.utility-grid,
.key-grid,
.help-grid {
  display: grid;
  gap: 0.7rem;
}

.difficulty-choices {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.difficulty-button {
  padding: 0.85rem 0.6rem;
}

.difficulty-button.active,
.utility-button.active {
  border-color: rgba(88, 228, 255, 0.74);
  background: linear-gradient(135deg, rgba(88, 228, 255, 0.18), rgba(79, 123, 255, 0.2));
}

.key-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.move-button {
  display: grid;
  gap: 0.2rem;
  justify-items: start;
  padding: 1rem;
  border-radius: 1rem;
  text-align: left;
}

.move-button span {
  font-size: 1.18rem;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.move-button small {
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.4;
}

.utility-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.help-modal,
.victory-banner {
  position: fixed;
  z-index: 5;
}

.help-modal {
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: rgba(3, 7, 14, 0.68);
  backdrop-filter: blur(10px);
}

.help-card {
  width: min(64rem, 100%);
}

.help-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.help-grid article {
  padding: 1rem;
  border-radius: 1.1rem;
  border: 1px solid rgba(109, 163, 255, 0.18);
  background: rgba(8, 16, 36, 0.42);
}

.help-grid p {
  color: var(--muted);
  line-height: 1.6;
}

.victory-banner {
  right: 2rem;
  bottom: 2rem;
  width: min(24rem, calc(100vw - 2rem));
  padding: 1.4rem;
  border-radius: 1.5rem;
  border: 1px solid rgba(88, 228, 255, 0.48);
  background: linear-gradient(180deg, rgba(11, 24, 52, 0.94), rgba(8, 14, 28, 0.96));
  box-shadow:
    0 18px 60px rgba(0, 0, 0, 0.34),
    0 0 40px rgba(88, 228, 255, 0.16);
}

.victory-banner p {
  color: var(--muted);
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

.victory-mode .app-shell::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at center, rgba(88, 228, 255, 0.16), transparent 28%),
    radial-gradient(circle at 30% 20%, rgba(255, 214, 106, 0.08), transparent 18%),
    radial-gradient(circle at 70% 30%, rgba(255, 109, 141, 0.08), transparent 20%);
  animation: pulseVictory 1.4s ease-in-out infinite alternate;
}

@keyframes pulseVictory {
  from {
    opacity: 0.48;
  }

  to {
    opacity: 0.9;
  }
}

@media (max-width: 1120px) {
  .dashboard {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 840px) {
  .app-shell {
    padding: 1rem;
  }

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

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stage-frame {
    min-height: 29rem;
  }

  .hint-strip,
  .help-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  :root {
    --cube-size: min(68vw, 18rem);
    --cubie-gap: 0.24rem;
  }

  .hero-actions,
  .difficulty-choices,
  .utility-grid,
  .key-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hero-actions {
    display: grid;
    width: 100%;
  }

  .move-button {
    min-height: 4.4rem;
  }

  .victory-banner {
    right: 1rem;
    left: 1rem;
    bottom: 1rem;
    width: auto;
  }
}

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