* { box-sizing: border-box; }

:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #f3f7f3;
  background: #111613;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top, #29382f 0%, #111613 58%);
}

button { font: inherit; }
button:focus-visible { outline: 3px solid #c7f0a8; outline-offset: 2px; }

.hidden { display: none !important; }

.primary,
.secondary {
  border: 1px solid rgba(255,255,255,.13);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
}

.primary {
  background: #a8df8b;
  color: #122016;
  font-weight: 750;
}

.secondary {
  background: #252e29;
  color: #f3f7f3;
}

.primary:hover,
.secondary:hover { filter: brightness(1.08); }

.big {
  min-width: 145px;
  padding: 13px 18px;
  font-size: 1.05rem;
}

.menu-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 20%, rgba(76, 127, 88, .34), transparent 45%),
    #101512;
  z-index: 2000;
}

.menu-card {
  width: min(520px, 94vw);
  padding: 32px;
  text-align: center;
  border-radius: 20px;
  border: 1px solid rgba(255,255,255,.11);
  background: #18201c;
  box-shadow: 0 26px 90px rgba(0,0,0,.48);
}

.menu-card h1 {
  margin: 8px 0 8px;
  font-size: clamp(2rem, 7vw, 3.4rem);
}

.menu-card p {
  color: #b6c2ba;
  line-height: 1.55;
}

.menu-card small { color: #839087; }

.menu-icon { font-size: 2rem; }

.menu-buttons {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 22px 0 16px;
}

.app {
  width: min(1180px, 96vw);
  margin: 0 auto;
  padding: 24px 0 40px;
}

.topbar,
.hud,
.layout,
.panel,
.game-wrap {
  border: 1px solid rgba(255,255,255,.08);
  background: rgba(14, 18, 16, .88);
  box-shadow: 0 16px 40px rgba(0,0,0,.2);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 20px;
  border-radius: 16px;
}

.topbar h1 { margin: 0 0 4px; }
.subtitle { margin: 0; color: #aab7af; }

.top-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.hud {
  margin-top: 14px;
  border-radius: 14px;
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.stat {
  background: rgba(255,255,255,.035);
  padding: 10px 12px;
  border-radius: 10px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.stat span { color: #9eaaa3; }
.stat strong { font-size: 1.15rem; }

.layout {
  margin-top: 14px;
  padding: 14px;
  border-radius: 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 14px;
}

.game-wrap {
  padding: 16px;
  border-radius: 12px;
  overflow: auto;
}

.message {
  min-height: 24px;
  margin-bottom: 12px;
  color: #d4ded8;
}

.tutorial-panel {
  width: min(620px, 100%);
  margin-bottom: 14px;
  padding: 13px 15px;
  border-radius: 12px;
  border: 1px solid rgba(199, 240, 168, .33);
  background: rgba(54, 84, 59, .48);
}

.tutorial-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  color: #e2f5d8;
}

.tutorial-panel p {
  margin: 0 0 10px;
  color: #d3ddd6;
  line-height: 1.5;
}

.grid {
  --size: 12;
  display: grid;
  grid-template-columns: repeat(var(--size), 42px);
  grid-template-rows: repeat(var(--size), 42px);
  gap: 3px;
  width: max-content;
  user-select: none;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 7px;
  font-size: 22px;
  transition: transform .08s ease, filter .08s ease, box-shadow .12s ease;
}

.cell.dry { background: #705033; cursor: not-allowed; }
.cell.green { background: #518d49; cursor: pointer; }
.cell.water { background: #3b7da6; cursor: default; }
.cell.fire { box-shadow: inset 0 0 0 3px #f59a3e; }

.cell.buildable {
  outline: 2px solid rgba(191, 237, 146, .55);
  outline-offset: -3px;
}

.cell.buildable:hover {
  transform: translateY(-1px);
  filter: brightness(1.1);
  outline-color: #d4ffac;
}

.cell.tutorial-target {
  animation: tilePulse .8s ease-in-out infinite alternate;
}

@keyframes tilePulse {
  from { box-shadow: 0 0 0 1px rgba(204, 246, 166, .12); }
  to { box-shadow: 0 0 0 6px rgba(204, 246, 166, .56); }
}

.building { position: relative; z-index: 2; }

.flame {
  position: absolute;
  z-index: 3;
  top: -5px;
  right: 2px;
  font-size: 20px;
}

.panel {
  border-radius: 12px;
  padding: 16px;
}

.panel h2 {
  margin: 12px 0 10px;
  font-size: 1rem;
}

.panel h2:first-child { margin-top: 0; }

.build {
  width: 100%;
  display: grid;
  gap: 4px;
  margin-bottom: 8px;
  padding: 10px 12px;
  text-align: left;
  cursor: pointer;
  color: #f3f7f3;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.09);
  background: #202824;
}

.build.active {
  outline: 2px solid #8ad47f;
  background: #29372f;
}

.build.tutorial-target {
  animation: buildPulse .8s ease-in-out infinite alternate;
}

@keyframes buildPulse {
  from { box-shadow: 0 0 0 0 rgba(204,246,166,.12); }
  to { box-shadow: 0 0 0 5px rgba(204,246,166,.42); }
}

.build small {
  color: #abb7b0;
  line-height: 1.35;
}

ul {
  padding-left: 20px;
  color: #aeb9b3;
  line-height: 1.5;
}

.log {
  height: 170px;
  overflow: auto;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.07);
  background: rgba(0,0,0,.16);
  color: #aeb9b3;
  font-size: .86rem;
}

.log div { margin-bottom: 5px; }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(5,8,6,.8);
  backdrop-filter: blur(7px);
}

.modal {
  width: min(440px, 94vw);
  padding: 24px;
  text-align: center;
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,.12);
  background: #18201c;
  box-shadow: 0 24px 80px rgba(0,0,0,.46);
}

.modal h2 { margin: 0 0 8px; }
.modal p { color: #b6c1bb; }
.modal small { color: #839087; }

.modal-icon {
  margin-bottom: 8px;
  font-size: 2rem;
}

.modal-actions {
  display: flex;
  gap: 9px;
  justify-content: center;
  margin: 18px 0 12px;
}

.modal-actions.stacked { flex-direction: column; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .hud { grid-template-columns: repeat(2, minmax(0,1fr)); }
}

@media (max-width: 560px) {
  .menu-buttons { flex-direction: column; }
  .topbar { align-items: flex-start; }
  .grid {
    grid-template-columns: repeat(var(--size), 36px);
    grid-template-rows: repeat(var(--size), 36px);
  }
  .cell { font-size: 19px; }
}
