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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #0d1117;
  color: #c9d1d9;
}

#root {
  flex: 1;
  width: 100%;
  position: relative;
  overflow: hidden;
}

.version-info a:hover {
  color: white;
}

.version-info {
  font-size: 11px;
  color: #4f5b66;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  margin-top: 2px;
  letter-spacing: 0.02em;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  font-family:
    ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;
}

.app {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  overflow-y: auto;
  /* Container A grows vertically as needed */
  background: #0d1117;
}

.main-content-layout {
  display: flex;
  flex-direction: row;
  /* Default Row (Widescreen) */
  flex: 1;
  /* Fills remaining space in Container A */
  min-height: 0;
}

.ui-overlay {
  width: 400px;
  padding: 20px;
  background: rgba(13, 17, 23, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-right: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  z-index: 100;

  /* Customize scrollbar for the overlay */
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.canvas-container {
  flex: 1;
  min-width: 0;
  height: 100%;
  position: relative;
}

.ui-overlay::-webkit-scrollbar {
  width: 6px;
}

.ui-overlay::-webkit-scrollbar-track {
  background: transparent;
}

.ui-overlay::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
}

h1 {
  font-size: 1.6rem;
  font-weight: 600;
  color: #8ab4f8;
  margin: 0;
  text-shadow: 0 0 20px rgba(138, 180, 248, 0.3);
}

.explainer {
  font-size: 14px;
  color: #8b949e;
  max-width: 300px;
  line-height: 1.4;
}

.explainer a {
  color: #8ab4f8;
  text-decoration: none;
}

.explainer a:hover {
  text-decoration: underline;
}

.stats {
  display: flex;
  gap: 20px;
  font-size: 14px;
  color: #aaa;
}

.controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

button {
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 500;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  background: #8ab4f8;
  color: #0d1117;
  transition: all 0.2s ease;
}

button:hover:not(:disabled) {
  background: #aecbfa;
  transform: translateY(-1px);
}

button:active:not(:disabled) {
  transform: translateY(0);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  color: #8b949e;
}

input[type="range"] {
  width: 150px;
  accent-color: #8ab4f8;
}

.mode-indicator {
  font-size: 14px;
  color: #8ab4f8;
  font-weight: 500;
}

.mode-indicator .hint {
  color: #666;
  font-weight: normal;
  font-size: 12px;
}

.mode-toggle-button {
  background: none;
  border: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  padding: 0;
}

.mode-toggle-button {
  /* use glass-button styles via class; reset text decoration */
  text-decoration: none;
  padding: 0 4px;
  font-size: 0.85rem;
}

/* mode indicator placed above configuration menu header */
.mode-indicator.above-menu {
  margin: 0 20px 8px 20px;
  text-align: center;
}


.instructions {
  font-size: 12px;
  color: #666;
  line-height: 1.5;
  max-width: 250px;
}

/* Wider leva panel */

/* Community sidebar */
.community-sidebar {
  margin-top: 16px;
  width: 100%;
  flex: 0 0 auto;
  padding: 20px;
}

.community-sidebar h3 {
  margin: 0 0 12px 0;
  font-size: 14px;
  color: #8ab4f8;
  font-weight: 600;
}

.community-sidebar .no-community {
  color: #8b949e;
  font-size: 13px;
  font-style: italic;
  line-height: 1.4;
}

.community-stats {
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
  font-size: 13px;
  color: #8b949e;
}

.community-3d-wrapper {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  /* CRITICAL for Canvas containment */
}

.community-3d-wrapper canvas {
  width: 100% !important;
  height: 100% !important;
}

/* Shape info styling */
.shape-info {
  font-family:
    ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;
  font-size: 13px;
  color: #ffaa00;
  font-weight: 500;
  padding: 4px 8px;
  background: rgba(255, 170, 0, 0.1);
  border-radius: 4px;
  display: inline-block;
}

.main-menu {
  position: relative;
  /* Flows inside ui-overlay */
  width: 100%;
  flex: 0 0 auto;
  /* Don't stretch/shrink, just fit content height naturally */
  display: flex;
  flex-direction: column;
  z-index: 1000;
  color: #fff;
  transition: all 0.3s ease;
  margin-top: 8px;
  /* Give it some breathing room from elements above it */
}

/* On large or tall displays, old layout rules for absolute positioning are removed
   since main-menu is now inside ui-overlay flexbox */


.menu-sticky-container {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  flex-shrink: 0;
  background: rgba(22, 27, 34, 0.3);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.main-menu.collapsed .menu-sticky-container {
  border-bottom: none;
}

.menu-scrollable-content {
  flex: 0 0 auto;
  /* Allow natural content height rather than forcing a scrollbox */
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.glass-panel {
  background: rgba(22, 27, 34, 0.5);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid silver;
  border-radius: 12px;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.4);
}



.menu-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
}

.menu-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0;
  color: #8ab4f8;
  text-shadow: 0 0 10px rgba(138, 180, 248, 0.2);
}

.collapse-toggle {
  background: none;
  border: none;
  color: #8ab4f8;
  font-size: 0.8rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 3px;
  transition: background 0.2s;
}

.menu-header:hover .collapse-toggle {
  background: rgba(255, 255, 255, 0.1);
}

.main-menu.collapsed .menu-section,
.main-menu.collapsed .menu-scrollable-content {
  display: none;
}

.menu-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.menu-section h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #888;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 4px;
  margin-bottom: 4px;
}

.button-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.actions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.actions-grid button:first-child {
  grid-column: span 2;
}

.config-actions {
  grid-template-columns: 1fr 1fr;
}

.config-actions button:first-child {
  grid-column: span 1;
}

.config-actions button:last-child {
  grid-column: span 2;
}

.glass-button {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.2s ease;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.glass-button:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.3);
  transform: translateY(-1px);
}

.glass-button:active:not(:disabled) {
  transform: translateY(1px);
}

.glass-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.glass-button.primary {
  background: rgba(138, 180, 248, 0.15);
  border-color: rgba(138, 180, 248, 0.3);
  color: #8ab4f8;
}

.glass-button.primary:hover:not(:disabled) {
  background: rgba(138, 180, 248, 0.25);
}

.glass-button.danger {
  background: rgba(242, 139, 130, 0.15);
  border-color: rgba(242, 139, 130, 0.3);
  color: #f28b82;
}

.glass-button.danger:hover:not(:disabled) {
  background: rgba(242, 139, 130, 0.25);
}

.control-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: #ccc;
}

.control-label.row {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}

/* neighbor controls layout */
.neighbor-controls {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
}

.neighbor-controls .control-label {
  font-size: 0.85rem;
}

.control-label span {
  display: flex;
  justify-content: space-between;
}

.rules-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.rules-grid .control-label.mini {
  font-size: 0.75rem;
}

input[type="range"] {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  height: 12px;
  width: 12px;
  border-radius: 50%;
  background: #8ab4f8;
  cursor: pointer;
  margin-top: -4px;
  box-shadow: 0 0 10px rgba(138, 180, 248, 0.4);
}

input[type="range"]::-webkit-slider-runnable-track {
  width: 100%;
  height: 4px;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.glass-select,
.glass-input {
  width: 100%;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: #fff;
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s;
}

.glass-select:focus,
.glass-input:focus {
  border-color: rgba(138, 180, 248, 0.5);
}

.glass-select option {
  background: #0d1117;
  color: #fff;
}

.glass-checkbox {
  width: 16px;
  height: 16px;
  accent-color: #8ab4f8;
  cursor: pointer;
}

/* Shortcuts Toggle Button */
.shortcuts-toggle {
  align-self: flex-start;
  margin-top: 4px;
  margin-bottom: 8px;
  padding: 6px 12px;
  font-size: 0.8rem;
  color: #8b949e;
  background: rgba(22, 27, 34, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.shortcuts-toggle:hover {
  color: #c9d1d9;
  background: rgba(22, 27, 34, 0.6);
  border-color: rgba(255, 255, 255, 0.15);
  transform: translateY(-1px);
}

.shortcuts-toggle:active {
  transform: translateY(0);
}

/* Shortcut Overlay Modal */
.shortcuts-modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(13, 17, 23, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease-out;
}

.shortcuts-modal {
  background: rgba(22, 27, 34, 0.65);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 24px;
  width: 90%;
  max-width: 600px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
  animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  color: #c9d1d9;
}

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

.shortcuts-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0;
  color: #8ab4f8;
  text-shadow: 0 0 10px rgba(138, 180, 248, 0.2);
}

.close-btn {
  background: transparent;
  color: #8b949e;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
  transition: color 0.2s;
}

.close-btn:hover {
  background: transparent;
  color: #fff;
}

.shortcuts-content {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 24px;
}

.shortcut-section h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #888;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 4px;
  margin-bottom: 12px;
}

.shortcut-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.08);
}

.shortcut-row:last-child {
  border-bottom: none;
}

.shortcut-desc {
  font-size: 0.85rem;
  color: #8b949e;
}

.shortcut-keys {
  display: flex;
  align-items: center;
  gap: 4px;
}

.shortcut-keys span {
  color: #666;
  font-size: 0.8rem;
}

kbd {
  background: rgba(22, 27, 34, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  padding: 3px 6px;
  font-family:
    ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;
  font-size: 0.75rem;
  color: #c9d1d9;
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* App Header Panel (Always visible top bar) */
.app-header-panel {
  position: sticky;
  top: 0;
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  background: rgba(13, 17, 23, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  flex-shrink: 0;
  z-index: 1000;
}

.app-header-panel .button-group {
  display: flex;
  gap: 10px;
}

.app-header-panel button {
  padding: 8px 12px;
  font-size: 1.1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Custom Tooltip */
[data-tooltip-bottom] {
  position: relative;
}

[data-tooltip-bottom]::before {
  content: attr(data-tooltip-bottom);
  position: absolute;
  top: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%) translateY(-4px);
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  color: #fff;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: all 0.15s ease;
  transition-delay: 0.05s;
  border: 1px solid rgba(255, 255, 255, 0.1);
  z-index: 1500;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

[data-tooltip-bottom]:hover::before {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

@keyframes slideInDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* --------------------------------------------------------------------------
   Mobile & Responsive Tweaks 
----------------------------------------------------------------------------- */
@media (max-width: 768px) {
  .main-content-layout {
    flex-direction: column;
    /* Small Screen: Stack vertically */
    flex: none;
    /* Allow Container A to scroll naturally */
  }

  .ui-overlay {
    width: 100%;
    flex: none;
    border-right: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(13, 17, 23, 0.8);
    overflow-y: visible;
    /* Let the main document handle scroll */
  }

  .canvas-container {
    width: 100%;
    aspect-ratio: 1 / 1;
    /* Make it square */
    flex: none;
    position: relative;
    height: auto;
    overflow: hidden;
    /* Ensure canvas doesn't bleed out */
    display: block;
  }

  .app-header-panel {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    padding: 15px;
  }

  /* Make sure titles fit */
  h1 {
    font-size: 1.3rem;
  }

  .explainer,
  .stats,
  .shape-info {
    font-size: 12px;
  }

  /* Reduce paddings in menu layout */
  .menu-sticky-container {
    padding: 12px;
    gap: 12px;
  }

  .menu-scrollable-content {
    padding: 12px;
    gap: 16px;
  }

  .glass-button {
    padding: 10px 14px;
    /* Larger tap targets on phone */
  }

  /* Ensure the config menu handles height gracefully */
  .main-menu {
    border-radius: 12px;
  }

  .main-menu.collapsed {
    flex: 0 0 auto;
  }
}

/* Modal Styles */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
  padding: 20px;
}

.modal-content {
  background: #161b22;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 24px;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-content h3 {
  margin: 0;
  color: #58a6ff;
  font-size: 1.2rem;
}

.modal-content p {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
  color: #8b949e;
}

.modal-content .warning-text {
  color: #ffa657;
  font-size: 13px;
  padding: 12px;
  background: rgba(255, 166, 87, 0.1);
  border-radius: 6px;
  border-left: 3px solid #ffa657;
}

.scene-delete-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 200px;
  overflow-y: auto;
  padding: 4px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 6px;
}

.scene-delete-item {
  padding: 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s ease;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.scene-delete-item:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.scene-delete-item.selected {
  background: rgba(88, 166, 255, 0.1);
  border-color: #58a6ff;
  color: #58a6ff;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 8px;
}