.cube-challenge {
  --cc-ink: #eef7ff;
  --cc-muted: #9db2cc;
  --cc-accent: #72e4ff;
  --cc-panel: rgba(13, 25, 40, 0.9);
  position: relative;
  z-index: 1;
  grid-column: 2;
  grid-row: 1;
  width: 100%;
  min-width: 0;
  overflow: auto;
  padding: clamp(12px, 3vw, 32px);
  color: var(--cc-ink);
  background:
    radial-gradient(ellipse at 50% 42%, rgba(43, 112, 158, 0.24), transparent 50%),
    radial-gradient(circle at 12% 8%, rgba(98, 229, 255, 0.08), transparent 28%),
    linear-gradient(145deg, #07101c, #091522 58%, #040a12);
  backdrop-filter: blur(18px);
}

.cube-challenge.hidden { display: none; }
.cube-challenge * { box-sizing: border-box; }
.cube-challenge button { font: inherit; }
.cube-challenge__fullscreen-exit { display: none; }
.cube-challenge__fullscreen-button { display: none; }
.cube-challenge:fullscreen .cube-challenge__fullscreen-exit,
.cube-challenge.cube-challenge-is-fullscreen .cube-challenge__fullscreen-exit,
body.cube-challenge-fullscreen .cube-challenge__fullscreen-exit {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  z-index: 3010;
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 50%;
  color: var(--cc-ink);
  background: rgba(2,8,16,.72);
  font-size: 1.7rem;
  line-height: 1;
}
.phone-layout body.cube-challenge-fullscreen .cube-challenge {
  position: fixed;
  inset: 0;
  z-index: 3000;
  width: 100dvw;
  height: 100dvh;
  overflow: auto;
}
body.cube-challenge-open .app-shell > :not(.cube-challenge):not(.toolbar) { display: none; }
body.cube-challenge-open .toolbar__status { display: none; }
body.cube-challenge-open #puzzleModeControls {
  max-height: 0;
  opacity: 0;
  transform: translateY(-10px);
  visibility: hidden;
  pointer-events: none;
  transition: max-height 260ms ease, opacity 180ms ease, transform 260ms ease,
    visibility 0s linear 260ms;
}
.phone-layout #fullscreenBtn { display: none; }
.cube-challenge__shell { container-type: inline-size; width: 100%; min-height: 100%; margin: 0 auto; }
.cube-challenge__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 2px 4px 8px;
}
.cube-challenge__eyebrow {
  margin: 0 0 6px;
  color: var(--cc-accent);
  font-size: 0.76rem;
  font-weight: 750;
  letter-spacing: 0.17em;
  text-transform: uppercase;
}
.cube-challenge__header h2 { margin: 0; font-size: clamp(1.8rem, 4vw, 3rem); letter-spacing: -0.04em; }
.cube-challenge__intro { margin: 0; color: var(--cc-muted); }
.cube-challenge__layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(245px, 300px);
  align-items: center;
  gap: clamp(16px, 3vw, 38px);
}
.cube-challenge__stage-panel {
  display: grid;
  min-width: 0;
  min-height: min(72vh, 720px);
  align-content: center;
  justify-items: center;
  padding: 12px;
  overflow: hidden;
  border: 1px solid rgba(166, 211, 255, .1);
  border-radius: 30px;
  background:
    radial-gradient(ellipse at 50% 58%, rgba(90, 190, 230, .11), transparent 47%),
    linear-gradient(155deg, rgba(255,255,255,.045), rgba(255,255,255,.012));
  box-shadow: inset 0 1px rgba(255,255,255,.04), 0 30px 90px rgba(0,0,0,.18);
}
.cube-challenge__stage {
  --cc-size: clamp(220px, min(38cqw, 54vh), 450px);
  --cc-half-size: clamp(110px, min(19cqw, 27vh), 225px);
  position: relative;
  display: grid;
  width: min(100%, 760px);
  height: min(70vh, 690px);
  min-height: 360px;
  place-items: center;
  perspective: var(--cube-perspective, 1250px);
  perspective-origin: 50% 46%;
  touch-action: none;
  user-select: none;
}
.cube-challenge__stage::after {
  position: absolute;
  z-index: 0;
  bottom: max(3%, calc(50% - var(--cc-size) * .62));
  left: 50%;
  width: calc(var(--cc-size) * 1.2);
  height: calc(var(--cc-size) * .22);
  border-radius: 50%;
  background: rgba(0,0,0,.52);
  content: "";
  filter: blur(26px);
  transform: translateX(-50%);
}
.cube-challenge__cube {
  position: relative;
  z-index: 1;
  width: var(--cc-size);
  height: var(--cc-size);
  transform: rotateX(-24deg) rotateY(-34deg);
  transform-style: preserve-3d;
  transition: transform 560ms cubic-bezier(.2,.78,.2,1);
  will-change: transform;
}
.cube-challenge__cube.is-zooming { transition: transform 120ms ease-out; }
.cube-challenge__cube.is-dragging { transition: none; }
.cube-challenge__cube.is-intro-animating,
.cube-challenge__mini-cube.is-intro-animating { transition: transform 700ms ease-in-out; }
.cube-challenge__roll-handle {
  position: absolute;
  z-index: 5;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  cursor: grab;
  touch-action: none;
  transform-style: preserve-3d;
}
.cube-challenge__roll-handle[data-corner-x="-1"] { left: 0; }
.cube-challenge__roll-handle[data-corner-x="1"] { left: 100%; }
.cube-challenge__roll-handle[data-corner-y="-1"] { top: 0; }
.cube-challenge__roll-handle[data-corner-y="1"] { top: 100%; }
.cube-challenge__roll-handle[data-corner-z="-1"] { transform: translateZ(calc(0px - var(--cc-half-size))) translate(-50%, -50%); }
.cube-challenge__roll-handle[data-corner-z="1"] { transform: translateZ(var(--cc-half-size)) translate(-50%, -50%); }
@media (min-width: 701px) {
  .cube-challenge__roll-handle { width: 34px; height: 34px; }
}
.cube-challenge__turn-sticker {
  position: absolute;
  top: 50%;
  left: 50%;
  box-sizing: border-box;
  overflow: hidden;
  border: 1px solid rgba(225,242,255,.23);
  border-radius: 7px;
  background-color: #182739;
  background-repeat: no-repeat;
  box-shadow: inset 0 1px rgba(255,255,255,.22), inset 0 -5px 10px rgba(0,0,0,.16), 0 3px 7px rgba(0,0,0,.3);
  backface-visibility: hidden;
  pointer-events: none;
  transform-style: preserve-3d;
}
.cube-challenge__face {
  --cc-cell-size: calc((var(--cc-size) - 28px) / 3);
  --cc-grid-gap: 5px;
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(190, 229, 255, .38);
  border-radius: 21px;
  background: linear-gradient(145deg, #344453, #101b28 62%, #070d15);
  box-shadow: inset 0 1px 2px rgba(255,255,255,.16), inset 0 -10px 24px rgba(0,0,0,.34), 0 0 30px rgba(66,186,238,.1);
  backface-visibility: hidden;
  transform-style: preserve-3d;
}
.cube-challenge__face-grid {
  display: grid;
  grid-template-columns: repeat(3, var(--cc-cell-size));
  grid-template-rows: repeat(3, var(--cc-cell-size));
  gap: var(--cc-grid-gap);
  transform-origin: center center;
  transform-style: preserve-3d;
}
.cube-challenge__face[data-face="front"] { transform: translateZ(calc(var(--cc-size) / 2)); }
.cube-challenge__face[data-face="back"] { transform: rotateY(180deg) translateZ(calc(var(--cc-size) / 2)); }
.cube-challenge__face[data-face="right"] { transform: rotateY(90deg) translateZ(calc(var(--cc-size) / 2)); }
.cube-challenge__face[data-face="left"] { transform: rotateY(-90deg) translateZ(calc(var(--cc-size) / 2)); }
.cube-challenge__face[data-face="top"] { transform: rotateX(90deg) translateZ(calc(var(--cc-size) / 2)); }
.cube-challenge__face[data-face="bottom"] { transform: rotateX(-90deg) translateZ(calc(var(--cc-size) / 2)); }
.cube-challenge__piece {
  position: relative;
  min-width: 0;
  min-height: 0;
  width: var(--cc-cell-size);
  height: var(--cc-cell-size);
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(225,242,255,.23);
  border-radius: 7px;
  outline: none;
  background-color: #182739;
  background-repeat: no-repeat;
  background-size: 300% 200%;
  box-shadow: inset 0 1px rgba(255,255,255,.22), inset 0 -5px 10px rgba(0,0,0,.16), 0 3px 7px rgba(0,0,0,.3);
  cursor: grab;
  touch-action: none;
  transition: border-color 150ms ease, filter 150ms ease, box-shadow 150ms ease, transform 150ms ease;
  -webkit-user-drag: none;
}
.cube-challenge__piece:hover { z-index: 2; border-color: rgba(163,238,255,.86); filter: brightness(1.12); }
.cube-challenge__piece:active { cursor: grabbing; }
.cube-challenge__piece.is-pointer-dragging { cursor: grabbing; filter: brightness(.62); }
.cube-challenge__scramble-cover,
.cube-challenge__scramble-reveal {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: inherit;
  clip-path: inset(0 100% 0 0);
  pointer-events: none;
}
.cube-challenge__scramble-cover {
  background: linear-gradient(135deg, #17222e, #03070c 52%, #111a24);
  box-shadow: inset 0 1px rgba(255,255,255,.18), inset 0 -5px 10px rgba(0,0,0,.45);
}
.cube-challenge__scramble-reveal { background-repeat: no-repeat; }
.cube-challenge__scramble-cover::after,
.cube-challenge__scramble-reveal::after {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 7px;
  background: linear-gradient(90deg, transparent, rgba(4, 10, 17, .78));
  box-shadow: 0 0 7px rgba(4, 10, 17, .42);
  content: "";
}
.cube-challenge__scramble-cover::after {
  background: linear-gradient(90deg, transparent, rgba(210,235,255,.38));
  box-shadow: 0 0 8px rgba(140,205,255,.28);
}
.cube-challenge__drag-preview {
  position: fixed;
  z-index: 5000;
  box-sizing: border-box;
  border: 2px solid rgba(201,248,255,.96);
  border-radius: 7px;
  background-repeat: no-repeat;
  box-shadow: 0 12px 32px rgba(0,0,0,.5), 0 0 18px rgba(80,218,255,.55);
  opacity: .94;
  pointer-events: none;
  transform: translate(-50%, -50%);
}
.cube-challenge__piece.is-selected {
  z-index: 3;
  border-color: #c9f8ff;
  box-shadow: 0 0 0 2px rgba(102,225,255,.82), 0 0 20px rgba(80,218,255,.76), inset 0 0 16px rgba(255,255,255,.18);
  transform: translateZ(5px) scale(.96);
}
.cube-challenge__face.is-solved {
  border-color: rgba(120,255,202,.72);
  box-shadow: inset 0 0 35px rgba(70,255,183,.13), 0 0 34px rgba(73,255,190,.28);
}
.cube-challenge__side-panel {
  display: grid;
  gap: 18px;
  padding: 22px;
  border: 1px solid rgba(166,211,255,.13);
  border-radius: 24px;
  background: var(--cc-panel);
  box-shadow: 0 24px 70px rgba(0,0,0,.22), inset 0 1px rgba(255,255,255,.05);
  backdrop-filter: blur(18px);
}
.cube-challenge__score-card { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cube-challenge__score-card div:last-child { grid-column: 1 / -1; }
.cube-challenge__score-card div { display: grid; gap: 5px; padding: 13px; border-radius: 15px; background: rgba(255,255,255,.055); }
.cube-challenge__score-card span { color: var(--cc-muted); font-size: .78rem; }
.cube-challenge__score-card strong { font-size: 1.45rem; }
.cube-challenge__status { display: none; }
.cube-challenge__test-tools { display: grid; gap: 9px; padding: 14px; border: 1px dashed rgba(114,228,255,.42); border-radius: 15px; background: rgba(114,228,255,.045); }
.cube-challenge__test-tools strong { color: var(--cc-accent); }
.cube-challenge__test-tools label { display: grid; gap: 6px; color: var(--cc-muted); font-size: .84rem; }
.cube-challenge__test-tools select { width: 100%; padding: 9px 10px; border: 1px solid rgba(166,211,255,.2); border-radius: 9px; color: var(--cc-ink); background: #102033; font: inherit; }
.cube-challenge__test-tools button:disabled,
.cube-challenge__test-tools select:disabled { opacity: .55; cursor: wait; }
.cube-challenge__completion { display: flex; align-items: center; justify-content: space-between; gap: 18px; min-height: 100px; padding: 14px 16px; border: 1px solid rgba(255,255,255,.08); border-radius: 16px; color: var(--cc-muted); background: rgba(255,255,255,.035); font-size: .9rem; perspective: 180px; perspective-origin: center; }
.cube-challenge__mini-cube { --cc-mini-size: 58px; position: relative; width: var(--cc-mini-size); height: var(--cc-mini-size); flex: 0 0 var(--cc-mini-size); transform: rotateX(-24deg) rotateY(-34deg); transform-style: preserve-3d; transition: transform 560ms cubic-bezier(.2,.78,.2,1); }
.cube-challenge__mini-cube.is-dragging { transition: none; }
.cube-challenge__mini-face { position: absolute; inset: 0; border: 1px solid rgba(195,225,246,.75); border-radius: 5px; background: linear-gradient(145deg,#657b8d,#223243 60%,#101a27); box-shadow: inset 0 1px 4px rgba(255,255,255,.25); backface-visibility: hidden; transition: background 180ms ease, box-shadow 180ms ease; }
.cube-challenge__mini-face[data-face="front"] { transform: translateZ(calc(var(--cc-mini-size) / 2)); }
.cube-challenge__mini-face[data-face="back"] { transform: rotateY(180deg) translateZ(calc(var(--cc-mini-size) / 2)); }
.cube-challenge__mini-face[data-face="right"] { transform: rotateY(90deg) translateZ(calc(var(--cc-mini-size) / 2)); }
.cube-challenge__mini-face[data-face="left"] { transform: rotateY(-90deg) translateZ(calc(var(--cc-mini-size) / 2)); }
.cube-challenge__mini-face[data-face="top"] { transform: rotateX(90deg) translateZ(calc(var(--cc-mini-size) / 2)); }
.cube-challenge__mini-face[data-face="bottom"] { transform: rotateX(-90deg) translateZ(calc(var(--cc-mini-size) / 2)); }
.cube-challenge__mini-face.is-solved { border-color: #b9ffe0; background: linear-gradient(145deg,#80f7c0,#22b978 65%,#08784c); box-shadow: inset 0 0 12px rgba(224,255,240,.48), 0 0 15px rgba(73,255,190,.45); }
.cube-challenge__swap-marker { position: absolute; z-index: 2; box-sizing: border-box; border: 1px solid rgba(228,249,255,.98); border-radius: 2px; background: rgba(49,174,255,.94); box-shadow: inset 0 0 5px rgba(255,255,255,.58), 0 0 9px rgba(55,181,255,.95); pointer-events: none; backface-visibility: hidden; }
.cube-challenge__actions { display: grid; gap: 9px; }
.cube-challenge__actions .button { width: 100%; }
.cube-challenge__error { max-width: 36rem; padding: 14px 18px; border: 1px solid rgba(255,145,145,.3); border-radius: 14px; color: #ffd0d0; background: rgba(117,31,42,.28); text-align: center; }
.toolbar__controls-group {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  max-height: 480px;
  opacity: 1;
  transform: translateY(0);
  overflow: hidden;
  transition: max-height 260ms ease, opacity 180ms ease, transform 260ms ease, visibility 0s;
}

@media (max-width: 700px) {
  .phone-layout #puzzleModeControls {
    grid-column: 1 / -1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 980px) {
  .phone-layout body.cube-challenge-open .cube-challenge { grid-column: 1; grid-row: 2; }
}

@container (max-width: 700px) {
  .cube-challenge__layout { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 820px) {
  .cube-challenge__stage-panel { min-height: 0; }
  .cube-challenge__stage { --cc-size: clamp(210px, min(62vw, 43vh), 390px); --cc-half-size: clamp(105px, min(31vw, 21.5vh), 195px); height: min(51vh, 500px); min-height: 270px; }
  .cube-challenge__side-panel { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; padding: 16px; }
  .cube-challenge__score-card, .cube-challenge__status, .cube-challenge__completion { grid-column: 1 / -1; }
  .cube-challenge__actions { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 520px) {
  .cube-challenge { padding: 10px; }
  .cube-challenge__header { gap: 12px; padding: 2px 2px 8px; }
  .cube-challenge__intro { max-width: 34ch; font-size: .88rem; }
  .cube-challenge__stage-panel { padding: 4px; border-radius: 20px; }
  .cube-challenge__stage { --cc-size: clamp(205px, min(70vw, 42vh), 340px); --cc-half-size: clamp(102.5px, min(35vw, 21vh), 170px); width: 100%; height: min(45vh, 410px); min-height: 245px; }
  .cube-challenge__face { --cc-cell-size: calc((var(--cc-size) - 20px) / 3); --cc-grid-gap: 3px; border-radius: 15px; }
  .cube-challenge__piece { border-radius: 4px; }
  .cube-challenge__side-panel { gap: 10px; padding: 12px; }
}

@media (max-width: 700px) {
  .cube-challenge__fullscreen-button {
    display: grid;
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    place-items: center;
    border: 1px solid rgba(255,255,255,.16);
    border-radius: 12px;
    color: var(--cc-ink);
    background: rgba(255,255,255,.07);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  .phone-layout body.cube-challenge-open .cube-challenge {
    grid-column: 2;
    grid-row: 1;
  }

  .phone-layout .cube-challenge__layout {
    grid-template-columns: minmax(0, 1fr) minmax(180px, 30vw);
    align-items: stretch;
    gap: 12px;
  }

  .phone-layout .cube-challenge__stage-panel {
    min-height: 0;
    padding: 6px;
  }

  .phone-layout .cube-challenge__stage {
    --cc-size: clamp(210px, min(38cqw, 70vh), 390px);
    --cc-half-size: clamp(105px, min(19cqw, 35vh), 195px);
    height: min(70vh, 390px);
    min-height: 240px;
  }

  .phone-layout .cube-challenge__side-panel {
    display: grid;
    grid-template-columns: 1fr;
    align-content: center;
    gap: 8px;
    padding: 10px;
    overflow-y: auto;
  }

  .phone-layout .cube-challenge__score-card,
  .phone-layout .cube-challenge__status,
  .phone-layout .cube-challenge__completion {
    grid-column: auto;
  }

  .phone-layout .cube-challenge__actions {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cube-challenge *, .cube-challenge *::before, .cube-challenge *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
