@import url('https://fonts.googleapis.com/css2?family=VT323&display=swap');

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  /* Dark mode DOS/Windows palette */
  --dos-blue: #4466aa;
  --dos-dark-blue: #334488;
  --dos-black: #0a0a0a;
  --win-gray: #2a2a2a;
  --win-dark-gray: #1a1a1a;
  --win-white: #3a3a3a;
  --win-highlight: #4a4a4a;
  --win-shadow: #0a0a0a;
  --win-black: #000000;
  --text-primary: #c0c0c0;
  --text-secondary: #888888;
  --text-yellow: #ccaa44;
  --text-cyan: #44aacc;
}

body {
  font-family: 'VT323', monospace;
  background: var(--dos-black);
  color: var(--win-white);
  min-height: 100vh;
  overflow: hidden;
}

.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
}

.canvas-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  overflow: hidden;
}

#simulation-canvas {
  max-width: 100%;
  max-height: 100%;
  image-rendering: pixelated;
}

/* Classic Windows 3.1 beveled border mixin-style */
.sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--win-gray);
  border-left: 2px solid var(--win-highlight);
  border-top: 2px solid var(--win-highlight);
  border-right: 2px solid var(--win-shadow);
  border-bottom: 2px solid var(--win-shadow);
  box-shadow: inset 1px 1px 0 var(--win-highlight);
  display: flex;
  flex-direction: column;
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.sidebar h1 {
  font-family: 'VT323', monospace;
  font-size: 1.3rem;
  font-weight: 400;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 10px;
  padding: 4px 6px;
  background: var(--dos-dark-blue);
  color: var(--win-white);
  text-align: center;
}

.control-group {
  margin-bottom: 8px;
  padding: 6px;
  background: var(--win-gray);
  border-top: 2px solid var(--win-shadow);
  border-left: 2px solid var(--win-shadow);
  border-bottom: 2px solid var(--win-white);
  border-right: 2px solid var(--win-white);
  overflow: visible;
  position: relative;
}


.control-group label {
  display: block;
  font-family: 'VT323', monospace;
  font-size: 1rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.control-group label span {
  color: var(--text-yellow);
  font-weight: 400;
}

input[type="range"] {
  width: 100%;
  height: 18px;
  border-radius: 0;
  background: var(--win-gray);
  appearance: none;
  cursor: pointer;
  border-top: 2px solid var(--win-shadow);
  border-left: 2px solid var(--win-shadow);
  border-bottom: 2px solid var(--win-white);
  border-right: 2px solid var(--win-white);
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 12px;
  height: 20px;
  border-radius: 0;
  background: var(--win-gray);
  cursor: pointer;
  border-top: 2px solid var(--win-highlight);
  border-left: 2px solid var(--win-highlight);
  border-bottom: 2px solid var(--win-shadow);
  border-right: 2px solid var(--win-shadow);
}

input[type="range"]::-webkit-slider-thumb:active {
  border-top: 2px solid var(--win-shadow);
  border-left: 2px solid var(--win-shadow);
  border-bottom: 2px solid var(--win-highlight);
  border-right: 2px solid var(--win-highlight);
}

input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 20px;
  border-radius: 0;
  background: var(--win-gray);
  cursor: pointer;
  border-top: 2px solid var(--win-highlight);
  border-left: 2px solid var(--win-highlight);
  border-bottom: 2px solid var(--win-shadow);
  border-right: 2px solid var(--win-shadow);
}

select {
  width: 100%;
  padding: 4px 6px;
  border-radius: 0;
  background: var(--win-dark-gray);
  color: var(--text-primary);
  font-family: 'VT323', monospace;
  font-size: 1rem;
  cursor: pointer;
  margin-bottom: 6px;
  border-top: 2px solid var(--win-shadow);
  border-left: 2px solid var(--win-shadow);
  border-bottom: 2px solid var(--win-white);
  border-right: 2px solid var(--win-white);
}

select:focus {
  outline: 1px dotted var(--text-primary);
  outline-offset: -3px;
}

select option {
  background: var(--win-dark-gray);
  color: var(--text-primary);
}

.upload-label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--win-gray);
  cursor: pointer;
  font-family: 'VT323', monospace;
  font-size: 1.1rem;
  color: var(--text-primary);
  text-transform: uppercase;
  border-top: 2px solid var(--win-highlight);
  border-left: 2px solid var(--win-highlight);
  border-bottom: 2px solid var(--win-shadow);
  border-right: 2px solid var(--win-shadow);
}

.upload-label:hover {
  background: var(--win-highlight);
  color: var(--text-primary);
}

.upload-label:active {
  border-top: 2px solid var(--win-shadow);
  border-left: 2px solid var(--win-shadow);
  border-bottom: 2px solid var(--win-highlight);
  border-right: 2px solid var(--win-highlight);
}

.upload-icon {
  font-size: 1rem;
}

.image-preview {
  margin-top: 6px;
  border: 2px solid var(--win-shadow);
  overflow: hidden;
}

.image-preview img {
  width: 100%;
  display: block;
  image-rendering: pixelated;
}

.button-group {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin-top: 6px;
}

.btn {
  padding: 6px 4px;
  background: var(--win-gray);
  color: var(--text-primary);
  font-family: 'VT323', monospace;
  font-size: 0.95rem;
  cursor: pointer;
  text-transform: uppercase;
  border-top: 2px solid var(--win-highlight);
  border-left: 2px solid var(--win-highlight);
  border-bottom: 2px solid var(--win-shadow);
  border-right: 2px solid var(--win-shadow);
}

.btn:hover {
  background: var(--win-highlight);
  color: var(--text-primary);
}

.btn:active {
  border-top: 2px solid var(--win-shadow);
  border-left: 2px solid var(--win-shadow);
  border-bottom: 2px solid var(--win-highlight);
  border-right: 2px solid var(--win-highlight);
}

.btn-primary {
  background: var(--dos-dark-blue);
  color: var(--text-primary);
}

.btn-primary:hover {
  background: var(--dos-blue);
}

.btn-secondary {
  background: #2a3a4a;
  color: var(--text-cyan);
}

.btn-secondary:hover {
  background: #3a4a5a;
}

.btn-gif {
  background: #4a2a2a;
  color: #cc8888;
}

.btn-gif:hover:not(:disabled) {
  background: #5a3a3a;
}

.btn-gif:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-gif.recording {
  background: #662222;
  color: #ff8888;
  animation: blink-recording 0.5s infinite;
}

@keyframes blink-recording {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.recording-status {
  margin-top: 8px;
  padding: 8px 10px;
  font-family: 'VT323', monospace;
  font-size: 1.1rem;
  font-weight: 400;
  text-align: center;
  text-transform: uppercase;
  display: none;
  background: var(--dos-dark-blue);
  color: var(--win-white);
  border: 2px solid var(--win-shadow);
}

.recording-status.visible {
  display: block;
}

.recording-status.countdown {
  background: #3a3a1a;
  color: var(--text-yellow);
}

.recording-status.recording {
  background: #3a1a1a;
  color: #cc6666;
  animation: pulse-recording 1s infinite;
}

.recording-status.processing {
  background: #1a2a2a;
  color: var(--text-cyan);
}

@keyframes pulse-recording {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.checkbox-group {
  margin-bottom: 8px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-family: 'VT323', monospace;
  font-size: 1rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  padding: 6px;
  background: var(--win-gray);
  border-top: 2px solid var(--win-shadow);
  border-left: 2px solid var(--win-shadow);
  border-bottom: 2px solid var(--win-white);
  border-right: 2px solid var(--win-white);
}

.checkbox-label input[type="checkbox"] {
  width: 14px;
  height: 14px;
  appearance: none;
  background: var(--win-dark-gray);
  cursor: pointer;
  position: relative;
  border-top: 2px solid var(--win-shadow);
  border-left: 2px solid var(--win-shadow);
  border-bottom: 2px solid var(--win-highlight);
  border-right: 2px solid var(--win-highlight);
}

.checkbox-label input[type="checkbox"]:checked::after {
  content: '✓';
  position: absolute;
  top: -2px;
  left: 1px;
  font-size: 14px;
  color: var(--text-yellow);
  font-weight: bold;
}

.checkbox-label span {
  color: var(--text-primary);
}

/* Custom tooltip */
#custom-tooltip {
  display: none;
  position: fixed;
  padding: 6px 10px;
  background: var(--win-dark-gray);
  color: var(--text-cyan);
  font-family: 'VT323', monospace;
  font-size: 0.95rem;
  line-height: 1.3;
  border: 2px solid var(--win-highlight);
  box-shadow: 3px 3px 0 rgba(0,0,0,0.5);
  z-index: 99999;
  pointer-events: none;
  max-width: 220px;
}

[data-tip] {
  cursor: help;
}


/* Windows 3.1 style scrollbar */
.sidebar-content::-webkit-scrollbar {
  width: 16px;
}

.sidebar-content::-webkit-scrollbar-track {
  background: var(--win-dark-gray);
  border-left: 1px solid var(--win-shadow);
}

.sidebar-content::-webkit-scrollbar-thumb {
  background: var(--win-gray);
  border-top: 2px solid var(--win-highlight);
  border-left: 2px solid var(--win-highlight);
  border-bottom: 2px solid var(--win-shadow);
  border-right: 2px solid var(--win-shadow);
}

.sidebar-content::-webkit-scrollbar-button:vertical:decrement {
  height: 16px;
  background: var(--win-gray);
  border-top: 2px solid var(--win-highlight);
  border-left: 2px solid var(--win-highlight);
  border-bottom: 2px solid var(--win-shadow);
  border-right: 2px solid var(--win-shadow);
}

.sidebar-content::-webkit-scrollbar-button:vertical:increment {
  height: 16px;
  background: var(--win-gray);
  border-top: 2px solid var(--win-highlight);
  border-left: 2px solid var(--win-highlight);
  border-bottom: 2px solid var(--win-shadow);
  border-right: 2px solid var(--win-shadow);
}

/* Behavior zones drag-and-drop layout */
.behavior-zones-section {
  padding: 4px 6px;
}

.behavior-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.behavior-header label {
  margin-bottom: 0;
}

.behavior-buttons {
  display: flex;
  gap: 4px;
}

.btn-small {
  padding: 2px 6px;
  font-family: 'VT323', monospace;
  font-size: 0.8rem;
  background: var(--win-gray);
  color: var(--text-secondary);
  cursor: pointer;
  text-transform: uppercase;
  border-top: 2px solid var(--win-highlight);
  border-left: 2px solid var(--win-highlight);
  border-bottom: 2px solid var(--win-shadow);
  border-right: 2px solid var(--win-shadow);
}

.btn-small:hover {
  background: var(--win-highlight);
  color: var(--text-primary);
}

.btn-small:active {
  border-top: 2px solid var(--win-shadow);
  border-left: 2px solid var(--win-shadow);
  border-bottom: 2px solid var(--win-highlight);
  border-right: 2px solid var(--win-highlight);
}

.behavior-zones {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.behavior-zone {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.zone-label {
  font-family: 'VT323', monospace;
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  padding-left: 2px;
}

.zone-droparea {
  min-height: 48px;
  height: 48px;
  padding: 3px;
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  align-content: flex-start;
  background: var(--win-dark-gray);
  border-top: 2px solid var(--win-shadow);
  border-left: 2px solid var(--win-shadow);
  border-bottom: 2px solid var(--win-highlight);
  border-right: 2px solid var(--win-highlight);
  overflow: hidden;
}

.zone-droparea.drag-over {
  background: var(--dos-dark-blue);
  box-shadow: inset 0 0 0 1px var(--dos-blue);
}

.zone-droparea:empty::after {
  content: '···';
  color: var(--win-shadow);
  font-family: 'VT323', monospace;
  font-size: 0.8rem;
  width: 100%;
  text-align: center;
  line-height: 22px;
}

/* Color swatches */
.color-swatch {
  width: 18px;
  height: 18px;
  cursor: grab;
  border-top: 2px solid var(--win-highlight);
  border-left: 2px solid var(--win-highlight);
  border-bottom: 2px solid var(--win-shadow);
  border-right: 2px solid var(--win-shadow);
  transition: transform 0.1s ease;
}

.color-swatch:hover {
  transform: scale(1.1);
}

.color-swatch.dragging {
  opacity: 0.5;
  cursor: grabbing;
  border-top: 2px solid var(--win-shadow);
  border-left: 2px solid var(--win-shadow);
  border-bottom: 2px solid var(--win-highlight);
  border-right: 2px solid var(--win-highlight);
}

.color-swatch.drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 10000;
  opacity: 0.9;
  transform: scale(1.2);
  box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

/* Image Gallery */
.image-gallery-section {
  margin-top: 8px;
}

.image-gallery-section > label {
  display: block;
  margin-bottom: 4px;
}

.image-gallery {
  display: flex;
  gap: 6px;
  justify-content: flex-start;
}

.image-preview {
  width: 48px;
  height: 48px;
  padding: 2px;
  background: var(--win-gray);
  cursor: pointer;
  border-top: 2px solid var(--win-highlight);
  border-left: 2px solid var(--win-highlight);
  border-bottom: 2px solid var(--win-shadow);
  border-right: 2px solid var(--win-shadow);
  overflow: hidden;
}

.image-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  image-rendering: pixelated;
}

.image-preview:hover {
  background: var(--win-highlight);
}

.image-preview:active,
.image-preview.active {
  border-top: 2px solid var(--win-shadow);
  border-left: 2px solid var(--win-shadow);
  border-bottom: 2px solid var(--win-highlight);
  border-right: 2px solid var(--win-highlight);
}

.image-preview.active {
  background: var(--win-dark);
}

.image-upload-btn {
  display: flex;
  align-items: center;
  justify-content: center;
}

.upload-plus {
  font-size: 24px;
  font-weight: bold;
  color: var(--text-secondary);
  line-height: 1;
}

.image-upload-btn:hover .upload-plus {
  color: var(--text-primary);
}

/* Uploaded image preview (dynamically added) */
.image-preview.uploaded {
  position: relative;
}

/* Collapsible Settings Menu */
.settings-section {
  margin-top: 8px;
}

.settings-toggle {
  width: 100%;
  padding: 6px 8px;
  background: var(--win-gray);
  color: var(--text-secondary);
  font-family: 'VT323', monospace;
  font-size: 1rem;
  text-transform: uppercase;
  text-align: left;
  cursor: pointer;
  border-top: 2px solid var(--win-highlight);
  border-left: 2px solid var(--win-highlight);
  border-bottom: 2px solid var(--win-shadow);
  border-right: 2px solid var(--win-shadow);
}

.settings-toggle:hover {
  background: var(--win-highlight);
  color: var(--text-primary);
}

.settings-toggle:active {
  border-top: 2px solid var(--win-shadow);
  border-left: 2px solid var(--win-shadow);
  border-bottom: 2px solid var(--win-highlight);
  border-right: 2px solid var(--win-highlight);
}

.settings-arrow {
  display: inline-block;
  width: 1em;
  margin-right: 4px;
  font-size: 0.8em;
}

.settings-content {
  display: none;
  padding-top: 4px;
}

.settings-content.open {
  display: block;
}

.settings-content .control-group {
  margin-bottom: 6px;
}

/* Sidebar Logo */
.sidebar-logo {
  flex-shrink: 0;
  padding: 8px 4px 6px;
  display: flex;
  justify-content: center;
}

.sidebar-logo img {
  max-width: 100%;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  opacity: 0.85;
  transition: opacity 0.2s ease;
}

.sidebar-logo img:hover {
  opacity: 1;
}

/* Mobile bar - hidden on desktop */
.mobile-bar {
  display: none;
}

/* Mobile close button - hidden on desktop */
.mobile-close-btn {
  display: none;
}

/* Mobile responsive */
@media (max-width: 768px) {
  .app-container {
    flex-direction: column;
    height: 100dvh; /* Dynamic viewport height - accounts for mobile browser chrome */
    height: 100vh; /* Fallback for older browsers */
    position: relative;
  }

  @supports (height: 100dvh) {
    .app-container {
      height: 100dvh;
    }
  }

  .canvas-container {
    flex: 1;
    min-height: 0; /* Allow shrinking in flex context */
  }

  /* Mobile bottom bar */
  .mobile-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--win-gray);
    border-top: 2px solid var(--win-highlight);
    height: 56px;
    flex-shrink: 0;
  }

  .mobile-logo {
    height: 40px;
    width: auto;
    image-rendering: pixelated;
  }

  .mobile-bar .btn {
    padding: 8px 16px;
    font-size: 1rem;
  }

  /* Sidebar - hidden by default, fullscreen overlay when open */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    max-height: 100%;
    min-width: 100%;
    z-index: 1000;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    border: none;
    flex-direction: column;
  }

  .sidebar.mobile-open {
    transform: translateY(0);
  }

  /* Mobile close button */
  .mobile-close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 8px;
    right: 12px; /* Align with content padding */
    width: 36px;
    height: 36px;
    background: var(--win-gray);
    color: var(--text-primary);
    font-size: 1.2rem;
    cursor: pointer;
    z-index: 10;
    border-top: 2px solid var(--win-highlight);
    border-left: 2px solid var(--win-highlight);
    border-bottom: 2px solid var(--win-shadow);
    border-right: 2px solid var(--win-shadow);
  }

  .mobile-close-btn:active {
    border-top: 2px solid var(--win-shadow);
    border-left: 2px solid var(--win-shadow);
    border-bottom: 2px solid var(--win-highlight);
    border-right: 2px solid var(--win-highlight);
  }

  .sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    padding-top: 50px; /* Space for close button */
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .control-group {
    margin-bottom: 0;
    padding: 6px;
  }

  .control-group label {
    font-size: 1rem;
  }

  .button-group {
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
  }

  .btn {
    padding: 10px 4px;
    font-size: 0.9rem;
  }

  .sidebar-logo {
    padding: 12px 8px;
    flex-shrink: 0;
  }

  .sidebar-logo img {
    max-width: 200px; /* Match desktop sidebar width */
    width: auto;
  }
}

@media (max-width: 480px) {
  .button-group {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Fullscreen mode */
.app-container.fullscreen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 9999;
}

.app-container.fullscreen .canvas-container {
  position: relative;
  z-index: 1;
}

.app-container.fullscreen .sidebar {
  position: absolute;
  right: 0;
  top: 0;
  height: 100%;
  z-index: 100;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.5);
}

.app-container.fullscreen .sidebar.visible {
  transform: translateX(0);
}

/* Hover trigger zone on the right edge */
.fullscreen-trigger {
  display: none;
  position: absolute;
  right: 0;
  top: 0;
  width: 30px;
  height: 100%;
  z-index: 50;
  cursor: pointer;
}

.app-container.fullscreen .fullscreen-trigger {
  display: block;
}

/* Visual indicator for sidebar trigger */
.fullscreen-trigger::after {
  content: '';
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 80px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  transition: background 0.2s ease, height 0.2s ease;
}

.fullscreen-trigger:hover::after {
  background: rgba(255, 255, 255, 0.4);
  height: 120px;
}
