:root {
  --void: #07060a;
  --plum: #140c14;
  --dusk: #3a2430;
  --crimson: #6e2434;
  --rose: #c4848c;
  --text: #eadde3;
  --muted: #a8909c;
  --visor: #8eafbc;
  --gold: #b1a36a;
  --moss: #8aa37a;
  --px: "Silkscreen", monospace;
  --px2: "Press Start 2P", monospace;
  --body: "IBM Plex Mono", ui-monospace, monospace;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--void);
  color: var(--text);
  font: 15px/1.55 var(--body);
  overflow: hidden;
}
button, a { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }
.stage {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--void);
}
#view {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: var(--void);
  touch-action: none;
}
#mini {
  position: fixed;
  z-index: 4;
  top: 74px;
  right: 16px;
  width: 132px;
  height: auto;
  image-rendering: pixelated;
  border: 2px solid var(--dusk);
  background: #050408;
  box-shadow: 0 0 0 2px var(--void);
  pointer-events: none;
  display: none;
}
body.playing #mini { display: block; }

.kicker, .eyebrow {
  font: 11px var(--px);
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--visor);
  margin: 0 0 8px;
}
.wordmark { width: min(280px, 78vw); height: auto; mix-blend-mode: screen; margin: 0 auto 8px; }
h1, h2 { font-family: var(--px); font-weight: 400; color: #fff; margin: 0 0 8px; }
h1 { font-size: 22px; letter-spacing: .04em; }
h2 { font-size: 16px; line-height: 1.35; }

.pix {
  font: 11px var(--px);
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text);
  text-decoration: none;
  background: rgba(20, 12, 20, .9);
  border: 2px solid var(--rose);
  padding: 10px 12px;
  cursor: pointer;
  box-shadow: 3px 3px 0 #3a1822;
}
.pix:hover { transform: translate(-1px, -1px); }
.pix:active { transform: translate(1px, 1px); box-shadow: none; }
.pix.primary { background: #8a3044; border-color: #e0a8ae; color: #fff; }
.pix:disabled { opacity: .55; cursor: wait; }

/* loader */
#loader {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: radial-gradient(ellipse at 50% 30%, #2a121c, var(--void) 62%);
  transition: opacity .45s ease;
  padding: 24px;
}
#loader.hide { opacity: 0; pointer-events: none; }
.loader-moon {
  position: absolute;
  width: min(540px, 90vw);
  top: -8%;
  mix-blend-mode: screen;
  opacity: .8;
  pointer-events: none;
  animation: moonpulse 5s ease-in-out infinite;
}
.loader-sprite {
  width: 110px;
  height: 150px;
  margin-bottom: 12px;
  background: url(/assets/img/entity-sprite.webp) 0 0 / 600% 100% no-repeat;
  image-rendering: pixelated;
  animation: sway 1.2s steps(6) infinite;
  filter: saturate(.9) drop-shadow(0 0 12px rgba(140, 40, 60, .45));
  position: relative;
  z-index: 1;
}
.loader-title { font: 20px var(--px); margin: 8px 0 18px; position: relative; }
.bar {
  width: min(280px, 70vw);
  height: 10px;
  border: 2px solid var(--crimson);
  background: #14080e;
  position: relative;
}
#loadBar { display: block; height: 100%; width: 0; background: #8a4050; }
#loadStatus { color: var(--muted); font-size: 13px; margin-top: 12px; position: relative; }

@keyframes sway { from { background-position: 0 0; } to { background-position: 120% 0; } }
@keyframes moonpulse { 50% { opacity: 1; transform: scale(1.03); } }

/* gate */
#gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  padding: 18px;
  transition: opacity .4s ease;
}
#gate.hide, #gate.hide .card { opacity: 0; pointer-events: none; }
#gate .card {
  pointer-events: auto;
  width: min(440px, 100%);
  max-height: min(92vh, 760px);
  overflow: auto;
  background: rgba(8, 4, 10, .9);
  border: 3px solid var(--crimson);
  box-shadow: 0 0 0 3px var(--void), 0 0 0 6px #3a1824, 0 0 36px rgba(90, 24, 40, .35);
  padding: 18px 18px 14px;
}
.lede { margin: 0 0 12px; color: var(--text); }
.preview { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.preview img {
  width: 88px; height: 88px;
  image-rendering: pixelated;
  border: 2px solid var(--crimson);
  background: #10080e;
  object-fit: cover;
}
.who { margin: 0; font: 13px var(--px); line-height: 1.45; color: #fff; }
.row-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 2px 8px;
  margin-bottom: 8px;
}
.row-scroll button, .token-grid button {
  flex: 0 0 auto;
  width: 64px;
  padding: 3px;
  background: #10080e;
  border: 2px solid var(--dusk);
  cursor: pointer;
}
.row-scroll button.on, .token-grid button.on { border-color: var(--rose); }
.row-scroll img, .token-grid img { width: 56px; height: 56px; image-rendering: pixelated; }
.token-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.token-grid[hidden] { display: none; }
.status { min-height: 1.3em; margin: 0 0 8px; color: var(--gold); font-size: 13px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.fine { margin: 0 0 6px; color: var(--muted); font-size: 12px; }
.fine a { color: var(--rose); }

/* hud */
#hud { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
.hud-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  padding: 14px 16px 0;
}
.hud-actions { display: flex; gap: 8px; pointer-events: auto; flex-wrap: wrap; justify-content: flex-end; }
.place-name { margin: 0; font: 14px var(--px); color: #fff; text-shadow: 0 2px 0 #000; max-width: 46vw; }
.hud-place .eyebrow { text-shadow: 0 1px 0 #000; }
.hint {
  position: absolute;
  left: 16px;
  bottom: 16px;
  margin: 0;
  color: var(--muted);
  font: 11px var(--px);
  letter-spacing: .04em;
  text-shadow: 0 2px 0 #000;
  transition: opacity .6s ease;
}
.hint.gone { opacity: 0; }
.hud-you {
  position: absolute;
  right: 16px;
  bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(8, 4, 10, .78);
  border: 2px solid var(--dusk);
  padding: 6px 10px 6px 6px;
  max-width: min(280px, 70vw);
}
#hudPortrait { width: 48px; height: 48px; image-rendering: pixelated; object-fit: cover; background: #10080e; }
#hudName { margin: 0; font: 11px var(--px); line-height: 1.4; }
.bark {
  position: absolute;
  left: 50%;
  bottom: 118px;
  transform: translateX(-50%);
  margin: 0;
  max-width: min(460px, calc(100% - 32px));
  background: rgba(8, 4, 10, .92);
  border: 2px solid var(--visor);
  padding: 10px 12px;
  font-size: 14px;
  text-align: center;
}
.prompt {
  position: absolute;
  left: 50%;
  bottom: 86px;
  transform: translateX(-50%);
  margin: 0;
  font: 11px var(--px);
  color: var(--visor);
  text-shadow: 0 2px 0 #000;
}

.panel {
  position: fixed;
  z-index: 6;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  width: min(520px, calc(100% - 32px));
  background: rgba(8, 4, 10, .94);
  border: 3px solid var(--crimson);
  box-shadow: 0 0 0 3px var(--void), 0 0 28px rgba(80, 20, 36, .4);
  padding: 14px 16px 12px;
}
.panel h2 { font-size: 15px; }
.panel .tag { margin: 0 0 8px; color: var(--gold); font: 11px var(--px); letter-spacing: .06em; }
.panel #panelBody { margin: 0 0 10px; }
.panel .pix { pointer-events: auto; }

#joy {
  display: none;
  position: fixed;
  z-index: 7;
  left: calc(16px + env(safe-area-inset-left));
  bottom: calc(16px + env(safe-area-inset-bottom));
  width: 118px;
  height: 118px;
  border-radius: 50%;
  border: 3px solid var(--dusk);
  background: rgba(12, 6, 12, .45);
  touch-action: none;
}
#knob {
  position: absolute;
  left: 41px;
  top: 41px;
  width: 36px;
  height: 36px;
  background: var(--crimson);
  border: 2px solid var(--rose);
}
.talk {
  display: none;
  position: fixed;
  z-index: 7;
  right: calc(16px + env(safe-area-inset-right));
  bottom: calc(92px + env(safe-area-inset-bottom));
}
body.touch.playing #joy { display: block; }
body.touch.playing .talk.show { display: block; }
body.touch.playing .hint { display: none; }
body.touch.playing .hud-you {
  top: auto;
  left: 12px;
  right: auto;
  bottom: calc(146px + env(safe-area-inset-bottom));
  max-width: 46vw;
}
body.touch.playing #mini { top: 86px; width: 96px; }

#plan {
  position: fixed;
  inset: 0;
  z-index: 12;
  background: rgba(5, 2, 8, .72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}
#plan[hidden] { display: none; }
.plan-card {
  width: min(460px, 100%);
  max-height: min(86vh, 720px);
  overflow: auto;
  background: #100810;
  border: 3px solid var(--crimson);
  padding: 16px;
}
.plan-card ol { list-style: none; margin: 0 0 12px; padding: 0; }
.plan-card li {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 7px 0;
  border-bottom: 1px solid #2a1822;
  color: var(--muted);
}
.plan-card li.seen { color: var(--text); }
.plan-card li b { font: 12px var(--px2); color: var(--rose); width: 28px; flex: none; }
.plan-card li.here { background: rgba(110, 36, 52, .28); }

#toast {
  position: fixed;
  z-index: 14;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(8, 4, 10, .94);
  border: 2px solid var(--gold);
  color: var(--gold);
  font: 12px var(--px);
  padding: 10px 14px;
  max-width: calc(100% - 28px);
  text-align: center;
}
#toast[hidden] { display: none; }

@media (min-width: 860px) {
  #gate { align-items: center; }
  #gate .card { max-height: calc(100vh - 36px); }
}
@media (max-width: 800px) {
  .panel { bottom: 132px; width: calc(100% - 20px); }
  .bark { bottom: 250px; }
  .prompt { bottom: 210px; }
  #hudName { font-size: 10px; }
  .place-name { font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .loader-sprite, .loader-moon { animation: none; }
  #loader, #gate { transition: none; }
}
