* {
  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;
  gap: 32px;
  padding: 0 24px 48px;
  background:
    radial-gradient(ellipse at top, #1a0a14 0%, transparent 60%),
    radial-gradient(ellipse at bottom, #0d0a1a 0%, #050505 70%);
  overflow-y: auto;
}

#hero-banner {
  width: 100%;
  max-width: 1100px;
  margin-top: 28px;
  position: relative;
  border-radius: 18px;
  overflow: hidden;
  box-shadow:
    0 12px 60px rgba(120, 30, 30, 0.35),
    0 4px 24px rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

#hero-banner img {
  display: block;
  width: 100%;
  height: auto;
}

#hero-banner::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, transparent 65%, rgba(5, 5, 5, 0.7) 100%);
  pointer-events: none;
}

#world-selector .subtitle {
  font-size: 15px;
  color: #888;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  margin-top: -4px;
}

#world-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  width: 100%;
  max-width: 1100px;
}

.world-card {
  position: relative;
  background: linear-gradient(160deg, rgba(28, 12, 18, 0.85), rgba(12, 12, 22, 0.85));
  border: 1px solid rgba(160, 90, 90, 0.25);
  border-radius: 14px;
  padding: 24px 26px;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
  overflow: hidden;
}

.world-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(180, 60, 60, 0.08), transparent 60%);
  pointer-events: none;
}

.world-card:hover {
  border-color: rgba(220, 140, 100, 0.65);
  background: linear-gradient(160deg, rgba(50, 18, 22, 0.95), rgba(18, 14, 26, 0.95));
  transform: translateY(-3px);
  box-shadow:
    0 10px 30px rgba(180, 60, 60, 0.25),
    0 2px 8px rgba(0, 0, 0, 0.4);
}

.world-card h2 {
  font-size: 21px;
  color: #f0e6d8;
  margin-bottom: 8px;
  letter-spacing: 0.5px;
}

.world-card p {
  font-size: 13.5px;
  color: #999;
  line-height: 1.55;
}

.world-tile-count {
  display: inline-block;
  margin-top: 14px;
  padding: 4px 12px;
  background: rgba(180, 90, 90, 0.15);
  border: 1px solid rgba(180, 90, 90, 0.3);
  border-radius: 10px;
  font-size: 11.5px;
  color: #c8a890;
  letter-spacing: 0.5px;
}

#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:not(:disabled) {
  background: #ff9b9b;
  transform: scale(1.1);
  box-shadow: 0 6px 30px rgba(255, 124, 124, 0.6);
}

.tile-pending .puzzle-btn.auto:disabled {
  background: #555;
  color: #888;
  cursor: not-allowed;
  box-shadow: none;
  opacity: 0.6;
}

#coin-display {
  position: fixed;
  top: 12px;
  right: 16px;
  font-size: 16px;
  font-weight: 600;
  color: #ffd966;
  z-index: 100;
  padding: 6px 14px;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 217, 102, 0.3);
  border-radius: 10px;
  backdrop-filter: blur(8px);
  letter-spacing: 0.3px;
  pointer-events: none;
  user-select: none;
}

#coin-display.coin-pulse {
  animation: coin-pulse 0.6s ease-out;
}

@keyframes coin-pulse {
  0% { transform: scale(1); color: #ffd966; }
  30% { transform: scale(1.25); color: #fff7c2; }
  100% { transform: scale(1); color: #ffd966; }
}

/* --- 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 .reward {
  font-size: 28px;
  font-weight: bold;
  color: #ffd966;
  letter-spacing: 1px;
}

#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;
}

/* --- Keyword Picker Modal --- */
.kw-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5000;
  font-family: monospace;
}

.kw-modal {
  background: #15151f;
  border: 1px solid #3a3a4a;
  border-radius: 12px;
  padding: 24px;
  max-width: 520px;
  width: 92vw;
  max-height: 80vh;
  overflow-y: auto;
  color: #e0e0e0;
  box-shadow: 0 0 40px rgba(124, 124, 255, 0.2);
}

.kw-modal h2 {
  margin: 0 0 6px;
  font-size: 18px;
  color: #9b9bff;
}

.kw-modal .kw-sub {
  margin: 0 0 18px;
  font-size: 13px;
  color: #888;
}

.kw-cat {
  margin-bottom: 16px;
}

.kw-cat-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #aaa;
  margin-bottom: 6px;
}

.kw-tokens {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.kw-token {
  background: #1f1f2e;
  border: 1px solid #3a3a4a;
  border-radius: 14px;
  padding: 5px 12px;
  cursor: pointer;
  font-size: 13px;
  color: #ccc;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  user-select: none;
}

.kw-token:hover {
  background: #2a2a3a;
  border-color: #5a5a7a;
}

.kw-token.selected {
  background: #7c7cff;
  border-color: #9b9bff;
  color: #0a0a0a;
  font-weight: bold;
}

.kw-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.kw-btn {
  background: #2a2a3a;
  color: #ddd;
  border: 1px solid #3a3a4a;
  border-radius: 8px;
  padding: 8px 18px;
  font-family: monospace;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.12s;
}

.kw-btn:hover {
  background: #3a3a4a;
}

.kw-btn.primary {
  background: #7c7cff;
  color: #0a0a0a;
  border-color: #7c7cff;
  font-weight: bold;
}

.kw-btn.primary:hover {
  background: #9b9bff;
}
