html, body, #c {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  background: #000;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

canvas {
  display: block;
}

/* ViewCube - Top Right */
#viewcube-container {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 150px;
  height: 150px;
  z-index: 40; /* Lower than menu (z-index: 50) so it appears behind */
  cursor: grab;
  user-select: none;
  pointer-events: none;
}

#viewcube-container:active {
  cursor: grabbing;
}

#viewcube-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: inherit;
  pointer-events: auto;
}

/* Save/Load Controls - Top Left */
.save-load-controls {
  position: fixed;
  top: 20px;
  left: 20px;
  display: flex;
  gap: 8px;
  z-index: 60;
}

/* Rotation Snap Controls - Below Save/Load */
.rotation-snap-controls {
  position: fixed;
  top: 68px;
  left: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;

  background: rgba(20, 20, 24, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);

  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;

  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);

  z-index: 60;
}

.snap-label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #e8e8e8;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
}

.snap-label input[type="checkbox"] {
  cursor: pointer;
  width: 16px;
  height: 16px;
}

.world-align-label {
  margin-left: 4px;
  padding-left: 8px;
  border-left: 1px solid rgba(255, 255, 255, 0.1);
}

.snap-select {
  padding: 4px 8px;
  background-color: #282830;
  color: #e8e8e8;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  min-width: 60px;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23888888' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 6px center;
  background-size: 12px;
  padding-right: 24px;
}

.snap-select:hover:not(:disabled) {
  background-color: #333340;
  border-color: rgba(255, 255, 255, 0.25);
}

.snap-select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background-color: #1e1e24;
}

.snap-select:focus {
  outline: none;
  border-color: rgba(68, 170, 255, 0.6);
  box-shadow: 0 0 0 2px rgba(68, 170, 255, 0.15);
}

.custom-angle-input {
  width: 70px;
  padding: 4px 8px;
  background-color: #282830;
  color: #e8e8e8;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s;
  text-align: center;
}

.custom-angle-input:hover:not(:disabled) {
  background-color: #333340;
  border-color: rgba(255, 255, 255, 0.25);
}

.custom-angle-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background-color: #1e1e24;
}

.custom-angle-input:focus {
  outline: none;
  border-color: rgba(68, 170, 255, 0.6);
  box-shadow: 0 0 0 2px rgba(68, 170, 255, 0.15);
}

.custom-angle-input::placeholder {
  color: #666;
  font-style: italic;
}

.manual-angle-input {
  width: 120px;
  padding: 4px 8px;
  background-color: #282830;
  color: #e8e8e8;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s;
  text-align: center;
}

.manual-angle-input:hover {
  background-color: #333340;
  border-color: rgba(255, 255, 255, 0.25);
}

.manual-angle-input:focus {
  outline: none;
  border-color: rgba(68, 170, 255, 0.6);
  box-shadow: 0 0 0 2px rgba(68, 170, 255, 0.15);
}

.manual-angle-input::placeholder {
  color: #666;
  font-style: italic;
  font-size: 12px;
}

/* Style dropdown options - note: limited browser support */
.snap-select option {
  background-color: #282830;
  color: #e8e8e8;
  padding: 8px;
}

.control-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;

  background: rgba(20, 20, 24, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);

  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;

  color: #e8e8e8;
  font-size: 14px;
  font-weight: 500;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;

  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);

  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.control-btn svg {
  color: #aaa;
  transition: color 0.2s;
}

.control-btn:hover {
  background: rgba(30, 30, 34, 0.95);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.control-btn:hover svg {
  color: #fff;
}

.save-btn:hover {
  border-color: rgba(76, 175, 80, 0.5);
}

.save-btn:hover svg {
  color: #4CAF50;
}

.load-btn:hover {
  border-color: rgba(33, 150, 243, 0.5);
}

.load-btn:hover svg {
  color: #2196F3;
}

.control-btn:active {
  transform: translateY(0);
  box-shadow:
    0 1px 4px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

/* Menu styles - Modern glassmorphism design */
.menu {
  position: fixed;
  right: 24px;
  top: 50%;
  transform: translateY(-50%);

  width: 360px;
  max-height: 85vh;
  box-sizing: border-box;

  overflow: hidden;
  display: flex;
  flex-direction: column;

  background: rgba(20, 20, 24, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #e8e8e8;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.8),
    0 2px 8px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  z-index: 50;

  animation: slideInRight 0.3s ease-out;
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateY(-50%) translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
  }
}

.menu.hidden {
  display: none;
}

.menu-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03) 0%, transparent 100%);
}

.menu-header h3 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  color: #fff;
  letter-spacing: -0.02em;
}

.menu-hint {
  font-size: 13px;
  color: #888;
  font-weight: 400;
}

.object-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
}

/* Custom scrollbar */
.object-list::-webkit-scrollbar {
  width: 6px;
}

.object-list::-webkit-scrollbar-track {
  background: transparent;
}

.object-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
}

.object-list::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.25);
}

.object-item {
  display: flex;
  align-items: stretch; /* Changed from center to stretch */
  gap: 12px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  min-height: 90px; /* Ensure minimum height */
}

.object-item::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.06) 0%, transparent 100%);
  opacity: 0;
  transition: opacity 0.2s;
}

.object-item:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.15);
  transform: translateX(-2px);
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.object-item:hover::before {
  opacity: 1;
}

.object-item:active {
  transform: translateX(-2px) scale(0.98);
}

.preview-canvas {
  width: 120px;
  height: 90px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  flex-shrink: 0; /* Prevent canvas from shrinking */
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
}

.object-label {
  flex: 1 1 auto;
  min-width: 0; /* Allow text to shrink and wrap */
  font-size: 14px;
  line-height: 1.4;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  overflow: hidden; /* Contain text */
}

.object-label strong {
  display: block;
  font-weight: 600;
  color: #fff;
  font-size: 15px;
  word-wrap: break-word; /* Allow long words to break */
  overflow-wrap: break-word;
  hyphens: auto;
}

.object-item small {
  display: block;
  color: #999;
  font-size: 12px;
  font-weight: 400;
  word-wrap: break-word; /* Allow long words to break */
  overflow-wrap: break-word;
  line-height: 1.3;
}

/* Undo/Redo indicator */
.undo-indicator {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);

  padding: 12px 20px;
  background: rgba(20, 20, 24, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #e8e8e8;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  box-shadow:
    0 4px 16px rgba(0, 0, 0, 0.6),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);

  font-size: 13px;
  font-weight: 500;
  z-index: 100;

  pointer-events: none;

  animation: fadeInUp 0.2s ease-out;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

.undo-indicator.hidden {
  display: none;
}

/* Keyboard shortcut hints */
.keyboard-hints {
  position: fixed;
  bottom: 24px;
  right: 24px;

  padding: 12px 16px;
  background: rgba(20, 20, 24, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #999;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;

  font-size: 12px;
  line-height: 1.6;
  z-index: 40;
}

.keyboard-hints kbd {
  display: inline-block;
  padding: 2px 6px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  font-family: monospace;
  font-size: 11px;
  color: #ccc;
  margin: 0 2px;
}

/* =============================================================================
   RESPONSIVE STYLES FOR SMALLER SCREENS
   ============================================================================= */

/* Medium screens (tablets, small laptops) */
@media screen and (max-width: 1200px) {
  .menu {
    width: 320px;
    max-height: 80vh;
  }

  .object-item {
    min-height: 85px;
  }

  .preview-canvas {
    width: 100px;
    height: 75px;
  }
}

/* Small screens */
@media screen and (max-width: 900px) {
  .menu {
    width: 280px;
    max-height: 70vh;
    right: 16px;
  }

  .menu-header {
    padding: 16px 16px 12px;
  }

  .menu-header h3 {
    font-size: 18px;
  }

  .object-list {
    padding: 12px;
    gap: 6px;
  }

  .object-item {
    padding: 10px;
    gap: 10px;
    min-height: 75px;
  }

  .preview-canvas {
    width: 80px;
    height: 60px;
  }

  .object-label {
    font-size: 13px;
  }

  .object-label strong {
    font-size: 14px;
  }

  .object-item small {
    font-size: 11px;
  }

  /* Stack rotation controls vertically */
  .rotation-snap-controls {
    flex-wrap: wrap;
    max-width: 200px;
  }

  .world-align-label {
    margin-left: 0;
    padding-left: 0;
    border-left: none;
    padding-top: 4px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    width: 100%;
  }
}

/* Extra small screens (phones) */
@media screen and (max-width: 600px) {
  .menu {
    position: fixed;
    right: 8px;
    left: 8px;
    top: auto;
    bottom: 8px;
    transform: none;
    width: auto;
    max-height: 50vh;
    border-radius: 12px;
  }

  @keyframes slideInRight {
    from {
      opacity: 0;
      transform: translateY(20px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .menu-header {
    padding: 14px 14px 10px;
  }

  .menu-header h3 {
    font-size: 16px;
  }

  .menu-hint {
    font-size: 12px;
  }

  .object-list {
    padding: 10px;
    gap: 6px;
  }

  .object-item {
    padding: 8px;
    gap: 8px;
    min-height: 60px;
  }

  .preview-canvas {
    width: 70px;
    height: 52px;
  }

  .object-label {
    font-size: 12px;
    gap: 2px;
  }

  .object-label strong {
    font-size: 13px;
    line-height: 1.2;
  }

  .object-item small {
    font-size: 10px;
    line-height: 1.3;
  }

  /* Move viewcube to be smaller on mobile */
  #viewcube-container {
    width: 100px;
    height: 100px;
    top: 10px;
    right: 10px;
  }

  /* Stack save/load buttons */
  .save-load-controls {
    top: 10px;
    left: 10px;
    gap: 4px;
  }

  .control-btn {
    padding: 8px 12px;
    font-size: 12px;
  }

  .control-btn span {
    display: none; /* Hide text, show only icons on mobile */
  }

  /* Compact rotation controls */
  .rotation-snap-controls {
    top: 55px;
    left: 10px;
    padding: 6px 10px;
    font-size: 12px;
    flex-wrap: wrap;
    max-width: 180px;
  }

  .snap-label {
    font-size: 12px;
  }

  .snap-select {
    font-size: 12px;
    padding: 3px 6px;
    min-width: 50px;
    padding-right: 20px;
    background-size: 10px;
  }

  .custom-angle-input,
  .manual-angle-input {
    font-size: 12px;
    padding: 3px 6px;
    width: 60px;
  }

  .manual-angle-input {
    width: 90px;
  }

  /* Hide keyboard hints on mobile */
  .keyboard-hints {
    display: none;
  }
}

/* Very short screens (landscape phones, small windows) */
@media screen and (max-height: 600px) {
  .menu {
    max-height: 90vh;
    top: 5%;
    transform: translateY(0);
  }

  .menu-header {
    padding: 12px 16px 10px;
  }

  .object-list {
    padding: 10px;
  }

  .object-item {
    padding: 8px;
    min-height: 65px;
  }

  .preview-canvas {
    width: 70px;
    height: 52px;
  }
}

