/* Screen-edge controls fill the viewport; windows keep their 960 x 740 box. */
#hud {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  font-size: var(--fs-base);
  line-height: var(--lh);
}

#hud > :is(#notices, .ol-chat, .town-bar, #installhint, #relock, .soundbtn,
  #teamask, #lootroll, #toast, #lockhint, .tower-banner, #hud-performance, .restart-banner, #touch-chat-toggle) {
  position: absolute;
  right: auto;
  bottom: auto;
  transform-origin: 0 0;
  box-sizing: border-box;
  transition-property: opacity;
}

#hud > :is(.town-bar, #teamask, #lootroll) { pointer-events: auto; }
#hud > :is(#toast, #lockhint, .tower-banner, #installhint, .restart-banner) { z-index: 41; }
#hud > #loading { z-index: 19; }
#hud > #notices { z-index: 21; }
#hud > .ol-chat { z-index: 20; }
#hud > #touch { z-index: 30; }
#hud .stick {
  left: calc(max(22px, var(--hud-inset)) + env(safe-area-inset-left, 0px));
  bottom: calc(max(22px, var(--hud-inset)) + env(safe-area-inset-bottom, 0px));
}
#hud .tbtns {
  right: calc(max(var(--touch-action-inset), var(--hud-inset)) + env(safe-area-inset-right, 0px));
  bottom: calc(max(var(--touch-action-inset), var(--hud-inset)) + env(safe-area-inset-bottom, 0px));
}
#hud .cmdbtn {
  top: calc(max(10px, var(--hud-inset)) + env(safe-area-inset-top, 0px));
  right: calc(max(10px, var(--hud-inset)) + env(safe-area-inset-right, 0px));
}
#hud > #touch-chat-toggle {
  min-width: 76px;
  min-height: 44px;
  padding: 4px 8px;
  pointer-events: auto;
  touch-action: manipulation;
  z-index: 30;
  color: var(--text-1);
  background: var(--surface-panel);
  border: 1px solid var(--line-3);
  border-radius: var(--radius);
  font: 600 var(--fs-base)/1.4 var(--ui);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
#hud > #touch-chat-toggle[hidden] { display: none; }
#hud > #touch-chat-toggle:hover { border-color: var(--ember); }
#hud > #touch-chat-toggle:focus-visible, #hud > #touch-chat-toggle.is-focus {
  outline: 2px solid var(--ember);
  outline-offset: 2px;
}
#hud .stick[hidden] { display: none; }
#hud .town-bar { flex-wrap: wrap; justify-content: center; white-space: normal; gap: 4px; padding: 3px 5px; }
#hud .town-bar .town-icon { min-height: 0; padding: 2px 5px; gap: 4px; }
html.touch-ui #hud .town-bar .town-icon { min-height: var(--ctl-touch); }
#hud .town-bar .tb-icon { flex: none; display: block; }
#hud .town-bar .kbd { min-width: 14px; height: 14px; padding: 0 3px; font-size: 10px; }
#hud > :is(.town-bar, #installhint, #relock, #toast, #lockhint, #hud-performance) { width: max-content; }
#hud > :is(#teamask, #lootroll, #toast, #lockhint, .tower-banner, #hud-performance, .restart-banner) { overflow-y: auto; }
#hud .tower-banner, #hud .restart-banner { font-size: var(--fs-base); }

/* Scroll the explanation while both installation controls stay in place. */
#hud #installhint { max-width: min(300px, 100%); overflow: visible; padding: 16px; }
#hud #installhint > div { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#hud #installhint p { min-height: 0; overflow-y: auto; }
#hud #installhint button { flex: none; }

#hud #notices { min-height: 0; }
#hud #notice-list { box-sizing: border-box; }
#hud #notices.header-only #notice-list { display: none; }
#hud #notices, #hud #notice-list { padding: 6px; }
#hud .ol-chat { width: 330px; overflow-y: auto; }
#hud .ol-chat > * { flex: none; }
#hud .oc-bar { flex-wrap: nowrap; padding: 4px 4px 0; gap: 2px; }
#hud .oc-bar .oc-tab { flex: none; }
#hud .ol-chat .oc-bar button { min-height: 0; }
html.touch-ui #hud .ol-chat .oc-bar button { min-height: var(--ctl-touch); }
#hud .ol-chat:focus-within .oc-bar { opacity: 1; }
#hud .oc-log { margin-top: 6px; }
#hud .oc-menu { position: static; width: auto; margin: 6px; gap: 8px; }
#hud .oc-menu button { margin: 2px; }
#hud .oc-ch, #hud .oc-in, #hud .ck-notice-toggle { font-size: var(--fs-base); }
#hud .oc-tab { font-size: var(--fs-xs); }
#hud .oc-line { min-width: 0; padding: 2px; }
#hud .oc-in { min-width: 44px; }
#hud .ol-chat.compact .oc-bar { flex-wrap: nowrap; overflow-x: auto; padding: 2px 3px; gap: 1px; }
#hud .ol-chat.compact .oc-bar button { flex: none; padding-inline: 2px; }

/* Loading fills the viewport while its type follows the shared format rule. */
#hud .ld { padding: 2% 6%; gap: 1.5%; }
#hud .ld-head, #hud .ld-foot { flex: none; }
#hud .ld-slot { flex: 1; min-height: 0; max-height: 46%; }
#hud .ld-town { font-size: calc(36px * var(--hud-scale, 1)); }
#hud .ld-sub, #hud .ld-tip, #hud .ld-slow-hint, #hud .ld-help { font-size: calc(12px * var(--hud-scale, 1)); }
#hud .ld-eyebrow, #hud .ld-label, #hud .ld-tip b { font-size: calc(11px * var(--hud-scale, 1)); }
#hud .ld-ph { font-size: calc(13px * var(--hud-scale, 1)); }
#hud .ld-slot figcaption { font-size: calc(14px * var(--hud-scale, 1)); }
#hud .ld-slot figcaption b { font-size: calc(20px * var(--hud-scale, 1)); }
#hud .ld-foot { width: min(560px, 90%); padding-bottom: calc(12px * var(--hud-scale, 1)); }
#hud .ld-tip, #hud .ld-slow-hint { margin-top: calc(8px * var(--hud-scale, 1)); }
#hud .ld-help, html.touch-ui #hud .ld-help { min-height: calc(44px * var(--hud-scale, 1)); margin-top: 4px; }

#hud #hud-performance {
  z-index: 41;
  pointer-events: none;
  font: 12px/1.3 ui-monospace, Menlo, Consolas, monospace;
  color: #cfe;
  background: rgba(0, 0, 0, 0.66);
  padding: 3px 6px;
  border-radius: 4px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

#hud ::-webkit-scrollbar { width: var(--scroll-size); height: var(--scroll-size); }
#hud ::-webkit-scrollbar-thumb { background: var(--line-3); border-radius: 5px; }
html.touch-ui #hud ::-webkit-scrollbar { width: var(--scroll-size-touch); }

/* Floor feedback wraps in the left slot between missions and the movement stick. */
#hud[data-format="phone-landscape"] .tower-banner { padding: 5px 8px; line-height: 1.1; }
#hud[data-format="phone-landscape"] .tower-banner h4 { font-size: 12px; margin-bottom: 2px; }
#hud[data-format="phone-landscape"] .tower-banner .eyebrow { display: none; }
#hud[data-format="phone-landscape"] .tower-banner-note { font-size: 10px; margin-top: 2px; }
#hud[data-format="phone-landscape"] .tower-banner ul { display: flex; flex-wrap: wrap; column-gap: 12px; }
#hud[data-format="phone-landscape"] .tower-banner li { flex: 1 0 auto; }

/* Keep item, metadata, member choices and actions in normal flow on short screens. */
#hud[data-compact-roll] #lootroll { overflow: visible; padding: 2px; }
#hud[data-compact-roll] #lootroll .lr-card { flex: none; padding: 4px 6px; }
#hud[data-compact-roll] #lootroll p { margin-bottom: 2px; line-height: 1.15; }
#hud[data-compact-roll] #lootroll .lr-name { font-size: 16px; }
#hud[data-compact-roll] #lootroll .lr-stats:empty { display: none; }
#hud[data-compact-roll] #lootroll ul { display: flex; flex-wrap: wrap; gap: 1px 4px; margin-bottom: 10px; }
#hud[data-compact-roll] #lootroll li { gap: 2px; padding: 0 0 0 2px; font-size: 10px; line-height: 1.15; }
#hud[data-compact-roll] #lootroll .acts { margin-bottom: 0; }
#hud[data-compact-roll] #lootroll .lr-choice { min-height: 44px; }

/* A crowded left slot still reports the floor and rewards as a compact toast. */
#hud .tower-banner[data-compact] { padding: 4px 6px; font-size: var(--fs-base); line-height: 1; }
#hud .tower-banner[data-compact] .eyebrow, #hud .tower-banner[data-compact] .tower-banner-note { display: none; }
#hud .tower-banner[data-compact] h4 { display: inline; font-size: inherit; margin: 0; }
#hud .tower-banner[data-compact] h4 small { display: none; }
#hud .tower-banner[data-compact] ul { display: inline; }
#hud .tower-banner[data-compact] li { display: inline-flex; gap: 3px; margin-left: 6px; }

#hud[data-compact-roll] #lootroll li small { display: none; }

#hud[data-compact-roll] #lootroll .lr-meta { font-size: 10px; }

#hud .tower-banner[data-compact] li:first-child span { display: none; }
