/* In-game HUD. One layout for every screen, adjusted by size and input type:
   - top bar (where you are, points/backpack, leave) and a column of icon tools on the right
   - objective + events under the top bar, panels (islands, chat, settings) open on demand
   - touch screens get a joystick and big action/jump buttons
   Safe areas keep everything clear of notches and home bars. */
.xhud {
  --g: 12px;                                         /* outer gap */
  --t: max(var(--g), env(safe-area-inset-top));
  --r: max(var(--g), env(safe-area-inset-right));
  --b: max(var(--g), env(safe-area-inset-bottom));
  --l: max(var(--g), env(safe-area-inset-left));
  --tool: 42px;                                      /* icon button size */
  --bg: rgba(6, 26, 36, .8);
  position: absolute; inset: 0; z-index: 6; pointer-events: none;
  font-size: 14px; color: #fff; -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none;
}
.xhud[hidden] { display: none; }
.xhud > * { pointer-events: auto; }
.xhud [hidden] { display: none !important; }
.xhud button { font: inherit; color: inherit; cursor: pointer; }
.xhud kbd { display: inline-block; padding: 1px 6px; border-radius: 4px; background: rgba(255, 255, 255, .16); font: 600 11px var(--mono); }
.xhud svg { width: 20px; height: 20px; display: block; }

/* ---- top bar ---- */
.hud-top { position: absolute; top: var(--t); left: var(--l); right: var(--r); height: 48px; display: flex; align-items: stretch; gap: 8px; pointer-events: none; }
.hud-top > * { pointer-events: auto; }
.hud-where { flex: 0 1 auto; min-width: 0; margin: 0 auto 0 0; padding: 6px 12px; border-radius: 10px; background: var(--bg); backdrop-filter: blur(8px); display: grid; align-content: center; gap: 1px; }
.hud-where > * { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-where .row { display: flex; gap: 8px; min-width: 0; line-height: 1.3; }
.hud-where .row > * { flex: 0 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-where span { font: 600 10px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--sea); }
.hud-where b { font: 700 16px/1.25 var(--head); }
.hud-where small { font: 600 10px var(--mono); letter-spacing: .04em; color: var(--muted); }
.hud-where small:empty { display: none; }
.hud-miner { flex: none; display: grid; grid-template-columns: auto auto; align-content: center; gap: 0 10px; padding: 7px 12px; border: 0; border-radius: 10px; background: var(--bg); backdrop-filter: blur(8px); text-align: left; }
.hud-miner > b { font: 700 14px var(--mono); color: var(--sand); }
.hud-miner > span { font-size: 12px; color: var(--muted); align-self: center; }
.hud-miner > span b { color: #fff; font-family: var(--mono); }
.hud-miner .bagbar { grid-column: 1 / -1; height: 4px; margin-top: 5px; border-radius: 2px; background: rgba(255, 255, 255, .15); overflow: hidden; }
.hud-miner .bagbar i { display: block; height: 100%; width: 0; background: var(--sea); transition: width .4s ease, background .3s; }
.hud-miner .bagbar i.full { background: var(--coral); }
.hud-exit { flex: none; display: flex; align-items: center; gap: 6px; padding: 0 14px; border: 0; border-radius: 10px; background: var(--coral); font-weight: 600; }
.hud-exit .x-only { display: none; font-size: 22px; line-height: 1; }

/* ---- tool column ---- */
.hud-tools { position: absolute; right: var(--r); top: calc(var(--t) + 58px); display: grid; gap: 6px; }
.hud-tools button { position: relative; width: var(--tool); height: var(--tool); display: grid; place-items: center; border: 0; border-radius: 10px; background: var(--bg); backdrop-filter: blur(8px); }
.hud-tools button:hover, .hud-tools button.on { background: rgba(63, 214, 200, .28); }
.hud-tools .q { font: 800 19px var(--head); }
.hud-tools .badge { position: absolute; right: -4px; top: -4px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--coral); font: 700 11px/18px var(--mono); text-align: center; }

/* ---- objective, events, tutorial (left column under the top bar) ---- */
.hud-left { position: absolute; left: var(--l); top: calc(var(--t) + 58px); width: min(520px, calc(100% - var(--l) - var(--r) - var(--tool) - 10px)); display: flex; flex-direction: column; align-items: flex-start; gap: 6px; pointer-events: none; }
.hud-left > * { max-width: 100%; }
.hud-rush, .hud-tut { pointer-events: auto; }
.hud-goal { display: flex; align-items: center; gap: 8px; padding: 7px 12px; border-radius: 10px; background: rgba(6, 26, 36, .72); font-size: 13px; pointer-events: none; }
.hud-goal span { min-width: 0; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.hud-goal .arrow { flex: none; color: var(--sand); transition: transform .15s linear; }
.hud-goal.carry { background: rgba(48, 36, 6, .86); box-shadow: inset 0 0 0 1.5px rgba(255, 217, 102, .7); color: #fff3c4; }
.hud-goal.carry .arrow { color: #ffd966; width: 22px; height: 22px; }
.hud-goal.carry b { color: #ffd966; }
.hud-goal.carry.full { animation: goal-full 1.4s ease-in-out infinite; }
@keyframes goal-full { 50% { box-shadow: inset 0 0 0 2px #ffd966, 0 0 18px rgba(255, 217, 102, .55); } }
@media (prefers-reduced-motion: reduce) { .hud-goal.carry.full { animation: none; box-shadow: inset 0 0 0 2px #ffd966; } }
.hud-goal b { flex: none; font: 600 11px var(--mono); color: var(--muted); }
.hud-goal b:empty { display: none; }
.hud-rush { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 7px 12px; border: 0; border-radius: 10px; background: linear-gradient(90deg, #f5c34a, #ffdf80); color: #3a2a00 !important; font: 700 12px var(--mono); text-align: left; animation: rushpulse 1.6s ease-in-out infinite; }
@keyframes rushpulse { 50% { box-shadow: 0 4px 22px rgba(245, 195, 74, .7); } }
.hud-tut { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; align-items: center; padding: 10px 12px; border-radius: 12px; background: #fff; color: var(--deep); box-shadow: 0 10px 28px rgba(0, 0, 0, .25); }
.hud-tut .n { grid-row: span 2; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--coral); color: #fff; font: 700 12px var(--mono); }
.hud-tut p { margin: 0; font-size: 13px; line-height: 1.4; }
.hud-tut button { justify-self: start; padding: 0; border: 0; background: none; color: #5a7a84 !important; font-size: 12px; text-decoration: underline; }

/* ---- panels: islands, chat, settings ---- */
.hud-panel { position: absolute; z-index: 4; display: flex; flex-direction: column; border-radius: 12px; background: rgba(6, 26, 36, .94); border: 1px solid var(--line); box-shadow: 0 14px 40px rgba(0, 0, 0, .3); overflow: hidden; }
.hud-panel > header { flex: none; display: flex; align-items: center; justify-content: space-between; padding: 10px 8px 6px 14px; }
.hud-panel > header b { font: 700 15px var(--head); }
.pclose { width: 32px; height: 32px; border: 0; border-radius: 8px; background: none; font-size: 22px !important; color: var(--muted) !important; }
.pclose:hover { background: rgba(255, 255, 255, .08); }
.xtravel { left: var(--l); top: calc(var(--t) + 58px); width: 230px; max-height: calc(100% - var(--t) - 58px - var(--b) - 10px); }
.xtravel.shut { display: none; }
#xIslands { overflow: auto; padding: 0 8px 8px; display: grid; gap: 2px; scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, .25) transparent; }
#xIslands button { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; padding: 8px; border: 0; border-radius: 6px; background: none; font-size: 13px; }
#xIslands button:hover { background: rgba(255, 255, 255, .1); }
#xIslands button i { width: 10px; height: 10px; flex: none; border-radius: 2px; }
#xIslands button.open { color: var(--muted); }
#xIslands button > b { margin-left: auto; flex: none; font: 11px var(--mono); color: var(--muted); }
#xIslands .nm { display: grid; min-width: 0; }
#xIslands .dl { display: none; font: normal 600 11px var(--mono); color: #ffd966; }
#xIslands button.deliver { color: #ffd966; background: rgba(255, 217, 102, .1); }
#xIslands button.deliver .dl { display: block; }
#xIslands button.deliver i { box-shadow: 0 0 0 2px #ffd966; }
.hud-chat { left: var(--l); bottom: var(--b); width: min(380px, calc(100% - var(--l) - var(--r))); height: min(420px, calc(100% - var(--t) - var(--b) - 60px)); }
#chatLog { flex: 1; min-height: 0; overflow: auto; list-style: none; margin: 0; padding: 0 14px 8px; display: flex; flex-direction: column; gap: 6px; scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, .25) transparent; user-select: text; -webkit-user-select: text; }
#chatLog li { font-size: 13px; line-height: 1.4; overflow-wrap: anywhere; }
#chatLog li b { color: var(--sand); font: 600 11px var(--mono); margin-right: 6px; }
#chatLog li time { color: var(--muted); font: 10px var(--mono); margin-right: 6px; }
#chatLog li.sys { color: #9fd6d0; font-style: italic; }
#chatLog li.me b { color: var(--sea); }
#chatLog:empty::before { content: 'No messages yet. Say hi!'; color: var(--muted); font-size: 13px; }
#chatForm { flex: none; display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--line); }
#chatForm input { flex: 1; min-width: 0; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--line); background: rgba(0, 0, 0, .3); color: #fff; font: 16px var(--body); outline: none; }
#chatForm input:focus { border-color: var(--sea); }
.chat-note { flex: none; margin: 0; padding: 0 12px 8px; font-size: 12px; color: var(--coral2); }
.chat-note:empty { display: none; }
.hud-settings { right: calc(var(--r) + var(--tool) + 8px); top: calc(var(--t) + 58px); width: 250px; padding-bottom: 12px; }
.hud-settings .lbl { margin: 0 14px 6px; font: 600 11px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.hud-settings .chips { padding: 0 14px 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.hud-settings .chip { padding: 6px 10px; font-size: 12px; }
.hud-settings .chip.on { background: var(--sea); color: var(--ink) !important; border-color: var(--sea); }
.hud-settings label { display: flex; align-items: center; gap: 8px; padding: 6px 14px 0; font-size: 14px; }

/* ---- action prompt + buttons ---- */
.xprompt { position: absolute; left: 50%; bottom: calc(var(--b) + 12px); transform: translateX(-50%); width: min(460px, calc(100% - var(--l) - var(--r) - 140px)); display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 5px 10px; padding: 10px 14px; border-radius: 10px; background: rgba(6, 26, 36, .88); pointer-events: none; }
.xprompt span { min-width: 0; font-size: 14px; line-height: 1.35; }
.xprompt kbd { background: var(--coral); color: #fff; padding: 3px 8px; font-size: 12px; }
.xprompt .bar { grid-column: 1 / -1; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, .12); overflow: hidden; }
.xprompt .bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--sea), #ffd966); }
.xact { position: absolute; right: var(--r); bottom: var(--b); min-width: 96px; height: 52px; padding: 0 18px; border: 0; border-radius: 26px; background: var(--coral); font-weight: 700 !important; box-shadow: 0 6px 18px rgba(0, 0, 0, .3); }
.xjump, .joy { display: none; }
.npc { position: absolute; left: 0; top: 0; z-index: 1; max-width: 250px; padding: 9px 12px; border-radius: 10px; background: #fff; color: var(--deep); font-size: 13px; line-height: 1.4; pointer-events: none; transform: translate(-50%, -100%); box-shadow: 0 6px 18px rgba(0, 0, 0, .25); }
.npc::after { content: ''; position: absolute; left: 50%; bottom: -6px; width: 12px; height: 12px; background: #fff; transform: translateX(-50%) rotate(45deg); }
/* "deliver ore" marker floating over the treasury chest while you carry ore */
.xdeliver { position: absolute; left: 0; top: 0; z-index: 1; display: grid; justify-items: center; gap: 1px; padding: 6px 12px 7px; border-radius: 10px; background: rgba(28, 20, 3, .86); box-shadow: inset 0 0 0 1.5px #ffd966, 0 6px 18px rgba(0, 0, 0, .3); color: #ffd966; pointer-events: none; transform: translate(-50%, calc(-100% - 14px)); animation: deliver-bob 1.6s ease-in-out infinite; }
.xdeliver b { font: 800 13px var(--head); letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; }
.xdeliver span { font: 600 11px var(--mono); color: #fff3c4; }
.xdeliver::after { content: ''; position: absolute; top: 100%; left: 50%; margin-left: -9px; border: 9px solid transparent; border-top: 12px solid #ffd966; border-bottom: 0; }
.xdeliver.full { background: #ffd966; color: #2a1e00; box-shadow: 0 0 22px rgba(255, 217, 102, .6), 0 6px 18px rgba(0, 0, 0, .3); }
.xdeliver.full span { color: #4a3600; }
.xdeliver.above { transform: translate(-50%, 0); }
.xdeliver.above::after { top: auto; bottom: 100%; border-top: 0; border-bottom: 12px solid #ffd966; }
@keyframes deliver-bob { 50% { translate: 0 -5px; } }
@media (prefers-reduced-motion: reduce) { .xdeliver { animation: none; } }
.xfade { position: absolute; inset: 0; background: #061a24; opacity: 0; pointer-events: none; transition: opacity .35s; }
.xfade.on { opacity: 1; }

/* ---- touch screens (phones, tablets, iPad) ---- */
@media (pointer: coarse) {
  .xhud { --tool: 44px; }
  .hud-exit kbd { display: none; }
  .joy { display: block; position: absolute; left: calc(var(--l) + 6px); bottom: calc(var(--b) + 6px); width: 120px; height: 120px; border-radius: 50%; background: rgba(6, 26, 36, .45); border: 2px solid rgba(255, 255, 255, .25); touch-action: none; }
  .joy i { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%; background: rgba(255, 255, 255, .88); box-shadow: 0 4px 12px rgba(0, 0, 0, .3); pointer-events: none; }
  .xact { right: calc(var(--r) + 4px); bottom: calc(var(--b) + 10px); min-width: 0; width: 82px; height: 82px; padding: 0 6px; border-radius: 50%; font-size: 14px; }
  .xjump { display: block; position: absolute; right: calc(var(--r) + 96px); bottom: calc(var(--b) + 14px); width: 60px; height: 60px; border: 0; border-radius: 50%; background: rgba(6, 26, 36, .78); font-size: 13px; font-weight: 600; touch-action: manipulation; }
  .xprompt { left: calc(var(--l) + 140px); right: calc(var(--r) + 170px); bottom: calc(var(--b) + 20px); width: auto; transform: none; }
  .hud-chat { height: min(420px, calc(100% - var(--t) - var(--b) - 60px)); }
}

/* ---- narrow screens (phones in portrait, small tablets) ---- */
@media (max-width: 760px) {
  .xhud { --g: 10px; }
  .hud-where b { font-size: 15px; }
  #xWho { display: none; }
  .hud-where .row:has(small:empty) { display: none; }
  .hud-miner { padding: 6px 10px; gap: 0 8px; }
  .hud-miner > b { font-size: 13px; }
  .hud-exit { padding: 0; width: 44px; justify-content: center; }
  .hud-exit .lbl, .hud-exit kbd { display: none; }
  .hud-exit .x-only { display: block; }
  .hud-goal { font-size: 12px; }
  .xtravel { width: min(230px, calc(100% - var(--l) - var(--r) - var(--tool) - 10px)); }
  .hud-chat { left: var(--l); right: calc(var(--r) + var(--tool) + 8px); width: auto; height: min(52%, calc(100% - var(--t) - var(--b) - 60px)); }
  .hud-settings { width: min(250px, calc(100% - var(--l) - var(--r) - var(--tool) - 10px)); }
  .npc { max-width: 200px; font-size: 12px; }
}
@media (max-width: 760px) and (pointer: coarse) {
  /* prompt sits above the joystick row in portrait */
  .xprompt { left: var(--l); right: var(--r); bottom: calc(var(--b) + 140px); }
}
@media (max-width: 380px) {
  .hud-where { padding: 6px 9px; }
  .hud-where b { font-size: 14px; }
  .hud-miner > span { display: none; }
  .joy { width: 108px; height: 108px; }
  .xact { width: 76px; height: 76px; }
  .xjump { right: calc(var(--r) + 88px); width: 54px; height: 54px; }
}

/* ---- short screens (phones in landscape) ---- */
@media (max-height: 500px) {
  .xhud { --g: 8px; --tool: 38px; }
  .hud-tools { top: calc(var(--t) + 50px); gap: 4px; grid-template-columns: repeat(2, var(--tool)); }
  .hud-left { top: calc(var(--t) + 50px); gap: 4px; width: min(440px, calc(100% - var(--l) - var(--r) - 2 * var(--tool) - 16px)); }
  .hud-settings { right: calc(var(--r) + 2 * var(--tool) + 12px); }
  .hud-goal { padding: 5px 10px; }
  .hud-tut { padding: 7px 10px; }
  .hud-tut .n { width: 26px; height: 26px; }
  .hud-tut p { font-size: 12px; }
  .hud-top { height: 40px; }
  .hud-where { padding: 4px 10px; }
  .hud-where .row { display: none; }
  .xtravel { top: calc(var(--t) + 50px); max-height: calc(100% - var(--t) - 50px - var(--b)); }
  .hud-settings { top: calc(var(--t) + 50px); max-height: calc(100% - var(--t) - 50px - var(--b)); overflow: auto; }
  .hud-chat { height: calc(100% - var(--t) - var(--b) - 52px); }
  .joy { width: 100px; height: 100px; }
  .joy i { width: 44px; height: 44px; margin: -22px 0 0 -22px; }
  .xact { width: 70px; height: 70px; }
  .xjump { right: calc(var(--r) + 82px); width: 52px; height: 52px; }
  .xprompt { left: calc(var(--l) + 116px); right: calc(var(--r) + 146px); bottom: calc(var(--b) + 8px); width: auto; transform: none; padding: 7px 10px; }
  .xprompt span { font-size: 12px; }
  .npc { max-width: 220px; font-size: 12px; padding: 6px 10px; }
}
@media (max-height: 500px) and (max-width: 760px) {
  .xprompt { left: calc(var(--l) + 110px); right: calc(var(--r) + 140px); bottom: calc(var(--b) + 8px); }
}

/* in-game messages: last item of the left column */
.hud-toast { margin: 0; padding: 0 12px; border-radius: 10px; background: rgba(15, 52, 66, .95); border: 8px solid transparent; border-left-width: 0; border-right-width: 0; box-shadow: inset 0 0 0 1px rgba(63, 214, 200, .35), 0 0 0 0 transparent; background-clip: border-box; font-size: 13px; line-height: 1.4; pointer-events: none; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; animation: toastin .25s ease; }
@keyframes toastin { from { opacity: 0; transform: translateY(-4px); } }
@media (max-height: 640px) {
  .hud-tut p, .hud-toast { font-size: 12px; }
  .hud-tut { padding: 7px 10px; }
  .hud-tut .n { width: 26px; height: 26px; }
  .hud-toast { padding: 0 10px; border-top-width: 6px; border-bottom-width: 6px; }
}

.xhud.left-busy .hud-left { visibility: hidden; }

/* ---- camera zoom: two buttons in the tool column on mouse screens; touch screens pinch (and the slider in Settings) ---- */
.hud-tools .zoom { background: rgba(6, 26, 36, .66); }
@media (pointer: coarse) { .hud-tools .zoom { display: none; } }
.zoomrow { display: grid; grid-template-columns: 34px 1fr 34px; align-items: center; gap: 8px; padding: 0 14px 8px; }
.zoomrow .zb { height: 34px; border: 1px solid var(--line); border-radius: 8px; background: rgba(0, 0, 0, .2); font: 700 18px/1 var(--mono); }
.zoomrow .zb:hover { background: rgba(63, 214, 200, .2); }
.zoomrow input { width: 100%; min-width: 0; accent-color: var(--sea); }
