:root {
  --cubie: 90px;
  --bg1: #10131a;
  --bg2: #1c2230;
  --panel: #171c26;
  --panel-border: #2a3245;
  --text: #e8ecf4;
  --muted: #8b94a7;
  --accent: #4f8cff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 800px at 30% 20%, var(--bg2), var(--bg1));
  overflow: hidden;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--panel-border);
  background: rgba(23, 28, 38, 0.6);
  backdrop-filter: blur(6px);
}

h1 { font-size: 20px; margin: 0; font-weight: 600; letter-spacing: 0.3px; }

.stats { display: flex; gap: 24px; }
.stat { display: flex; flex-direction: column; align-items: flex-end; min-width: 70px; }
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.stat span:last-child { font-size: 20px; font-variant-numeric: tabular-nums; font-weight: 600; }

main {
  display: flex;
  height: calc(100% - 61px);
}

/* ---------- Stage / 3D scene ---------- */

#stage {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  touch-action: none;
  user-select: none;
  min-width: 0;
}
#stage.dragging { cursor: grabbing; }

.scene {
  width: calc(var(--cubie) * 3);
  height: calc(var(--cubie) * 3);
  perspective: 1200px;
}

.pivot, .cube {
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
}

.pivot { transform: rotateX(-25deg) rotateY(-35deg); }

.cube { position: relative; }

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

.face {
  position: absolute;
  inset: 0;
  border: 5px solid #0b0d12;
  border-radius: 12px;
  background: #1a1e27;
  backface-visibility: hidden;
}

.face.c-white  { background: #f4f6f8; }
.face.c-yellow { background: #ffd53d; }
.face.c-green  { background: #2fbf4f; }
.face.c-blue   { background: #2f6fe0; }
.face.c-red    { background: #e33b3b; }
.face.c-orange { background: #ff8b1f; }

.face.sticker {
  box-shadow: inset 0 0 14px rgba(0, 0, 0, 0.25);
}

.floor-shadow {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 340px;
  height: 70px;
  transform: translate(-50%, 210px);
  background: radial-gradient(ellipse at center, rgba(0,0,0,0.5), transparent 70%);
  pointer-events: none;
}

/* ---------- Solved banner ---------- */

.solved-banner {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.solved-banner.hidden { display: none; }

.solved-inner {
  background: rgba(20, 26, 38, 0.92);
  border: 1px solid var(--accent);
  border-radius: 16px;
  padding: 24px 44px;
  text-align: center;
  animation: pop 0.45s cubic-bezier(0.2, 1.6, 0.4, 1);
  box-shadow: 0 12px 50px rgba(0, 0, 0, 0.5), 0 0 40px rgba(79, 140, 255, 0.25);
}
.solved-emoji { font-size: 42px; }
.solved-title { font-size: 28px; font-weight: 700; margin-top: 4px; }
.solved-detail { color: var(--muted); margin-top: 6px; font-size: 14px; }

@keyframes pop {
  from { transform: scale(0.6); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

/* ---------- Side panel ---------- */

#panel {
  width: 300px;
  flex-shrink: 0;
  padding: 20px;
  border-left: 1px solid var(--panel-border);
  background: rgba(23, 28, 38, 0.55);
  backdrop-filter: blur(6px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.panel-section h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--muted);
  margin: 0 0 10px;
  font-weight: 600;
}

.move-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.btn {
  appearance: none;
  border: 1px solid var(--panel-border);
  background: #202737;
  color: var(--text);
  border-radius: 10px;
  padding: 10px 0;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, transform 0.06s, border-color 0.12s;
  font-family: inherit;
}
.btn:hover { background: #2a3348; border-color: #3b4763; }
.btn:active { transform: scale(0.94); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #6a9dff; }
.btn:disabled { opacity: 0.45; cursor: default; transform: none; }

.move-btn { position: relative; }
.move-btn .dot {
  position: absolute;
  top: 5px; right: 7px;
  width: 7px; height: 7px;
  border-radius: 50%;
}

.action-row { display: flex; gap: 10px; }
.action-row .btn { flex: 1; padding: 12px 0; }

.hint { font-size: 12.5px; color: var(--muted); line-height: 1.55; margin: 12px 0 0; }
.drag-hint { margin-top: auto; }

kbd {
  background: #262e40;
  border: 1px solid #39445e;
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 11px;
  font-family: inherit;
}

.history {
  font-family: "Consolas", "Menlo", monospace;
  font-size: 14px;
  line-height: 1.7;
  color: #b9c3d8;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 42px;
  max-height: 120px;
  overflow-y: auto;
  word-spacing: 4px;
}

@media (max-width: 820px) {
  html, body { overflow: auto; }
  main { flex-direction: column; height: auto; }
  #stage { height: 60vh; min-height: 380px; }
  #panel { width: auto; border-left: none; border-top: 1px solid var(--panel-border); }
  :root { --cubie: 72px; }
}
