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

body {
  background: #0a0a0f;
  color: #e0e0e0;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

canvas {
  display: block;
  cursor: crosshair;
}

canvas.placing {
  cursor: copy;
}

.toolbar {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: rgba(18, 18, 28, 0.92);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 8px 14px;
  z-index: 100;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.toolbar-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.toolbar-secondary {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, padding 0.3s ease;
  padding-top: 0;
}

.toolbar-secondary.expanded {
  max-height: 120px;
  padding-top: 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.btn-toggle {
  opacity: 0.5;
  padding: 6px 8px !important;
  font-size: 10px !important;
}

.btn-toggle:hover {
  opacity: 0.9;
}

.btn-toggle.expanded {
  transform: rotate(180deg);
}

.btn-share {
  opacity: 0.5;
}

.btn-share:hover {
  opacity: 0.9;
}

.share-toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(18, 18, 28, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 12px 24px;
  font-family: monospace;
  font-size: 13px;
  color: #8cc8ff;
  z-index: 300;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.share-toast.visible {
  opacity: 1;
}

.discover-panel {
  display: none;
  position: fixed;
  background: rgba(18, 18, 28, 0.96);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 16px;
  z-index: 150;
  max-height: 70vh;
  overflow-y: auto;
  min-width: 280px;
  max-width: 340px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.6);
}

.discover-panel.open { display: block; }

.discover-panel .header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.discover-panel .header h3 {
  font-size: 13px;
  color: #fff;
  font-weight: 500;
}

.discover-panel .counter {
  font-size: 11px;
  color: #666;
}

.discover-panel .entry {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s;
  font-size: 12px;
}

.discover-panel .entry:hover {
  background: rgba(255,255,255,0.04);
}

.discover-panel .entry .mini-canvas {
  width: 24px;
  height: 24px;
  border-radius: 3px;
  flex-shrink: 0;
  image-rendering: pixelated;
}

.discover-panel .entry .info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.discover-panel .entry .name {
  color: #ccc;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.discover-panel .entry .count {
  color: #666;
  font-size: 10px;
}

.discover-panel .entry .btn-add {
  background: rgba(100, 180, 255, 0.15);
  border: none;
  color: #8cc8ff;
  border-radius: 5px;
  padding: 3px 8px;
  font-family: inherit;
  font-size: 10px;
  cursor: pointer;
  transition: background 0.12s;
  flex-shrink: 0;
}

.discover-panel .entry .btn-add:hover {
  background: rgba(100, 180, 255, 0.3);
}

.discover-panel .separator {
  height: 1px;
  background: rgba(255,255,255,0.06);
  margin: 6px 0;
}

.discover-panel .empty {
  text-align: center;
  color: #555;
  font-size: 12px;
  padding: 20px 0;
}

.btn-discover {
  opacity: 0.6;
}

.btn-discover:hover {
  opacity: 0.9;
}

.btn-discover.active {
  opacity: 1;
  color: #6aff8a;
}

.toolbar button, .toolbar select {
  background: rgba(255, 255, 255, 0.06);
  color: #e0e0e0;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 6px 12px;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}

.toolbar .btn-undo,
.toolbar .btn-redo {
  opacity: 0.6;
}

.toolbar .btn-undo:hover,
.toolbar .btn-redo:hover {
  opacity: 1;
}

.pattern-deselect {
  opacity: 0.5;
  font-size: 11px;
}

.toolbar button:hover, .toolbar select:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
}

.toolbar button.active {
  background: rgba(100, 180, 255, 0.2);
  border-color: rgba(100, 180, 255, 0.4);
  color: #8cc8ff;
}

.toolbar .separator {
  width: 1px;
  height: 24px;
  background: rgba(255, 255, 255, 0.1);
}

.toolbar .speed-control {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #888;
}

.speed-control button {
  padding: 4px 9px !important;
  font-size: 16px !important;
  line-height: 1;
}

.speed-control button:disabled {
  opacity: 0.25;
  cursor: default;
}

#speed-display {
  font-size: 12px;
  color: #aaa;
  min-width: 44px;
  text-align: center;
  user-select: none;
  white-space: nowrap;
}

@media (max-width: 768px) {
    .toolbar {
      top: 8px;
      left: 8px;
      right: 8px;
      transform: none;
      gap: 4px;
      padding: 6px 10px;
      max-width: none;
    }

    .toolbar-row {
      flex-wrap: wrap;
      gap: 6px;
    }

    .toolbar .separator {
      display: none;
    }

    .toolbar-secondary.expanded {
      max-height: 200px;
    }

    .info-bar {
      bottom: 8px;
      left: 8px;
      right: 8px;
      transform: none;
      flex-wrap: wrap;
      justify-content: center;
      gap: 3px 10px;
      font-size: 10px;
      padding: 3px 8px;
      max-width: none;
    }

    .info-bar .github-link {
      font-size: 9px;
    }

    .info-bar .placement-hint.visible {
      max-width: 100%;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }

.info-bar {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: #666;
  background: rgba(18, 18, 28, 0.85);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  padding: 6px 14px;
  z-index: 100;
}

.info-bar span { color: #888; }
.info-bar .placement-hint {
  color: #8cc8ff;
  display: none;
}

.info-bar .placement-hint.visible {
  display: inline;
}

.info-bar .github-link {
  color: #555;
  text-decoration: none;
  transition: color 0.15s;
}

.info-bar .github-link:hover {
  color: #888;
}

.birth-heading {
  color: #6aff8a;
}

.survival-heading {
  color: #6ab4ff;
}

.visuals-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.patterns-dropdown {
  display: none;
  position: fixed;
  background: rgba(18, 18, 28, 0.96);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 16px;
  z-index: 150;
  max-height: 70vh;
  overflow-y: auto;
  min-width: 220px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.6);
}

.patterns-dropdown.open { display: block; }

.color-dropdown {
  display: none;
  position: fixed;
  background: rgba(18, 18, 28, 0.96);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 16px;
  z-index: 150;
  box-shadow: 0 16px 48px rgba(0,0,0,0.6);
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.color-dropdown.open { display: flex; }

.color-wheel-container {
  position: relative;
  width: 200px;
  height: 200px;
}

.color-wheel {
  width: 200px;
  height: 200px;
  border-radius: 50%;
  cursor: crosshair;
}

.color-wheel-indicator {
  position: absolute;
  width: 12px;
  height: 12px;
  border: 2px solid white;
  border-radius: 50%;
  pointer-events: none;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 4px rgba(0,0,0,0.5);
}

.color-slider-container {
  width: 200px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.color-slider-container label {
  font-size: 11px;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.color-slider {
  width: 100%;
  height: 20px;
  border-radius: 10px;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
}

.color-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: white;
  border: 2px solid rgba(0,0,0,0.3);
  cursor: pointer;
}

.color-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: white;
  border: 2px solid rgba(0,0,0,0.3);
  cursor: pointer;
}

.color-preview {
  width: 200px;
  height: 40px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.1);
}

.color-presets {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  width: 200px;
}

.color-presets .color-swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
}

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

.color-presets .color-swatch.active {
  border-color: #fff;
}

.patterns-category { margin-bottom: 14px; }
.patterns-category:last-child { margin-bottom: 0; }

.patterns-category h3 {
  font-size: 10px;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.patterns-category button {
  display: block;
  width: 100%;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 6px;
  padding: 6px 10px;
  color: #ccc;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  text-align: left;
  margin-bottom: 3px;
  transition: all 0.15s;
}

.patterns-category button:hover {
  background: rgba(100, 180, 255, 0.12);
  border-color: rgba(100, 180, 255, 0.25);
  color: #fff;
}

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 200;
  justify-content: center;
  align-items: center;
}

.modal-overlay.open { display: flex; }

.modal {
  background: #14141e;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 28px 32px;
  width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 24px 80px rgba(0,0,0,0.7);
}

.modal h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
  color: #fff;
}

.modal label {
  display: block;
  font-size: 11px;
  color: #777;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.modal .rule-input {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.modal .rule-input input {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 8px 12px;
  color: #e0e0e0;
  font-family: inherit;
  font-size: 14px;
}

.modal .rule-input input:focus {
  outline: none;
  border-color: rgba(100, 180, 255, 0.4);
}

.modal .checkboxes {
  display: flex;
  gap: 3px;
  margin-bottom: 20px;
}

.modal .checkboxes .cb {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1;
}

.modal .checkboxes .cb label {
  margin: 0;
  font-size: 10px;
  color: #555;
}

.modal .checkboxes .cb input[type="checkbox"] {
  width: 26px;
  height: 26px;
  accent-color: #6ab4ff;
  cursor: pointer;
}

.modal .section { margin-bottom: 20px; }

.modal .section h3 {
  font-size: 12px;
  font-weight: 500;
  color: #999;
  margin-bottom: 10px;
}

.modal .presets {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  margin-bottom: 20px;
}

.modal .presets button {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 8px 10px;
  color: #ccc;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
}

.modal .presets button:hover {
  background: rgba(100, 180, 255, 0.1);
  border-color: rgba(100, 180, 255, 0.3);
}

.modal .presets button .preset-rule {
  font-size: 10px;
  color: #555;
  display: block;
  margin-top: 2px;
}

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

.modal .actions button {
  padding: 8px 20px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: all 0.15s;
}

.modal .actions .btn-cancel {
  background: transparent;
  color: #888;
}

.modal .actions .btn-apply {
  background: rgba(100, 180, 255, 0.2);
  color: #8cc8ff;
  border-color: rgba(100, 180, 255, 0.3);
}

.modal .actions .btn-apply:hover {
  background: rgba(100, 180, 255, 0.3);
}

.visual-grid {
  display: grid;
  grid-template-columns: repeat(3, 18px);
  grid-template-rows: repeat(3, 18px);
  gap: 1px;
  margin: 0 auto;
  width: fit-content;
}

.visual-cell {
  width: 18px;
  height: 18px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.visual-cell.neighbor {
  background: rgba(255, 255, 255, 0.3);
  border-color: rgba(255, 255, 255, 0.4);
}

.visual-cell.center-birth {
  background: #6aff8a;
  border-color: #6aff8a;
  box-shadow: 0 0 8px rgba(106, 255, 138, 0.4);
}

.visual-cell.center-dead {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.08);
}

.visual-cell.center-survive {
  background: #6ab4ff;
  border-color: #6ab4ff;
  box-shadow: 0 0 8px rgba(106, 180, 255, 0.4);
}

.visual-cell.center-die {
  background: rgba(255, 100, 100, 0.3);
  border-color: rgba(255, 100, 100, 0.4);
}

.visual-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 6px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}

.visual-item:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.15);
  transform: translateY(-1px);
}

.visual-item.active {
  border-color: rgba(106, 255, 138, 0.3);
  background: rgba(106, 255, 138, 0.05);
}

.visual-item.active.survival-active {
  border-color: rgba(106, 180, 255, 0.3);
  background: rgba(106, 180, 255, 0.05);
}

.visual-item.inactive {
  opacity: 0.5;
}

.visual-label {
  font-size: 10px;
  color: #888;
  text-align: center;
}

.visual-label.active-label {
  color: #6aff8a;
  font-weight: 600;
}

.visual-label.survive-label {
  color: #6ab4ff;
  font-weight: 600;
}

.modal-shortcuts {
  width: 380px;
}

.shortcuts-modal-content {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 16px;
  font-size: 13px;
}

.shortcuts-modal-content kbd {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  padding: 2px 8px;
  font-family: inherit;
  font-size: 12px;
  color: #e0e0e0;
  white-space: nowrap;
}

.shortcuts-modal-content .shortcut-desc {
  color: #999;
}
