/* -------------------------------------------------------------
   3D Block Builder - Stylesheet
   Pure CSS 3D transforms, glassmorphic UI, responsive layout
   ------------------------------------------------------------- */

:root {
  --cube-size: 60px;
  --half-size: 30px;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --bg-dark: #090d16;
  --panel-bg: rgba(15, 23, 42, 0.82);
  --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: 1100px;
  perspective-origin: 50% 50%;
  /* Clean, light neutral studio gray background for maximum block visibility */
  background: radial-gradient(circle at 50% 40%, #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 */
#ground-grid {
  position: absolute;
  width: 1400px;
  height: 1400px;
  left: -700px;
  top: -700px;
  transform: translateY(220px) rotateX(90deg);
  background-size: 60px 60px;
  background-image: 
    linear-gradient(to right, rgba(15, 23, 42, 0.12) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(15, 23, 42, 0.12) 1px, transparent 1px);
  border-radius: 50%;
  mask-image: radial-gradient(circle, rgba(0, 0, 0, 0.85) 0%, rgba(0, 0, 0, 0.35) 50%, transparent 72%);
  -webkit-mask-image: radial-gradient(circle, rgba(0, 0, 0, 0.85) 0%, rgba(0, 0, 0, 0.35) 50%, transparent 72%);
  pointer-events: none;
}

#blocks-container {
  transform-style: preserve-3d;
}

/* -------------------------------------------------------------
   3D Cube & Faces
   ------------------------------------------------------------- */
.cube {
  position: absolute;
  width: var(--cube-size);
  height: var(--cube-size);
  left: calc(var(--cube-size) / -2);
  top: calc(var(--cube-size) / -2);
  transform-style: preserve-3d;
}

/* Cut / Sliced Blocks: displayed transparent, colorless, and lightly outlined as ghost guides */
.cube.cut-hidden {
  display: block !important;
  pointer-events: none !important;
}

#viewport .cube.cut-hidden .face,
#viewport.arch-view .cube.cut-hidden .face,
#viewport.white-mode .cube.cut-hidden .face,
.cube.cut-hidden .face {
  pointer-events: none !important;
  cursor: default !important;
  background-color: rgba(255, 255, 255, 0.22) !important;
  border: 1px solid rgba(100, 116, 139, 0.35) !important;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.3) !important;
  filter: none !important;
  opacity: 1 !important;
}

#viewport.xray-mode .cube.cut-hidden .face {
  border: 1px dashed rgba(100, 116, 139, 0.4) !important;
  background-color: rgba(255, 255, 255, 0.12) !important;
  box-shadow: none !important;
}

.cube.cut-hidden .height-tag,
.cube.cut-hidden .face:hover::after {
  display: none !important;
}

.cube.new-cube-anim {
  animation: spawnPop 0.22s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes spawnPop {
  0% {
    scale: 0.05;
    opacity: 0;
  }
  70% {
    scale: 1.08;
    opacity: 1;
  }
  100% {
    scale: 1;
    opacity: 1;
  }
}

.face {
  position: absolute;
  width: var(--cube-size);
  height: var(--cube-size);
  backface-visibility: hidden;
  box-sizing: border-box;
  background-color: var(--block-color, #ffffff);
  /* Razor-sharp solid dark charcoal border that stands out against gray background */
  border: 2px solid #0f172a;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.65);
  cursor: pointer;
  transition: background-color 0.15s ease, filter 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

/* 3D Directional Lighting Shaders (Tuned for White & Light Cubes) */
.face.front {
  transform: translateZ(var(--half-size));
  filter: brightness(0.93);
}
.face.back {
  transform: rotateY(180deg) translateZ(var(--half-size));
  filter: brightness(0.74);
}
.face.right {
  transform: rotateY(90deg) translateZ(var(--half-size));
  filter: brightness(0.85);
}
.face.left {
  transform: rotateY(-90deg) translateZ(var(--half-size));
  filter: brightness(0.80);
}
.face.top {
  transform: rotateX(90deg) translateZ(var(--half-size));
  filter: brightness(1.0);
}
.face.bottom {
  transform: rotateX(-90deg) translateZ(var(--half-size));
  filter: brightness(0.68);
}

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

#viewport.arch-view .face {
  border: 2.5px solid #0f172a !important;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.8) !important;
  filter: none !important; /* Pure flat architectural drawing without perspective dimming */
}

#viewport.arch-view #ground-grid {
  opacity: 0.2;
}

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

/* In 2D Top Plan View, orient all direction badges upright for architectural readability */
#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 to view lower & internal blocks */
#viewport.xray-mode .face {
  opacity: 0.44 !important;
  border: 2px solid #0284c7 !important;
  box-shadow: inset 0 0 10px rgba(2, 132, 199, 0.5), 0 0 8px rgba(2, 132, 199, 0.25) !important;
  backface-visibility: visible !important;
}

/* -------------------------------------------------------------
   Seamless Mode (Invisible Inner Grids, Single Piece Look)
   ------------------------------------------------------------- */
#viewport.seamless-mode .cube:not(.ghost-cube) .face {
  box-shadow: none !important;
}

#viewport.seamless-mode .cube:not(.ghost-cube) .face.no-border-top {
  border-top: none !important;
}

#viewport.seamless-mode .cube:not(.ghost-cube) .face.no-border-bottom {
  border-bottom: none !important;
}

#viewport.seamless-mode .cube:not(.ghost-cube) .face.no-border-left {
  border-left: none !important;
}

#viewport.seamless-mode .cube:not(.ghost-cube) .face.no-border-right {
  border-right: none !important;
}

/* 2D Architectural Projection in Seamless Mode */
#viewport.arch-view.seamless-mode .cube:not(.ghost-cube) .face {
  box-shadow: none !important;
}

#viewport.arch-view.seamless-mode .cube:not(.ghost-cube) .face.no-border-top {
  border-top: none !important;
}

#viewport.arch-view.seamless-mode .cube:not(.ghost-cube) .face.no-border-bottom {
  border-bottom: none !important;
}

#viewport.arch-view.seamless-mode .cube:not(.ghost-cube) .face.no-border-left {
  border-left: none !important;
}

#viewport.arch-view.seamless-mode .cube:not(.ghost-cube) .face.no-border-right {
  border-right: none !important;
}

/* Hover overrides in Seamless Mode: clearly highlight the hovered face/block */
body[data-active-mode="add"] #viewport.seamless-mode .face:hover {
  border: 2px solid #2563eb !important;
  box-shadow: inset 0 0 0 2px #2563eb, 0 0 12px rgba(37, 99, 235, 0.35) !important;
}

body[data-active-mode="delete"] #viewport.seamless-mode .cube:hover .face {
  border: 2px solid #991b1b !important;
  box-shadow: inset 0 0 0 2px #991b1b, 0 0 16px rgba(239, 68, 68, 0.4) !important;
}

body[data-active-mode="paint"] #viewport.seamless-mode .cube:hover .face {
  border: 2px solid #0284c7 !important;
  box-shadow: inset 0 0 0 2px #0284c7, 0 0 15px rgba(2, 132, 199, 0.4) !important;
}

/* -------------------------------------------------------------
   White Mode / Temporarily Disable Colors
   ------------------------------------------------------------- */
#viewport.white-mode .cube:not(.ghost-cube) .face {
  --block-color: #ffffff !important;
  background-color: #ffffff !important;
}

/* Elevation Height Tag inside faces - Dark, crisp, readable on white */
.height-tag {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
  color: #0f172a;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 4px;
  margin: 18px;
  border: 1px solid rgba(15, 23, 42, 0.25);
  pointer-events: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

#viewport.show-heights .height-tag {
  display: flex;
}

/* Face Hover States in Add Mode */
body[data-active-mode="add"] .face:hover {
  filter: brightness(1.06) !important;
  border-color: #2563eb !important;
  box-shadow: inset 0 0 0 2px #2563eb, 0 0 12px rgba(37, 99, 235, 0.35);
}

body[data-active-mode="add"] .face:hover::after {
  content: "+";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 800;
  color: #2563eb;
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.9);
  pointer-events: none;
}

/* Face Hover States in Delete Mode */
body[data-active-mode="delete"] .cube:hover .face {
  background-color: #ef4444 !important;
  border-color: #991b1b !important;
  box-shadow: inset 0 0 0 2px #991b1b, 0 0 16px rgba(239, 68, 68, 0.4) !important;
  cursor: pointer;
}

body[data-active-mode="delete"] .cube:hover .face::after {
  content: "×";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  font-weight: 800;
  color: #ffffff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7);
  pointer-events: none;
}

/* Face Hover States in Paint Mode */
body[data-active-mode="paint"] .cube:hover .face {
  filter: brightness(1.15) !important;
  box-shadow: inset 0 0 0 2px #0284c7, 0 0 15px rgba(2, 132, 199, 0.4);
  cursor: pointer;
}

/* -------------------------------------------------------------
   Section Cut: View-Only Mode (No Ghost Preview or Add/Edit Hover)
   ------------------------------------------------------------- */
body.cut-active .face {
  cursor: default !important;
}

body.cut-active[data-active-mode="add"] .face:hover,
body.cut-active [data-active-mode="add"] .face:hover {
  filter: none !important;
  border-color: #0f172a !important;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.65) !important;
}

body.cut-active[data-active-mode="delete"] .cube:hover .face,
body.cut-active [data-active-mode="delete"] .cube:hover .face,
body.cut-active[data-active-mode="paint"] .cube:hover .face,
body.cut-active [data-active-mode="paint"] .cube:hover .face {
  filter: none !important;
  background-color: var(--block-color, #ffffff) !important;
  border-color: #0f172a !important;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.65) !important;
  cursor: default !important;
}

body.cut-active .face:hover::after,
body.cut-active .ghost-cube {
  display: none !important;
}

/* Ghost / Snap preview block */
.ghost-cube,
.ghost-cube .face {
  pointer-events: none !important;
  transition: none !important;
}

.ghost-cube {
  z-index: 100;
}

.ghost-cube .face {
  background-color: var(--ghost-color, rgba(59, 130, 246, 0.3)) !important;
  border: 2px dashed #2563eb !important;
  box-shadow: 0 0 14px rgba(37, 99, 235, 0.35) !important;
  animation: ghostPulse 1.4s infinite ease-in-out;
}

@keyframes ghostPulse {
  0%, 100% {
    opacity: 0.65;
  }
  50% {
    opacity: 0.95;
  }
}

/* Empty scene starting prompt button */
#empty-starter {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--panel-border);
  padding: 14px 22px;
  border-radius: var(--radius-md);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  z-index: 20;
}
#empty-starter:hover {
  background: var(--primary);
  border-color: #60a5fa;
}

/* 2D Architecture View Banner */
.arch-banner {
  position: absolute;
  top: 86px;
  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;
  display: flex;
  align-items: center;
  gap: 5px;
}

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

.arch-rotate-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 4px;
}

.arch-btn-rotate {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #f1f5f9;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.16s ease;
}

.arch-btn-rotate .icon {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.arch-btn-rotate:hover {
  background: rgba(56, 189, 248, 0.25);
  border-color: #38bdf8;
  color: #38bdf8;
  transform: translateY(-1px);
}

.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;
}

/* -------------------------------------------------------------
   Section Cut / Slice Structure Floating Control Bar
   ------------------------------------------------------------- */
.section-cut-bar {
  position: absolute;
  top: 86px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  background: rgba(15, 23, 42, 0.94);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(56, 189, 248, 0.45);
  padding: 6px 10px 6px 14px;
  border-radius: 30px;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.08);
  z-index: 46;
  pointer-events: auto;
  transition: top 0.22s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease, transform 0.2s ease;
  user-select: none;
  max-width: calc(100vw - 40px);
  animation: bannerEnter 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

/* When 2D Arch Banner is also visible, position Section Cut bar right below it */
#viewport.has-arch-banner .section-cut-bar {
  top: 142px;
}

.section-cut-bar.hidden {
  display: none !important;
}

.cut-bar-main {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.cut-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #38bdf8;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.8px;
  text-transform: uppercase;
}

.cut-badge .icon {
  width: 16px;
  height: 16px;
  fill: #38bdf8;
}

.cut-sep {
  width: 1px;
  height: 20px;
  background: rgba(255, 255, 255, 0.15);
}

.cut-btn-pills {
  display: flex;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 2px;
  gap: 2px;
}

.cut-pill-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.cut-pill-btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

.cut-pill-btn.active {
  background: #0284c7;
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(2, 132, 199, 0.5);
}

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

.cut-step-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-main);
  border-radius: 50%;
  width: 24px;
  height: 24px;
  font-size: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.cut-step-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #38bdf8;
}

#cut-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 95px;
  height: 6px;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}

#cut-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #38bdf8;
  box-shadow: 0 0 8px rgba(56, 189, 248, 0.7);
  cursor: pointer;
  border: 2px solid #0f172a;
  transition: transform 0.1s ease;
}

#cut-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

.cut-coord-badge {
  font-size: 12px;
  font-weight: 700;
  font-family: monospace, sans-serif;
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.35);
  padding: 3px 8px;
  border-radius: 6px;
  min-width: 58px;
  text-align: center;
}

.cut-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.cut-tool-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}

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

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

.cut-tool-btn.active {
  background: rgba(56, 189, 248, 0.2);
  color: #38bdf8;
  border-color: rgba(56, 189, 248, 0.5);
}

.cut-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  line-height: 1;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.15s ease;
}

.cut-close-btn:hover {
  color: #fff;
  background: rgba(239, 68, 68, 0.3);
}

/* -------------------------------------------------------------
   3D Section Cut Plane Visualizer in the 3D World
   ------------------------------------------------------------- */
.section-plane {
  position: absolute;
  pointer-events: none;
  transform-style: preserve-3d;
  will-change: transform;
  z-index: 5;
  transition: transform 0.14s ease-out, opacity 0.2s ease;
}

.section-plane.hidden {
  display: none !important;
}

.section-plane-surface {
  position: absolute;
  border: 2px dashed rgba(56, 189, 248, 0.9);
  background: radial-gradient(circle at 50% 50%, rgba(14, 165, 233, 0.18) 0%, rgba(56, 189, 248, 0.05) 75%, transparent 100%);
  box-shadow: 0 0 24px rgba(14, 165, 233, 0.35), inset 0 0 35px rgba(14, 165, 233, 0.15);
  border-radius: 8px;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 8px;
  box-sizing: border-box;
}

.section-plane-badge {
  background: rgba(15, 23, 42, 0.92);
  color: #38bdf8;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid rgba(56, 189, 248, 0.6);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  transform: translateZ(2px);
}

/* Hidden internal occluded faces or hidden items */
.hidden {
  display: none !important;
}

/* -------------------------------------------------------------
   Top Navigation Bar
   ------------------------------------------------------------- */
.top-bar {
  position: fixed;
  top: 16px;
  left: 20px;
  right: 20px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 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);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  z-index: 50;
  pointer-events: auto;
}

.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: 18px;
  height: 18px;
  position: relative;
  transform-style: preserve-3d;
  transform: rotateX(-30deg) rotateY(45deg);
  animation: miniCubeSpin 8s infinite linear;
}

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

.m-face {
  position: absolute;
  width: 18px;
  height: 18px;
  background: #3b82f6;
  border: 1px solid rgba(255,255,255,0.4);
}
.m-front { transform: translateZ(9px); background: #2563eb; }
.m-top   { transform: rotateX(90deg) translateZ(9px); background: #60a5fa; }
.m-right { transform: rotateY(90deg) translateZ(9px); 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,
.size-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 14px;
  background: transparent;
  color: var(--text-muted);
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s ease;
}

.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);
}

.size-btn,
.plane-btn {
  padding: 6px 10px;
  font-variant-numeric: tabular-nums;
}

/* Stats & Icons */
.stats-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.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 12px;
  border-radius: 20px;
  font-size: 12px;
}
.stat-label {
  color: var(--text-muted);
}
.stat-value {
  color: #38bdf8;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.icon-btn {
  width: 36px;
  height: 36px;
  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;
}

.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: 90px;
  left: 20px;
  width: 220px;
  z-index: 40;
  pointer-events: 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: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
}

.palette-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  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, #ec4899, #8b5cf6, #3b82f6);
}

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

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

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

.swatch {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  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.12);
  z-index: 2;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.swatch.active {
  border-color: #ffffff;
  transform: scale(1.08);
  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: 13px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

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

.custom-color-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 6px 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: 20px;
  height: 20px;
  border-radius: 6px;
  background-color: #3b82f6;
  border: 1px solid rgba(255, 255, 255, 0.4);
  box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.3);
}

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

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

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

.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: 6px;
}

.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;
}

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

/* Random Structure Builder Section */
.random-builder-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.random-input-group {
  display: flex;
  gap: 6px;
  align-items: stretch;
}

.number-input-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
}

.number-input-wrap input[type="number"] {
  width: 100%;
  padding: 6px 8px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  outline: none;
  box-sizing: border-box;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.number-input-wrap input[type="number"]:focus {
  border-color: #38bdf8;
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.25);
}

.btn-generate {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.18s ease;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.35);
}

.btn-generate:hover {
  background: linear-gradient(135deg, #1d4ed8, #6d28d9);
  box-shadow: 0 4px 14px rgba(124, 58, 237, 0.5);
  transform: translateY(-1px);
}

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

.random-quick-chips {
  display: flex;
  gap: 4px;
  align-items: center;
  justify-content: space-between;
}

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

.chip-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.3);
}

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

.btn {
  padding: 8px 12px;
  border-radius: var(--radius-md);
  font-size: 12px;
  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);
}

/* -------------------------------------------------------------
   Floating Camera HUD (Right Bottom)
   ------------------------------------------------------------- */
.camera-controls {
  position: fixed;
  bottom: 24px;
  right: 20px;
  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 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 40;
  pointer-events: auto;
  flex-wrap: wrap;
  max-width: calc(100vw - 40px);
}

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

.cam-btn {
  width: 34px;
  height: 34px;
  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: 18px;
  height: 18px;
  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: 44px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

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

.view-preset-pills {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.pill-btn {
  padding: 6px 10px;
  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;
  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);
}

/* Color indicators on view preset pills */
.pill-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 6px;
  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: 76px;
  right: 20px;
  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: center;
  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);
}

/* Arrowhead pointing toward model */
.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;
}

/* Connecting stem line */
.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);
}

/* Pill badge with icon and direction name */
.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;
}

/* Direction Themes */
.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);
}

/* Hover and Highlight States */
.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;
  transition: opacity 0.2s ease;
}

.modal-card {
  width: 90%;
  max-width: 460px;
  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: 65vh;
  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;
}

/* -------------------------------------------------------------
   Responsive Breakpoints
   ------------------------------------------------------------- */
@media (max-width: 860px) {
  .left-palette {
    top: auto;
    bottom: 84px;
    left: 12px;
    width: calc(100% - 24px);
    max-width: 320px;
  }
  .bottom-hint {
    display: none;
  }
  .camera-controls {
    bottom: 12px;
    right: 12px;
  }
  .top-bar {
    top: 10px;
    left: 12px;
    right: 12px;
    padding: 0 12px;
  }
  .brand-subtitle {
    display: none;
  }
}

/* -------------------------------------------------------------
   Quiz Mode Styles
   ------------------------------------------------------------- */
.quiz-nav-btn {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.25) 0%, rgba(59, 130, 246, 0.25) 100%) !important;
  border: 1px solid rgba(139, 92, 246, 0.5) !important;
  color: #c084fc !important;
  font-weight: 700;
  gap: 6px;
  padding: 6px 14px;
}

.quiz-nav-btn:hover {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.45) 0%, rgba(59, 130, 246, 0.45) 100%) !important;
  border-color: #a855f7 !important;
  color: #fff !important;
  transform: translateY(-1px);
}

.quiz-nav-btn.active {
  background: linear-gradient(135deg, #8b5cf6 0%, #3b82f6 100%) !important;
  color: #fff !important;
  border-color: #c084fc !important;
  box-shadow: 0 0 16px rgba(139, 92, 246, 0.5) !important;
}

/* Quiz Mode Active State */
body.quiz-active .mode-selector,
body.quiz-active .size-selector,
body.quiz-active .plane-selector,
body.quiz-active .left-palette,
body.quiz-active #empty-starter {
  display: none !important;
}

body.quiz-active #viewport {
  right: 410px;
  transition: right 0.25s ease;
}

body.quiz-active .camera-controls {
  right: 426px;
  transition: right 0.25s ease;
}

body.quiz-active .viewcube-widget {
  right: 426px;
  transition: right 0.25s ease;
}

/* Floating Quiz Panel on Right */
.quiz-panel {
  position: fixed;
  right: 16px;
  top: 76px;
  bottom: 16px;
  width: 380px;
  z-index: 60;
  display: flex;
  flex-direction: column;
}

.quiz-card {
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px;
  box-shadow: 0 16px 45px rgba(0, 0, 0, 0.55);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100%;
  overflow-y: auto;
  box-sizing: border-box;
}

.quiz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 10px;
}

.quiz-badge {
  display: flex;
  align-items: center;
  gap: 8px;
}

.quiz-badge-icon {
  font-size: 18px;
}

.quiz-badge-title {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.6px;
  color: #c084fc;
  text-transform: uppercase;
}

.quiz-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
  transition: color 0.16s ease;
}

.quiz-close-btn:hover {
  color: #ef4444;
}

.quiz-stats-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 8px 12px;
}

.quiz-stat-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.q-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
}

.q-val {
  font-size: 13px;
  font-weight: 800;
  color: #f8fafc;
}

.q-streak {
  color: #f59e0b;
}

.quiz-question-box {
  background: rgba(56, 189, 248, 0.06);
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.quiz-target-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(56, 189, 248, 0.2);
  border: 1px solid #38bdf8;
  color: #38bdf8;
  font-size: 11px;
  font-weight: 800;
  padding: 3px 10px;
  border-radius: 20px;
  width: fit-content;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.target-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #38bdf8;
  box-shadow: 0 0 8px #38bdf8;
}

.quiz-prompt-text {
  font-size: 14px;
  font-weight: 700;
  color: #f8fafc;
  line-height: 1.35;
}

.quiz-hint-text {
  font-size: 11px;
  color: #94a3b8;
  line-height: 1.4;
}

/* 2x2 Grid of Option Cards */
.quiz-options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 4px 0;
}

.quiz-opt-card {
  position: relative;
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 130px;
  transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  user-select: none;
}

.quiz-opt-card:hover:not(.disabled) {
  border-color: #38bdf8;
  background: rgba(56, 189, 248, 0.12);
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(56, 189, 248, 0.2);
}

.quiz-opt-letter {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #f8fafc;
  font-size: 11px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

.quiz-opt-card svg {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Card States */
.quiz-opt-card.is-correct {
  border-color: #10b981 !important;
  background: rgba(16, 185, 129, 0.2) !important;
  box-shadow: 0 0 20px rgba(16, 185, 129, 0.45) !important;
}

.quiz-opt-card.is-correct .quiz-opt-letter {
  background: #10b981;
  border-color: #10b981;
  color: #fff;
}

.quiz-opt-card.is-wrong {
  border-color: #ef4444 !important;
  background: rgba(239, 68, 68, 0.15) !important;
  opacity: 0.6;
  animation: shake 0.35s ease;
}

.quiz-opt-card.is-wrong .quiz-opt-letter {
  background: #ef4444;
  border-color: #ef4444;
  color: #fff;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* Feedback Box */
.quiz-feedback-box {
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.quiz-feedback-box.feedback-correct {
  border-color: #10b981;
  background: rgba(16, 185, 129, 0.12);
}

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

.quiz-feedback-content {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.4;
}

.quiz-feedback-box.feedback-correct .quiz-feedback-content {
  color: #34d399;
}

.quiz-feedback-box.feedback-wrong .quiz-feedback-content {
  color: #f87171;
}

.quiz-feedback-actions {
  display: flex;
  gap: 8px;
}

.btn-sm {
  padding: 6px 12px !important;
  font-size: 12px !important;
}

/* Footer Actions */
.quiz-footer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.quiz-ghost-btn {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #94a3b8;
  font-size: 11px;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.16s ease;
}

.quiz-ghost-btn:hover {
  color: #f8fafc;
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.3);
}
