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

* {
  box-sizing: border-box;
}

html,
body,
#game-shell {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: #071311;
  touch-action: none;
  user-select: none;
}

#game-shell {
  display: grid;
  place-items: center;
}

#stage {
  position: relative;
  width: min(100%, calc(100vh * 16 / 9));
  max-height: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #071311;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
}

#game-canvas:focus-visible {
  outline: 3px solid #ffd166;
  outline-offset: -3px;
}

#status-panel {
  position: absolute;
  top: 6%;
  bottom: 6%;
  left: 2.5%;
  z-index: 2;
  width: 22%;
  pointer-events: none;
}

.game-mark,
#status-panel label,
#status-panel dt {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 800;
  letter-spacing: 0;
}

.game-mark {
  margin: 0 0 12%;
  color: #42e0a4;
  font-size: 13px;
}

#status-panel label {
  display: block;
  margin-bottom: 5px;
  color: #8ca5a0;
  font-size: 10px;
}

#level-select {
  width: 100%;
  min-height: 42px;
  padding: 0 34px 0 12px;
  border: 1px solid #3f665d;
  border-radius: 6px;
  background: #10231e;
  color: #f4fff9;
  font: inherit;
  font-weight: 750;
  pointer-events: auto;
}

#status-panel dl {
  display: grid;
  gap: 12px;
  margin: 18% 0 0;
}

#status-panel dl div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 7px;
  border-bottom: 1px solid rgba(140, 165, 160, 0.22);
}

#status-panel dt {
  color: #8ca5a0;
  font-size: 9px;
}

#status-panel dd {
  margin: 0;
  color: #f4fff9;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 18px;
  font-weight: 850;
}

.utility-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  display: flex;
  gap: 9px;
  pointer-events: auto;
}

button {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid #3f665d;
  border-radius: 6px;
  background: #10231e;
  color: #f4fff9;
  font: inherit;
  font-weight: 850;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:hover,
button:focus-visible {
  border-color: #42e0a4;
  color: #42e0a4;
  outline: none;
}

button:active {
  background: #173a30;
  transform: translateY(1px);
}

button:disabled {
  cursor: default;
  opacity: 0.42;
}

.utility-controls button {
  font-size: 24px;
}

#touch-controls {
  position: absolute;
  right: 4.5%;
  bottom: 12%;
  z-index: 3;
  display: grid;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(3, 52px);
  gap: 6px;
}

#touch-controls button {
  border-color: #55736c;
  background: rgba(16, 35, 30, 0.94);
  font-size: 23px;
}

#touch-controls .up {
  grid-column: 2;
  grid-row: 1;
}

#touch-controls .left {
  grid-column: 1;
  grid-row: 2;
}

#touch-controls .right {
  grid-column: 3;
  grid-row: 2;
}

#touch-controls .down {
  grid-column: 2;
  grid-row: 3;
}

.panel {
  position: absolute;
  inset: 50% auto auto 50%;
  z-index: 6;
  width: min(430px, calc(100% - 32px));
  transform: translate(-50%, -50%);
  padding: 24px;
  border: 1px solid #42e0a4;
  border-radius: 8px;
  background: rgba(7, 19, 17, 0.97);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.58);
  text-align: center;
}

.panel[hidden] {
  display: none;
}

.panel .eyebrow {
  margin: 0;
  color: #42e0a4;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  font-weight: 850;
}

.panel h1 {
  margin: 8px 0;
  color: #f4fff9;
  font-size: 30px;
  letter-spacing: 0;
  line-height: 1.1;
}

.panel p {
  margin: 0;
  color: #a9bdb8;
  font-size: 14px;
}

.result-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 20px;
}

.result-actions button {
  min-width: 140px;
  padding: 0 16px;
}

.result-actions .primary {
  border-color: #42e0a4;
  background: #42e0a4;
  color: #071311;
}

body[data-game-state="complete"] #touch-controls,
body[data-game-state="complete"] #status-panel {
  opacity: 0.35;
}

@media (max-width: 700px), (max-height: 390px) {
  #status-panel {
    top: 4%;
    bottom: 4%;
    left: 2%;
    width: 23%;
  }

  .game-mark {
    margin-bottom: 7%;
    font-size: 9px;
  }

  #status-panel label,
  #status-panel dt {
    font-size: 7px;
  }

  #level-select {
    min-height: 30px;
    padding: 0 22px 0 7px;
    font-size: 10px;
  }

  #status-panel dl {
    gap: 5px;
    margin-top: 8%;
  }

  #status-panel dl div {
    padding-bottom: 3px;
  }

  #status-panel dd {
    font-size: 12px;
  }

  button {
    min-width: 32px;
    min-height: 32px;
  }

  .utility-controls {
    gap: 5px;
  }

  .utility-controls button {
    font-size: 17px;
  }

  #touch-controls {
    right: 3%;
    bottom: 8%;
    grid-template-columns: repeat(3, 34px);
    grid-template-rows: repeat(3, 34px);
    gap: 4px;
  }

  #touch-controls button {
    font-size: 16px;
  }

  .panel {
    width: min(320px, calc(100% - 24px));
    padding: 13px;
  }

  .panel .eyebrow {
    font-size: 8px;
  }

  .panel h1 {
    margin: 4px 0;
    font-size: 20px;
  }

  .panel p {
    font-size: 10px;
  }

  .result-actions {
    gap: 7px;
    margin-top: 10px;
  }

  .result-actions button {
    min-width: 112px;
    min-height: 32px;
    padding: 0 8px;
    font-size: 10px;
  }
}
