:root {
  --cream: #f8f0da;
  --cream-2: #fff8e6;
  --ink: #1a120c;
  --ink-soft: #3a2a1c;
  --line: #23160e;
  --barn: #9b2d1f;
  --amber: #f6b73c;
  --good: #215c28;
  --bad: #9b2d1f;
  --shadow: 4px 4px 0 #1a120c;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; height: 100dvh; overflow: hidden; }
body {
  font-family: "Courier New", ui-monospace, monospace;
  color: var(--ink);
  letter-spacing: normal;
  background: var(--cream);
  min-height: 100%;
  display: flex;
  flex-direction: column;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 3px solid var(--line);
  box-shadow: 3px 3px 0 #1a120c;
  background: var(--cream-2);
  color: var(--ink);
  padding: 6px 10px;
  min-height: 36px;
}
.strip .btn { color: var(--ink); background: var(--cream-2); }
.btn-amber { background: var(--amber); }
.btn-barn { background: var(--barn); color: var(--cream-2); }
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--line); }

.topbar {
  position: relative;
  flex: 0 0 auto;
  z-index: 20;
  background: var(--cream);
  border-bottom: 4px solid var(--line);
  padding: 6px 8px;
  display: flex;
  justify-content: space-between;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}
.disclaimer {
  background: var(--barn); color: var(--cream-2);
  border: 3px solid var(--line); padding: 3px 8px; font-size: 11px;
}
.hud { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; font-size: 13px; }
.hud b { color: var(--barn); }
.top-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.top-actions .btn { min-height: 34px; padding: 4px 8px; font-size: 13px; }

.workspace {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  background: #1a3a1c;
}
.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: stretch;
  justify-content: center;
  background: #1a3a1c;
}
canvas { image-rendering: pixelated; image-rendering: crisp-edges; width: 100%; height: 100%; display: block; }

.prompt {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%);
  background: var(--cream); border: 3px solid var(--line);
  box-shadow: var(--shadow); padding: 6px 10px; z-index: 15;
  max-width: min(92vw, 420px); text-align: center;
  pointer-events: none;
}
.quest {
  position: absolute; left: 8px; top: 8px; z-index: 15;
  background: var(--cream-2); border: 3px solid var(--line);
  padding: 6px 8px; max-width: min(46vw, 220px); font-size: 11px;
  box-shadow: var(--shadow);
  max-height: min(46%, 280px);
  overflow: auto;
}
.quest h3 { margin: 0 0 4px; font-size: 12px; }

.mobile-dock {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--cream);
  border-top: 4px solid var(--line);
  padding: 8px 10px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  z-index: 16;
}
.controls {
  display: grid;
  grid-template-columns: 48px 48px 48px;
  gap: 6px;
}
.controls .pad {
  width: 48px; height: 48px; background: var(--amber);
  border: 3px solid var(--line); color: var(--ink); font-size: 18px;
}
.controls .empty { visibility: hidden; }
#btn-interact {
  min-width: 88px; min-height: 56px; background: var(--amber);
}

.overlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(26,18,12,.55);
  display: none; overflow: auto; padding: 20px 12px;
}
.overlay.show { display: block; }
.panel {
  width: min(560px, 100%);
  margin: 6vh auto;
  background: var(--cream);
  border: 4px solid var(--line);
  box-shadow: 8px 8px 0 #1a120c;
}
.strip {
  background: var(--barn); color: var(--cream-2);
  border-bottom: 4px solid var(--line);
  padding: 10px 12px;
  display: flex; justify-content: space-between; gap: 8px; align-items: center;
}
.strip h2 { margin: 0; font-size: 16px; }
.body { padding: 14px; background: var(--cream-2); }
.body p:first-child { margin-top: 0; }
.note { font-size: 13px; color: var(--ink-soft); }
.msg { min-height: 1.3em; margin: 8px 0 0; font-size: 13px; }
.msg.err { color: var(--bad); font-weight: 700; }
.msg.ok { color: var(--good); }
.field {
  width: 100%; border: 3px solid var(--line); background: #fffdf6;
  padding: 8px; min-height: 40px;
}
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.list { display: grid; gap: 8px; margin: 10px 0; }
.item {
  background: var(--cream); border: 3px solid var(--line); padding: 8px;
  display: flex; justify-content: space-between; gap: 8px; align-items: center; flex-wrap: wrap;
}
code {
  display: block; background: #fffdf6; border: 2px solid var(--line);
  padding: 8px; word-break: break-all;
}
.burst { text-align: center; font-size: 28px; margin: 8px 0; }
.log { font-size: 12px; max-height: 180px; overflow: auto; background: var(--cream); border: 2px solid var(--line); padding: 8px; }
select.field { appearance: none; border-radius: 0; }

@media (min-width: 900px) {
  .mobile-dock {
    position: absolute;
    left: 12px;
    bottom: 12px;
    right: auto;
    background: transparent;
    border: none;
    padding: 0;
    width: auto;
  }
  .controls { display: none; }
}
