:root {
  color-scheme: dark;
  --bg: #11150f;
  --panel: #1f2a19;
  --panel-soft: #e9f4cf;
  --panel-text: #12310f;
  --accent: #d5ee6b;
  --accent-strong: #86be3f;
  --line: rgba(255, 255, 255, 0.16);
  font-family: "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top left, #2d3e1e 0, #11150f 42%, #080a07 100%);
  color: #f5f7ed;
  display: grid;
  place-items: center;
}

button,
select {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: #202b1d;
  color: #f5f7ed;
  padding: 0.62rem 0.85rem;
  border-radius: 6px;
  cursor: pointer;
}

button:hover,
button:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.game-shell {
  width: min(1080px, 100vw);
  min-height: min(888px, 100vh);
  display: grid;
  grid-template-rows: auto 1fr;
  position: relative;
  background: #050604;
  border: 1px solid var(--line);
}

.topbar {
  min-height: 48px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: #050604;
  border-bottom: 1px solid var(--line);
}

.level-select {
  display: flex;
  align-items: center;
  gap: 8px;
}

.level-select label {
  color: #c7d5bb;
  font-size: 0.92rem;
}

select {
  min-width: 112px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.55rem 0.7rem;
  background: #202b1d;
  color: #f5f7ed;
}

.play-area {
  display: grid;
  grid-template-columns: 120px minmax(0, 840px) 120px;
  align-items: stretch;
  justify-content: center;
  min-height: 0;
}

.side-panel {
  padding: 15px;
  background-color: var(--panel);
  background-image:
    linear-gradient(45deg, rgba(255, 255, 255, 0.04) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.04) 25%, transparent 25%);
  background-size: 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.square-button {
  width: 100%;
  aspect-ratio: 1;
  font-size: 2rem;
  display: grid;
  place-items: center;
}

#gameCanvas {
  width: min(840px, calc(100vw - 240px));
  aspect-ratio: 1;
  height: auto;
  display: block;
  background: #000;
  image-rendering: crisp-edges;
}

.stats > div {
  min-height: 72px;
  padding: 8px;
  background: var(--panel-soft);
  color: var(--panel-text);
  display: grid;
  place-items: center;
  text-align: center;
}

.stats span {
  font-size: 1rem;
}

.stats strong {
  font-size: 1.25rem;
}

.keys {
  min-height: 54px;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
}

.keys img {
  width: 34px;
  height: 34px;
  object-fit: contain;
}

.message-panel {
  position: absolute;
  inset: 48px 120px 0 120px;
  background: rgba(5, 6, 4, 0.84);
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  text-align: center;
  padding: 24px;
}

.message-panel[hidden] {
  display: none;
}

.message-panel h1 {
  margin: 0;
  font-size: 2rem;
}

.message-panel p {
  margin: 0;
  max-width: 540px;
  line-height: 1.5;
}

@media (max-width: 760px) {
  body {
    place-items: start center;
  }

  .game-shell {
    min-height: 100vh;
    border: 0;
  }

  .topbar {
    flex-wrap: wrap;
  }

  .play-area {
    grid-template-columns: 1fr;
  }

  .side-panel {
    min-height: auto;
    flex-direction: row;
    background-size: 18px 18px;
  }

  .square-button {
    width: 56px;
  }

  #gameCanvas {
    width: 100vw;
  }

  .stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
  }

  .stats > div {
    min-height: 62px;
  }

  .message-panel {
    inset: 96px 0 0 0;
  }
}
