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

body {
  background: #0a0a0a;
  overflow: hidden;
  font-family: monospace;
  color: #ccc;
  user-select: none;
}

.hidden {
  display: none !important;
}

/* --- World Selector --- */

#world-selector {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  background: radial-gradient(ellipse at center, #0d0d2a 0%, #0a0a0a 70%);
}

#world-selector h1 {
  font-size: 48px;
  color: #7c7cff;
  letter-spacing: 4px;
  text-transform: uppercase;
}

#world-selector .subtitle {
  font-size: 16px;
  color: #555;
  margin-bottom: 16px;
}

#world-list {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 900px;
}

.world-card {
  background: #111;
  border: 2px solid #2a2a4e;
  border-radius: 16px;
  padding: 32px 40px;
  min-width: 260px;
  max-width: 360px;
  cursor: pointer;
  transition: all 0.2s;
}

.world-card:hover {
  border-color: #7c7cff;
  background: #1a1a3e;
  transform: translateY(-4px);
  box-shadow: 0 8px 30px rgba(124, 124, 255, 0.2);
}

.world-card h2 {
  font-size: 22px;
  color: #ddd;
  margin-bottom: 8px;
}

.world-card p {
  font-size: 14px;
  color: #777;
  line-height: 1.5;
}

.world-tile-count {
  display: inline-block;
  margin-top: 10px;
  padding: 3px 10px;
  background: rgba(255,255,255,0.08);
  border-radius: 12px;
  font-size: 12px;
  color: #999;
}

#world-name {
  position: fixed;
  top: 12px;
  left: 16px;
  font-size: 16px;
  font-weight: 600;
  color: #ccc;
  cursor: pointer;
  z-index: 100;
  padding: 6px 16px;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  backdrop-filter: blur(8px);
  transition: all 0.2s;
  letter-spacing: 0.3px;
}

#world-name:hover {
  color: #fff;
  background: rgba(80, 80, 200, 0.4);
  border-color: #7c7cff;
}

#world-name:empty {
  display: none;
}

/* --- Explorer Mode --- */

#viewport {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  cursor: grab;
  position: relative;
}

#viewport.dragging {
  cursor: grabbing;
}

#canvas {
  position: absolute;
  top: 0;
  left: 0;
}

.tile {
  position: absolute;
  width: 1024px;
  height: 1024px;
  image-rendering: crisp-edges;
  -webkit-image-rendering: crisp-edges;
}

.tile img {
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  -webkit-user-drag: none;
}

.tile-empty {
  position: absolute;
  width: 1024px;
  height: 1024px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed #333;
}


/* Generating state — tile is being created */
.tile-generating {
  position: absolute;
  width: 1024px;
  height: 1024px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  border: 1px solid #2a2a4e;
  background: radial-gradient(circle, #1a1a3e 0%, #0d0d1a 100%);
}

.generating-spinner {
  width: 64px;
  height: 64px;
  border: 4px solid #2a2a4e;
  border-top-color: #ffcc00;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.generating-label {
  font-size: 20px;
  color: #ffcc00;
  font-family: monospace;
}

/* Pending tile — generated but not revealed */
.tile-pending {
  position: absolute;
  width: 1024px;
  height: 1024px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #2a2a4e;
  background: radial-gradient(circle, #1a1a3e 0%, #0d0d1a 100%);
}

.tile-pending .pending-icon {
  font-size: 120px;
  color: #7c7cff;
  opacity: 0.6;
  animation: pulse 2s ease-in-out infinite;
  user-select: none;
}

.tile-pending .pending-icon.clickable {
  cursor: pointer;
  transition: transform 0.2s, opacity 0.2s;
}

.tile-pending .pending-icon.clickable:hover {
  opacity: 1;
  transform: scale(1.2);
  animation: none;
  filter: drop-shadow(0 0 20px rgba(124, 124, 255, 0.8));
}

@keyframes pulse {
  0%, 100% { opacity: 0.4; transform: scale(0.95); }
  50% { opacity: 0.7; transform: scale(1.05); }
}

#coords {
  position: fixed;
  bottom: 12px;
  right: 16px;
  font-size: 13px;
  color: #555;
  pointer-events: none;
  z-index: 100;
}

#pending-count {
  position: fixed;
  bottom: 12px;
  left: 16px;
  font-size: 13px;
  color: #7c7cff;
  pointer-events: none;
  z-index: 100;
}

.tile-pending {
  flex-direction: column;
  gap: 24px;
}

.tile-pending .puzzle-btn.auto {
  background: #ff7c7c;
  color: #0a0a0a;
  border: none;
  border-radius: 12px;
  padding: 10px 28px;
  font-family: monospace;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 20px rgba(255, 124, 124, 0.4);
  z-index: 10;
}

.tile-pending .puzzle-btn.auto:hover {
  background: #ff9b9b;
  transform: scale(1.1);
  box-shadow: 0 6px 30px rgba(255, 124, 124, 0.6);
}

/* --- Puzzle Mode Overlay --- */

#puzzle-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 1000;
  background: rgba(5, 5, 15, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

#puzzle-container {
  width: 100%;
  height: calc(100vh - 48px);
  position: relative;
}

#puzzle-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Puzzle Toolbar */
#puzzle-toolbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 48px;
  background: #111;
  border-top: 1px solid #333;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  z-index: 1001;
}

#puzzle-toolbar span {
  font-size: 14px;
  color: #aaa;
}

#puzzle-toolbar button {
  background: #222;
  color: #ccc;
  border: 1px solid #444;
  border-radius: 6px;
  padding: 4px 12px;
  font-family: monospace;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}

#puzzle-toolbar button:hover {
  background: #333;
  border-color: #666;
}

#puzzle-toolbar button.active {
  background: #2a2a5e;
  border-color: #7c7cff;
  color: #7c7cff;
}

#puzzle-close-btn {
  margin-left: auto;
  color: #f55 !important;
  border-color: #f55 !important;
}

#puzzle-close-btn:hover {
  background: #f55 !important;
  color: #fff !important;
}

.settings-wrapper {
  position: relative;
}

#settings-dropdown {
  position: absolute;
  bottom: 48px;
  right: 0;
  background: #1a1a1a;
  border: 1px solid #444;
  border-radius: 8px;
  padding: 4px;
  min-width: 150px;
}

.settings-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  border: none !important;
  border-radius: 4px !important;
  padding: 8px 12px !important;
}

.settings-divider {
  height: 1px;
  background: #333;
  margin: 4px 8px;
}

.settings-label {
  font-size: 11px;
  color: #666;
  padding: 4px 12px 2px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.bg-color-row {
  display: flex;
  gap: 4px;
  padding: 4px 8px 6px;
  flex-wrap: wrap;
}

.bg-swatch {
  width: 24px !important;
  height: 24px !important;
  min-width: 24px;
  border-radius: 50% !important;
  border: 2px solid #555 !important;
  padding: 0 !important;
  cursor: pointer;
  transition: all 0.15s;
}

.bg-swatch:hover {
  transform: scale(1.2);
  border-color: #aaa !important;
}

.bg-swatch.active {
  border-color: #7c7cff !important;
  box-shadow: 0 0 8px rgba(124, 124, 255, 0.6);
}

/* Win screen */
#puzzle-win {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 2000;
  background: rgba(5, 5, 15, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
}

#puzzle-win h1 {
  font-size: 48px;
  color: #7c7cff;
}

#puzzle-win .stats {
  font-size: 20px;
  color: #aaa;
}

#puzzle-win button {
  background: #7c7cff;
  color: #0a0a0a;
  border: none;
  border-radius: 16px;
  padding: 14px 40px;
  font-family: monospace;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
}

#puzzle-win button:hover {
  background: #9b9bff;
}
