:root {
  --bg: #131b1a;
  --panel: #243330;
  --text: #edf5f2;
  --accent: #8ad7bf;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: radial-gradient(circle at top, #1d2b2a, var(--bg));
  color: var(--text);
}

.app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  overflow: hidden;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1rem, 2.5vw, 1.5rem);
}

.topbar p {
  margin: 6px 0 0;
  opacity: 0.9;
  font-size: 0.92rem;
}

.hud {
  margin-top: 8px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.hud span {
  border: 1px solid #4f6f6a;
  background: rgba(21, 33, 31, 0.75);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.82rem;
}

.stage {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 12px;
  min-height: 0;
}

.viewport {
  position: relative;
  background: #0b1010;
  border: 1px solid #304544;
  border-radius: 10px;
  min-height: 0;
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.prompt {
  position: absolute;
  left: 50%;
  top: 14px;
  transform: translateX(-50%);
  background: rgba(19, 27, 26, 0.92);
  border: 1px solid #51706a;
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 0.85rem;
  white-space: nowrap;
  z-index: 2;
}

.debug-readout {
  position: absolute;
  left: 10px;
  top: 52px;
  margin: 0;
  padding: 6px 8px;
  font-size: 11px;
  line-height: 1.25;
  color: #d5f4ec;
  background: rgba(10, 16, 16, 0.78);
  border: 1px solid #3d5752;
  border-radius: 6px;
  cursor: copy;
  user-select: text;
  white-space: pre-wrap;
  max-width: min(86vw, 520px);
}

.panel {
  background: var(--panel);
  border: 1px solid #3b5652;
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
}

.panel h2 {
  margin: 0;
  font-size: 1.1rem;
}

.panel p {
  margin: 0;
  line-height: 1.45;
}

.panel button {
  align-self: flex-start;
  border: 1px solid #5b8580;
  background: #2f4542;
  color: var(--text);
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
}

.hidden {
  display: none;
}

.toast {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(19, 27, 26, 0.94);
  border: 1px solid #51706a;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 0.92rem;
  white-space: nowrap;
  z-index: 5;
  color: #ffd27a;
  font-weight: 600;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}

.toast.toast-show {
  opacity: 1;
}

.debug-canvas-only .topbar,
.debug-canvas-only .panel,
.debug-canvas-only .prompt,
.debug-canvas-only .touch-ui,
.debug-canvas-only .debug-readout {
  display: none !important;
}

.debug-canvas-only .app {
  padding: 0;
  gap: 0;
}

.debug-canvas-only .stage {
  grid-template-columns: 1fr;
  height: 100%;
}

.debug-canvas-only .viewport {
  border: 0;
  border-radius: 0;
}

.touch-ui {
  position: fixed;
  left: 10px;
  right: 10px;
  bottom: max(10px, env(safe-area-inset-bottom));
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(3, 52px);
  gap: 6px;
  pointer-events: auto;
}

.dpad button,
.action-btn {
  border: 1px solid #5b8580;
  background: rgba(36, 51, 48, 0.9);
  color: #fff;
  border-radius: 10px;
  font-size: 1.1rem;
  font-weight: 700;
}

.dpad button[data-dir="up"] {
  grid-column: 2;
  grid-row: 1;
}
.dpad button[data-dir="left"] {
  grid-column: 1;
  grid-row: 2;
}
.dpad button[data-dir="down"] {
  grid-column: 2;
  grid-row: 3;
}
.dpad button[data-dir="right"] {
  grid-column: 3;
  grid-row: 2;
}

.action-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  pointer-events: auto;
}

@media (max-width: 980px) {
  .stage {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .panel {
    min-height: 100px;
    max-height: 28dvh;
  }

  .hud {
    gap: 6px;
  }

  .hud span {
    font-size: 0.78rem;
  }

  .debug-readout {
    font-size: 10px;
    padding: 5px 6px;
  }
}

@media (hover: none), (pointer: coarse) {
  .touch-ui {
    display: flex;
  }
}
