:root {
  color-scheme: dark;
  --panel: rgba(21, 23, 24, 0.76);
  --panel-strong: rgba(12, 14, 15, 0.92);
  --text: #fff5d6;
  --accent: #f4c447;
  --danger: #ff6848;
  --edge: #36291d;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background: #171b20;
  color: var(--text);
  font-family: "Trebuchet MS", Arial, sans-serif;
}

body {
  display: grid;
  place-items: center;
  overflow: hidden;
}

button {
  font: inherit;
}

#app {
  width: min(100vw, 1180px);
  padding: clamp(8px, 1.8vw, 20px);
}

#gameShell {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: calc(100vh - 32px);
  margin: 0 auto;
  overflow: hidden;
  background: #111;
  border: 4px solid #2b2119;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.42);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  background: #1b2430;
}

#hud {
  position: absolute;
  inset: 0 0 auto 0;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  pointer-events: none;
  text-shadow: 2px 2px 0 #18100a;
  font-weight: 700;
  letter-spacing: 0;
}

.hud-group {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex-wrap: wrap;
}

.hud-group span,
.icon-button {
  min-height: 32px;
  padding: 6px 10px;
  border: 2px solid rgba(255, 245, 214, 0.3);
  background: var(--panel);
  color: var(--text);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.22);
}

.icon-button {
  pointer-events: auto;
  cursor: pointer;
}

.icon-button:focus-visible,
.touch-button:focus-visible,
.screen-button:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(9, 11, 12, 0.52);
  text-align: center;
}

.overlay.visible {
  display: flex;
}

.screen-panel {
  width: min(680px, 92%);
  padding: clamp(18px, 3vw, 32px);
  border: 4px solid #533a24;
  background: var(--panel-strong);
  box-shadow: inset 0 0 0 4px rgba(244, 196, 71, 0.12), 0 20px 60px rgba(0, 0, 0, 0.4);
}

.screen-panel h1,
.screen-panel h2 {
  margin: 0 0 12px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0;
  text-shadow: 3px 3px 0 #321b11;
}

.screen-panel h1 {
  font-size: clamp(28px, 5.2vw, 56px);
}

.screen-panel h2 {
  font-size: clamp(24px, 4vw, 42px);
}

.screen-panel p {
  margin: 8px auto;
  max-width: 58ch;
  line-height: 1.45;
}

.screen-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 18px auto;
  text-align: left;
}

.screen-grid span {
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 255, 255, 0.08);
}

.screen-button {
  min-width: 160px;
  min-height: 42px;
  margin-top: 12px;
  border: 3px solid #21150e;
  background: var(--accent);
  color: #21150e;
  cursor: pointer;
  font-weight: 800;
  text-transform: uppercase;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.22);
}

#touchControls {
  position: absolute;
  inset: auto 0 10px 0;
  display: none;
  justify-content: space-between;
  padding: 0 12px;
  pointer-events: none;
}

.touch-left,
.touch-right {
  display: flex;
  gap: 8px;
}

.touch-button {
  width: 72px;
  height: 52px;
  border: 3px solid rgba(255, 245, 214, 0.35);
  background: rgba(21, 23, 24, 0.66);
  color: var(--text);
  font-weight: 800;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
}

.touch-button.is-held {
  background: #f4c447;
  color: #20150e;
}

@media (pointer: coarse), (max-width: 760px) {
  #touchControls {
    display: flex;
  }

  #hud {
    padding: 7px;
    font-size: 13px;
  }

  .hud-group span,
  .icon-button {
    min-height: 28px;
    padding: 4px 7px;
  }

  .screen-grid {
    grid-template-columns: 1fr;
  }
}
