:root {
  --bg: #0f2119;
  --panel: #f6ead2;
  --panel-2: #ead9b7;
  --ink: #1e1812;
  --muted: #6b5c4c;
  --line: #2a2118;
  --accent: #b8322b;
  --shadow: #07140f;
}

@font-face {
  font-family: PokemonEmerald;
  src: url("./assets/fonts/pokemon-emerald.ttf") format("truetype");
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 245, 190, 0.08), transparent 34rem),
    linear-gradient(#132c21, #0b1b15);
  color: var(--ink);
  font-family: PokemonEmerald, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
.import-button {
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 800;
  min-height: 36px;
  padding: 6px 10px;
}

button.active {
  background: var(--accent);
  color: #fff7df;
}

.app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100dvh;
  gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: #fff4d8;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
}

h2 {
  font-size: 13px;
  margin-bottom: 8px;
}

#statusText {
  color: #cfbea0;
  font-size: 12px;
  margin-top: 2px;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
  gap: 6px;
}

.import-button {
  position: relative;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
}

.import-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 10px;
  min-height: 0;
}

.stage-panel {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
}

#gameCanvas {
  width: min(100%, calc((100dvh - 184px) * 3 / 2));
  max-height: calc(100dvh - 184px);
  aspect-ratio: 3 / 2;
  border: 4px solid var(--shadow);
  border-radius: 4px;
  background: #7eb46b;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  box-shadow:
    0 0 0 3px #d8c18d,
    0 12px 34px rgba(0, 0, 0, 0.45);
  touch-action: none;
}

.dialogue {
  position: absolute;
  left: 50%;
  bottom: 12px;
  width: min(92%, 680px);
  min-height: 62px;
  transform: translateX(-50%);
  padding: 10px 12px;
  border: 3px solid var(--line);
  border-radius: 4px;
  background: var(--panel) url("./assets/ui/message_box.png") center / 100% 100%;
  line-height: 1.35;
  box-shadow: inset 0 0 0 3px #fff8e8;
}

.hidden {
  display: none;
}

.tools-panel {
  display: grid;
  align-content: start;
  gap: 10px;
  overflow: auto;
}

.tools-panel section {
  border: 2px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  padding: 10px;
  box-shadow: inset 0 0 0 2px #fff8e8;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.palette {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.swatch {
  min-height: 40px;
  border-radius: 6px;
  border: 2px solid var(--line);
}

.swatch.active {
  outline: 3px solid var(--accent);
}

label {
  display: grid;
  gap: 4px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  border: 2px solid #8d785e;
  border-radius: 6px;
  background: #fff8e8;
  color: var(--ink);
  padding: 6px;
}

textarea {
  resize: vertical;
}

.touch-controls {
  display: none;
  grid-template-columns: 132px 1fr;
  align-items: end;
  gap: 16px;
  width: min(100%, 520px);
  margin: 0 auto;
}

.dpad {
  display: grid;
  grid-template-columns: 44px 44px 44px;
  grid-template-rows: 44px 44px 44px;
}

.dpad button {
  width: 44px;
  height: 44px;
  padding: 0;
}

.dpad [data-dir="up"] {
  grid-column: 2;
}

.dpad [data-dir="left"] {
  grid-column: 1;
  grid-row: 2;
}

.dpad [data-dir="right"] {
  grid-column: 3;
  grid-row: 2;
}

.dpad [data-dir="down"] {
  grid-column: 2;
  grid-row: 3;
}

.action {
  justify-self: end;
  width: 86px;
  height: 86px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff7df;
}

body.playing .tools-panel {
  display: none;
}

body.playing .workspace {
  grid-template-columns: 1fr;
}

body.playing .touch-controls {
  display: grid;
}

@media (max-width: 840px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .tools-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #gameCanvas {
    width: 100%;
    max-height: none;
  }
}

@media (max-width: 560px) {
  .topbar {
    align-items: start;
    flex-direction: column;
  }

  .tools-panel {
    grid-template-columns: 1fr;
  }
}
