* { box-sizing: border-box; }
:root {
  --bg: #17151b;
  --panel: #23202a;
  --panel2: #2f2a37;
  --ink: #efe6cf;
  --muted: #b7ab91;
  --accent: #e1b95d;
  --danger: #d46a64;
  --line: #51475d;
}
html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 48% 18%, #2a2730 0, #1d1a22 38%, var(--bg) 72%);
  color: var(--ink);
  font-family: "Courier New", monospace;
  overscroll-behavior: none;
}
body { padding: 22px; }
button { font: inherit; }
.frame { max-width: 1180px; margin: 0 auto; }
header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  border-bottom: 4px solid var(--line);
  padding-bottom: 12px;
  margin-bottom: 18px;
}
h1 { margin: 0; font-size: 34px; letter-spacing: 5px; }
header p { margin: 3px 0 0; color: var(--muted); }
.badge {
  background: var(--accent);
  color: #241d11;
  padding: 6px 9px;
  font-weight: bold;
  box-shadow: 4px 4px 0 #000;
}
.game-shell {
  display: grid;
  grid-template-columns: minmax(0, 768px) 1fr;
  gap: 18px;
  align-items: start;
}
.play-column {
  min-width: 0;
  position: relative;
}
.play-column::before {
  content: "";
  position: absolute;
  inset: -10px 8px auto -10px;
  height: 72%;
  border: 1px solid #ffffff0a;
  pointer-events: none;
  transform: translate(8px, 8px);
}
canvas {
  display: block;
  width: 100%;
  max-width: 768px;
  aspect-ratio: 4 / 3;
  height: auto;
  image-rendering: pixelated;
  border: 5px solid #111016;
  border-radius: 2px;
  box-shadow: 0 18px 42px #0009, 8px 8px 0 #000;
  background: #000;
  touch-action: none;
}
aside {
  min-height: 576px;
  background: var(--panel);
  border: 3px solid var(--line);
  padding: 14px;
  box-shadow: 7px 7px 0 #000;
}
aside h2 {
  font-size: 14px;
  letter-spacing: 2px;
  color: var(--accent);
  margin: 10px 0 8px;
  border-bottom: 2px solid var(--line);
  padding-bottom: 5px;
}
#situation, #log { font-size: 13px; line-height: 1.4; }
#log { max-height: 220px; overflow: hidden; color: var(--muted); }
.logline { margin-bottom: 7px; }
.controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 5px 10px;
  font-size: 12px;
  color: var(--muted);
}
.controls b { color: var(--ink); }
footer { margin-top: 16px; color: var(--muted); font-size: 12px; }

.touch-controls {
  display: none;
  justify-content: space-between;
  align-items: end;
  gap: 18px;
  margin-top: 14px;
  padding: 10px 2px 2px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.dpad {
  display: grid;
  grid-template-columns: repeat(3, 58px);
  grid-template-rows: repeat(2, 58px);
  gap: 5px;
}
.dpad .up { grid-column: 2; grid-row: 1; }
.dpad .left { grid-column: 1; grid-row: 2; }
.dpad .down { grid-column: 2; grid-row: 2; }
.dpad .right { grid-column: 3; grid-row: 2; }
.actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(92px, 1fr));
  gap: 8px;
}
.actions .action:last-child { grid-column: 1 / -1; }
.touch-btn, .small-btn, .choice {
  border: 2px solid var(--line);
  background: var(--panel2);
  color: var(--ink);
  box-shadow: 3px 3px 0 #000;
  min-height: 44px;
  cursor: pointer;
}
.touch-btn:active, .small-btn:active, .choice:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 #000;
}
.touch-btn.danger { border-color: #7f4a4a; }
.small-btn { padding: 7px 12px; min-height: 36px; }

.dialogue, .journal {
  position: fixed;
  z-index: 10;
  left: 50%;
  transform: translateX(-50%);
  bottom: max(26px, env(safe-area-inset-bottom));
  width: min(900px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  overflow: auto;
  background: #19161f;
  border: 4px solid var(--accent);
  box-shadow: 8px 8px 0 #000;
  padding: 15px;
}
.dialogue { display: grid; grid-template-columns: 64px 1fr; gap: 15px; }
.portrait {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  border: 3px solid var(--line);
  background: var(--panel2);
  font-size: 28px;
  font-weight: bold;
}
.speaker { color: var(--accent); font-weight: bold; margin-bottom: 7px; }
#dialogueText, #journalText { line-height: 1.45; }
.choices { margin-top: 10px; display: grid; gap: 7px; }
.choice {
  color: #d9cdef;
  text-align: left;
  padding: 9px 11px;
}
.hint { color: #82768e; font-size: 11px; }
.modal-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
}
.hidden { display: none !important; }
.journal {
  top: 50%;
  bottom: auto;
  transform: translate(-50%, -50%);
  max-width: 650px;
}
.journal h2 { margin-top: 0; color: var(--accent); }
.state-good { color: #a9d18e; }
.state-bad { color: #e58e88; }
.state-open { color: #ecd280; }

@media (max-width: 1040px) {
  body { padding: 14px; }
  .game-shell { grid-template-columns: 1fr; }
  aside { min-height: auto; }
}

@media (pointer: coarse), (max-width: 760px) {
  body {
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }
  header { margin-bottom: 10px; }
  h1 { font-size: 25px; letter-spacing: 3px; }
  header p { font-size: 11px; }
  .badge { font-size: 12px; }
  canvas { border-width: 3px; box-shadow: 4px 4px 0 #000; }
  .touch-controls { display: flex; }
  aside .controls { display: none; }
  aside h2:nth-of-type(2) { display: none; }
  aside { box-shadow: 4px 4px 0 #000; }
  .dialogue {
    grid-template-columns: 48px 1fr;
    padding: 11px;
  }
  .portrait { width: 48px; height: 48px; font-size: 22px; }
}

@media (max-width: 520px) {
  .touch-controls { gap: 10px; }
  .dpad {
    grid-template-columns: repeat(3, 48px);
    grid-template-rows: repeat(2, 48px);
    gap: 4px;
  }
  .actions { grid-template-columns: repeat(2, minmax(76px, 1fr)); gap: 6px; }
  .touch-btn { min-height: 48px; font-size: 11px; }
  .dialogue, .journal { width: calc(100vw - 16px); }
}