html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
}

.conway-container {
  width: 100vw;
  height: 100vh;
  background: var(--bg-color, #0f0f23);
  color: white;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  overflow: hidden;
  position: relative;
  user-select: none;
}

/* Fullscreen Grid Container */
.fullscreen-grid-container {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

.fullscreen-grid {
  display: grid;
  background: var(--dead-color, #1a1a2e);
}

.fullscreen-grid.with-grid {
  gap: 1px;
  background: var(--grid-color, #2a2a4a);
}

.cell {
  background: var(--dead-color, #1a1a2e);
  cursor: crosshair;
  transition: background-color 0.05s ease;
}

.cell:hover {
  background: rgba(255, 255, 255, 0.15);
}

.cell.alive {
  background: var(--alive-color, #2ecc71);
  box-shadow: 0 0 6px var(--alive-color, #2ecc71);
}

/* Floating Top Bar */
.floating-topbar {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 20px;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(16px);
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  z-index: 100;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-left h1 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  background: linear-gradient(135deg, var(--alive-color, #2ecc71), #3498db);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  white-space: nowrap;
}

.back-link {
  color: white;
  text-decoration: none;
  font-size: 20px;
  opacity: 0.7;
  transition: opacity 0.2s;
  padding: 4px 8px;
}

.back-link:hover {
  opacity: 1;
}

.topbar-center {
  display: flex;
  gap: 12px;
}

.stat-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  font-size: 13px;
}

.stat-pill .stat-icon {
  font-size: 14px;
}

.stat-pill .stat-value {
  font-weight: 600;
  color: var(--alive-color, #2ecc71);
  min-width: 40px;
  text-align: center;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.divider {
  width: 1px;
  height: 24px;
  background: rgba(255, 255, 255, 0.2);
  margin: 0 6px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  color: white;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.2s;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.25);
  transform: translateY(-1px);
}

.icon-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.icon-btn.active {
  background: color-mix(in srgb, var(--alive-color, #2ecc71) 25%, transparent);
  border-color: var(--alive-color, #2ecc71);
}

.icon-btn.pulse {
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--alive-color, #2ecc71) 40%, transparent); }
  50% { box-shadow: 0 0 0 8px transparent; }
}

/* Inline Speed Control in Topbar */
.speed-control {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 12px;
}

.speed-btn {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  color: white;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.speed-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.speed-display {
  font-size: 13px;
  font-weight: 600;
  min-width: 42px;
  text-align: center;
  color: var(--alive-color, #2ecc71);
}

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

.modal {
  background: linear-gradient(135deg, rgba(30, 30, 50, 0.95) 0%, rgba(15, 15, 30, 0.95) 100%);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 20px;
  padding: 28px;
  max-width: 500px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal h2 {
  margin: 0 0 24px 0;
  font-size: 24px;
  color: var(--alive-color, #2ecc71);
}

.modal h3 {
  margin: 20px 0 12px 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  opacity: 0.6;
}

/* Settings */
.setting-group {
  margin-bottom: 24px;
  padding-bottom: 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.setting-group:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.setting-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.setting-row label {
  font-size: 14px;
  opacity: 0.9;
}

.setting-row input[type="range"] {
  width: 100%;
  height: 8px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.15);
  outline: none;
  -webkit-appearance: none;
  cursor: pointer;
}

.setting-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--alive-color, #2ecc71);
  cursor: pointer;
  box-shadow: 0 0 10px var(--alive-color, #2ecc71);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  cursor: pointer;
  margin-bottom: 12px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 10px;
  transition: background 0.2s;
}

.checkbox-label:hover {
  background: rgba(255, 255, 255, 0.08);
}

.checkbox-label input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--alive-color, #2ecc71);
  cursor: pointer;
}

/* Theme Buttons */
.theme-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.theme-btn {
  padding: 12px 8px;
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  color: white;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}

.theme-btn::before {
  content: '';
  position: absolute;
  top: 6px;
  right: 6px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--preview-color);
  box-shadow: 0 0 8px var(--preview-color);
}

.theme-btn:hover {
  border-color: rgba(255, 255, 255, 0.3);
  transform: translateY(-2px);
}

.theme-btn.active {
  border-color: var(--preview-color);
  background: rgba(255, 255, 255, 0.1);
  box-shadow: 0 0 20px color-mix(in srgb, var(--preview-color) 30%, transparent);
}

/* Patterns Modal */
.patterns-modal {
  max-width: 650px;
}

.pattern-category {
  margin-bottom: 20px;
}

.pattern-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.pattern-btn {
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  color: white;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.pattern-btn:hover {
  background: rgba(var(--alive-color, 46, 204, 113), 0.2);
  border-color: var(--alive-color, #2ecc71);
  transform: translateY(-2px);
}

/* Help Modal */
.help-modal {
  max-width: 600px;
}

.help-section {
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.help-section:last-of-type {
  border-bottom: none;
}

.help-section h3 {
  margin-bottom: 12px;
  color: var(--alive-color, #2ecc71);
  opacity: 1;
}

.help-section ul {
  margin: 0;
  padding-left: 0;
  list-style: none;
}

.help-section li {
  font-size: 14px;
  opacity: 0.9;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.help-section li:last-child {
  border-bottom: none;
}

.help-section p {
  font-size: 14px;
  opacity: 0.8;
  margin: 10px 0;
  line-height: 1.6;
}

/* Primary Button */
.btn-primary {
  width: 100%;
  padding: 14px 28px;
  background: linear-gradient(135deg, var(--alive-color, #2ecc71), #27ae60);
  border: none;
  border-radius: 12px;
  color: white;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 20px;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(var(--alive-color, 46, 204, 113), 0.4);
}

/* Responsive */
@media (max-width: 900px) {
  .floating-topbar {
    flex-wrap: wrap;
    justify-content: center;
    max-width: 95%;
    gap: 12px;
  }

  .topbar-left h1 {
    display: none;
  }

  .topbar-center {
    order: 3;
    width: 100%;
    justify-content: center;
  }

  .stat-pill {
    padding: 4px 10px;
    font-size: 12px;
  }
}

@media (max-width: 600px) {
  .floating-topbar {
    top: 8px;
    padding: 8px 12px;
    gap: 8px;
  }

  .icon-btn {
    width: 32px;
    height: 32px;
    font-size: 14px;
  }

  .divider {
    display: none;
  }

  .speed-control {
    display: none;
  }

  .theme-buttons {
    grid-template-columns: repeat(2, 1fr);
  }

  .modal {
    padding: 20px;
    max-height: 85vh;
  }
}