/* pixelart.bar - Retro HUD, dialogue box and node cards (Tier 3, DOM).
   Everything is sized in LOGICAL pixels via --u (CSS px per logical pixel, set by the renderer),
   so the UI scales in lockstep with the integer-scaled canvas and sits exactly over it.
   Font: Silkscreen (SIL OFL 1.1), bundled locally. It is drawn on an 8px grid, so text is always
   8 logical px (multiples of 8 only). No CDN, font-display: block (no fallback-font flash). */

@font-face {
  font-family: "Silkscreen";
  src: url("../assets/fonts/Silkscreen-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: block;
}

:root {
  --white: #fcfcfc;   /* TEXT_WHITE */
  --amber: #fc9838;   /* FIRE_AMBER */
}

[hidden] {
  display: none !important;
}

/* The overlay is exactly the canvas' box: 256x240 logical px. Like the canvas it is laid out in
   device px (--u = whole device px per logical px) and transformed back to CSS px. */
#ui-layer {
  position: absolute;
  left: 0;
  top: 0;
  width: calc(256 * var(--u, 1px));
  height: calc(240 * var(--u, 1px));
  transform-origin: 0 0;
  transform: translate(var(--canvas-x), var(--canvas-y)) scale(var(--canvas-s));
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
  visibility: hidden;                       /* revealed with the canvas: no layout shift */
  font-family: "Silkscreen", monospace;
  font-size: calc(8 * var(--u, 1px));
  line-height: calc(12 * var(--u, 1px));
  color: var(--white);
  text-transform: uppercase;
  font-kerning: none;
  letter-spacing: 0;
  text-rendering: optimizeSpeed;
  -webkit-font-smoothing: none;
}

#game-canvas[data-ready] ~ #ui-layer {
  visibility: visible;
}

#ui-layer p,
#ui-layer h2 {
  margin: 0;
  font: inherit;
}

/* ---- Top HUD: current room -------------------------------------------- */

#hud {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: calc(16 * var(--u, 1px));
  padding: 0 calc(8 * var(--u, 1px));
  display: flex;
  align-items: center;
  background: var(--backdrop);
  border-bottom: calc(2 * var(--u, 1px)) solid var(--white);
  color: var(--white);              /* TEXT_WHITE */
  gap: calc(4 * var(--u, 1px));
}

/* Banner text: white face with a hard 1-logical-pixel STONE_DARK drop shadow (no blur). */
#hud-title {
  text-shadow: var(--u, 1px) var(--u, 1px) 0 var(--slate);
}

/* Pint icon: 12x12 logical px, integer scaled, same 1px shadow. */
#hud-pint {
  flex: none;
  width: calc(12 * var(--u, 1px));
  height: calc(12 * var(--u, 1px));
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  filter: drop-shadow(var(--u, 1px) var(--u, 1px) 0 var(--slate));
}

/* ---- Bottom/top dialogue box: classic NES white border on near-black ------ */

.dlg {
  position: absolute;
  left: calc(8 * var(--u, 1px));
  width: calc(240 * var(--u, 1px));
  padding: calc(6 * var(--u, 1px)) calc(8 * var(--u, 1px));
  background: var(--backdrop);
  border: calc(2 * var(--u, 1px)) solid var(--white);
}

/* Placed on the half of the screen away from the Wanderer so it never covers them. */
.dlg.at-bottom { bottom: calc(8 * var(--u, 1px)); top: auto; }
.dlg.at-top    { top: calc(20 * var(--u, 1px));   bottom: auto; }

.dlg-title  { color: var(--amber); }
.dlg-flavor { margin-top: calc(4 * var(--u, 1px)) !important; }
.dlg-prompt {
  margin-top: calc(4 * var(--u, 1px)) !important;
  text-align: right;
  animation: prompt-blink 1s steps(1, end) infinite;   /* 2-frame blink */
}

@keyframes prompt-blink {
  50% { visibility: hidden; }
}

/* Keyboard prompt by default; touch prompt when the on-screen controls are showing. */
.p-touch { display: none; }
#app[data-controls="on"] .p-key   { display: none; }
#app[data-controls="on"] .p-touch { display: inline; }

@media (prefers-reduced-motion: reduce) {
  .dlg-prompt { animation: none; }
}

/* ---- Node card: full-screen retro modal inside the NES frame ------------------ */

#ui-layer { --tap: 0px; }
@media (pointer: coarse) {
  /* 44 CSS px touch targets. The layer is laid out in device px, so convert through --canvas-s (= 1/dpr). */
  #ui-layer { --tap: calc(44px / var(--canvas-s, 1)); }
}

#card {
  position: absolute;
  inset: 0;
  z-index: 2;
  background: var(--backdrop);
  pointer-events: auto;                       /* swallows clicks: the world is suspended */
  outline: none;
}

.card-frame {
  position: absolute;
  inset: calc(4 * var(--u, 1px));
  border: calc(4 * var(--u, 1px)) solid var(--white);
  padding: calc(6 * var(--u, 1px));
  display: flex;
  flex-direction: column;
  gap: calc(6 * var(--u, 1px));
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: calc(8 * var(--u, 1px));
}

.card-head h2 {
  color: var(--amber);
  align-self: center;
}

.card-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}

.card-body p + p { margin-top: calc(6 * var(--u, 1px)); }
.card-lore { color: var(--foam); }

.card-actions {
  display: flex;
  flex-direction: column;
  gap: calc(4 * var(--u, 1px));
}

.card-btn,
.card-x {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0 calc(6 * var(--u, 1px));
  border: calc(2 * var(--u, 1px)) solid var(--white);
  border-radius: 0;
  background: var(--backdrop);
  color: var(--white);
  font: inherit;
  line-height: calc(12 * var(--u, 1px));
  letter-spacing: inherit;
  text-transform: inherit;
  text-decoration: none;
  text-align: center;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: transparent;
}

/* Touch targets: 44 CSS px where the frame has room, capped at 33 logical px so the longest card (4B:
   header + 3 buttons + 4 lines of text) always fits on small phones (never below ~33 CSS px there). */
.card-btn { min-height: max(calc(16 * var(--u, 1px)), min(var(--tap), calc(33 * var(--u, 1px)))); }
.card-x   { flex: none;
            min-height: max(calc(16 * var(--u, 1px)), min(var(--tap), calc(33 * var(--u, 1px))));
            min-width:  max(calc(24 * var(--u, 1px)), min(var(--tap), calc(33 * var(--u, 1px)))); }

/* Focus / hover: classic inverted selection. Never relies on an outline ring. */
.card-btn:hover, .card-btn:focus,
.card-x:hover,   .card-x:focus {
  background: var(--white);
  color: var(--backdrop);
  outline: none;
}
