/* Nusa Island hotbar, needs bars, binoculars. Uses the tokens defined on #ui (ui.css). */

#ui .hud {
  --hb-slot: 56px;
  --hb-gap: 6px;
  --hb-bottom: 16px;
  --hb-w: calc(var(--hb-slot) * var(--hb-n, 6) + var(--hb-gap) * (var(--hb-n, 6) - 1)); /* Stage 20: 8 slots with the hide pouch */
  --hb-top: calc(var(--hb-bottom) + var(--hb-slot));
}

/* ---------- Hotbar ---------- */
#ui .hotbar {
  position: absolute;
  left: 50%;
  bottom: var(--hb-bottom);
  transform: translateX(-50%);
  display: flex;
  gap: var(--hb-gap);
  pointer-events: auto;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
#ui .hb-slot {
  position: relative;
  flex: none;
  width: var(--hb-slot);
  height: var(--hb-slot);
  padding: 0;
  border: 0;
  border-radius: 3px;
  background: rgba(23, 20, 15, .58);
  box-shadow: inset 0 0 0 1px rgba(244, 239, 227, .3), 0 2px 6px rgba(0, 0, 0, .35);
  color: var(--hud);
  overflow: hidden;
  touch-action: none;
  transition: transform .14s var(--ease), background-color .12s, box-shadow .12s;
}
#ui .hb-slot::after { /* stitching, same as the bag pockets */
  content: '';
  position: absolute;
  inset: 3px;
  border: 1.5px dashed rgba(244, 239, 227, .22);
  border-radius: 1px;
  pointer-events: none;
}
#ui .hb-slot.is-empty { background: rgba(23, 20, 15, .34); }
#ui .hb-slot:hover { background: rgba(23, 20, 15, .74); }
#ui .hb-slot.is-selected {
  transform: translateY(-5px);
  background: rgba(23, 20, 15, .86);
  box-shadow: inset 0 0 0 2px var(--signal), 0 6px 14px rgba(0, 0, 0, .45);
}
#ui .hb-slot.is-selected::after { border-color: rgba(255, 91, 31, .5); }
#ui .hb-slot:focus-visible { outline-offset: -2px; }
#ui .hb-img { position: absolute; inset: 5px; display: grid; place-items: center; pointer-events: none; }
#ui .hb-img img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .5)); }
#ui .hb-fallback {
  max-width: 100%;
  font-family: var(--f-label);
  font-weight: 700;
  font-size: 11px;
  line-height: 1.05;
  letter-spacing: .05em;
  text-transform: uppercase;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
}
#ui .hb-num {
  position: absolute;
  top: 3px; left: 5px;
  z-index: 1;
  font-family: var(--f-label);
  font-weight: 700;
  font-size: 11px;
  line-height: 1;
  letter-spacing: .04em;
  color: rgba(244, 239, 227, .7);
  text-shadow: var(--hud-shadow);
  pointer-events: none;
}
#ui .hb-slot.is-selected .hb-num { color: var(--signal); }
#ui .hb-qty {
  position: absolute;
  right: 4px; bottom: 2px;
  z-index: 1;
  font-family: var(--f-display);
  font-weight: 900;
  font-size: 16px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--hud);
  text-shadow: var(--hud-shadow);
  pointer-events: none;
}
#ui .hb-sub {
  position: absolute;
  left: 5px; bottom: 3px;
  z-index: 1;
  font-family: var(--f-label);
  font-weight: 700;
  font-size: 11px;
  line-height: 1;
  letter-spacing: .04em;
  color: var(--signal);
  text-shadow: var(--hud-shadow);
  pointer-events: none;
}

/* Hidden with the HUD (inherited), while the bag is open and while an item is examined */
#ui .hud.is-inv .hotbar, #ui .hud.is-inv .needs,
#ui .hud.is-examining .hotbar, #ui .hud.is-examining .needs { visibility: hidden; pointer-events: none; }

/* ---------- Needs ---------- */
#ui .needs {
  position: absolute;
  left: calc(50% - var(--hb-w) / 2);
  bottom: calc(var(--hb-top) + 10px);
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 112px;
  pointer-events: none;
}
#ui .need { display: flex; align-items: center; gap: 6px; color: var(--hud); filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .55)); }
#ui .nd-ic { flex: none; display: block; }
#ui .need-bar {
  position: relative;
  flex: 1;
  height: 6px;
  border-radius: 1px;
  background: rgba(23, 20, 15, .6);
  box-shadow: inset 0 0 0 1px rgba(244, 239, 227, .28);
  overflow: hidden;
}
#ui .need-fill {
  position: absolute;
  inset: 0;
  transform-origin: left center;
  background: var(--hud);
  transition: transform .3s linear;
}
#ui .need--thirst .need-fill { background: #BFE3EA; }
#ui .need--hunger .need-fill { background: #E3D79E; }
#ui .need.is-low { color: var(--signal); animation: need-pulse 1.1s ease-in-out infinite; }
#ui .need.is-low .need-fill { background: var(--signal); }
@keyframes need-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .5; } }

/* ---------- Binoculars ---------- */
#ui .bino {
  position: fixed;
  inset: 0;
  z-index: 15;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity .15s linear, visibility 0s linear .15s;
}
#ui .bino svg { display: block; }
#ui .bino.is-on { opacity: 1; visibility: visible; transition: opacity .15s linear; }
#ui .crosshair.is-bino { opacity: 0; }

/* ---------- Layout against the hotbar ---------- */
#ui .hint { bottom: calc(var(--hb-top) + 44px); }

/* Touch: >= 44px targets, no number keys */
html.is-touch #ui .hud { --hb-slot: 48px; --hb-gap: 4px; --hb-bottom: max(8px, env(safe-area-inset-bottom, 0px)); }
html.is-touch #ui .hb-num { display: none; }
html.is-touch #ui .hb-slot.is-selected { transform: translateY(-3px); }
html.is-touch #ui .needs { width: 92px; bottom: calc(var(--hb-top) + 8px); }
@media (max-width: 800px) {
  html.is-touch #ui .hud { --hb-slot: 44px; }
}
@media (max-height: 500px), (max-width: 900px) {
  /* weapon readout sits centred just above the hotbar; needs sit above its left end */
  html.is-touch #ui .weapon { bottom: calc(var(--hb-top) + 8px); }
  /* to the right of the needs bars, never across them: long names ellipsize */
  html.is-touch #ui .weapon {
    left: calc(50% - var(--hb-n, 6) * 0.5 * var(--hb-slot) - (var(--hb-n, 6) - 1) * 0.5 * var(--hb-gap) + 104px);
    transform: none;
    text-align: left;
    max-width: calc(var(--hb-n, 6) * var(--hb-slot) + (var(--hb-n, 6) - 1) * var(--hb-gap) - 104px);
  }
  html.is-touch #ui .weapon-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}

@media (prefers-reduced-motion: reduce) {
  #ui .need.is-low { animation: none; }
}

/* Stage 20: slots 7-8 exist only with the hide pouch */
#ui .hb-slot[hidden] { display: none; }
