:root {
  --ink: #1a1f16;
  --panel: #f4efe0;
  --edge: #2c2618;
  --sun: #f0d46a;
  --leaf: #243f22;
  --accent: #c45c26;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "VT323", monospace;
  font-size: 22px;
  color: var(--ink);
  background:
    radial-gradient(ellipse at 10% 0%, #9fd0ff 0%, transparent 45%),
    linear-gradient(180deg, #5a9bc8 0%, #6aaa5a 55%, #3d6b3a 100%);
}

#app {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.card {
  width: min(520px, 100%);
  background: var(--panel);
  border: 4px solid var(--edge);
  box-shadow: 8px 8px 0 #00000055;
  padding: 24px;
}

h1 {
  font-family: "Press Start 2P", monospace;
  font-size: 16px;
  margin: 0 0 8px;
  color: var(--leaf);
  text-shadow: 2px 2px 0 var(--sun);
}

.tag {
  margin: 0 0 18px;
  line-height: 1.2;
  color: #4a4335;
}

label {
  display: block;
  font-family: "Press Start 2P", monospace;
  font-size: 9px;
  margin: 10px 0 6px;
}

input,
button {
  font: inherit;
}

input[type="text"],
input[type="password"],
input[type="file"] {
  width: 100%;
  padding: 8px;
  border: 3px solid var(--edge);
  background: #fffdf6;
  margin-bottom: 8px;
}

.row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

button {
  font-family: "Press Start 2P", monospace;
  font-size: 10px;
  padding: 12px 14px;
  border: 3px solid var(--edge);
  background: var(--sun);
  cursor: pointer;
  box-shadow: 3px 3px 0 #00000044;
}

button.secondary {
  background: #dfe9ef;
}

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

.status {
  min-height: 1.4em;
  margin-top: 10px;
  color: var(--accent);
}

.play {
  width: min(520px, 100%);
  display: grid;
  gap: 12px;
  margin: 0 auto;
}

.screen-wrap {
  border: 4px solid var(--edge);
  box-shadow: 8px 8px 0 #00000055;
  background: #000;
  line-height: 0;
  width: min(480px, 100%);
  max-width: 100%;
  margin: 0 auto;
  aspect-ratio: 3 / 2;
  overflow: hidden;
}

#screen {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
  object-fit: contain;
  display: block;
}

  .hud {
  background: var(--panel);
  border: 4px solid var(--edge);
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  font-family: "Press Start 2P", monospace;
  font-size: 9px;
  line-height: 1.5;
}

.hud-left {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.hud button.leave {
  font-size: 8px;
  padding: 8px 10px;
  background: #e8a090;
  flex-shrink: 0;
}

.hud button.leave:disabled {
  opacity: 0.6;
}

.help {
  font-size: 20px;
  color: #3d382c;
  line-height: 1.25;
  white-space: pre-line;
}

.saves {
  display: grid;
  gap: 8px;
  margin-bottom: 0;
}

.save-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: #fffdf6;
  border: 3px solid var(--edge);
  font-size: 18px;
}

.save-line span {
  flex: 1 1 180px;
}

button.tiny {
  font-size: 8px;
  padding: 8px 10px;
}

.data-summary {
  display: grid;
  gap: 4px;
  margin: 12px 0 8px;
  padding: 10px 12px;
  background: #fffdf6;
  border: 3px solid var(--edge);
  font-size: 20px;
  line-height: 1.3;
}

.summary-line.ok {
  color: var(--leaf);
}

.summary-line.warn {
  color: var(--accent);
}

.data-panel {
  margin: 8px 0 12px;
  border: 3px solid var(--edge);
  background: #efe9d8;
}

.data-panel > summary {
  cursor: pointer;
  list-style: none;
  font-family: "Press Start 2P", monospace;
  font-size: 9px;
  padding: 12px;
  user-select: none;
}

.data-panel > summary::-webkit-details-marker {
  display: none;
}

.data-panel > summary::before {
  content: "▸ ";
}

.data-panel[open] > summary::before {
  content: "▾ ";
}

.data-panel-body {
  padding: 0 12px 12px;
  display: grid;
  gap: 14px;
  border-top: 2px solid #00000022;
}

.data-block-title {
  font-family: "Press Start 2P", monospace;
  font-size: 8px;
  margin: 10px 0 6px;
}

.data-hint {
  margin: 0 0 8px;
  font-size: 18px;
  line-height: 1.25;
  color: #4a4335;
}

.row.tight {
  margin-top: 0;
}

/* —— Mobile / touch play layout —— */
.touch-controls {
  display: none;
  flex-direction: column;
  gap: 10px;
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
  background: var(--panel);
  border: 4px solid var(--edge);
  border-top: none;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.touch-shoulders,
.touch-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.touch-shoulders {
  justify-content: space-between;
}

.touch-main {
  align-items: center;
}

.touch-move {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.touch-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex: 1;
  min-width: 0;
}

.touch-btn {
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  border: 3px solid var(--edge);
  background: #dfe9ef;
  color: var(--ink);
  font-family: "Press Start 2P", monospace;
  font-size: 11px;
  line-height: 1;
  box-shadow: 3px 3px 0 #00000044;
  cursor: pointer;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  display: grid;
  place-items: center;
  min-width: 52px;
  min-height: 44px;
  padding: 10px;
}

.touch-btn.active,
.touch-btn:active {
  background: var(--sun);
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 #00000044;
}

.touch-btn.shoulder {
  flex: 1;
  max-width: 42%;
  min-height: 40px;
  background: #c8d4dc;
}

.touch-stick {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.touch-stick-base {
  width: 168px;
  height: 168px;
  border-radius: 50%;
  border: 4px solid var(--edge);
  background:
    radial-gradient(circle at 50% 50%, #fffdf6 0%, #dfe9ef 70%, #c5d0d8 100%);
  box-shadow: inset 0 0 0 2px #00000018, 3px 3px 0 #00000044;
  position: relative;
  touch-action: none;
}

.touch-stick.active .touch-stick-base {
  background:
    radial-gradient(circle at 50% 50%, #fff8d6 0%, #f0d46a 55%, #d4b84a 100%);
}

.touch-stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 64px;
  height: 64px;
  margin: -32px 0 0 -32px;
  border-radius: 50%;
  border: 3px solid var(--edge);
  background: #243f22;
  box-shadow: 2px 2px 0 #00000055;
  pointer-events: none;
  transition: transform 0.05s linear;
}

.touch-stick-label,
.touch-dpad-label {
  font-family: "Press Start 2P", monospace;
  font-size: 7px;
  color: #4a4335;
  letter-spacing: 0.04em;
}

.touch-dpad {
  display: grid;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(3, 52px);
  gap: 4px;
  width: calc(52px * 3 + 8px);
  flex-shrink: 0;
}

.touch-dpad .touch-btn {
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border-radius: 6px;
  font-size: 14px;
}

.touch-dpad .gap {
  pointer-events: none;
}

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

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

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

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

.touch-meta {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.touch-btn.meta {
  min-width: 88px;
  min-height: 40px;
  font-size: 8px;
  padding: 10px 12px;
  border-radius: 999px;
  background: #b9b3a4;
}

.touch-face {
  display: grid;
  grid-template-columns: 72px 72px;
  grid-template-rows: 72px 72px;
  gap: 10px;
  width: calc(72px * 2 + 10px);
  flex-shrink: 0;
}

.touch-face .touch-btn {
  width: 72px;
  height: 72px;
  min-width: 72px;
  min-height: 72px;
  border-radius: 50%;
  font-size: 16px;
  padding: 0;
}

.touch-face .b {
  grid-column: 1;
  grid-row: 2;
  background: #e8a090;
}

.touch-face .a {
  grid-column: 2;
  grid-row: 1;
  background: #e07060;
  color: #fff;
}

.touch-hint {
  margin: 0;
  text-align: center;
  font-size: 16px;
  color: #4a4335;
  line-height: 1.2;
}

@media (max-width: 900px), (pointer: coarse) {
  #app {
    padding: 0;
    place-items: stretch;
    align-content: start;
  }

  .card {
    width: 100%;
    min-height: 100dvh;
    border-left: none;
    border-right: none;
    box-shadow: none;
    border-radius: 0;
  }

  .play {
    width: 100%;
    min-height: 100dvh;
    gap: 0;
    display: flex;
    flex-direction: column;
  }

  .play .hud {
    border-left: none;
    border-right: none;
    border-bottom: none;
    box-shadow: none;
    font-size: 8px;
    padding: 10px 12px;
  }

  .play .screen-wrap {
    border-left: none;
    border-right: none;
    box-shadow: none;
    width: min(480px, 100%);
    max-height: min(40dvh, calc(100vw * 2 / 3));
    flex-shrink: 0;
  }

  .play .help.desktop-help {
    display: none;
  }

  .touch-controls {
    display: flex;
    flex: 1;
    border-left: none;
    border-right: none;
    border-bottom: none;
  }
}

@media (max-width: 420px) {
  .touch-stick-base {
    width: 148px;
    height: 148px;
  }

  .touch-stick-knob {
    width: 56px;
    height: 56px;
    margin: -28px 0 0 -28px;
  }

  .touch-dpad {
    grid-template-columns: repeat(3, 46px);
    grid-template-rows: repeat(3, 46px);
    width: calc(46px * 3 + 8px);
  }

  .touch-face {
    grid-template-columns: 64px 64px;
    grid-template-rows: 64px 64px;
    width: calc(64px * 2 + 10px);
  }

  .touch-face .touch-btn {
    width: 64px;
    height: 64px;
    min-width: 64px;
    min-height: 64px;
  }
}
