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

body {
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #1a1a2e;
  color: #eee;
  min-height: 100vh;
  display: flex;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: 500px;
  padding: 1rem;
}

/* Header */
header {
  text-align: center;
  margin-bottom: 1rem;
}

header h1 {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}

/* Food Chain Drawer */
#drawer-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 90;
}

#drawer-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

#food-chain-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 90%;
  max-width: 400px;
  background: #252535;
  box-shadow: -2px 0 20px rgba(0, 0, 0, 0.3);
  transform: translateX(100%);
  transition: transform 0.2s ease-out;
  z-index: 100;
  overflow-y: auto;
  padding: 1.5rem;
}

#food-chain-drawer.open {
  transform: translateX(0);
}

#food-chain-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid #333;
  position: sticky;
  top: -1.5rem;
  background: #252535;
  padding-top: 1.5rem;
  margin-top: -1.5rem;
  z-index: 1;
}

#food-chain-header h2 {
  font-size: 1.25rem;
  color: #fff;
}

#food-chain-close {
  background: none;
  border: none;
  color: #999;
  font-size: 2rem;
  cursor: pointer;
  padding: 0;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s;
  line-height: 1;
}

#food-chain-close:hover {
  color: #fff;
}

.chain-section {
  font-size: 0.6rem;
  color: #555;
  text-align: center;
  margin-top: 0.5rem;
  margin-bottom: 0.15rem;
}

.chain-section:first-of-type {
  margin-top: 1.5rem;
}

.chain-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.1rem;
  margin: 0.2rem 0;
  font-size: 1.4rem;
}

.chain-arrow {
  color: #555;
  font-size: 0.8rem;
  margin: 0 0.15rem;
}

.chain-item {
  opacity: 0.3;
  transition: opacity 0.3s;
}

.chain-item.achieved {
  opacity: 1;
}

/* Help Section */
.help-section {
  margin-bottom: 1.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid #333;
}

.help-section h3 {
  color: #fff;
  font-size: 1rem;
  margin-bottom: 0.75rem;
}

.help-section h4 {
  color: #ccc;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
  font-weight: 500;
}

/* Ecosystem Guide spacing */
.help-section:has(#guide-does) {
  margin-top: 2rem;
}

.guide-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
  color: #ccc;
  font-size: 0.9rem;
}

.guide-row select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background: #1a1a2e;
  background-image: url('data:image/svg+xml;charset=UTF-8,%3csvg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12"%3e%3cpath fill="%23999" d="M6 9L1 4h10z"/%3e%3c/svg%3e');
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  background-size: 12px;
  color: #fff;
  border: 1px solid #444;
  border-radius: 4px;
  padding: 0.4rem 2rem 0.4rem 0.6rem;
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 0.2s;
}

.guide-row select:hover {
  border-color: #666;
}

.guide-row select:focus {
  outline: none;
  border-color: #888;
}

.guide-expl {
  color: #999;
  font-size: 0.85rem;
  font-style: italic;
  line-height: 1.4;
}

.help-section p {
  color: #aaa;
  font-size: 0.85rem;
  line-height: 1.5;
  margin-bottom: 0.5rem;
}

.help-section p strong {
  color: #ccc;
}

.help-section a {
  color: #777;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-decoration-color: #555;
  text-underline-offset: 2px;
  transition:
    color 0.2s,
    text-decoration-color 0.2s;
}

.help-section a:hover {
  color: #aaa;
  text-decoration-style: solid;
  text-decoration-color: #888;
}

/* Board */
#board-container {
  width: 100%;
  aspect-ratio: 1;
  margin-bottom: 1rem;
}

#board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  gap: 2px;
  width: 100%;
  height: 100%;
  background: #333;
  border-radius: 8px;
  overflow: hidden;
}

.cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition:
    transform 0.1s,
    box-shadow 0.1s;
  position: relative;
}

.cell:active {
  transform: scale(0.95);
}

.cell.selected {
  box-shadow: inset 0 0 0 3px #fff;
}

.emoji {
  font-size: clamp(1.2rem, 5vw, 2rem);
  line-height: 1;
}

.hunger-bar {
  position: absolute;
  bottom: 2px;
  left: 50%;
  transform: translateX(-50%);
  width: 80%;
  height: 4px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 2px;
  overflow: hidden;
}

.hunger-fill {
  height: 100%;
  background: linear-gradient(90deg, #ffeb3b 0%, #ff9800 50%, #ff6b6b 100%);
  transition: width 0.3s ease;
  border-radius: 2px;
}

/* Info Panel */
#info-panel {
  background: #252535;
  border-radius: 8px;
  padding: 0.75rem;
  margin-bottom: 0.75rem;
  min-height: 60px;
}

#info-content {
  font-size: 0.9rem;
  line-height: 1.5;
  color: #ccc;
}

#info-content strong {
  color: #fff;
  font-size: 1rem;
}

.eats-label {
  font-size: 1rem;
  display: block;
  margin-top: 0.25rem;
}

.info-line {
  font-size: 0.9rem;
  color: #ccc;
}

.zone-square {
  display: inline-block;
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 2px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  vertical-align: middle;
}

.action-tag {
  display: inline-block;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
  margin-left: 0.5rem;
}

.action-tag.merge {
  background: #2d5a27;
  color: #8f8;
}

.action-tag.reproduce {
  background: #4a3a6a;
  color: #c8b8f8;
}

.action-tag.move {
  background: #3a4a5a;
  color: #a8c8f8;
}

.action-tag.terminal {
  background: #4a4a4a;
  color: #999;
}

.learn-more-link {
  color: #777;
  text-decoration: none;
  font-size: 0.85rem;
  transition: color 0.2s;
  display: inline-block;
  margin-top: 0.25rem;
}

.learn-more-link:hover {
  color: #aaa;
  text-decoration: underline;
}

.move-indicator {
  font-size: 0.7rem;
  color: #666;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Controls */
#controls {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

#controls button {
  flex: 1;
  padding: 0.75rem;
  font-size: 1rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
  font-weight: 500;
}

#controls button {
  background: #3a3a4a;
  color: #ccc;
}

#controls button:hover:not(:disabled) {
  background: #4a4a5a;
  color: #eee;
}

#skip-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Footer */
footer {
  text-align: center;
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid #333;
}

footer p {
  font-size: 0.8rem;
  color: #666;
}

footer a {
  color: #777;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-decoration-color: #555;
  text-underline-offset: 2px;
  transition:
    color 0.2s,
    text-decoration-color 0.2s;
}

footer a:hover {
  color: #aaa;
  text-decoration-style: solid;
  text-decoration-color: #888;
}

/* Event Log */
#event-log {
  position: relative;
  background: #252535;
  border-radius: 8px;
  padding: 0.75rem;
  max-height: 20vh;
  overflow-y: auto;
}

/* Log Header (score + goal meter) */
#log-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #333;
  font-size: 0.9rem;
}

#copy-log-btn {
  position: absolute;
  top: 0.25rem;
  right: 0.25rem;
  background: none;
  border: none;
  color: #666;
  cursor: pointer;
  padding: 0.25rem;
  width: 1.5rem;
  height: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition:
    color 0.2s,
    background 0.2s;
  opacity: 0;
  z-index: 10;
}

#event-log:hover #copy-log-btn {
  opacity: 1;
}

#copy-log-btn:hover {
  color: #aaa;
  background: #333;
}

#copy-log-btn:active {
  transform: scale(0.95);
}

#copy-log-btn svg {
  width: 100%;
  height: 100%;
}

#points {
  color: #eee;
  font-weight: 500;
}

#victory-badge {
  color: #ffd700;
  font-weight: 600;
  font-size: 1.2rem;
  margin-top: 0.5rem;
  animation: victoryPulse 2s ease-in-out infinite;
}

#victory-badge.hidden {
  display: none;
}

@keyframes victoryPulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
}

#goal-meter {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 1.1rem;
  margin-left: auto;
}

.goal-item {
  opacity: 0.3;
  transition: opacity 0.3s;
}

.goal-item.achieved {
  opacity: 1;
}

.goal-item.dragon {
  font-size: 1.3rem;
}

/* Dragon progress states */
/* 50-75% progress - warming up */
.goal-item.dragon-heating {
  opacity: 0.6;
  filter: brightness(1.1);
}

/* 75%+ progress - getting hot */
.goal-item.dragon-hot {
  opacity: 0.85;
  filter: brightness(1.3);
  animation: dragonPulse 2s ease-in-out infinite;
}

/* 100% progress - ready to win! */
.goal-item.dragon-ready {
  opacity: 1;
  filter: brightness(1.5);
  animation: dragonGlow 1.5s ease-in-out infinite;
}

@keyframes dragonPulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.85;
  }
  50% {
    transform: scale(1.05);
    opacity: 1;
  }
}

@keyframes dragonGlow {
  0%,
  100% {
    transform: scale(1);
    filter: brightness(1.5) drop-shadow(0 0 2px #ffd700);
  }
  50% {
    transform: scale(1.1);
    filter: brightness(1.7) drop-shadow(0 0 4px #ffd700);
  }
}

.goal-arrow {
  color: #555;
  font-size: 0.8rem;
  margin: 0 0.1rem;
}

#events {
  position: relative;
  font-size: 0.85rem;
  line-height: 1.4;
}

.turn-group {
  margin-bottom: 0.75rem;
  animation: fadeIn 0.3s;
}

.turn-header {
  font-weight: 600;
  color: #888;
  font-size: 0.75rem;
  margin-bottom: 0.25rem;
  text-transform: uppercase;
}

.event {
  padding: 0.15rem 0;
  padding-left: 0.5rem;
  border-left: 2px solid #444;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Overlay */
#overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

#overlay.hidden {
  display: none;
}

#overlay-content {
  background: #252535;
  padding: 2rem;
  border-radius: 16px;
  text-align: center;
  max-width: 300px;
}

#overlay-title {
  font-size: 1.5rem;
  margin-bottom: 1rem;
}

#overlay-message {
  color: #aaa;
  margin-bottom: 1.5rem;
}

#overlay-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

#overlay-buttons button {
  border: none;
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.2s;
}

.btn-primary {
  background: #2d5a27;
  color: #fff;
}

.btn-primary:hover {
  background: #3d7a37;
}

.btn-secondary {
  background: #3a3a4a;
  color: #ccc;
}

.btn-secondary:hover {
  background: #4a4a5a;
  color: #eee;
}

/* Loading */
#loading {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #1a1a2e;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

#loading.hidden {
  display: none;
}

#loading p {
  font-size: 1.2rem;
  color: #aaa;
}

/* Responsive */
@media (min-width: 600px) {
  #app {
    padding: 2rem;
  }

  header h1 {
    font-size: 2rem;
  }
}

/* Desktop: allow playing while help drawer is open */
@media (min-width: 900px) {
  #drawer-overlay.open {
    opacity: 0;
    pointer-events: none;
  }
}
