:root {
  color-scheme: dark;
  --ink: #f7ffe9;
  --muted: #c5d2a6;
  --panel: rgba(21, 31, 26, 0.84);
  --line: rgba(255, 255, 255, 0.18);
  --leaf: #7ac943;
  --apple: #f24f43;
  --gold: #f2cb54;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #132018;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: var(--gold);
  color: #1d230f;
  cursor: pointer;
  font: inherit;
  font-weight: 900;
  padding: 0.68rem 0.85rem;
  box-shadow: 0 5px 0 #7d6b23;
}

button:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #7d6b23;
}

.game-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  isolation: isolate;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(circle at 50% 10%, rgba(122, 201, 67, 0.12), transparent 34%),
    linear-gradient(180deg, #1e3226 0%, #142119 58%, #0d130f 100%);
}

.biome-bar,
.hud,
.controls,
.leaderboards {
  position: absolute;
  left: clamp(12px, 3vw, 34px);
  right: clamp(12px, 3vw, 34px);
  z-index: 2;
  pointer-events: none;
}

.biome-bar {
  top: 12px;
  left: 50%;
  right: auto;
  transform: translateX(-50%);
  width: min(420px, calc(100vw - 24px));
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0.48rem 0.8rem;
}

.biome-bar strong {
  color: var(--ink);
  font-size: 0.98rem;
  line-height: 1;
}

.hud {
  top: 62px;
  display: grid;
  grid-template-columns: minmax(96px, 0.8fr) minmax(210px, 1fr) minmax(96px, 0.8fr);
  gap: 10px;
  align-items: start;
}

.meter,
.round,
.controls {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(10px);
}

.meter {
  min-height: 60px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0.75rem clamp(0.75rem, 2vw, 1rem);
}

.name {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.score {
  color: var(--ink);
  font-size: 2rem;
  font-weight: 950;
  line-height: 1;
}

.round {
  min-height: 60px;
  border-radius: 8px;
  display: grid;
  align-content: center;
  justify-items: center;
  padding: 0.55rem 0.9rem;
  text-align: center;
}

.round strong {
  font-size: clamp(1.05rem, 2.2vw, 1.55rem);
  line-height: 1.05;
}

.round span {
  color: var(--muted);
  font-size: 0.82rem;
}

.controls {
  right: auto;
  bottom: 16px;
  width: min(680px, calc(100vw - 24px));
  border-radius: 8px;
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  pointer-events: auto;
}

.controls div {
  display: grid;
  grid-template-columns: auto 1fr 1fr;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.controls b {
  color: var(--ink);
  font-size: 0.82rem;
}

.controls span {
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.leaderboards {
  left: auto;
  bottom: 16px;
  width: min(390px, calc(100vw - 24px));
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  pointer-events: auto;
}

.leaderboards div,
.score-dialog form {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(10px);
}

.leaderboards div {
  min-width: 0;
  padding: 10px;
}

.leaderboards h2,
.score-dialog h2 {
  margin: 0 0 8px;
  color: var(--ink);
  font-size: 0.82rem;
  line-height: 1;
  text-transform: uppercase;
}

.leaderboards ol {
  height: 104px;
  margin: 0;
  padding: 0 4px 0 0;
  list-style: none;
  display: grid;
  align-content: start;
  gap: 6px;
  overflow-y: auto;
  scrollbar-color: rgba(242, 203, 84, 0.65) rgba(255, 255, 255, 0.08);
}

.leaderboards li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.15;
}

.leaderboards li span {
  min-width: 0;
  display: flex;
  gap: 6px;
  align-items: baseline;
}

.leaderboards li b {
  color: var(--gold);
  font-size: 0.72rem;
  min-width: 24px;
}

.leaderboards li.empty {
  color: rgba(197, 210, 166, 0.6);
}

.score-dialog {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.42);
}

.score-dialog[hidden] {
  display: none;
}

.score-dialog form {
  width: min(360px, 100%);
  display: grid;
  gap: 10px;
  padding: 16px;
}

.score-dialog p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.score-dialog label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.score-dialog input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  padding: 0.72rem 0.8rem;
  outline: none;
}

.score-dialog input:focus {
  border-color: var(--gold);
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

@media (max-width: 740px) {
  .hud {
    grid-template-columns: 1fr 1fr;
    top: 58px;
  }

  .round {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .meter {
    grid-row: 2;
  }

  .controls {
    grid-template-columns: 1fr auto;
    bottom: 116px;
  }

  .controls div {
    grid-column: 1;
    grid-template-columns: 72px 1fr;
  }

  .controls span:last-child {
    display: none;
  }

  #restartButton {
    grid-column: 2;
    grid-row: 1 / span 2;
    align-self: stretch;
  }

  .leaderboards {
    left: clamp(12px, 3vw, 34px);
    right: clamp(12px, 3vw, 34px);
    bottom: 12px;
    width: auto;
  }
}
