:root {
  --ink: #1b1220;
  --paper: #f4efe4;
  --night: #14121c;
  --purple: #6b4c9a;
  --green: #3d8b6e;
  --candy: #ff7eb3;
  --dock: #8b5a2b;
  --sea: #143d66;
  --ui: "Comic Sans MS", "Chalkboard SE", "Marker Felt", "Segoe Print", fantasy;
  --body: "Segoe UI", "Helvetica Neue", sans-serif;
  color: var(--paper);
  background: var(--night);
  font-family: var(--ui);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--night);
}

body.run {
  touch-action: none;
  overflow: hidden;
}

button, .hit, a.button {
  min-width: 44px;
  min-height: 44px;
  font-family: var(--ui);
  font-size: 16px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: #2a2438;
  color: var(--paper);
  padding: 8px 12px;
  cursor: pointer;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.primary { background: var(--green); color: #102018; }
button.warn { background: #c45a4a; }

#app { min-height: 100vh; }

.screen {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

.logo {
  font-size: clamp(40px, 8vw, 72px);
  margin: 0;
  letter-spacing: -1px;
}

.pitch { font-size: 22px; max-width: 40rem; }

.actions, .chips, .hud, .tower-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.quotes { font-family: var(--body); max-width: 40rem; }
.quotes blockquote { margin: 12px 0; }
.quotes cite { display: block; opacity: 0.8; }

.keyart { width: min(100%, 640px); height: auto; display: block; }

.pack {
  margin: 20px 0;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.card {
  text-align: left;
  min-height: 88px;
  background: #221c30;
}

.card .meta { display: block; font-family: var(--body); font-size: 13px; opacity: 0.85; }
.card .check { color: #9be7a8; }

.stage-wrap {
  width: min(1024px, 100vw, calc((100dvh - 88px) * 1024 / 640));
  margin: 0 auto;
}

.playfield {
  position: relative;
  width: 100%;
  aspect-ratio: 1024 / 640;
  background: #101018;
  transform: none;
}

.playfield canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  transform: none;
}

.hud {
  position: sticky;
  top: 0;
  z-index: 5;
  background: rgba(20, 18, 28, 0.92);
  padding: 8px;
  justify-content: flex-start;
}

#bed-badge {
  position: fixed;
  top: 8px;
  right: 8px;
  z-index: 40;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #6fbf8a;
  color: #102018;
  border: 3px solid var(--ink);
  border-radius: 999px;
  font-weight: 700;
}

.dock {
  width: min(1024px, 100%);
  margin: 8px auto 0;
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
}

.palette, .tower-actions {
  background: #1c1826;
  border: 3px solid var(--ink);
  border-radius: 16px;
  padding: 8px;
}

.tower-actions {
  min-width: min(100%, 420px);
  justify-content: space-between;
}

.tower-actions .sell {
  margin-left: 48px;
}

.palette button, .tower-actions button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.palette img, .codex img, .brief img {
  width: 40px;
  height: 40px;
  object-fit: contain;
  background: transparent;
}

.codex-body, .settings p, .blurb {
  font-family: var(--body);
  line-height: 1.45;
}

.codex-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}

.entry {
  border: 3px solid var(--ink);
  border-radius: 12px;
  padding: 12px;
  background: #221c30;
  min-height: 44px;
}

.entry.locked { opacity: 0.55; }
.entry.pinned { outline: 3px solid #f2d23a; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(8, 6, 14, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}

.modal .panel {
  background: #241c32;
  border: 3px solid var(--ink);
  border-radius: 16px;
  padding: 16px;
  max-width: 420px;
  width: 100%;
}

.error-file {
  font-family: var(--body);
  font-weight: 700;
}

.hidden { display: none !important; }

.reduced-motion .playfield, .reduced-motion .modal {
  scroll-behavior: auto;
}

@media (max-width: 700px) {
  .dock { flex-direction: column; }
  .tower-actions .sell { margin-left: 32px; }
}
