:root {
  --bg-dark: #113322;
  --bg-mid: #1c5a3f;
  --text: #f4ffe9;
  --panel: rgba(18, 32, 24, 0.85);
  --accent: #8ad16f;
  --producer: #3ea95b;
  --primary: #e6c84a;
  --secondary: #d85b49;
  --decomposer: #8a5a2c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 8%, rgba(176, 255, 120, 0.32), transparent 35%),
    radial-gradient(circle at 82% 12%, rgba(109, 201, 255, 0.24), transparent 38%),
    linear-gradient(160deg, #09311f, #1b6a47 52%, #44a071 88%);
  overflow: hidden;
  position: relative;
}

html,
body {
  width: 100%;
}

body::before {
  content: "🌺🪴";
  position: fixed;
  right: 130px;
  bottom: 18px;
  font-size: 4.8rem;
  line-height: 1;
  opacity: 0.62;
  pointer-events: none;
  z-index: 6;
  filter: drop-shadow(0 4px 4px rgba(0, 0, 0, 0.35));
}

body::after {
  content: "🌴🦜";
  position: fixed;
  right: 10px;
  bottom: 6px;
  font-size: 7.2rem;
  line-height: 1;
  opacity: 0.62;
  pointer-events: none;
  z-index: 6;
  filter: drop-shadow(0 6px 5px rgba(0, 0, 0, 0.35));
}

.hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.start-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  background:
    linear-gradient(rgba(70, 145, 104, 0.35), rgba(23, 63, 43, 0.52)),
    radial-gradient(circle at top left, #8fdf9f 0%, #4f9d73 45%, #2b6a49 100%);
  z-index: 10;
  transition: opacity 0.6s ease;
  overflow: hidden;
}

.start-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}

.start-screen::before {
  content: "";
  position: absolute;
  width: 260px;
  height: 260px;
  top: -70px;
  right: -40px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 244, 170, 0.95) 0%, rgba(255, 214, 94, 0.7) 45%, rgba(255, 200, 88, 0.25) 70%, transparent 78%);
  filter: blur(1px);
  animation: title-sun-glow 2.6s ease-in-out infinite;
}

.start-overlay {
  width: min(900px, 95vw);
  max-height: 92vh;
  overflow: auto;
  background: rgba(238, 255, 228, 0.13);
  border: 1px solid rgba(230, 255, 205, 0.42);
  border-radius: 14px;
  padding: 1.25rem 1.5rem;
  backdrop-filter: blur(5px);
}

h1,
h2 {
  margin-top: 0;
}

.start-overlay h1 {
  text-align: center;
  margin-bottom: 1rem;
}

.start-overlay section {
  margin-bottom: 1rem;
}

.intro-lead {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.5;
}

.key-term {
  font-size: 1.15em;
  font-weight: 800;
  letter-spacing: 0.03em;
  color: #e7ff8f;
}

.start-overlay ul {
  margin: 0.4rem 0 0;
  padding-left: 1.2rem;
}

.rule-highlight {
  display: inline-block;
  padding: 0.05rem 0.28rem;
  border-radius: 6px;
  background: rgba(240, 255, 166, 0.28);
  border: 1px solid rgba(233, 255, 155, 0.45);
  color: #f7ffd0;
  font-weight: 800;
}

.start-btn,
.control-btn {
  border: none;
  border-radius: 10px;
  padding: 0.7rem 1rem;
  font-weight: 700;
  cursor: pointer;
}

.start-btn {
  width: 100%;
  background: var(--accent);
  color: #17311f;
  font-size: 1rem;
}

@keyframes title-sun-glow {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.85;
  }
  50% {
    transform: scale(1.08);
    opacity: 1;
  }
}

.game-container {
  width: 100vw;
  max-width: 100vw;
  margin: 0;
  padding: 0.35rem;
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr);
  grid-template-rows: auto auto auto 1fr auto;
  gap: 0.35rem;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.4s ease;
  height: 100vh;
  max-height: 100vh;
  position: relative;
  z-index: 1;
}

.game-container::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(
      120deg,
      rgba(210, 255, 190, 0.08) 0px,
      rgba(210, 255, 190, 0.08) 2px,
      transparent 2px,
      transparent 12px
    );
  mix-blend-mode: soft-light;
  opacity: 0.5;
}

.game-container::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 10% 88%, rgba(33, 126, 78, 0.32), transparent 25%),
    radial-gradient(circle at 90% 84%, rgba(16, 80, 49, 0.34), transparent 22%);
}

.game-container > h1,
.rule-note,
.controls {
  grid-column: 1 / -1;
}

.rule-note {
  margin: 0;
  font-weight: 700;
  color: #dfffcf;
  font-size: 0.9rem;
}

.ecosystem-grid {
  grid-column: 1 / 2;
  background: var(--panel);
  border-radius: 12px;
  padding: 0.55rem;
  display: grid;
  gap: 0.42rem;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-content: start;
  background:
    linear-gradient(180deg, rgba(20, 64, 42, 0.92), rgba(11, 43, 28, 0.9)),
    radial-gradient(circle at 20% 18%, rgba(120, 255, 130, 0.12), transparent 35%);
}

.organism {
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-radius: 10px;
  min-height: 78px;
  color: #102517;
  font-weight: 700;
  font-size: 0.8rem;
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.2s ease, box-shadow 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  text-align: center;
  line-height: 1.2;
}

.emoji-icon {
  font-size: 1.9rem;
}

.organism-label {
  font-size: 0.72rem;
}

.organism:hover:enabled {
  transform: translateY(-2px);
  filter: brightness(1.1);
  box-shadow: 0 0 0 2px rgba(214, 255, 186, 0.38), 0 7px 14px rgba(0, 0, 0, 0.28);
}

.organism:disabled,
.organism.blocked {
  opacity: 0.5;
  cursor: not-allowed;
}

.organism.vanished {
  visibility: hidden;
}

.sun {
  grid-column: 1 / -1;
  background: radial-gradient(circle at 35% 35%, #fff2b0, #f4cd4d 62%, #deac24);
  box-shadow: 0 0 18px rgba(255, 225, 133, 0.62);
  animation: tropical-sun 2.3s ease-in-out infinite;
}

.producer {
  background: linear-gradient(140deg, #85ee9d 2%, var(--producer) 55%, #2f8d4d 100%);
}

.primary {
  background: linear-gradient(140deg, #f9eb8c 0%, var(--primary) 58%, #cfaa2a 100%);
}

.secondary {
  background: linear-gradient(140deg, #f19180 0%, var(--secondary) 56%, #b34337 100%);
}

.decomposer {
  background: linear-gradient(140deg, #c48f5c 0%, var(--decomposer) 56%, #643d1f 100%);
  color: #f5e9da;
}

.side-panel {
  grid-column: 2 / 3;
  grid-row: 3 / span 2;
  background: linear-gradient(
    180deg,
    rgba(20, 58, 39, 0.95),
    rgba(13, 35, 24, 0.93)
  );
  border-radius: 12px;
  padding: 0.55rem 0.7rem;
  width: 100%;
}

.side-panel p {
  margin: 0.28rem 0;
  font-size: 0.86rem;
}

.process-panel {
  grid-column: 1 / 2;
  margin-bottom: 0.15rem;
  padding: 0.65rem 0.75rem;
  border: 2px solid rgba(210, 255, 198, 0.45);
  border-radius: 12px;
  background: linear-gradient(
    180deg,
    rgba(19, 56, 37, 0.9),
    rgba(13, 35, 24, 0.9)
  );
  min-height: 220px;
  width: 100%;
}

.process-panel h3 {
  margin: 0 0 0.22rem;
  font-size: 0.98rem;
  color: #f0ffd9;
}

.process-hint {
  margin: 0 0 0.45rem;
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.3;
  color: #f8ffdd;
  background: rgba(210, 255, 140, 0.2);
  border: 1px solid rgba(220, 255, 170, 0.45);
  border-radius: 8px;
  padding: 0.35rem 0.45rem;
}

.molecule-board {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.4rem;
  margin-bottom: 0.2rem;
}

.process-btn {
  border: none;
  border-radius: 10px;
  background: linear-gradient(180deg, #ecffd9, #cbf4ae);
  color: #123122;
  font-size: 1rem;
  font-weight: 700;
  padding: 0.5rem 0.3rem;
  min-height: 66px;
  cursor: pointer;
  white-space: normal;
  line-height: 1.15;
  text-align: center;
  overflow-wrap: anywhere;
}

.process-btn.active {
  outline: 2px solid #f8ffd5;
  background: #9de78c;
}

.process-btn.wrong-input {
  background: linear-gradient(180deg, #ffd9c4, #f5c1a3);
}

.management-panel {
  margin-top: 0.45rem;
  padding-top: 0.45rem;
  border-top: 1px solid rgba(255, 255, 255, 0.18);
}

.management-panel h3 {
  margin: 0.05rem 0 0.35rem;
  font-size: 0.85rem;
}

.population-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.28rem;
}

.population-controls {
  display: flex;
  gap: 0.4rem;
}

.manage-btn {
  border: none;
  border-radius: 7px;
  padding: 0.18rem 0.32rem;
  font-size: 0.68rem;
  font-weight: 700;
  cursor: pointer;
  color: #163122;
  background: #d5f4be;
}

.manage-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.remove-btn {
  background: #f4d3b5;
}

#ecosystem-status {
  font-weight: 700;
}

#ecosystem-status.stable {
  color: #8fffa8;
}

#ecosystem-status.unstable {
  color: #ffe67f;
}

#ecosystem-status.blocked {
  color: #ff9d9d;
}

.energy-bar-wrap {
  height: 10px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  overflow: hidden;
}

.energy-bar {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #e6ff7d, #ffc649);
  transition: width 0.3s ease;
}

.message-box {
  margin-top: 0.42rem;
  min-height: 84px;
  background:
    linear-gradient(180deg, rgba(228, 255, 168, 0.3), rgba(186, 221, 119, 0.22));
  border: 2px solid rgba(220, 255, 170, 0.55);
  border-radius: 10px;
  padding: 0.5rem;
  line-height: 1.35;
  font-size: 1rem;
  font-weight: 800;
  color: #f7ffde;
}

@keyframes tropical-sun {
  0%,
  100% {
    box-shadow: 0 0 14px rgba(255, 225, 133, 0.45);
  }
  50% {
    box-shadow: 0 0 26px rgba(255, 225, 133, 0.82);
  }
}

.controls {
  display: flex;
  gap: 0.6rem;
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 9;
}

.control-btn {
  background: #e9ffb8;
  color: #123122;
  padding: 0.95rem 1.35rem;
  font-size: 1.35rem;
  font-weight: 900;
  border-radius: 14px;
  border: 3px solid rgba(18, 49, 30, 0.55);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.3);
}

.secondary-btn {
  background: #f1e4c9;
}

.error-overlay {
  position: fixed;
  inset: 0;
  background: rgba(18, 4, 4, 0.78);
  display: grid;
  place-items: center;
  z-index: 20;
}

.error-card {
  width: min(460px, 92vw);
  background: #3f1212;
  border: 2px solid #ff7777;
  border-radius: 12px;
  padding: 1rem;
  text-align: center;
}

.error-card h2 {
  margin: 0 0 0.6rem;
  color: #ffd4d4;
  font-size: 1.5rem;
  letter-spacing: 0.04em;
}

.error-card p {
  margin: 0 0 0.9rem;
  font-size: 1.05rem;
  color: #fff2f2;
}

.win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(7, 34, 13, 0.8);
  display: grid;
  place-items: center;
  z-index: 21;
}

.win-card {
  width: min(700px, 95vw);
  background: #1f5a2d;
  border: 3px solid #b5ff9e;
  border-radius: 16px;
  padding: 1.6rem 1.2rem;
  text-align: center;
  box-shadow: 0 10px 35px rgba(0, 0, 0, 0.35);
}

.win-card h2 {
  margin: 0 0 0.65rem;
  font-size: 3rem;
  color: #ecffd8;
  letter-spacing: 0.06em;
}

.win-card p {
  margin: 0 0 1rem;
  font-size: 1.25rem;
  color: #f5ffe9;
}

@media (max-width: 850px) {
  body {
    overflow: auto;
  }

  .game-container {
    grid-template-columns: 1fr;
    height: auto;
    max-height: none;
  }

  .controls {
    position: static;
    justify-content: flex-end;
  }

  .process-panel,
  .ecosystem-grid,
  .side-panel {
    grid-column: 1 / -1;
    grid-row: auto;
  }

  .win-card h2 {
    font-size: 2.3rem;
  }
}
