:root {
  --snap-grid-size: 20px;
  --snap-grid-line: rgba(255, 255, 255, 0.025);
  --snap-grid-line-strong: rgba(255, 255, 255, 0.05);
}

/* Base styles */
html,
body {
  margin: 0;
  height: 100%;
  background: #0a0a0a;
  color: #e8e8e8;
  font:
    14px/1.4 -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    system-ui,
    sans-serif;
}

/* Only apply full viewport sizing to canvas in main view, not in floating preview */
.canvas-wrapper canvas,
body > canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  display: block;
}

#gpu-canvas {
  z-index: 0;
}

#ui-canvas {
  z-index: 10;
  background-color: #0a0a0a;
}

/* Ensure canvas in floating preview maintains proper positioning and sizing */
.floating-gpu-preview canvas,
.preview-canvas-wrapper canvas {
  position: relative !important;
  /* Width and height are controlled by JavaScript based on resolution settings */
  /* Do not use auto or !important here as it would override resolution changes */
}

body {
  overflow: hidden;
  height: 100vh;
}

/* Toolbar */
.toolbar {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 100;
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(28, 28, 30, 0.9);
  backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.toolbar button {
  padding: 6px 12px;
  background: rgba(58, 58, 62, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  color: #ffffff;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.toolbar button:hover {
  background: rgba(74, 74, 78, 0.8);
  border-color: rgba(255, 255, 255, 0.15);
}

/* HUD */
#hud {
  position: fixed;
  bottom: 220px;
  right: 16px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background: rgba(28, 28, 30, 0.9);
  backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  min-width: 160px;
  transition: transform 0.25s ease, opacity 0.25s ease;
}

#hud.collapsed {
  gap: 4px;
  min-width: auto;
}

.hud-content {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

#hud.collapsed .hud-content {
  display: none;
}

.hud-collapse-toggle {
  width: auto;
  align-self: flex-end;
  padding: 6px 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

#hud.collapsed .hud-collapse-toggle {
  align-self: stretch;
  text-transform: none;
  letter-spacing: normal;
}

#hud button {
  padding: 8px 12px;
  background: rgba(58, 58, 62, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  color: #ffffff;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  width: 100%;
}

#hud button:hover {
  background: rgba(74, 74, 78, 0.8);
  border-color: rgba(255, 255, 255, 0.15);
}

#hud label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #e8e8e8;
  font-size: 12px;
  cursor: pointer;
}

#hud input[type="checkbox"] {
  width: 14px;
  height: 14px;
}

.snap-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}

#hud .snap-size {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #cfcfcf;
  font-size: 11px;
  cursor: default;
}

#hud .snap-size span {
  opacity: 0.7;
}

#hud input[type="number"] {
  width: 64px;
  padding: 4px 6px;
  background: rgba(20, 20, 20, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  color: #e8e8e8;
  font-size: 11px;
}

#hud input[type="number"]:focus {
  outline: none;
  border-color: rgba(102, 170, 255, 0.6);
  box-shadow: 0 0 0 1px rgba(102, 170, 255, 0.35);
}

#hud input[type="number"]:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#status {
  font-size: 11px;
  color: #888;
  text-align: center;
  padding: 4px;
}

/* Code console */
#code-console {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 220px;
  display: flex;
  flex-direction: column;
  background: linear-gradient(135deg, #141414 0%, #1a1a1a 100%);
  border-top: 1px solid #333;
  backdrop-filter: blur(10px);
  z-index: 50;
  transition: transform 0.25s ease, opacity 0.25s ease;
}

#code-console.closed {
  pointer-events: none;
  opacity: 0;
  transform: translateY(100%);
}

.code-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.35);
}

.code-title {
  color: #e8e8e8;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

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

.code-actions button {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #f3f3f3;
  font-size: 11px;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.code-actions button:hover {
  background: rgba(102, 170, 255, 0.2);
  border-color: rgba(102, 170, 255, 0.4);
}

.code-actions button:active {
  transform: translateY(1px);
}

/* Code panel */
#code {
  flex: 1;
  margin: 0;
  overflow-y: scroll;
  scrollbar-width: thin;
  scrollbar-color: rgba(102, 170, 255, 0.6) rgba(255, 255, 255, 0.05);
  font-family:
    "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", Consolas, "Courier New",
    monospace;
  padding: 16px;
  box-sizing: border-box;
  color: #e8e8e8;
  font-size: 12px;
  line-height: 1.4;
}

/* Error Overlay */
#err-overlay {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 200;
  background: rgba(139, 69, 19, 0.95);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 69, 58, 0.3);
  border-radius: 12px;
  padding: 20px;
  max-width: 80vw;
  max-height: 70vh;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}

#err-overlay.hidden {
  display: none;
}

.err-title {
  color: #ff6b9d;
  font-weight: 600;
  font-size: 16px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.err-title::before {
  content: "⚠️";
  font-size: 18px;
}

#err-log {
  color: #ffffff;
  background: rgba(0, 0, 0, 0.3);
  padding: 12px;
  border-radius: 6px;
  font-family: "SF Mono", Monaco, "Cascadia Code", monospace;
  font-size: 12px;
  line-height: 1.4;
  overflow: auto;
  max-height: 300px;
  white-space: pre-wrap;
}

/* Hidden elements */
.hidden {
  display: none !important;
}

/* Parameter Panel - Modern glassmorphism design */
.param-panel {
  background: rgba(42, 42, 46, 0.95);
  backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 16px;
  min-width: 280px;
  max-width: 400px;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.4),
    0 2px 8px rgba(0, 0, 0, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  animation: paramPanelSlideIn 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  transform-origin: top left;
}

@keyframes paramPanelSlideIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(-8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.param-header {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 16px;
  color: #ffffff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.param-header::before {
  content: "⚙";
  font-size: 16px;
  opacity: 0.7;
}

/* Input groups */
.param-input-group {
  margin-bottom: 14px;
  position: relative;
}

.param-input-group label {
  display: block;
  color: #b8b8b8;
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Enhanced input styling */
.param-input {
  width: 100%;
  padding: 10px 12px;
  background: rgba(26, 26, 30, 0.8);
  border: 1.5px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  color: #ffffff;
  font-family:
    "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", Consolas, monospace;
  font-size: 13px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-sizing: border-box;
}

.param-input:focus {
  outline: none;
  border-color: #007aff;
  background: rgba(26, 26, 30, 1);
  box-shadow:
    0 0 0 3px rgba(0, 122, 255, 0.15),
    0 4px 12px rgba(0, 0, 0, 0.2);
  transform: translateY(-1px);
}

.param-input:hover:not(:focus) {
  border-color: rgba(255, 255, 255, 0.15);
  background: rgba(26, 26, 30, 0.9);
}

/* Special styling for draggable float inputs */
.param-input[title*="drag"] {
  border-left: 3px solid #007aff;
  padding-left: 10px;
  background-image: linear-gradient(
    90deg,
    rgba(0, 122, 255, 0.05) 0%,
    transparent 20%
  );
}

.param-input[title*="drag"]:hover {
  border-left-color: #0099ff;
  cursor: ns-resize;
}

/* Buttons */
.param-buttons {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.param-buttons button {
  flex: 1;
  padding: 10px 16px;
  border: 1.5px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: rgba(58, 58, 62, 0.6);
  color: #ffffff;
  font-weight: 500;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(10px);
}

.param-buttons button:hover {
  background: rgba(74, 74, 78, 0.8);
  border-color: rgba(255, 255, 255, 0.15);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.param-buttons button:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

/* Drag hint styling */
.param-input-group::after {
  content: "Shift+drag";
  position: absolute;
  right: 12px;
  top: 32px;
  font-size: 10px;
  color: rgba(255, 255, 255, 0.3);
  pointer-events: none;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.param-input-group:hover::after {
  opacity: 1;
}

/* Float input specific styling */
.param-input[data-param-type="float"] {
  background-image:
    linear-gradient(90deg, rgba(0, 122, 255, 0.03) 0%, transparent 30%),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 10px,
      rgba(255, 255, 255, 0.01) 10px,
      rgba(255, 255, 255, 0.01) 11px
    );
}

/* Menu styling (if you have menus) */
.menu-panel {
  background: rgba(28, 28, 30, 0.95);
  backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 8px;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.4),
    0 2px 8px rgba(0, 0, 0, 0.2);
  animation: menuSlideIn 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes menuSlideIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.menu-item {
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.15s ease;
  font-size: 13px;
  color: #e8e8e8;
}

.menu-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

/* Selection and interaction states */
.param-input:user-invalid {
  border-color: #ff453a;
  box-shadow: 0 0 0 3px rgba(255, 69, 58, 0.15);
}

/* Scrollbar styling for code panel */
#code::-webkit-scrollbar {
  width: 10px;
}

#code::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.08);
}

#code::-webkit-scrollbar-thumb {
  background: rgba(102, 170, 255, 0.6);
  border-radius: 4px;
}

#code::-webkit-scrollbar-thumb:hover {
  background: rgba(129, 196, 255, 0.75);
}

/* Responsive adjustments */
@media (max-width: 480px) {
  .param-panel {
    min-width: 260px;
    padding: 14px;
  }

  .param-buttons {
    flex-direction: column;
  }
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
  .param-panel,
  .menu-panel,
  .param-input,
  .param-buttons button {
    animation: none;
    transition: none;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .param-panel {
    border-color: #ffffff;
    background: rgba(0, 0, 0, 0.95);
  }

  .param-input {
    border-color: #ffffff;
  }
}

/* Add this to your existing style.css */

/* Status message styles */
#status {
  transition: all 0.3s ease;
  padding: 4px 8px;
  border-radius: 4px;
  font-weight: 500;
}

#status.info {
  background-color: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.3);
  color: #3b82f6;
}

#status.warning {
  background-color: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.3);
  color: #f59e0b;
}

#status.error {
  background-color: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #ef4444;
}

/* Enhanced HUD layout */
#hud {
  align-items: stretch;
}

#hud button {
  white-space: nowrap;
}

#hud .hud-content button {
  min-width: 100%;
}

.hud-collapse-toggle {
  min-width: fit-content;
}

/* File input styling when visible */
#file-import {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

/* Improved error overlay */
#err-overlay {
  z-index: 10000;
  backdrop-filter: blur(4px);
}

#err-overlay .err-title {
  background: rgba(239, 68, 68, 0.9);
  color: white;
  padding: 12px 16px;
  font-weight: 600;
  border-radius: 8px 8px 0 0;
}

#err-overlay #err-log {
  background: rgba(0, 0, 0, 0.9);
  color: #ff6b6b;
  padding: 16px;
  margin: 0;
  border-radius: 0 0 8px 8px;
  max-height: 300px;
  overflow-y: auto;
  font-family: "Courier New", monospace;
  font-size: 12px;
  line-height: 1.4;
}

/* Loading states */
.loading {
  position: relative;
  pointer-events: none;
}

.loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border: 2px solid transparent;
  border-top: 2px solid currentColor;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}
