:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #15120d;
  color: #f9f2dc;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  background: #15120d;
}

body {
  position: fixed;
  inset: 0;
  touch-action: none;
}

#app {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
  background: radial-gradient(circle at top, #3d2c1b, #15120d 65%);
}

header {
  position: absolute;
  z-index: 3;
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  right: max(10px, env(safe-area-inset-right));
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  align-items: stretch;
  padding: 10px 12px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(21,18,13,0.82), rgba(21,18,13,0.4));
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  box-shadow: 0 12px 42px rgba(0,0,0,0.22);
}

header > div:first-child {
  min-width: 0;
  flex: 1 1 220px;
}

h1 {
  margin: 0;
  letter-spacing: 0.03em;
  font-size: clamp(24px, 5vw, 44px);
  line-height: 0.95;
  color: #ffd45a;
  text-shadow: 0 4px 0 #5a3513;
}

p { margin: 4px 0; color: #e7d7aa; }
header p { display: none; }

#hud,
#meters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

#hud {
  flex: 0 1 auto;
  justify-content: flex-start;
  min-width: 0;
  width: 100%;
  gap: 6px;
}

#hud span {
  white-space: nowrap;
}

#hud span,
#meters label,
#message,
#roundSummary {
  background: rgba(0, 0, 0, 0.42);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 999px;
  padding: 7px 10px;
}

#meters {
  position: absolute;
  z-index: 3;
  top: calc(max(10px, env(safe-area-inset-top)) + 118px);
  left: max(10px, env(safe-area-inset-left));
  right: max(10px, env(safe-area-inset-right));
  pointer-events: none;
}

meter {
  width: min(24vw, 120px);
  height: 14px;
  vertical-align: middle;
}

#game {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  touch-action: none;
  display: block;
  border: 0;
  border-radius: 0;
  background: #8bd45b;
  box-shadow: none;
}

#panel {
  position: absolute;
  z-index: 3;
  left: max(10px, env(safe-area-inset-left));
  right: max(10px, env(safe-area-inset-right));
  bottom: max(10px, env(safe-area-inset-bottom));
  display: grid;
  gap: 9px;
  max-height: min(46dvh, 330px);
  overflow: auto;
  padding: 10px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(21,18,13,0.34), rgba(21,18,13,0.78));
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  box-shadow: 0 -12px 42px rgba(0,0,0,0.28);
  -webkit-overflow-scrolling: touch;
}

#message {
  border-radius: 14px;
  font-weight: 800;
}

#roundSummary {
  border-radius: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  color: #fff8df;
}

#roundSummary strong {
  color: #ffd45a;
  font-size: 18px;
}

#roundSummary span {
  background: rgba(255, 212, 90, 0.14);
  border-radius: 999px;
  padding: 4px 9px;
}

#foodButtons,
#upgradeButtons,
#speciesButtons {
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x proximity;
  padding-bottom: 2px;
  gap: 9px;
}

#foodButtons button,
#upgradeButtons button,
#speciesButtons button {
  flex: 0 0 clamp(118px, 17vw, 158px);
  scroll-snap-align: start;
}

#speciesButtons button.selected {
  outline: 3px solid #fff8df;
  background: linear-gradient(#94f06e, #44bf52);
}

button {
  border: 0;
  border-radius: 14px;
  padding: 11px 13px;
  color: #241406;
  background: linear-gradient(#ffd45a, #ff9d2e);
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 5px 0 #7f4c12;
}

#fullscreenToggle {
  padding: 8px 10px;
  font-size: 13px;
  white-space: nowrap;
  box-shadow: 0 4px 0 #7f4c12;
}

button:active { transform: translateY(3px); box-shadow: 0 2px 0 #7f4c12; }
button[hidden], [hidden] { display: none !important; }
small { color: #44240a; font-weight: 700; }
footer { display: none; }

@media (max-width: 760px) {
  header {
    gap: 8px;
    padding: 8px;
  }

  header p {
    display: none;
  }

  #hud span,
  #meters label,
  #message,
  #roundSummary {
    font-size: 12px;
    padding: 6px 8px;
  }

  #meters {
    top: calc(max(8px, env(safe-area-inset-top)) + 104px);
  }

  #panel {
    max-height: min(48dvh, 315px);
    padding: 8px;
  }

  #foodButtons,
  #upgradeButtons,
  #speciesButtons {
    gap: 8px;
  }

  #foodButtons button,
  #upgradeButtons button,
  #speciesButtons button {
    flex-basis: 118px;
  }

  button {
    padding: 9px 10px;
    font-size: 12px;
  }

  #fullscreenToggle {
    padding: 7px 9px;
  }
}

@media (max-width: 900px), (max-height: 620px) {
  header p {
    display: none;
  }

  header {
    align-items: stretch;
  }

  #hud span,
  #meters label {
    font-size: 12px;
    padding: 6px 8px;
  }
}

@media (max-width: 520px) {
  h1 { font-size: 24px; }
  #hud { gap: 5px; }
  #hud span:nth-child(2),
  #hud span:nth-child(3) { display: none; }
  meter { width: 82px; }
}
