/* -------------------------------------------------------------
   FOLDING DICE 3D - Stylesheet
   Pure CSS 3D kinematic hinge transforms, glassmorphic UI
   ------------------------------------------------------------- */

:root {
  --square-size: 84px;
  --half-size: 42px;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --bg-dark: #090d16;
  --panel-bg: rgba(15, 23, 42, 0.85);
  --panel-border: rgba(255, 255, 255, 0.12);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent-glow: rgba(59, 130, 246, 0.35);
  --radius-md: 10px;
  --radius-lg: 14px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-main);
  user-select: none;
  -webkit-user-select: none;
}

/* -------------------------------------------------------------
   3D Scene & Viewport
   ------------------------------------------------------------- */
#viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  perspective: 1150px;
  perspective-origin: 50% 50%;
  background: radial-gradient(circle at 50% 42%, #e2e8f0 0%, #cbd5e1 100%);
  cursor: grab;
  z-index: 1;
}

#viewport.grabbing {
  cursor: grabbing !important;
}

#viewport.panning {
  cursor: move !important;
}

#world {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  transform-style: preserve-3d;
  transform-origin: 0 0 0;
  will-change: transform;
}

/* Ground grid plane aligned right beneath the base square (Y = half-size) */
#ground-grid {
  position: absolute;
  width: 1512px;
  height: 1512px;
  left: -756px;
  top: -756px;
  transform: translateY(calc(var(--half-size) + 2px)) rotateX(90deg);
  background-size: var(--square-size) var(--square-size);
  background-position: var(--half-size) var(--half-size);
  background-image:
    linear-gradient(to right, rgba(15, 23, 42, 0.14) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(15, 23, 42, 0.14) 1px, transparent 1px);
  border-radius: 50%;
  mask-image: radial-gradient(circle, rgba(0, 0, 0, 0.88) 0%, rgba(0, 0, 0, 0.35) 52%, transparent 72%);
  -webkit-mask-image: radial-gradient(circle, rgba(0, 0, 0, 0.88) 0%, rgba(0, 0, 0, 0.35) 52%, transparent 72%);
  pointer-events: none;
}

#net-tree-container,
#candidate-slots-container {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  transform-style: preserve-3d;
}

/* -------------------------------------------------------------
   Hierarchical 3D Kinematic Square Nodes & Hinges
   ------------------------------------------------------------- */
.square-node {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--square-size);
  height: var(--square-size);
  transform-style: preserve-3d;
  will-change: transform;
}

.square-tile {
  position: absolute;
  inset: 0;
  width: var(--square-size);
  height: var(--square-size);
  transform-style: preserve-3d;
  cursor: pointer;
}

.square-tile.spawn-anim {
  animation: squarePop 0.24s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes squarePop {
  0% {
    transform: scale3d(0.1, 0.1, 1);
    opacity: 0;
  }
  70% {
    transform: scale3d(1.06, 1.06, 1);
    opacity: 1;
  }
  100% {
    transform: scale3d(1, 1, 1);
    opacity: 1;
  }
}

/* Double-sided faces so squares are visible both when flat in 2D and when folded into 3D */
.tile-face {
  position: absolute;
  inset: 0;
  width: var(--square-size);
  height: var(--square-size);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background-color: var(--sq-color, #ffffff);
  border: 2.5px solid #0f172a;
  border-radius: 6px;
  box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.65);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
  overflow: hidden;
}

/* Inner face (+Z local): faces UP when flat on the 2D surface, faces INWARD when folded */
.tile-face.tile-inner {
  transform: translateZ(0.6px);
  filter: brightness(0.97);
}

/* Outer face (-Z local): faces DOWN when flat, becomes the EXTERIOR 3D DICE FACE when folded */
.tile-face.tile-outer {
  transform: rotateY(180deg) translateZ(0.6px);
  filter: brightness(0.92);
}

/* Active folding step highlight */
.square-node.active-folding > .square-tile > .tile-face {
  border-color: #2563eb !important;
  box-shadow: inset 0 0 0 2.5px #3b82f6, 0 0 18px rgba(59, 130, 246, 0.55) !important;
}

/* Overlap / Collision warning state when two squares fold into the same 3D face */
.square-node.collision-warning > .square-tile > .tile-face {
  border-color: #dc2626 !important;
  box-shadow: inset 0 0 0 2.5px #ef4444, 0 0 18px rgba(239, 68, 68, 0.65) !important;
}

/* Base / Anchor square subtle corner indicator */
.square-node.is-base-node > .square-tile > .tile-face {
  box-shadow: inset 0 0 0 2px rgba(15, 23, 42, 0.35), inset 0 0 0 1px rgba(255, 255, 255, 0.8);
}

/* Hinge Crease Line along the shared edge with parent */
.hinge-crease {
  position: absolute;
  pointer-events: none;
  z-index: 10;
  border-radius: 3px;
  background: rgba(15, 23, 42, 0.45);
  transition: background 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
  transform: translateZ(1.2px);
}

/* East child: hinge is on its West (left) edge */
.square-node[data-dir="east"] > .hinge-crease {
  left: -3px;
  top: 4px;
  width: 6px;
  height: calc(var(--square-size) - 8px);
}
/* West child: hinge is on its East (right) edge */
.square-node[data-dir="west"] > .hinge-crease {
  right: -3px;
  top: 4px;
  width: 6px;
  height: calc(var(--square-size) - 8px);
}
/* South child: hinge is on its North (top) edge */
.square-node[data-dir="south"] > .hinge-crease {
  top: -3px;
  left: 4px;
  height: 6px;
  width: calc(var(--square-size) - 8px);
}
/* North child: hinge is on its South (bottom) edge */
.square-node[data-dir="north"] > .hinge-crease {
  bottom: -3px;
  left: 4px;
  height: 6px;
  width: calc(var(--square-size) - 8px);
}

.square-node.active-folding > .hinge-crease {
  background: #f59e0b;
  box-shadow: 0 0 12px #f59e0b, 0 0 4px #ffffff;
}

/* -------------------------------------------------------------
   Geometric Die Symbols Inside Each Square Face
   (1: Plus, 2: Empty Square, 3: Filled Black Square,
    4: Empty Circle, 5: Filled Black Circle, 6: Four Dots)
   ------------------------------------------------------------- */
.face-symbol-wrap {
  width: 50px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--symbol-color, #0f172a);
  pointer-events: none;
  z-index: 2;
}

.face-symbol-svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
  filter: drop-shadow(0 1px 1px rgba(255, 255, 255, 0.25));
}

#viewport.hide-symbols .face-symbol-wrap {
  display: none;
}

/* In Quiz Mode, hide candidate slots and target-face spoiler badges until solved */
body.quiz-active .candidate-slot {
  display: none !important;
}

body.quiz-active:not(.quiz-revealed) .target-face-badge {
  display: none !important;
}

/* -------------------------------------------------------------
   Educational Badges on Squares (Step #, Target 3D Face,
   Corner 3-Lines Hint, Opposite Pairs Hint, and Zip Edges Hint)
   ------------------------------------------------------------- */
.step-order-badge {
  position: absolute;
  top: 4px;
  left: 4px;
  padding: 1px 5px;
  font-size: 9px;
  font-weight: 800;
  border-radius: 4px;
  background: rgba(15, 23, 42, 0.78);
  color: #f8fafc;
  letter-spacing: 0.3px;
  pointer-events: none;
  z-index: 3;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.step-order-badge.base-badge {
  background: #0f172a;
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.45);
}

.target-face-badge {
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  padding: 1px 6px;
  font-size: 8.5px;
  font-weight: 800;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.92);
  color: #0f172a;
  border: 1px solid rgba(15, 23, 42, 0.3);
  white-space: nowrap;
  pointer-events: none;
  z-index: 4;
}

.target-face-badge.overlap-badge {
  background: #ef4444;
  color: #ffffff;
  border-color: #991b1b;
}

/* Corner 3-Lines Hint: 3 directional lines + corner vertex dot on 2D net */
.corner-hint-line {
  display: none;
  position: absolute;
  background: var(--corner-line-color, #06b6d4);
  box-shadow: 0 0 10px var(--corner-line-color, #06b6d4);
  pointer-events: none;
  z-index: 6;
}

body.quiz-hint-corner .corner-hint-line {
  display: block;
}

.corner-hint-line.line-north {
  top: -1px;
  left: 0;
  right: 0;
  height: 7px;
}

.corner-hint-line.line-south {
  bottom: -1px;
  left: 0;
  right: 0;
  height: 7px;
}

.corner-hint-line.line-west {
  left: -1px;
  top: 0;
  bottom: 0;
  width: 7px;
}

.corner-hint-line.line-east {
  right: -1px;
  top: 0;
  bottom: 0;
  width: 7px;
}

.corner-hint-vertex {
  display: none;
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #ffffff;
  border: 3px solid #0f172a;
  box-shadow: 0 0 0 2px #a855f7, 0 0 12px #a855f7;
  pointer-events: none;
  z-index: 8;
}

body.quiz-hint-corner .corner-hint-vertex {
  display: block;
}

.corner-hint-vertex.vertex-nw { top: -6px; left: -6px; }
.corner-hint-vertex.vertex-ne { top: -6px; right: -6px; }
.corner-hint-vertex.vertex-sw { bottom: -6px; left: -6px; }
.corner-hint-vertex.vertex-se { bottom: -6px; right: -6px; }

/* Opposite Pair Hint Badge & Colored Frame */
.opp-pair-badge {
  display: none;
  position: absolute;
  top: 4px;
  right: 4px;
  padding: 1px 5px;
  font-size: 8.5px;
  font-weight: 900;
  letter-spacing: 0.3px;
  border-radius: 4px;
  background: var(--opp-color, #2563eb);
  color: #ffffff;
  pointer-events: none;
  z-index: 4;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

body.quiz-hint-opposites .opp-pair-badge {
  display: inline-block;
}

body.quiz-hint-opposites .square-tile .tile-face {
  border-color: var(--opp-color, #2563eb) !important;
  box-shadow: inset 0 0 0 3.5px var(--opp-color, #2563eb), inset 0 0 18px var(--opp-bg, rgba(37, 99, 235, 0.22)) !important;
}

/* Zip Edges Hint Bars along Open 2D Perimeter Edges */
.zip-edge-bar {
  display: none;
  position: absolute;
  background: var(--edge-color, #ec4899);
  box-shadow: 0 0 8px var(--edge-color, #ec4899);
  pointer-events: none;
  z-index: 5;
  align-items: center;
  justify-content: center;
}

body.quiz-hint-edges .zip-edge-bar {
  display: flex;
}

.zip-edge-bar.edge-north {
  top: 0;
  left: 8px;
  right: 8px;
  height: 6px;
  border-radius: 0 0 4px 4px;
}

.zip-edge-bar.edge-south {
  bottom: 0;
  left: 8px;
  right: 8px;
  height: 6px;
  border-radius: 4px 4px 0 0;
}

.zip-edge-bar.edge-west {
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 6px;
  border-radius: 0 4px 4px 0;
}

.zip-edge-bar.edge-east {
  right: 0;
  top: 8px;
  bottom: 8px;
  width: 6px;
  border-radius: 4px 0 0 4px;
}

.zip-edge-tag {
  background: var(--edge-color, #ec4899);
  color: #ffffff;
  font-size: 8px;
  font-weight: 900;
  padding: 0 4px;
  border-radius: 4px;
  line-height: 1.35;
  border: 1px solid #0f172a;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
}

#viewport.hide-face-labels .target-face-badge,
#viewport.hide-face-labels .step-order-badge {
  display: none;
}

/* -------------------------------------------------------------
   Interactive Mode Hover States on Squares
   ------------------------------------------------------------- */
body[data-active-mode="delete"] .square-tile:hover .tile-face {
  background-color: #ef4444 !important;
  border-color: #991b1b !important;
}

body[data-active-mode="delete"] .square-tile:hover .tile-face::after {
  content: "×";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  font-weight: 900;
  color: #ffffff;
  background: rgba(239, 68, 68, 0.75);
  z-index: 5;
}

body:not(.quiz-active)[data-active-mode="add"] .square-tile:hover .tile-face,
body:not(.quiz-active)[data-active-mode="paint"] .square-tile:hover .tile-face {
  filter: brightness(1.06) !important;
  border-color: #0284c7 !important;
  box-shadow: inset 0 0 0 2.5px #38bdf8, 0 0 14px rgba(56, 189, 248, 0.45) !important;
}

body[data-active-mode="anchor"] .square-tile:hover .tile-face {
  border-color: #f59e0b !important;
  box-shadow: inset 0 0 0 2.5px #f59e0b, 0 0 16px rgba(245, 158, 11, 0.5) !important;
}

body[data-active-mode="anchor"] .square-tile:hover .tile-face::after {
  content: "SET BASE";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.6px;
  color: #ffffff;
  background: rgba(15, 23, 42, 0.72);
  z-index: 5;
}

/* -------------------------------------------------------------
   2D Candidate Slot Buttons (For Adding Adjacent Squares)
   ------------------------------------------------------------- */
.candidate-slot {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--square-size);
  height: var(--square-size);
  transform-origin: 0 0 0;
  border: 2px dashed rgba(37, 99, 235, 0.55);
  border-radius: 6px;
  background: rgba(59, 130, 246, 0.10);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

.candidate-slot .slot-plus {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(37, 99, 235, 0.85);
  color: #ffffff;
  font-size: 20px;
  font-weight: 800;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.4);
  transition: transform 0.16s ease, background 0.16s ease;
  pointer-events: none;
}

.candidate-slot:hover {
  background: rgba(59, 130, 246, 0.28);
  border: 2.5px dashed #1d4ed8;
  box-shadow: 0 0 16px rgba(37, 99, 235, 0.4);
}

.candidate-slot:hover .slot-plus {
  transform: scale(1.18);
  background: #1d4ed8;
}

/* Hide candidate slots when not in add mode or when folded */
body:not([data-active-mode="add"]) .candidate-slot,
#viewport.is-folded .candidate-slot {
  display: none !important;
}

/* -------------------------------------------------------------
   2D Architectural Mode & X-Ray Projection
   ------------------------------------------------------------- */
#viewport.arch-view {
  perspective: none !important;
}

#viewport.arch-view .tile-face {
  filter: none !important;
}

#viewport.arch-view:not(.arch-top) #ground-compass {
  display: none !important;
}

#viewport.arch-top .dir-back .dir-pill {
  transform: translateX(-50%) rotateZ(180deg);
}
#viewport.arch-top .dir-left .dir-pill {
  transform: translateX(-50%) rotateZ(-90deg);
}
#viewport.arch-top .dir-right .dir-pill {
  transform: translateX(-50%) rotateZ(90deg);
}

/* X-Ray / See-Through Mode */
#viewport.xray-mode .tile-face {
  opacity: 0.48 !important;
  border: 2px solid #0284c7 !important;
  box-shadow: inset 0 0 12px rgba(2, 132, 199, 0.45) !important;
}

/* 2D Architecture View Banner */
.arch-banner {
  position: absolute;
  top: 84px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(56, 189, 248, 0.4);
  padding: 6px 14px 6px 16px;
  border-radius: 30px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  z-index: 45;
  pointer-events: auto;
  animation: bannerEnter 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes bannerEnter {
  0% { transform: translate(-50%, -10px); opacity: 0; }
  100% { transform: translate(-50%, 0); opacity: 1; }
}

.arch-badge {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.6px;
  color: #38bdf8;
  text-transform: uppercase;
}

.arch-title {
  font-size: 13px;
  font-weight: 700;
  color: #f8fafc;
}

.arch-btn-switch {
  background: rgba(56, 189, 248, 0.15);
  border: 1px solid rgba(56, 189, 248, 0.45);
  color: #38bdf8;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.16s ease;
}

.arch-btn-switch:hover {
  background: #38bdf8;
  color: #0f172a;
}

.hidden {
  display: none !important;
}

/* -------------------------------------------------------------
   Top Navigation Bar
   ------------------------------------------------------------- */
.top-bar {
  position: fixed;
  top: 14px;
  left: 18px;
  right: 18px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--panel-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  z-index: 50;
  pointer-events: auto;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  perspective: 200px;
}

.mini-cube {
  width: 20px;
  height: 20px;
  position: relative;
  transform-style: preserve-3d;
  transform: rotateX(-28deg) rotateY(45deg);
  animation: miniCubeSpin 9s infinite linear;
}

@keyframes miniCubeSpin {
  0% { transform: rotateX(-28deg) rotateY(0deg); }
  100% { transform: rotateX(-28deg) rotateY(360deg); }
}

.m-face {
  position: absolute;
  width: 20px;
  height: 20px;
  background: #3b82f6;
  border: 1px solid rgba(255, 255, 255, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: #fff;
}
.m-front { transform: translateZ(10px); background: #2563eb; }
.m-top   { transform: rotateX(90deg) translateZ(10px); background: #60a5fa; }
.m-right { transform: rotateY(90deg) translateZ(10px); background: #1d4ed8; }

.brand-text {
  display: flex;
  flex-direction: column;
}
.brand-title {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.8px;
  color: #fff;
}
.brand-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

/* Tool Mode Selector */
.mode-selector {
  display: flex;
  background: rgba(0, 0, 0, 0.3);
  padding: 4px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.08);
  gap: 4px;
}

.tool-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: transparent;
  color: var(--text-muted);
  border: none;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s ease;
  white-space: nowrap;
}

.tool-btn .icon {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.tool-btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.06);
}

.tool-btn.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 10px rgba(59, 130, 246, 0.45);
}

.tool-btn[data-mode="delete"].active {
  background: var(--danger);
  box-shadow: 0 2px 10px rgba(239, 68, 68, 0.45);
}

.tool-btn[data-mode="paint"].active {
  background: #0284c7;
  box-shadow: 0 2px 10px rgba(2, 132, 199, 0.45);
}

.tool-btn[data-mode="anchor"].active {
  background: #d97706;
  box-shadow: 0 2px 10px rgba(217, 119, 6, 0.45);
}

/* Stats & Net Status */
.stats-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stat-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 6px 11px;
  border-radius: 20px;
  font-size: 12px;
  white-space: nowrap;
}
.stat-label {
  color: var(--text-muted);
}
.stat-value {
  color: #38bdf8;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.net-status-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 700;
  background: rgba(148, 163, 184, 0.14);
  border: 1px solid rgba(148, 163, 184, 0.3);
  color: #cbd5e1;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.net-status-badge.status-valid {
  background: rgba(16, 185, 129, 0.18);
  border-color: rgba(16, 185, 129, 0.5);
  color: #34d399;
}

.net-status-badge.status-invalid {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.55);
  color: #fca5a5;
}

.icon-btn {
  width: 35px;
  height: 35px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.18s ease;
  flex-shrink: 0;
}

.icon-btn .icon {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.icon-btn:hover:not(:disabled) {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.25);
  transform: translateY(-1px);
}

.icon-btn.active {
  background: var(--primary) !important;
  color: #fff !important;
  border-color: #60a5fa !important;
  box-shadow: 0 0 12px rgba(59, 130, 246, 0.5) !important;
}

.icon-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* -------------------------------------------------------------
   Left Floating Palette Toolbar
   ------------------------------------------------------------- */
.left-palette {
  position: fixed;
  top: 84px;
  left: 18px;
  width: 230px;
  z-index: 40;
  pointer-events: auto;
  max-height: calc(100vh - 104px);
  overflow-y: auto;
}

.palette-card {
  background: var(--panel-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  padding: 14px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.palette-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
}

.rainbow-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.rainbow-toggle input {
  display: none;
}

.rainbow-toggle .slider {
  width: 28px;
  height: 16px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  position: relative;
  transition: background 0.2s ease;
}

.rainbow-toggle .slider::before {
  content: "";
  position: absolute;
  width: 12px;
  height: 12px;
  left: 2px;
  top: 2px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s ease;
}

.rainbow-toggle input:checked + .slider {
  background: linear-gradient(90deg, #3b82f6, #10b981, #f59e0b);
}

.rainbow-toggle input:checked + .slider::before {
  transform: translateX(12px);
}

.rainbow-toggle .label-text {
  font-size: 10.5px;
  color: var(--text-muted);
}

/* Color Swatches Grid */
.color-swatches {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
}

.swatch {
  width: 100%;
  aspect-ratio: 1.2;
  border-radius: 7px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.16s ease;
  position: relative;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

.swatch:hover {
  transform: scale(1.1);
  z-index: 2;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.swatch.active {
  border-color: #ffffff;
  transform: scale(1.06);
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.6);
}

.swatch.active::after {
  content: "✓";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
}

/* Custom Color Input Row */
.custom-color-row {
  display: flex;
}

.custom-color-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 5px 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.16s ease;
  position: relative;
}

.custom-color-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.25);
}

.custom-color-btn input[type="color"] {
  position: absolute;
  opacity: 0;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.custom-color-preview {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  background-color: #3b82f6;
  border: 1px solid rgba(255, 255, 255, 0.4);
}

.custom-color-label {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-main);
}

.divider {
  height: 1px;
  background: var(--panel-border);
  margin: 1px 0;
}

/* Pip Value Selector */
.pip-selector-section {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.mini-action-btn {
  background: rgba(56, 189, 248, 0.16);
  border: 1px solid rgba(56, 189, 248, 0.4);
  color: #38bdf8;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.mini-action-btn:hover {
  background: #38bdf8;
  color: #0f172a;
}

.pip-buttons-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
}

.pip-btn {
  padding: 5px 4px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}

.pip-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.pip-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: #60a5fa;
}

/* Presets */
.presets-section {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
}

.presets-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 5px;
}

.preset-btn {
  padding: 6px 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.16s ease;
  text-align: center;
}

.preset-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.25);
}

.preset-btn.preset-invalid {
  border-color: rgba(239, 68, 68, 0.35);
  color: #fca5a5;
}
.preset-btn.preset-invalid:hover {
  background: rgba(239, 68, 68, 0.2);
  color: #fff;
  border-color: #ef4444;
}

/* Action Buttons */
.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.action-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.btn {
  padding: 7px 10px;
  border-radius: var(--radius-md);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s ease;
  border: 1px solid transparent;
  text-align: center;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--panel-border);
  color: var(--text-muted);
}
.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.25);
}

/* -------------------------------------------------------------
   Bottom Center: Step-by-Step Folding Controller Dock
   ------------------------------------------------------------- */
.fold-controller-dock {
  position: fixed;
  bottom: 20px;
  left: 264px;
  right: 455px;
  display: flex;
  justify-content: center;
  z-index: 45;
  pointer-events: none;
}

.fold-card {
  width: 100%;
  max-width: 600px;
  background: var(--panel-bg);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(59, 130, 246, 0.32);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.45), 0 0 20px rgba(59, 130, 246, 0.12);
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: auto;
}

.fold-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.fold-stage-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.fold-stage-badge {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.7px;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(56, 189, 248, 0.18);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.4);
  text-transform: uppercase;
}

.fold-stage-badge.stage-folding {
  background: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
  border-color: rgba(245, 158, 11, 0.5);
}

.fold-stage-badge.stage-3d {
  background: rgba(16, 185, 129, 0.22);
  color: #34d399;
  border-color: rgba(16, 185, 129, 0.55);
}

.fold-step-title {
  font-size: 12.5px;
  font-weight: 700;
  color: #f8fafc;
}

.fold-speed-group {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(0, 0, 0, 0.3);
  padding: 3px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.speed-label {
  font-size: 10.5px;
  color: var(--text-muted);
  padding: 0 5px;
  font-weight: 600;
}

.speed-btn {
  padding: 3px 8px;
  font-size: 10.5px;
  font-weight: 700;
  border: none;
  border-radius: 5px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.speed-btn:hover {
  color: #fff;
}

.speed-btn.active {
  background: rgba(59, 130, 246, 0.35);
  color: #60a5fa;
}

/* Timeline Step Pills & Scrubber Slider */
.fold-timeline-row {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.step-pills-container {
  display: flex;
  align-items: center;
  gap: 5px;
}

.step-pill {
  flex: 1;
  padding: 5px 6px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.16s ease;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.step-pill:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.step-pill.completed {
  background: rgba(59, 130, 246, 0.22);
  border-color: rgba(59, 130, 246, 0.5);
  color: #93c5fd;
}

.step-pill.current {
  background: var(--primary);
  border-color: #60a5fa;
  color: #ffffff;
  box-shadow: 0 0 12px rgba(59, 130, 246, 0.5);
}

.slider-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.slider-end-label {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}

#fold-progress-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.15);
  outline: none;
  cursor: pointer;
}

#fold-progress-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #38bdf8;
  border: 2px solid #ffffff;
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.7);
  cursor: grab;
  transition: transform 0.12s ease;
}

#fold-progress-slider::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

/* Primary Step-by-Step Buttons */
.fold-actions-row {
  display: grid;
  grid-template-columns: auto 1fr 1.15fr auto;
  gap: 8px;
}

.fold-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.18s ease;
  border: 1px solid transparent;
  white-space: nowrap;
}

.fold-btn .icon {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.fold-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none !important;
}

.fold-btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--panel-border);
  color: var(--text-muted);
}

.fold-btn-secondary:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
}

.fold-btn-step {
  background: rgba(59, 130, 246, 0.16);
  border-color: rgba(59, 130, 246, 0.45);
  color: #93c5fd;
}

.fold-btn-step:hover:not(:disabled) {
  background: rgba(59, 130, 246, 0.32);
  color: #fff;
  transform: translateY(-1px);
}

.fold-btn-primary {
  background: linear-gradient(135deg, #2563eb, #0284c7);
  border-color: rgba(255, 255, 255, 0.25);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.45);
}

.fold-btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #1d4ed8, #0369a1);
  box-shadow: 0 6px 20px rgba(37, 99, 235, 0.65);
  transform: translateY(-1px);
}

.fold-btn-play {
  background: linear-gradient(135deg, #059669, #10b981);
  border-color: rgba(255, 255, 255, 0.22);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.35);
}

.fold-btn-play:hover:not(:disabled) {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.fold-btn-play.playing {
  background: linear-gradient(135deg, #d97706, #f59e0b);
}

/* -------------------------------------------------------------
   Floating Camera HUD (Right Bottom)
   ------------------------------------------------------------- */
.camera-controls {
  position: fixed;
  bottom: 20px;
  right: 18px;
  background: var(--panel-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  padding: 8px 10px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 7px;
  z-index: 40;
  pointer-events: auto;
}

.cam-nav-group {
  display: flex;
  align-items: center;
  gap: 5px;
}

.cam-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.16s ease;
}

.cam-btn .icon {
  width: 17px;
  height: 17px;
  fill: currentColor;
}

.cam-btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.25);
  transform: translateY(-1px);
}

.cam-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: #60a5fa;
  box-shadow: 0 0 10px rgba(59, 130, 246, 0.5);
}

.zoom-level-display {
  font-size: 11px;
  font-weight: 700;
  color: #38bdf8;
  min-width: 42px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.cam-divider {
  width: 1px;
  height: 20px;
  background: var(--panel-border);
  margin: 0 2px;
}

.view-preset-pills {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.pill-btn {
  padding: 5px 8px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.3px;
  cursor: pointer;
  transition: all 0.16s ease;
  white-space: nowrap;
}

.pill-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.25);
  transform: translateY(-1px);
}

.pill-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: #60a5fa;
  box-shadow: 0 0 12px rgba(59, 130, 246, 0.45);
}

.pill-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
}
.dot-iso    { background: #38bdf8; box-shadow: 0 0 6px #38bdf8; }
.dot-top    { background: #0284c7; box-shadow: 0 0 6px #0284c7; }
.dot-bottom { background: #64748b; box-shadow: 0 0 6px #64748b; }
.dot-front  { background: #3b82f6; box-shadow: 0 0 6px #3b82f6; }
.dot-back   { background: #8b5cf6; box-shadow: 0 0 6px #8b5cf6; }
.dot-left   { background: #f59e0b; box-shadow: 0 0 6px #f59e0b; }
.dot-right  { background: #10b981; box-shadow: 0 0 6px #10b981; }

/* -------------------------------------------------------------
   3D Orientation ViewCube Gizmo (Top Right)
   ------------------------------------------------------------- */
.viewcube-widget {
  position: fixed;
  top: 84px;
  right: 18px;
  width: 96px;
  background: var(--panel-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  padding: 8px 6px 10px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 40;
  pointer-events: auto;
  user-select: none;
}

.viewcube-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin-bottom: 6px;
  padding: 0 4px;
}

.viewcube-title {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.8px;
  color: var(--text-muted);
}

.viewcube-home-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.15s ease;
}

.viewcube-home-btn .icon {
  width: 13px;
  height: 13px;
  fill: currentColor;
}

.viewcube-home-btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
}

.viewcube-viewport {
  width: 78px;
  height: 78px;
  perspective: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
}

.viewcube-viewport:active {
  cursor: grabbing;
}

.viewcube {
  position: relative;
  width: 48px;
  height: 48px;
  transform-style: preserve-3d;
  transform-origin: 24px 24px 0px;
  will-change: transform;
}

.vface {
  position: absolute;
  width: 48px;
  height: 48px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.6px;
  color: #ffffff;
  border: 1.5px solid rgba(255, 255, 255, 0.45);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
  user-select: none;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.35);
  backface-visibility: hidden;
}

.vface:hover,
.vface.highlighted {
  border-color: #ffffff !important;
  box-shadow: inset 0 0 14px rgba(255, 255, 255, 0.65), 0 0 12px rgba(255, 255, 255, 0.45) !important;
  filter: brightness(1.28);
}

.vface.v-front  { transform: translateZ(24px); background: #2563eb; }
.vface.v-back   { transform: rotateY(180deg) translateZ(24px); background: #7c3aed; }
.vface.v-left   { transform: rotateY(-90deg) translateZ(24px); background: #d97706; }
.vface.v-right  { transform: rotateY(90deg) translateZ(24px); background: #059669; }
.vface.v-top    { transform: rotateX(90deg) translateZ(24px); background: #0284c7; }
.vface.v-bottom { transform: rotateX(-90deg) translateZ(24px); background: #475569; }

/* -------------------------------------------------------------
   3D Ground Compass Arrows & Badges
   ------------------------------------------------------------- */
.ground-compass {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  transform-style: preserve-3d;
  pointer-events: none;
}

.dir-indicator {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  transform-style: preserve-3d;
  cursor: pointer;
  pointer-events: auto;
  user-select: none;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.dir-arrow-head {
  position: absolute;
  left: -11px;
  top: -48px;
  width: 0;
  height: 0;
  border-left: 11px solid transparent;
  border-right: 11px solid transparent;
  border-bottom: 18px solid var(--dir-color);
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.35));
  transition: transform 0.16s ease, filter 0.16s ease;
}

.dir-line {
  position: absolute;
  left: -2px;
  top: -30px;
  width: 4px;
  height: 30px;
  background: var(--dir-color);
  border-radius: 2px;
  box-shadow: 0 0 6px var(--dir-glow);
}

.dir-pill {
  position: absolute;
  left: 50%;
  top: 4px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5px 14px;
  background: #0f172a;
  border: 2px solid var(--dir-color);
  border-radius: 20px;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.8px;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4), 0 0 12px var(--dir-glow);
  transition: transform 0.16s ease, box-shadow 0.16s ease, filter 0.16s ease;
}

.dir-front { --dir-color: #2563eb; --dir-glow: rgba(37, 99, 235, 0.45); }
.dir-back  { --dir-color: #7c3aed; --dir-glow: rgba(124, 58, 237, 0.45); }
.dir-left  { --dir-color: #d97706; --dir-glow: rgba(217, 119, 6, 0.45); }
.dir-right { --dir-color: #059669; --dir-glow: rgba(5, 150, 105, 0.45); }

.dir-indicator:hover .dir-pill,
.dir-indicator.highlighted .dir-pill {
  transform: translateX(-50%) scale(1.15);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5), 0 0 22px var(--dir-color);
  filter: brightness(1.2);
}

.dir-indicator:hover .dir-arrow-head,
.dir-indicator.highlighted .dir-arrow-head {
  transform: translateY(-5px);
  filter: drop-shadow(0 0 10px var(--dir-color));
}

/* -------------------------------------------------------------
   Help & Shortcuts Modal
   ------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-card {
  width: 90%;
  max-width: 500px;
  background: #0f172a;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  animation: modalEnter 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalEnter {
  0% { transform: scale(0.95); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--panel-border);
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 700;
}

.modal-close-btn {
  background: transparent;
  border: none;
  font-size: 24px;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
}
.modal-close-btn:hover {
  color: #fff;
}

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: 68vh;
  overflow-y: auto;
}

.help-section h4 {
  font-size: 13px;
  color: #38bdf8;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.help-section p {
  font-size: 13px;
  line-height: 1.5;
  color: #cbd5e1;
  margin-bottom: 6px;
}

.help-section ul {
  list-style: none;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.help-section li {
  font-size: 12px;
  color: #cbd5e1;
  display: flex;
  align-items: center;
  gap: 6px;
}

.help-section .kbd {
  background: rgba(255, 255, 255, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
  font-weight: 600;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.18);
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--panel-border);
  display: flex;
  justify-content: flex-end;
}

/* -------------------------------------------------------------
   Interactive Face Editor Modal (Symbol & Color Picker)
   ------------------------------------------------------------- */
.face-editor-card {
  max-width: 460px;
}

.face-editor-subtitle {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.face-editor-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.face-editor-label {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #38bdf8;
}

.face-editor-symbols-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
}

.face-symbol-option {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 8px 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.16s ease;
  color: #f8fafc;
}

.face-symbol-option:hover {
  background: rgba(59, 130, 246, 0.18);
  border-color: #60a5fa;
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.28);
}

.face-symbol-option.active {
  background: rgba(59, 130, 246, 0.25);
  border-color: #38bdf8;
  box-shadow: 0 0 16px rgba(56, 189, 248, 0.45);
}

.face-symbol-option.active::after {
  content: "CURRENT";
  position: absolute;
  top: 5px;
  right: 6px;
  font-size: 8px;
  font-weight: 900;
  letter-spacing: 0.4px;
  padding: 1px 4px;
  border-radius: 4px;
  background: #38bdf8;
  color: #0f172a;
}

.face-symbol-preview-box {
  width: 46px;
  height: 46px;
  border-radius: 7px;
  background: #ffffff;
  color: #0f172a;
  border: 2px solid #0f172a;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

.face-symbol-preview-box .face-symbol-svg {
  width: 32px;
  height: 32px;
}

.face-symbol-preview-blank {
  font-size: 16px;
  font-weight: 800;
  color: #94a3b8;
}

.face-symbol-option-name {
  font-size: 11px;
  font-weight: 700;
  color: #e2e8f0;
  text-align: center;
}

.face-editor-colors-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

.face-color-option {
  height: 30px;
  border-radius: 7px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
}

.face-color-option:hover {
  transform: scale(1.08);
  border-color: #ffffff;
}

.face-color-option.active {
  border-color: #38bdf8;
  box-shadow: 0 0 0 2px #0f172a, 0 0 12px #38bdf8;
  transform: scale(1.06);
}

.face-editor-footer {
  justify-content: space-between;
  gap: 10px;
}

.face-editor-left-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-danger-outline {
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.45);
  color: #fca5a5;
}

.btn-danger-outline:hover:not(:disabled) {
  background: #ef4444;
  border-color: #ef4444;
  color: #ffffff;
}

.btn-danger-outline:disabled,
.face-editor-left-actions .btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* -------------------------------------------------------------
   Quiz Mode Sidebar & 4 3D Perspective Options
   ------------------------------------------------------------- */
.mode-divider {
  width: 1px;
  height: 20px;
  background: rgba(255, 255, 255, 0.14);
  margin: 0 2px;
  align-self: center;
}

.quiz-mode-btn {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.22), rgba(236, 72, 153, 0.22));
  border: 1px solid rgba(167, 139, 250, 0.4) !important;
  color: #e9d5ff !important;
}

.quiz-mode-btn:hover {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.4), rgba(236, 72, 153, 0.4)) !important;
  color: #ffffff !important;
}

.quiz-mode-btn.active {
  background: linear-gradient(135deg, #7c3aed, #db2777) !important;
  border-color: #f472b6 !important;
  color: #ffffff !important;
  box-shadow: 0 0 16px rgba(219, 39, 119, 0.55) !important;
}

.quiz-sidebar {
  position: fixed;
  top: 84px;
  left: 18px;
  width: 316px;
  z-index: 46;
  pointer-events: auto;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
}

.quiz-card {
  background: var(--panel-bg);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(167, 139, 250, 0.38);
  border-radius: var(--radius-lg);
  padding: 14px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.45), 0 0 24px rgba(124, 58, 237, 0.15);
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.quiz-top-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.quiz-badge-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.quiz-mode-pill {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.6px;
  padding: 3px 8px;
  border-radius: 6px;
  background: linear-gradient(135deg, #7c3aed, #db2777);
  color: #ffffff;
}

.quiz-score-pill,
.quiz-streak-pill {
  font-size: 11px;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #38bdf8;
  font-variant-numeric: tabular-nums;
}

.quiz-streak-pill {
  color: #fbbf24;
}

.quiz-exit-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--panel-border);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.quiz-exit-btn:hover {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
}

.quiz-prompt-text {
  font-size: 12px;
  line-height: 1.45;
  color: #e2e8f0;
}

/* 2x2 Grid of 4 3D Cube Perspective Options */
.quiz-options-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 9px;
}

.quiz-option-card {
  position: relative;
  background: rgba(15, 23, 42, 0.65);
  border: 2px solid rgba(255, 255, 255, 0.14);
  border-radius: 11px;
  padding: 10px 6px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.18s ease;
}

.quiz-option-card:hover:not(.disabled-option) {
  background: rgba(30, 41, 59, 0.9);
  border-color: #60a5fa;
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.3);
}

.quiz-option-letter {
  position: absolute;
  top: 6px;
  left: 7px;
  width: 20px;
  height: 20px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.1);
  color: #cbd5e1;
  font-size: 11px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

.quiz-option-status {
  position: absolute;
  top: 6px;
  right: 7px;
  font-size: 13px;
  font-weight: 900;
}

/* Correct / Wrong Option States */
.quiz-option-card.option-correct {
  background: rgba(16, 185, 129, 0.22) !important;
  border-color: #10b981 !important;
  box-shadow: 0 0 18px rgba(16, 185, 129, 0.45) !important;
}

.quiz-option-card.option-correct .quiz-option-letter {
  background: #10b981;
  color: #0f172a;
}

.quiz-option-card.option-wrong {
  background: rgba(239, 68, 68, 0.18) !important;
  border-color: #ef4444 !important;
  opacity: 0.78;
}

.quiz-option-card.option-wrong .quiz-option-letter {
  background: #ef4444;
  color: #ffffff;
}

/* 3D Isometric Mini-Cube inside each Option Card */
.option-cube-scene {
  width: 74px;
  height: 74px;
  display: flex;
  align-items: center;
  justify-content: center;
  perspective: 300px;
  margin-top: 4px;
  pointer-events: none;
}

.option-cube {
  position: relative;
  width: 44px;
  height: 44px;
  transform-style: preserve-3d;
  transform: rotateX(-30deg) rotateY(-45deg);
}

.opt-face {
  position: absolute;
  width: 44px;
  height: 44px;
  box-sizing: border-box;
  border: 2px solid #0f172a;
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  backface-visibility: hidden;
  user-select: none;
}

.opt-face .face-symbol-svg {
  width: 30px;
  height: 30px;
}

/* Top face (+Y up -> rotateX(90deg) translateZ(22px)) */
.opt-face.opt-top {
  transform: rotateX(90deg) translateZ(22px);
  filter: brightness(1.03);
}

/* Front-Left face (+Z -> translateZ(22px)) */
.opt-face.opt-front {
  transform: translateZ(22px);
  filter: brightness(0.93);
}

/* Front-Right face (+X -> rotateY(90deg) translateZ(22px)) */
.opt-face.opt-right {
  transform: rotateY(90deg) translateZ(22px);
  filter: brightness(0.83);
}

/* When Corner Hint is active, highlight the 3 meeting Y-edges on each 3D option cube:
   - Cyan (#06b6d4): Top <-> Left edge
   - Amber (#f59e0b): Top <-> Right edge
   - Pink (#ec4899): Left <-> Right vertical edge */
body.quiz-hint-corner .opt-face.opt-top {
  border-bottom: 3.5px solid #06b6d4;
  border-right: 3.5px solid #f59e0b;
}

body.quiz-hint-corner .opt-face.opt-front {
  border-top: 3.5px solid #06b6d4;
  border-right: 3.5px solid #ec4899;
}

body.quiz-hint-corner .opt-face.opt-right {
  border-top: 3.5px solid #f59e0b;
  border-left: 3.5px solid #ec4899;
}

.option-faces-summary {
  font-size: 10px;
  font-weight: 700;
  color: #cbd5e1;
  letter-spacing: 0.2px;
  text-align: center;
  white-space: nowrap;
}

/* Quiz Feedback Banner */
.quiz-feedback-box {
  padding: 9px 11px;
  border-radius: 9px;
  font-size: 11.5px;
  line-height: 1.4;
  border: 1px solid transparent;
}

.quiz-feedback-box.feedback-correct {
  background: rgba(16, 185, 129, 0.18);
  border-color: rgba(16, 185, 129, 0.5);
  color: #d1fae5;
}

.quiz-feedback-box.feedback-wrong {
  background: rgba(239, 68, 68, 0.18);
  border-color: rgba(239, 68, 68, 0.5);
  color: #fee2e2;
}

.quiz-feedback-title {
  font-weight: 800;
  margin-bottom: 3px;
  font-size: 12px;
}

.quiz-feedback-desc {
  color: #f1f5f9;
  font-size: 11px;
}

/* Quiz Non-Folding Visual Hints Section */
.quiz-hint-section {
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 9px;
  padding: 9px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.quiz-hint-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 700;
  color: #fbbf24;
}

.quiz-hint-pills {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.quiz-hint-pill {
  padding: 6px 8px;
  font-size: 11px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 7px;
  color: #e2e8f0;
  cursor: pointer;
  transition: all 0.16s ease;
  text-align: center;
  white-space: nowrap;
}

.quiz-hint-pill:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.28);
}

.quiz-hint-pill.active {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.32), rgba(217, 119, 6, 0.35));
  border-color: #fbbf24;
  color: #fef3c7;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.35);
}

.quiz-hint-pill:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.quiz-hint-info {
  font-size: 11px;
  line-height: 1.45;
  color: #f1f5f9;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid rgba(251, 191, 36, 0.35);
  border-radius: 7px;
  padding: 7px 9px;
}

.quiz-hint-info strong {
  color: #fde68a;
}

.quiz-option-card.option-eliminated {
  opacity: 0.42 !important;
  border-color: rgba(239, 68, 68, 0.45) !important;
  background: rgba(15, 23, 42, 0.35) !important;
}

.quiz-option-card.option-eliminated::after {
  content: "ELIMINATED";
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) rotate(-8deg);
  background: rgba(239, 68, 68, 0.92);
  color: #ffffff;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.6px;
  padding: 2px 6px;
  border-radius: 4px;
  pointer-events: none;
}

.btn-next-question {
  width: 100%;
  padding: 9px 12px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: #ffffff;
  font-size: 12.5px;
  font-weight: 800;
  box-shadow: 0 4px 14px rgba(124, 58, 237, 0.4);
}

.btn-next-question:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

body.quiz-active .fold-controller-dock {
  left: 348px;
}

/* -------------------------------------------------------------
   Responsive Breakpoints
   ------------------------------------------------------------- */
@media (max-width: 1180px) {
  .fold-controller-dock,
  body.quiz-active .fold-controller-dock {
    left: 256px;
    right: 18px;
    bottom: 108px;
  }
  body.quiz-active .fold-controller-dock {
    left: 344px;
  }
}

@media (max-width: 860px) {
  .left-palette {
    display: none;
  }
  .quiz-sidebar {
    width: calc(100vw - 24px);
    left: 12px;
    top: 76px;
    max-height: 52vh;
  }
  .fold-controller-dock,
  body.quiz-active .fold-controller-dock {
    left: 12px;
    right: 12px;
    bottom: 96px;
  }
  .camera-controls {
    bottom: 12px;
    right: 12px;
  }
  .top-bar {
    top: 10px;
    left: 12px;
    right: 12px;
    padding: 0 12px;
  }
  .brand-subtitle,
  .net-status-badge {
    display: none;
  }
}
