:root {
  --bg-color: #0f1115;
  --card-bg: rgba(30, 34, 42, 0.6);
  --card-border: rgba(255, 255, 255, 0.1);
  --accent: #3b82f6;
  --accent-glow: rgba(59, 130, 246, 0.3);
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --grid-gap: 0px;
  --slot-size: 100px;
  --slot-bg: rgba(255, 255, 255, 0.03);
  --slot-hover: rgba(255, 255, 255, 0.08);

  --font-main: 'Outfit', sans-serif;
}

* {
  box-sizing: border-box;
  user-select: none;
  /* Prevent text selection during drag */
}

body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-color);
  color: var(--text-primary);
  font-family: var(--font-main);
  overflow: hidden;
  /* Prevent body scroll, we handle it internally */
  height: 100vh;
  width: 100vw;
  background-image:
    radial-gradient(circle at 10% 20%, rgba(59, 130, 246, 0.15) 0%, transparent 20%),
    radial-gradient(circle at 90% 80%, rgba(139, 92, 246, 0.15) 0%, transparent 20%);
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* --- Resource Bar (Top 15%) --- */
#resource-bar {
  height: 15vh;
  display: flex;
  align-items: center;
  padding: 0 1rem;
  gap: 1rem;
  overflow-x: auto;
  background: rgba(15, 17, 21, 0.8);
  border-bottom: 1px solid var(--card-border);
  backdrop-filter: blur(10px);
  scrollbar-width: thin;
  scrollbar-color: var(--accent) transparent;
}

.resource-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  min-width: 80px;
  padding: 0.5rem;
  transition: transform 0.2s;
}

.resource-item:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}

.resource-icon {
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
}

.resource-count {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-primary);
}

.resource-name {
  font-size: 0.7rem;
  color: var(--text-secondary);
}

.resource-rate {
  font-size: 0.75rem;
  color: #94a3b8;
  /* Grey / Secondary Text */
  margin-top: 2px;
  font-family: monospace;
}
/* --- Game Grid (Middle 45%) --- */
#game-container {
  flex: 1;
  /* Fills remaining space */
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

#grid-container {
  padding: 2rem;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 24px;
  border: 1px solid var(--card-border);
  box-shadow: 0 0 50px rgba(0, 0, 0, 0.3);
}

#game-grid {
  display: grid;
  grid-template-columns: repeat(3, var(--slot-size));
  grid-template-rows: repeat(3, var(--slot-size));
  gap: var(--grid-gap);
}

.grid-slot {
  width: var(--slot-size);
  height: var(--slot-size);
  background: var(--slot-bg);
  border-radius: 16px;
  border: 2px dashed var(--card-border);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  position: relative;
}

.grid-slot.drag-over {
  background: var(--slot-hover);
  border-color: var(--accent);
  transform: scale(1.05);
}

.building {
  width: 90%;
  height: 90%;
  background: linear-gradient(135deg, #334155 0%, #1e293b 100%);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: grab;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.building:active {
  cursor: grabbing;
}

.building-emoji {
  font-size: 2rem;
}

.building-level {
  position: absolute;
  bottom: -5px;
  right: -5px;
  background: var(--accent);
  color: white;
  font-size: 0.7rem;
  font-weight: bold;
  padding: 2px 6px;
  border-radius: 10px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.status-light {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.status-light.green {
  background-color: #10b981;
  box-shadow: 0 0 8px #10b981;
}

.status-light.red {
  background-color: #ef4444;
  box-shadow: 0 0 8px #ef4444;
}
/* --- Buffer Visuals --- */
.buffer-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px;
}

.buffer-side {
  display: flex;
  flex-direction: column;
  gap: 2px;
  height: 100%;
  justify-content: center;
}

.buffer-left {
  align-items: flex-start;
}

.buffer-right {
  align-items: flex-end;
}

.buffer-icon {
  width: 16px;
  height: 16px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 4px;
  padding: 1px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.buffer-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.buffer-count {
  position: absolute;
  right: -4px;
  bottom: -4px;
  font-size: 8px;
  background: #000;
  color: #fff;
  padding: 1px 2px;
  border-radius: 4px;
  line-height: 1;
}
/* --- Shop IO --- */
.shop-item {
  position: relative;
}

.shop-visuals {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  width: 100%;
  gap: 4px;
}

.shop-inputs {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  justify-self: center;
}

.shop-outputs {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  justify-self: center;
}

.io-icon-container {
  position: relative;
  width: 24px;
  height: 24px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 4px;
  padding: 2px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.io-icon {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.io-count {
  position: absolute;
  bottom: -2px;
  right: -2px;
  font-size: 10px;
  font-weight: bold;
  color: white;
  background: rgba(0, 0, 0, 0.8);
  padding: 0 3px;
  border-radius: 4px;
  line-height: 1;
}
/* --- Shop (Bottom ~40%) --- */
#shop-panel {
  height: 35vh;
  /* Adjustable */
  background: rgba(15, 17, 21, 0.95);
  border-top: 1px solid var(--card-border);
  display: flex;
  flex-direction: column;
  backdrop-filter: blur(20px);
  touch-action: pan-y;
    z-index: 50;
}

.tabs-header {
  display: flex;
    background: rgba(0, 0, 0, 0.2);
      border-bottom: 1px solid var(--card-border);
}

.tab-btn {
  flex: 1;
  padding: 1rem;
  text-align: center;
  cursor: pointer;
  color: var(--text-secondary);
  font-weight: 600;
    font-size: 0.9rem;
      transition: all 0.2s;
      border-bottom: 2px solid transparent;
}

.tab-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
}

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: rgba(59, 130, 246, 0.1);
}

.tab-content {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
    user-select: auto;
    overscroll-behavior: auto;
}

.shop-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
      gap: 1rem;
}

.shop-header {
  padding: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  border-bottom: 1px solid var(--card-border);
}

/* ... existing styles ... */
.shop-item {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 180px;
}

.shop-item.finished {
  border-color: #10b981;
  opacity: 0.8;
}

.shop-item h3 {
  margin: 0;
  font-size: 0.9rem;
  text-align: center;
}

.shop-item .desc {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-align: center;
  margin: 0;
  flex: 1;
}

/* ... details panel ... */
.details-panel {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  height: 100%;
}

.details-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--card-border);
}

.big-emoji {
  font-size: 3rem;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 0.5rem;
}

.process-viz {
  display: flex;
  align-items: center;
  justify-content: space-around;
  flex: 1;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 16px;
  padding: 1rem;
}

.io-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.io-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(255, 255, 255, 0.05);
  padding: 0.5rem 1rem;
  border-radius: 8px;
}

.arrow {
  font-size: 2rem;
  opacity: 0.5;
}

.grid-slot.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}
.shop-emoji {
  font-size: 2rem;
}

.shop-cost {
  font-size: 0.8rem;
  color: #fbbf24;
  /* Amber for cost */
  display: flex;
  align-items: center;
  gap: 4px;
}

.shop-btn {
  margin-top: auto;
  width: 100%;
  padding: 6px;
  border-radius: 6px;
  border: none;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.buy-btn {
  background: var(--accent);
  color: white;
}

.buy-btn:hover:not(:disabled) {
  background: #2563eb;
}

.buy-btn:disabled {
  background: rgba(59, 130, 246, 0.2);
  cursor: not-allowed;
  color: rgba(255, 255, 255, 0.3);
}

.unlock-btn {
  background: #8b5cf6;
  color: white;
}

.unlock-btn:hover:not(:disabled) {
  background: #7c3aed;
}

.unlock-btn:disabled {
  background: rgba(139, 92, 246, 0.2);
  cursor: not-allowed;
  color: rgba(255, 255, 255, 0.3);
}

.text-red-500 {
  color: #ef4444;
}

/* --- Responsive Adjustments --- */
@media (max-width: 600px) {
  :root {
    --slot-size: 80px;
  }

  #resource-bar {
    height: auto;
      min-height: min-content;
      padding: 0.25rem;
      gap: 0.25rem;
      overflow-y: hidden;
  }

  #game-container {
    flex: 1;
  }

  #shop-panel {
    height: 30vh;
  }

  .shop-item {
    min-width: 100px;
    padding: 0.5rem;
  }
/* Compact Resources */
.resource-item {
  min-width: 60px;
  padding: 0.25rem;
  margin: 0.25rem;
  border-radius: 8px;
}

.resource-icon-img {
  width: 20px;
  height: 20px;
}

.resource-count {
  font-size: 0.8rem;
}

.resource-name {
  font-size: 0.55rem;
  line-height: 1;
}

/* Compact Tabs */
.tab-btn {
  padding: 0.5rem 0.2rem;
  font-size: 0.75rem;
  white-space: nowrap;
}
}
/* --- Images --- */
img {
  image-rendering: pixelated;
  user-select: none;
  -webkit-user-drag: none;
}

.resource-icon-img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  margin-bottom: 0.25rem;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

.building-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 5px;
  /* Padding for border/glow space */
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.5));
}

.shop-item-img {
  width: 64px;
  height: 64px;
  object-fit: contain;
  margin-bottom: 0.5rem;
}

.icon-small {
  width: 16px;
  height: 16px;
  vertical-align: middle;
}

.icon-medium {
  width: 24px;
  height: 24px;
  vertical-align: middle;
}

.big-img {
  width: 80px;
  height: 80px;
  object-fit: contain;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 0.5rem;
}

.cost-span {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.status-light.yellow {
  background-color: #eab308;
  box-shadow: 0 0 8px #eab308;
}

.fractal-action-btn {
  position: absolute;
  bottom: 15%;
  left: 50%;
  transform: translateX(-50%);
  width: 25%;
  height: 25%;
  background-color: #3b82f6;
  /* Blue */
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  cursor: pointer;
  z-index: 10;
  box-shadow: 0 0 10px rgba(59, 130, 246, 0.6);
  transition: transform 0.1s, background-color 0.1s;
}

.fractal-action-btn:hover {
  transform: translateX(-50%) scale(1.1);
  background-color: #2563eb;
}

.fractal-action-btn:active {
  transform: translateX(-50%) scale(0.9);
}

.beacon-action-btn {
  position: absolute;
  bottom: 15%;
  left: 50%;
  transform: translateX(-50%);
  width: 25%;
  height: 25%;
  background-color: #ef4444;
  /* Red */
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  cursor: pointer;
  z-index: 10;
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.6);
  transition: transform 0.1s, background-color 0.1s;
}

.beacon-action-btn:hover {
  transform: translateX(-50%) scale(1.1);
  background-color: #dc2626;
}

.beacon-action-btn:active {
  transform: translateX(-50%) scale(0.9);
}
/* --- Victory Resource --- */
#victory-resource {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #fef3c7 0%, #f59e0b 50%, #b45309 100%);
  border: 2px solid #fffbeb;
  border-radius: 12px;
  min-width: 100px;
  padding: 0.75rem;
  transition: all 0.5s ease;
  box-shadow: 0 0 20px rgba(245, 158, 11, 0.4);
  order: -999;
  /* Force to far left */
  animation: gleam 3s infinite ease-in-out;
}

#victory-resource.hidden {
  display: none !important;
}

@keyframes gleam {
  0% {
    box-shadow: 0 0 15px rgba(245, 158, 11, 0.4);
  }

  50% {
    box-shadow: 0 0 30px rgba(245, 158, 11, 0.8), 0 0 10px rgba(255, 255, 255, 0.8) inset;
  }

  100% {
    box-shadow: 0 0 15px rgba(245, 158, 11, 0.4);
  }
}

#victory-resource .resource-count {
  color: #78350f;
  /* Dark amber text for contrast */
  font-size: 1.2rem;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.4);
}

#victory-resource .resource-name {
  color: #92400e;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
}
/* --- Compact Details Panel --- */
.details-io-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 12px;
  padding: 1rem;
  margin: 0.5rem 0;
  flex: 1;
  min-height: 0;
  /* Allow shrinking */
}

.io-column {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
}

.io-row-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(255, 255, 255, 0.05);
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  /* Pill shape */
  min-width: 120px;
}

.icon-medium-large {
  width: 32px;
  height: 32px;
  object-fit: contain;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.3));
}

.io-text {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}

.arrow-col {
  font-size: 1.5rem;
  opacity: 0.5;
  color: var(--text-secondary);
}

.details-footer {
  margin-top: auto;
  padding-top: 0.5rem;
  width: 100%;
}

.text-primary {
  color: var(--text-primary);
}

.text-red-500 {
  color: #ef4444;
}
#fractal-intro-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(15, 17, 21, 0.95);
    backdrop-filter: blur(10px);
  z-index: 200;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  color: #fff;
    font-family: 'Outfit', sans-serif;
}

#fractal-intro-screen img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

#game-grid {
  touch-action: none;
}

#game-grid {
  touch-action: none;
}

/* --- Action Text (Replaces Buttons) --- */
.action-text {
  font-weight: bold;
  font-size: 0.9rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: auto;
  padding-top: 5px;
  display: block;
  text-align: center;
  line-height: 1.4;
}

.action-text img {
  vertical-align: middle;
  transform: translateY(-2px);
}

.action-text.disabled {
  color: var(--text-secondary);
  opacity: 0.5;
}

.shop-item.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
  /* Prevent clicks if disabled */
}

.shop-item:hover:not(.disabled):not(.finished) {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
}

.shop-item:active:not(.disabled):not(.finished) {
  transform: translateY(0);
}

/* --- Intro Screen --- */
#intro-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(15, 17, 21, 0.95);
  backdrop-filter: blur(10px);
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #fff;
  font-family: 'Outfit', sans-serif;
}

.intro-content {
  text-align: center;
  max-width: 600px;
  padding: 2rem;
  background: rgba(30, 34, 42, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 24px;
  box-shadow: 0 0 50px rgba(59, 130, 246, 0.2);
}

.intro-title {
  font-family: 'Orbitron', sans-serif;
  font-size: 3rem;
  font-weight: 700;
  margin: 0 0 2rem 0;
  background: linear-gradient(135deg, #60a5fa 0%, #3b82f6 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: 4px;
  text-shadow: 0 0 30px rgba(59, 130, 246, 0.5);
}

.intro-steps {
  text-align: left;
  margin-bottom: 2rem;
  padding-left: 1.5rem;
  font-size: 1.1rem;
  line-height: 1.6;
  color: #e2e8f0;
}

.intro-steps li {
  margin-bottom: 0.5rem;
}

.intro-subtext {
  font-size: 0.9rem;
  color: #94a3b8;
  margin-bottom: 2rem;
  font-style: italic;
  padding: 0 1rem;
}

.tap-hint {
  font-family: 'Orbitron', sans-serif;
  font-size: 1.2rem;
  color: #60a5fa;
  animation: pulse 2s infinite;
  text-transform: uppercase;
  letter-spacing: 2px;
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }

  50% {
    opacity: 0.5;
    transform: scale(0.95);
  }
}

@media (max-width: 600px) {
  .intro-title {
    font-size: 2rem;
  }

  .intro-content {
    width: 90%;
    padding: 1.5rem;
  }

  .intro-steps {
    font-size: 1rem;
  }
}