/* ------------------------------------------------------------------
   3D view and view switcher */

:root {
    --hud-panel: rgba(14, 12, 10, 0.82);
    --hud-border: rgba(217, 179, 108, 0.45);
    --hud-gold: #d9b36c;
    --hud-text: #e8e2d4;
    --hud-dim: #9a927f;
    --hud-chip: #221d17;
    --hud-chip-border: #4a4134;
    --hud-sans: "DejaVu Sans", Arial, sans-serif;
    --hud-mono: "DejaVu Sans Mono", monospace;
    --hud-serif: "DejaVu Serif", Georgia, serif;
}

#three_view {
    position: fixed;
    inset: 0;
    z-index: 50;
    overflow: hidden;
    cursor: crosshair;
    touch-action: none;
}
#three_view canvas { display: block; }

/* Health bars over damaged monsters (three_view places them at their heads).
   Crawl only tells the player a damage level, so the fill steps with it. */
#crawl3d_hpbars {
    position: absolute;
    inset: 0;
    pointer-events: none;
}
.hpbar {
    position: absolute;
    left: 0;
    top: 0;
    width: 36px;
    height: 5px;
    margin: -5px 0 0 -18px;
    padding: 1px;
    background: rgba(0, 0, 0, 0.75);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 2px;
    will-change: transform;
}
.hpbar-fill { height: 100%; border-radius: 1px; }
.hpbar[data-level="1"] .hpbar-fill { width: 80%; background: #8ae234; }
.hpbar[data-level="2"] .hpbar-fill { width: 60%; background: #edd400; }
.hpbar[data-level="3"] .hpbar-fill { width: 40%; background: #f57900; }
.hpbar[data-level="4"] .hpbar-fill { width: 22%; background: #ef2929; }
.hpbar[data-level="5"] .hpbar-fill { width: 8%; background: #cc0000; }

#three_toolbar {
    position: absolute;
    z-index: 60;
    display: flex;
    gap: 6px;
    align-items: center;
    font: 12px/1 var(--hud-sans);
}
#three_toolbar .seg { display: flex; gap: 2px; }
#three_toolbar button {
    background: rgba(20, 16, 30, 0.8);
    color: var(--hud-text);
    border: 1px solid #6b5a3a;
    border-radius: 5px;
    padding: 6px 10px;
    cursor: pointer;
    font: inherit;
}
#three_toolbar button:hover { background: rgba(60, 45, 25, 0.9); }
#three_toolbar button.on {
    background: var(--hud-gold);
    border-color: var(--hud-gold);
    color: #1a140c;
    font-weight: 700;
}
#three_toolbar.hud {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 70;
    padding: 6px;
    background: var(--hud-panel);
    border: 1px solid var(--hud-border);
    border-radius: 10px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.6);
}
#three_toolbar.hud button { background: transparent; border-color: transparent; }
#three_toolbar.hud button:hover { background: rgba(217, 179, 108, 0.15); }
#three_toolbar.hud button.on { background: var(--hud-gold); color: #1a140c; }
#three_toolbar.hud button[data-act^=rot] { color: var(--hud-dim); }

/* ------------------------------------------------------------------
   HUD (3D mode only: three_view.js puts .crawl3d-hud on <body>) */

#hud_root { display: none; }
body.crawl3d-hud #hud_root { display: block; }

/* Crawl's menus and popups live in #ui-stack. Stock CSS gives it z-index
   3000 but no position, so the z-index does nothing and the popups (fixed,
   z auto) end up under the 3D view: a menu opens, unseen, and swallows keys.
   Positioning it makes the 3000 count. */
#ui-stack { position: relative; z-index: 3000; }

/* Spectator/chat bar: meaningless in a single-player browser game */
body.crawl3d-hud #chat,
body.crawl3d-hud #chat_hidden { display: none !important; }

/* The stock sidebar keeps running (the client writes into it), just unseen. */
body.crawl3d-hud #right_column { visibility: hidden; }

.hud-panel,
body.crawl3d-hud #message_pane {
    position: fixed;
    z-index: 70;
    background: var(--hud-panel);
    border: 1px solid var(--hud-border);
    border-radius: 10px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.6);
    color: var(--hud-text);
    font-family: var(--hud-sans);
}
#hud_root .dim { color: var(--hud-dim); }
.hud-key {
    display: inline-block;
    min-width: 18px;
    padding: 1px 5px;
    border: 1px solid #6d6150;
    border-bottom-width: 2px;
    border-radius: 4px;
    background: #221d17;
    color: #f0d9a4;
    font: 600 11px var(--hud-mono);
    text-align: center;
}

/* 1: character card */
#hud_char { left: 16px; top: 16px; width: 340px; padding: 12px; }
#hud_char .hud-top { display: flex; gap: 12px; align-items: center; }
.hud-port {
    position: relative;
    flex: 0 0 60px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 2px solid var(--hud-gold);
    background: radial-gradient(circle at 50% 35%, #3b5fb0, #14213d);
}
.hud-port canvas { width: 56px; height: 56px; border-radius: 50%; image-rendering: pixelated; }
.hud-xl {
    position: absolute;
    bottom: -6px;
    right: -10px;
    background: var(--hud-gold);
    color: #1a140c;
    font: 700 11px var(--hud-sans);
    border-radius: 10px;
    padding: 2px 6px;
    white-space: nowrap;
}
.hud-who { flex: 1; min-width: 0; }
.hud-name { font: 19px var(--hud-serif); color: var(--hud-gold); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hud-sub { font-size: 12px; color: var(--hud-dim); }
.hud-xpbar { height: 4px; background: #2a2420; border-radius: 2px; margin-top: 7px; overflow: hidden; }
#hud_xp_fill { height: 100%; background: var(--hud-gold); transition: width 0.4s; }
.hud-xptext { font-size: 10px; color: var(--hud-dim); margin-top: 2px; }

.hud-bar {
    position: relative;
    height: 20px;
    margin-top: 8px;
    border-radius: 5px;
    background: #2a2420;
    border: 1px solid #000;
    overflow: hidden;
}
.hud-bar > div { position: absolute; left: 0; top: 0; bottom: 0; width: 0; }
.hud-bar .ghost { background: rgba(255, 225, 225, 0.55); transition: width 0.6s ease 0.4s; }
.hud-bar.rising .ghost { transition: none; }
#hud_hp .poison { background: linear-gradient(#a65fd8, #5e2a8a); }
#hud_hp .fill { background: linear-gradient(#ff7387, #c42f48); }
#hud_mp .fill { background: linear-gradient(#6f8cff, #3048b8); }
.hud-bar > span {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 8px;
    font: 600 12px var(--hud-mono);
    color: #fff;
    text-shadow: 0 1px 2px #000;
}
#hud_hp.low { animation: hud-pulse 1s ease-in-out infinite; }
@keyframes hud-pulse {
    50% { box-shadow: 0 0 10px 2px rgba(255, 60, 80, 0.85); border-color: #ff3c50; }
}

.hud-chips { display: flex; gap: 5px; margin-top: 8px; flex-wrap: wrap; }
.hud-chip {
    font-size: 12px;
    padding: 3px 8px;
    border-radius: 12px;
    background: var(--hud-chip);
    border: 1px solid var(--hud-chip-border);
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.hud-chip.dim { color: var(--hud-dim); }
.hud-chip.best { color: #9fc0ff; }
.hud-chip.drained { color: #ff8a8a; border-color: #6b2f2f; }

.hud-status { display: flex; gap: 5px; margin-top: 8px; flex-wrap: wrap; }
.hud-light, .hud-noise {
    font: 11px var(--hud-sans);
    padding: 3px 7px;
    border-radius: 4px;
    border: 1px solid currentColor;
    background: rgba(0, 0, 0, 0.35);
    cursor: default;
}
.hud-noise { color: #8fe39b; }
.hud-noise[data-level=loud] { color: #ffcc77; }
.hud-noise[data-level=veryloud] { color: #ff9a4a; }
.hud-noise[data-level=superloud] { color: #ff5c5c; }
.hud-noise[data-level=blank] { color: #9fc0ff; }

/* 2: location banner */
#hud_loc {
    left: 50%;
    top: 16px;
    transform: translateX(-50%);
    padding: 7px 22px;
    text-align: center;
    white-space: nowrap;
}
.hud-place { font: 18px var(--hud-serif); }
.hud-time { font: 12px var(--hud-mono); color: var(--hud-dim); }
#hud_loc.flash { animation: hud-flash 1.6s ease-out; }
@keyframes hud-flash {
    0% { box-shadow: 0 0 0 0 rgba(255, 215, 122, 0.9); transform: translateX(-50%) scale(1.12); }
    100% { box-shadow: 0 6px 24px rgba(0, 0, 0, 0.6); transform: translateX(-50%) scale(1); }
}

/* right column: 3 minimap, 4 monsters in view */
#hud_right {
    position: fixed;
    right: 16px;
    top: 16px;
    width: 300px;
    z-index: 70;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
#hud_right .hud-panel { position: static; padding: 10px 12px; }
.hud-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 11px; margin-bottom: 6px; }
.hud-title { font: 14px var(--hud-serif); color: var(--hud-gold); }
#hud_map_canvas {
    display: block;
    width: 100%;
    height: 190px;
    border-radius: 6px;
    border: 1px solid #333;
    background: #050505;
    cursor: pointer;
}
.hud-legend { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 7px; font-size: 11px; color: var(--hud-dim); }
.hud-legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 3px; vertical-align: middle; }
.hud-btnrow { display: flex; gap: 6px; margin-top: 8px; }
.hud-btnrow button, #hud_coach button {
    flex: 1;
    font: 12px var(--hud-sans);
    color: var(--hud-text);
    padding: 5px 4px;
    border-radius: 6px;
    background: var(--hud-chip);
    border: 1px solid #5a4e3c;
    cursor: pointer;
}
.hud-btnrow button:hover { border-color: var(--hud-gold); }

#hud_mons { display: none; }
.hud-mon {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 0;
    border-top: 1px solid #2c261f;
    font-size: 13px;
    cursor: pointer;
}
.hud-mon:hover { background: rgba(217, 179, 108, 0.08); }
.hud-mon-icon { width: 28px; height: 28px; flex: 0 0 28px; border-radius: 5px; background: #3b2a1a; image-rendering: pixelated; }
.hud-mon-text { flex: 1; min-width: 0; }
.hud-mon-text > div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hud-mon-text .dim { font-size: 11px; }
.hud-mon-more { font-size: 11px; padding-top: 4px; border-top: 1px solid #2c261f; }
.hud-threat { font-size: 11px; padding: 2px 6px; border-radius: 3px; background: #2a2a2a; color: #aaa; }
.hud-threat.easy { background: #2c2c2c; color: #ddd; }
.hud-threat.tough { background: #3a3412; color: #f2dc6b; }
.hud-threat.nasty { background: #3e1616; color: #ff7a7a; }
.hud-threat.ally { background: #1f3a20; color: #8fe39b; }

/* 5: hotbar */
#hud_bar {
    left: 50%;
    bottom: 16px;
    transform: translateX(-50%);
    padding: 8px;
    display: flex;
    gap: 6px;
    align-items: flex-end;
}
.hud-grp-name { font-size: 9px; letter-spacing: 1px; color: #8a8170; text-align: center; margin-bottom: 4px; text-transform: uppercase; }
.hud-slots { display: flex; gap: 6px; }
.hud-sep { width: 1px; height: 50px; background: #4a4134; margin: 0 3px; align-self: center; }
.hud-slot {
    position: relative;
    width: 56px;
    height: 56px;
    border-radius: 8px;
    background: #1c1813;
    border: 1px solid #5a4e3c;
    color: var(--hud-text);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    font-family: var(--hud-sans);
}
.hud-slot:hover { border-color: var(--hud-gold); background: #262017; }
.hud-slot .hud-icon { font-size: 22px; line-height: 1; }
.hud-slot small { font-size: 9.5px; color: #cfc6b2; margin-top: 4px; white-space: nowrap; }
.hud-slot .hud-key { position: absolute; top: -8px; left: -6px; font-size: 10px; padding: 0 4px; min-width: 0; }
.hud-slot.off { opacity: 0.4; }
.hud-slot.hl { border-color: #ffd77a; box-shadow: 0 0 12px rgba(255, 215, 122, 0.6); }

/* Slot badges: counts, and a caret on slots that open a picker */
.hud-slot .hud-count {
    position: absolute;
    top: 3px;
    right: 4px;
    color: #f0d9a4;
    font: 600 10px/1 var(--hud-mono);
}
#hud_slot_cast::after,
#hud_slot_fire::after,
#hud_slot_quaff::after,
#hud_slot_read::after {
    content: "\25B4";
    position: absolute;
    right: 4px;
    bottom: 1px;
    font-size: 9px;
    color: #8a8170;
}

/* Pickers: Fire / Quaff / Read (#hud_picker), and Cast, which redraws the
   engine's spell menu inside its own popup (#hud_spells) */
#hud_picker {
    display: none;
    left: 50%;
    bottom: 112px;
    transform: translateX(-50%);
    width: max-content;
    max-width: min(760px, calc(100vw - 32px));
    padding: 10px 12px 12px;
}
.hud-close {
    margin-left: 8px;
    background: none;
    border: 0;
    color: var(--hud-dim);
    cursor: pointer;
    font-size: 13px;
}
.hud-close:hover { color: var(--hud-text); }
#hud_picker .hud-head > .dim { margin-left: auto; padding-left: 24px; }
.hud-cards {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    max-height: 46vh;
    overflow-y: auto;
    padding: 8px 6px 2px;
}
.hud-card {
    position: relative;
    flex: 0 0 230px;
    display: flex;
    align-items: center;
    gap: 9px;
    min-width: 0;
    padding: 6px 10px 6px 6px;
    background: #1c1813;
    border: 1px solid #5a4e3c;
    border-radius: 8px;
    color: var(--hud-text);
    font: 12px var(--hud-sans);
    text-align: left;
    cursor: pointer;
}
.hud-card:hover { border-color: var(--hud-gold); background: #262017; }
.hud-card.off { opacity: 0.45; }
.hud-card.quivered,
.hud-card.last { border-color: #b8924a; box-shadow: 0 0 10px rgba(255, 215, 122, 0.25); }
.hud-card > .hud-key { position: absolute; top: -7px; left: -6px; font-size: 10px; padding: 0 4px; min-width: 0; }
.hud-card-icon {
    flex: 0 0 32px;
    width: 32px;
    height: 32px;
    border-radius: 5px;
    background: #2a2118;
    image-rendering: pixelated;
}
.hud-card-text { flex: 1; min-width: 0; }
.hud-card-text > div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hud-card-name { font-size: 13px; }
.hud-card .dim, #hud_spells .dim { color: var(--hud-dim); font-size: 11px; }
.hud-card-stats { display: flex; gap: 8px; font-size: 11px; margin-top: 2px; }
.hud-card .hud-count { margin-left: auto; font: 600 12px var(--hud-mono); color: #f0d9a4; white-space: nowrap; }
.hud-mp { color: #7fb2ff; }
.hud-mp.hp { color: #ff8a8a; }
.hud-warn { color: #ff7a7a; }
.hud-fail.ok { color: #8fe39b; }
.hud-fail.fair { color: #f2dc6b; }
.hud-fail.risky { color: #ffa65c; }
.hud-fail.bad { color: #ff6b6b; }
.hud-empty { padding: 10px 4px; }

.ui-popup.crawl3d-spells { align-items: flex-end; padding: 0 16px 112px; }
.ui-popup.crawl3d-spells .ui-popup-overlay { background-color: rgba(0, 0, 0, 0.2); }
.ui-popup.crawl3d-spells .ui-popup-outer {
    margin: 0;
    padding: 10px 12px 12px;
    width: max-content;
    max-width: min(760px, calc(100vw - 32px));
    background: var(--hud-panel);
    border: 1px solid var(--hud-border);
    border-radius: 10px;
    outline: none;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.6);
}
.ui-popup.crawl3d-spells .ui-popup-inner { display: block; width: 100%; }
.ui-popup.crawl3d-spells .menu_spell > :not(#hud_spells) { display: none; }
#hud_spells { color: var(--hud-text); font-family: var(--hud-sans); }
#hud_spells .hud-head { align-items: center; }
.hud-head-keys { display: flex; gap: 6px; margin-left: auto; padding-left: 24px; }
.hud-head-keys button {
    font: 11px var(--hud-sans);
    color: var(--hud-dim);
    background: none;
    border: 1px solid transparent;
    border-radius: 6px;
    padding: 2px 6px;
    cursor: pointer;
}
.hud-head-keys button:hover { color: var(--hud-text); border-color: #5a4e3c; background: #262017; }
.hud-head-keys b { color: var(--hud-text); font-weight: normal; }
/* Inside the stock popup, so the stock "#ui-stack button" and
   "button:focus" looks apply to whatever we don't set here */
#hud_spells button { margin: 0; font-family: var(--hud-sans); }
#hud_spells .hud-card:focus { background: #262017; border-color: var(--hud-gold); }
#hud_spells .hud-head-keys button { display: inline-flex; align-items: center; gap: 5px; }
#hud_spells .hud-close { display: inline; padding: 0 2px; }
#hud_spells .hud-card { flex-basis: 270px; }

/* Inventory: the engine's inventory menu redrawn as a character sheet
   (#hud_inv, inventory.js), with a paper doll of equipment slots */
body.crawl3d-hud .ui-popup.crawl3d-inv .ui-popup-outer,
body.crawl3d-hud .ui-popup.crawl3d-desc .ui-popup-outer {
    background: rgba(14, 12, 10, 0.97);
    border: 1px solid var(--hud-border);
    border-radius: 12px;
    outline: none;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.7);
}
body.crawl3d-hud .ui-popup.crawl3d-inv .ui-popup-outer {
    width: min(900px, calc(100vw - 32px));
    max-width: none;
    padding: 12px 16px 10px;
}
body.crawl3d-hud .ui-popup.crawl3d-inv .ui-popup-inner { display: block; width: 100%; }
body.crawl3d-hud .ui-popup.crawl3d-inv .menu_inventory > :not(#hud_inv) { display: none; }
#hud_inv { color: var(--hud-text); font-family: var(--hud-sans); }
#hud_inv button { margin: 0; font-family: var(--hud-sans); }
#hud_inv .hud-head { align-items: center; margin-bottom: 10px; }
#hud_inv .hud-title { font-size: 18px; letter-spacing: 0.04em; }
.hud-inv-meta { display: flex; gap: 14px; margin-left: auto; font-size: 12px; }
.hud-inv-gold { color: #f2cf6b; }
#hud_inv .hud-close { display: inline; padding: 0 2px; }
.hud-inv-body {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}
.hud-inv-left {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 14px 16px 12px;
    border: 1px solid #3b3227;
    border-radius: 10px;
    background: radial-gradient(ellipse at 50% 40%, #2a2218 0%, #15110d 75%);
}
.hud-inv-doll {
    display: grid;
    grid-template-columns: repeat(3, 64px);
    grid-template-rows: repeat(4, 64px);
    grid-template-areas:
        "cloak  head  amulet"
        "weapon body  offhand"
        "hands  .     ring1"
        ".      feet  ring2";
    gap: 24px 22px;
    padding-bottom: 14px;
    /* a figure behind the middle column */
    background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 300'><g fill='%23d9b36c' fill-opacity='0.09'><circle cx='50' cy='38' r='22'/><path d='M22 70 h56 l16 70 -14 4 -10 -40 v76 l8 100 h-20 l-8 -96 -8 96 h-20 l8 -100 v-76 l-10 40 -14 -4z'/></g></svg>") center 8px / 92px 290px no-repeat;
}
.hud-inv-extra { display: flex; flex-wrap: wrap; justify-content: center; gap: 22px 14px; padding-bottom: 14px; }
.hud-inv-slot {
    position: relative;
    width: 64px;
    height: 64px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at 50% 35%, #2b241b, #16120e);
    border: 1px solid #4d4232;
    border-radius: 10px;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.7);
    cursor: pointer;
}
.hud-inv-slot.filled {
    border-color: #b8924a;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.6), 0 0 10px rgba(255, 215, 122, 0.18);
}
.hud-inv-slot:hover, .hud-inv-slot:focus { border-color: var(--hud-gold); background: #2c241a; }
.hud-inv-slot canvas, .hud-inv-item canvas { width: 48px; height: 48px; image-rendering: pixelated; }
.hud-inv-slot canvas.ghost { opacity: 0.16; filter: grayscale(1); }
.hud-inv-label {
    position: absolute;
    top: calc(100% + 3px);
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
    color: var(--hud-dim);
    font-size: 10px;
    letter-spacing: 0.03em;
}
.hud-inv-slot.filled .hud-inv-label { color: #d8c79f; }
.hud-inv-slot > .hud-key,
.hud-inv-item > .hud-key { position: absolute; top: -7px; left: -6px; font-size: 10px; padding: 0 4px; min-width: 0; }
.hud-inv-plus {
    position: absolute;
    right: 4px;
    bottom: 2px;
    font: 600 11px var(--hud-mono);
    color: #9fe08f;
    text-shadow: 0 1px 2px #000;
}
.hud-inv-defs { display: flex; gap: 6px; }
.hud-inv-defs .hud-chip b { font-weight: 600; }
.hud-inv-bag {
    max-height: min(62vh, 560px);
    overflow-y: auto;
    padding: 2px 4px 4px;
}
.hud-inv-group + .hud-inv-group { margin-top: 12px; }
.hud-inv-group-name {
    margin-bottom: 8px;
    padding-bottom: 3px;
    border-bottom: 1px solid #3b3227;
    color: var(--hud-gold);
    font: 12px var(--hud-serif);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.hud-inv-tiles { display: flex; flex-wrap: wrap; gap: 10px; padding: 4px 0 0 4px; }
.hud-inv-item {
    position: relative;
    width: 56px;
    height: 56px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1c1813;
    border: 1px solid #4d4232;
    border-radius: 8px;
    cursor: pointer;
}
.hud-inv-item:hover, .hud-inv-item:focus { border-color: var(--hud-gold); background: #262017; }
.hud-inv-item.off { opacity: 0.45; }
.hud-inv-item.fits { border-color: #7fd18b; box-shadow: 0 0 10px rgba(127, 209, 139, 0.45); }
.hud-inv-item > .hud-count {
    position: absolute;
    right: 3px;
    bottom: 1px;
    font: 600 11px var(--hud-mono);
    color: #f0d9a4;
    text-shadow: 0 1px 2px #000;
}
.hud-inv-info {
    min-height: 22px;
    margin-top: 12px;
    padding-top: 8px;
    border-top: 1px solid #3b3227;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.hud-inv-info .hud-key { margin-right: 4px; }
.hud-inv-ann { margin-left: 8px; padding: 0 6px; border-radius: 8px; background: #3a2f1c; color: #f2cf6b; font-size: 11px; }
@media (max-width: 720px) {
    .hud-inv-body { grid-template-columns: minmax(0, 1fr); }
    .hud-inv-bag { max-height: 36vh; }
}

/* Item description: its actions as buttons */
body.crawl3d-hud .ui-popup.crawl3d-desc .header > canvas {
    padding: 4px;
    background: radial-gradient(circle at 50% 35%, #2b241b, #16120e);
    border: 1px solid #b8924a;
    border-radius: 10px;
    image-rendering: pixelated;
}
body.crawl3d-hud .ui-popup.crawl3d-desc .header > span { font: 16px var(--hud-serif); color: var(--hud-gold); }
body.crawl3d-hud .ui-popup.crawl3d-desc .hud-desc-close {
    align-self: flex-start;
    flex: none;
    width: 28px;
    height: 28px;
    margin: -4px -6px 0 auto;
    padding: 0;
    border-radius: 6px;
    font-size: 16px;
    line-height: 28px;
}
body.crawl3d-hud .ui-popup.crawl3d-desc .hud-desc-close:hover { background: #2c241a; }
/* menus.js: the other describe popups and text pages, close in the corner */
.hud-desc-other { display: none; }
body.crawl3d-hud .ui-popup.crawl3d-desc .hud-desc-other { display: block; position: absolute; top: 8px; right: 10px; z-index: 1; margin: 0; }

/* Item description: the engine's stash search terms and menu colouring
   prefixes as chips (inventory.js tagify_desc), and its quote */
body.crawl3d-hud .describe-item .hud-desc-tags {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 14px 0 4px;
    padding-top: 10px;
    border-top: 1px solid #3b3227;
    white-space: normal;
}
.hud-tag-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.hud-tag-label {
    width: 52px;
    color: var(--hud-dim);
    font: 10px var(--hud-sans);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.hud-tag {
    padding: 1px 8px;
    background: #1c1813;
    border: 1px solid #5a4e3c;
    border-radius: 10px;
    color: #f2cf6b;
    font: 12px var(--hud-sans);
}
.hud-tag.dim { color: var(--hud-dim); }
body.crawl3d-hud .describe-item pre.hud-desc-quote {
    margin-top: 14px;
    padding-left: 12px;
    border-left: 2px solid #5a4e3c;
    font-family: var(--hud-serif);
    font-style: italic;
    white-space: pre-wrap;
}
body.crawl3d-hud .describe-item > .actions.hud-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid #3b3227;
}
body.crawl3d-hud .describe-item > .actions > .hud-act {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 6px 12px 6px 7px;
    background: #1c1813;
    border: 1px solid #5a4e3c;
    border-radius: 8px;
    color: var(--hud-text);
    font: 13px var(--hud-sans);
    cursor: pointer;
    user-select: none;
}
body.crawl3d-hud .describe-item > .actions > .hud-act:hover { background: #2c241a; border-color: var(--hud-gold); }
body.crawl3d-hud .describe-item > .actions > .hud-act.primary {
    background: linear-gradient(#e2bf78, #b8924a);
    border-color: #f0d9a4;
    color: #1a140c;
    font-weight: 600;
}
body.crawl3d-hud .describe-item > .actions > .hud-act.primary:hover { background: linear-gradient(#f0d08a, #c9a35a); }
body.crawl3d-hud .describe-item > .actions > .hud-act.primary .hud-key { background: #f6e7c4; border-color: #8a6a32; color: #1a140c; }

/* The engine's other menus (menus.js): drop, wear / wield, quiver,
   abilities... keep the stock list, dressed. Our markup is in the menu in
   2D too, so it's all hidden there and shown under body.crawl3d-hud. */
.hud-menu-close,
.hud-menu-hk,
.hud-menu-foot,
#hud_pickup { display: none; }
body.crawl3d-hud .ui-popup.crawl3d-menu .ui-popup-outer {
    max-width: calc(100vw - 32px);
    padding: 14px 16px 12px;
    background: rgba(14, 12, 10, 0.97);
    border: 1px solid var(--hud-border);
    border-radius: 12px;
    outline: none;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.7);
}
body.crawl3d-hud .crawl3d-menu .menu { position: relative; min-width: min(36em, calc(100vw - 64px)); color: var(--hud-text); }
body.crawl3d-hud .crawl3d-menu .menu_title {
    margin-bottom: 8px;
    padding: 2px 40px 8px 0;
    border-bottom: 1px solid #3b3227;
    color: var(--hud-gold);
    font: 16px var(--hud-serif);
    white-space: pre-wrap;
}
body.crawl3d-hud .crawl3d-menu .menu_more { display: none; }
body.crawl3d-hud .crawl3d-menu .hud-menu-close {
    display: block;
    position: absolute;
    top: -4px;
    right: -6px;
    z-index: 1;
    width: 28px;
    height: 28px;
    margin: 0;
    padding: 0;
    border-radius: 6px;
    font-size: 16px;
    line-height: 28px;
}
body.crawl3d-hud .crawl3d-menu .hud-menu-close:hover { background: #2c241a; }
body.crawl3d-hud .crawl3d-menu .menu_contents li.hud-menu-head {
    margin: 10px 2px 4px;
    padding: 0 0 3px;
    border: 0;
    border-bottom: 1px solid #3b3227;
    color: var(--hud-gold);
    font: 12px var(--hud-serif);
    letter-spacing: 0.08em;
}
body.crawl3d-hud .crawl3d-menu .menu_contents li.hud-menu-head:first-child { margin-top: 2px; }
body.crawl3d-hud .crawl3d-menu .menu_contents li.selectable {
    margin: 4px 2px;
    padding: 3px 10px 3px 6px;
    background: #1c1813;
    border: 1px solid #5a4e3c;
    border-radius: 8px;
    cursor: pointer;
}
body.crawl3d-hud .crawl3d-menu .menu_contents li.selectable:hover,
body.crawl3d-hud .crawl3d-menu .menu_contents li.hovered { background: #262017; border-color: var(--hud-gold); color: inherit; }
body.crawl3d-hud .crawl3d-menu .menu_contents li.selectable:active { background: #2c241a; border-color: var(--hud-gold); }
body.crawl3d-hud .crawl3d-menu .menu_contents li.hud-picked {
    background: #2a2116;
    border-color: #b8924a;
    box-shadow: inset 3px 0 0 var(--hud-gold), 0 0 8px rgba(255, 215, 122, 0.18);
}
body.crawl3d-hud .crawl3d-menu .menu_contents li > canvas { margin-right: 4px; }
body.crawl3d-hud .crawl3d-menu .hud-menu-prefix { display: none; }
body.crawl3d-hud .crawl3d-menu .hud-menu-hk { display: inline-block; vertical-align: middle; }
body.crawl3d-hud .crawl3d-menu li.hud-picked .hud-menu-hk .hud-key { background: var(--hud-gold); border-color: #f0d9a4; color: #1a140c; }
body.crawl3d-hud .crawl3d-menu .hud-menu-foot {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #3b3227;
    font: 12px var(--hud-sans);
    white-space: normal;
}
.hud-menu-hint { color: var(--hud-dim); margin-right: 4px; }
body.crawl3d-hud .crawl3d-menu .hud-menu-btn,
#hud_pickup .hud-pickup-foot button,
#hud_pickup .hud-pickup-group-all {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    padding: 4px 10px 4px 5px;
    background: #1c1813;
    border: 1px solid #5a4e3c;
    border-radius: 8px;
    color: var(--hud-text);
    font: 12px var(--hud-sans);
    cursor: pointer;
}
body.crawl3d-hud .crawl3d-menu .hud-menu-btn:hover,
#hud_pickup .hud-pickup-foot button:hover:not(:disabled),
#hud_pickup .hud-pickup-group-all:hover { background: #2c241a; border-color: var(--hud-gold); }

/* Pickup: the engine's pickup menu redrawn as item cards (#hud_pickup) */
body.crawl3d-hud .ui-popup.crawl3d-pickup .ui-popup-outer { width: min(760px, calc(100vw - 32px)); }
body.crawl3d-hud .ui-popup.crawl3d-pickup .ui-popup-inner { display: block; width: 100%; }
body.crawl3d-hud .ui-popup.crawl3d-pickup .menu { min-width: 0; }
body.crawl3d-hud .ui-popup.crawl3d-pickup .menu > :not(#hud_pickup) { display: none; }
body.crawl3d-hud #hud_pickup { display: block; color: var(--hud-text); font-family: var(--hud-sans); }
#hud_pickup button { margin: 0; font-family: var(--hud-sans); }
#hud_pickup .hud-head { align-items: center; margin-bottom: 10px; }
#hud_pickup .hud-title { font: 18px var(--hud-serif); letter-spacing: 0.04em; color: var(--hud-gold); }
.hud-pickup-meta { margin-left: auto; font-size: 12px; }
#hud_pickup .hud-close { display: inline; margin-left: 14px; padding: 0 2px; }
.hud-pickup-body { max-height: 52vh; overflow-y: auto; padding-right: 4px; }
.hud-pickup-group + .hud-pickup-group { margin-top: 12px; }
.hud-pickup-group .hud-inv-group-name { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; }
#hud_pickup .hud-pickup-group-all { margin-left: auto; padding: 1px 8px 1px 3px; font-size: 11px; text-transform: none; letter-spacing: 0; }
#hud_pickup .hud-pickup-group-all .hud-key { font-size: 10px; padding: 0 4px; min-width: 0; }
.hud-pickup-group .hud-cards { max-height: none; overflow: visible; }
#hud_pickup .hud-pickup-card { flex: 1 1 300px; max-width: 360px; padding-right: 36px; }
#hud_pickup .hud-pickup-card:focus { background: #262017; border-color: var(--hud-gold); }
#hud_pickup .hud-pickup-card.picked {
    background: #2a2116;
    border-color: var(--hud-gold);
    box-shadow: 0 0 10px rgba(255, 215, 122, 0.25);
}
#hud_pickup .hud-pickup-card.picked .dim { color: #e2bf78; }
.hud-pickup-check {
    position: absolute;
    right: 10px;
    top: 50%;
    width: 18px;
    height: 18px;
    margin-top: -10px;
    border: 1px solid #6d6150;
    border-radius: 50%;
    color: #1a140c;
    font: 700 12px/18px var(--hud-sans);
    text-align: center;
}
.hud-pickup-card.picked .hud-pickup-check { background: var(--hud-gold); border-color: #f0d9a4; }
.hud-pickup-info {
    min-height: 20px;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid #3b3227;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.hud-pickup-info .hud-key { margin-right: 4px; }
.hud-pickup-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 10px; }
.hud-pickup-count { margin-right: 8px; color: var(--hud-dim); font-size: 12px; }
.hud-pickup-gap { flex: 1; }
#hud_pickup .hud-pickup-foot button:disabled { opacity: 0.4; cursor: default; }
#hud_pickup #hud_pickup_go {
    padding: 6px 14px 6px 6px;
    background: linear-gradient(#e2bf78, #b8924a);
    border-color: #f0d9a4;
    color: #1a140c;
    font-size: 13px;
    font-weight: 600;
}
#hud_pickup #hud_pickup_go:hover { background: linear-gradient(#f0d08a, #c9a35a); }
#hud_pickup #hud_pickup_go .hud-key { background: #f6e7c4; border-color: #8a6a32; color: #1a140c; }

/* Aiming banner */
#hud_aim {
    display: none;
    left: 50%;
    top: 84px;
    pointer-events: none;
    transform: translateX(-50%);
    align-items: center;
    gap: 12px;
    padding: 8px 10px 8px 16px;
    border-color: #ff5a3c;
    font-size: 13px;
    white-space: nowrap;
}
#hud_aim.on { display: flex; }
#hud_root.aiming #hud_coach { visibility: hidden; }
#hud_aim button { pointer-events: auto; }
#hud_aim .hud-aim-what b { color: #ffb199; }
#hud_aim button {
    font: 12px var(--hud-sans);
    color: var(--hud-text);
    background: #1c1813;
    border: 1px solid #5a4e3c;
    border-radius: 6px;
    padding: 4px 8px;
    cursor: pointer;
}
#hud_aim button:hover { border-color: var(--hud-gold); }

/* 10: coach strip */
#hud_coach {
    left: 50%;
    top: 84px;
    transform: translateX(-50%);
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 7px 8px 7px 16px;
    font-size: 13px;
    border-color: #7fa0ff;
    background: rgba(20, 28, 52, 0.85);
    white-space: nowrap;
}
#hud_coach button { flex: 0 0 auto; padding: 2px 8px; background: transparent; border-color: transparent; color: var(--hud-dim); }
#hud_coach button:hover { color: var(--hud-text); }

/* 6: floor-context prompt, beside the player's feet (three_view places it) */
#hud_floor {
    display: none;
    padding: 6px 10px;
    font-size: 13px;
    white-space: nowrap;
    z-index: 65;
}
#hud_floor.docked {
    left: 50%;
    top: auto;
    bottom: 104px;
    transform: translateX(-50%);
}
.hud-floor-row { display: flex; gap: 8px; align-items: center; }
.hud-floor-row + .hud-floor-row { margin-top: 4px; }
.hud-floor-row .what { color: var(--hud-gold); }
.hud-floor-row button.hud-key { cursor: pointer; }
.hud-floor-row button.hud-key:hover { border-color: var(--hud-gold); }

/* 7: hover tooltip, with a leader line to the pointer */
#hud_tip {
    display: none;
    width: max-content;
    max-width: 260px;
    padding: 9px 12px;
    font-size: 12px;
    pointer-events: none;
    z-index: 80;
    --lead-x: 40px;
}
#hud_tip::after {
    content: "";
    position: absolute;
    left: var(--lead-x);
    top: 100%;
    width: 2px;
    height: 26px;
    background: rgba(217, 179, 108, 0.6);
}
#hud_tip.below::after { top: auto; bottom: 100%; }
.hud-tip-title { font: 14px var(--hud-serif); color: var(--hud-gold); }
.hud-tip-sub { margin-top: 2px; }
.hud-tip-hint { margin-top: 5px; color: var(--hud-text); }
.hud-tip-mouse { margin-top: 6px; color: #cfc6b2; line-height: 1.5; }
.hud-tip-mouse b { color: var(--hud-text); font-weight: 600; }


/* 8: message log -- the stock pane, moved into a panel */
#hud_log_head { display: none; }
body.crawl3d-hud #message_pane {
    left: 16px;
    bottom: 16px;
    width: min(470px, calc(100vw - 32px));
    padding: 8px 12px;
    background: linear-gradient(rgba(14, 12, 10, 0.4), rgba(14, 12, 10, 0.88));
    font: 13px/1.5 var(--hud-mono);
}
body.crawl3d-hud #hud_log_head {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
    font: 11px var(--hud-sans);
    color: var(--hud-dim);
}
body.crawl3d-hud #hud_log_head > span:first-child {
    color: var(--hud-gold);
    letter-spacing: 1px;
    text-transform: uppercase;
}
body.crawl3d-hud #messages_container {
    width: auto !important;
    max-height: 7.5em !important;
    /* older lines fade out toward the top */
    -webkit-mask-image: linear-gradient(transparent, #000 2.2em);
    mask-image: linear-gradient(transparent, #000 2.2em);
}
body.crawl3d-hud #messages { line-height: 1.5em; }
body.crawl3d-hud #messages .game_message[data-turn]::before {
    content: attr(data-turn);
    display: inline-block;
    min-width: 3.5em;
    margin-right: 4px;
    color: #6f6757;
    font-size: 11px;
}
body.crawl3d-hud #more {
    color: #1a140c;
    background: var(--hud-gold);
    border-radius: 4px;
    padding: 1px 8px;
    margin-top: 4px;
    display: inline-block;
    font-weight: 700;
}
body.crawl3d-hud #more[style*="display: none"] { display: none !important; }

/* The stock consumables bar, pinned to the left edge */
body.crawl3d-hud #action-panel,
body.crawl3d-hud #action-panel-placeholder {
    position: fixed;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 70;
}

/* The start screen (title.js): a hallway walk behind, the stone title, then the panel */
#crawl3d_start {
    position: fixed;
    inset: 0;
    z-index: 5000;
    background: radial-gradient(ellipse at center, #241a12 0%, #060408 70%);
    color: #e8dcc0;
    display: flex;
    font: 15px/1.5 system-ui, sans-serif;
    overflow: hidden auto;
}
#crawl3d_hall {
    position: fixed;
    inset: 0;
    pointer-events: none;
}
#crawl3d_hall canvas {
    display: block;
    width: 100%;
    height: 100%;
}
/* a vignette, so the panel sits in the dark and the hall glows in the middle */
#crawl3d_start::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background: radial-gradient(ellipse 70% 65% at 50% 55%, transparent 35%, rgba(3, 2, 4, 0.85) 100%);
}
#crawl3d_start .start_column {
    position: relative;
    margin: auto;
    padding: 24px 16px;
    width: 100%;
    max-width: 760px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
}
#crawl3d_start .visually_hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}
#crawl3d_title {
    width: min(100%, 720px);
    margin-bottom: 18px;
}
#crawl3d_title svg { display: block; width: 100%; height: auto; overflow: visible; }
#crawl3d_start .panel {
    width: 100%;
    max-width: 520px;
    box-sizing: border-box;
    padding: 22px 26px;
    border: 1px solid rgba(150, 120, 80, 0.45);
    border-radius: 8px;
    background: linear-gradient(rgba(16, 12, 14, 0.86), rgba(8, 6, 10, 0.9));
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.7), inset 0 1px 0 rgba(255, 220, 160, 0.06);
}
#crawl3d_start .sub { color: #a89a80; margin: 0 0 16px; text-align: center; }
#crawl3d_start .sub.over { color: #e8dcc0; font-size: 18px; }
#crawl3d_start h2 {
    margin: 0 0 8px;
    font: 600 13px/1.4 system-ui, sans-serif;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #c9b88f;
}
#crawl3d_start label { display: block; margin-bottom: 6px; color: #c9b88f; }
#crawl3d_start .start_row { display: flex; gap: 8px; }
#crawl3d_start input {
    font: inherit;
    padding: 7px 10px;
    flex: 1;
    min-width: 0;
    background: #15111a;
    color: #fff;
    border: 1px solid #6b5a3a;
    border-radius: 4px;
}
#crawl3d_start button {
    font: inherit;
    padding: 7px 18px;
    background: #8a6a2a;
    color: #fff;
    border: 0;
    border-radius: 4px;
    cursor: pointer;
}
#crawl3d_start button:hover:not(:disabled) { background: #a07c34; }
#crawl3d_start button:disabled { opacity: 0.5; cursor: default; }
#crawl3d_start .start_again { display: block; margin: 0 auto; }
#crawl3d_start .hint:empty, #crawl3d_start .status:empty { display: none; }
#crawl3d_start .hint { margin-top: 6px; font-size: 13px; color: #c9b88f; }
#crawl3d_start .status { margin-top: 10px; color: #c9b88f; }

#crawl3d_saves { margin-bottom: 18px; }
#crawl3d_saves[hidden] { display: none; }
#crawl3d_start .crawl3d_save {
    display: flex;
    flex-direction: column;
    gap: 2px;
    width: 100%;
    margin-bottom: 8px;
    padding: 10px 14px;
    text-align: left;
    background: rgba(30, 24, 20, 0.9);
    border: 1px solid #6b5a3a;
    color: #e8dcc0;
}
#crawl3d_start .crawl3d_save:hover:not(:disabled),
#crawl3d_start .crawl3d_save:focus-visible {
    background: rgba(56, 42, 26, 0.95);
    border-color: #c9a35a;
    outline: none;
}
#crawl3d_start .save_head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
#crawl3d_start .save_name { font: 600 18px/1.3 Georgia, serif; color: #f3d38a; overflow-wrap: anywhere; }
#crawl3d_start .save_go {
    flex: none;
    font-size: 12px;
    padding: 1px 8px;
    border: 1px solid #8a6a2a;
    border-radius: 3px;
    color: #f3d38a;
}
#crawl3d_start .save_who { color: #d8ccb0; }
#crawl3d_start .save_stats,
#crawl3d_start .save_when { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: #a89a80; }
#crawl3d_start .save_xl,
#crawl3d_start .save_place { color: #e8dcc0; }
#crawl3d_start .save_unknown { font-style: italic; }

#crawl3d_start .controls { margin-top: 12px; color: #a89a80; font-size: 13px; }
#crawl3d_start .controls summary { cursor: pointer; color: #c9b88f; }
#crawl3d_start ul { padding-left: 18px; margin: 6px 0 0; }
#crawl3d_start .fine { font-size: 12px; color: #7d7262; margin: 14px 0 0; }
#crawl3d_start .fine a { color: #c9b88f; }
@media (max-width: 560px) {
    #crawl3d_start .panel { padding: 18px 16px; }
    #crawl3d_title { margin-bottom: 12px; }
}

/* Narrower windows: the hotbar gets the bottom row to itself */
@media (max-width: 1720px) {
    body.crawl3d-hud #message_pane,
    body.crawl3d-hud #three_toolbar.hud { bottom: 104px; }
}
@media (max-width: 1100px) {
    #hud_coach { display: none; }
}

/* ------------------------------------------------------------------
   Touch: the Keys drawer (hud.js), for keys a phone can't press */

.hud-touch { display: none; }
#hud_keys {
    display: none;
    left: 50%;
    bottom: 112px;
    transform: translateX(-50%);
    /* above #ui-stack (3000), so Esc can close an open menu */
    z-index: 3100;
    width: max-content;
    max-width: calc(100vw - 16px);
    padding: 6px;
    flex-wrap: wrap;
    justify-content: center;
    gap: 5px;
}
#hud_keys.on { display: flex; }
#hud_keys button {
    min-width: 44px;
    height: 36px;
    padding: 0 10px;
    border-radius: 6px;
    background: var(--hud-chip);
    border: 1px solid #5a4e3c;
    color: var(--hud-text);
    font: 13px var(--hud-sans);
    cursor: pointer;
}
#hud_keys button:active { border-color: var(--hud-gold); background: #2c241a; }
#hud_keys_type { color: var(--hud-gold) !important; }
/* off screen but focusable, so it can summon the phone's keyboard */
#hud_keys_input {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 1px;
    height: 1px;
    padding: 0;
    border: 0;
    opacity: 0;
    font-size: 16px; /* under 16px, iOS zooms the page on focus */
}
#hud_mon_badge, .hud-fold-ico { display: none; }
@media (pointer: coarse) {
    body.crawl3d-hud .hud-touch { display: block; }
    body.crawl3d-hud #hud_tip { display: none !important; }
}

/* ------------------------------------------------------------------
   Phones: one column. The card and the map fold to a line along the top
   (hud.js toggles .folded), the log and a two-row hotbar along the
   bottom, and the 3D view keeps the middle. */
@media (max-width: 720px) {
    body.crawl3d-hud .hud-touch { display: block; }
    body.crawl3d-hud #hud_loc,
    body.crawl3d-hud #hud_coach,
    body.crawl3d-hud #action-panel,
    body.crawl3d-hud #action-panel-placeholder,
    body.crawl3d-hud #hud_log_head > span:last-child,
    body.crawl3d-hud .hud-sep,
    body.crawl3d-hud .hud-grp-name,
    body.crawl3d-hud .hud-slot .hud-key,
    body.crawl3d-hud #hud_right .hud-hint,
    body.crawl3d-hud .hud-legend { display: none !important; }

    /* character card: portrait and name, then HP | MP side by side */
    #hud_char {
        left: 8px;
        right: 8px;
        top: 8px;
        width: auto;
        padding: 8px 10px;
        display: grid;
        grid-template-columns: 1fr 1fr;
        column-gap: 8px;
    }
    #hud_char > :not(.hud-bar) { grid-column: 1 / -1; }
    #hud_char .hud-top { gap: 10px; cursor: pointer; }
    .hud-port { flex-basis: 36px; width: 36px; height: 36px; }
    .hud-port canvas { width: 32px; height: 32px; }
    .hud-xl { font-size: 10px; padding: 1px 5px; bottom: -5px; right: -6px; }
    .hud-name { font-size: 15px; }
    .hud-sub { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .hud-xpbar { margin-top: 4px; }
    .hud-bar { height: 16px; margin-top: 6px; }
    .hud-bar > span { font-size: 11px; padding: 0 6px; }
    .hud-chips, .hud-status { margin-top: 6px; }
    #hud_char.folded .hud-xptext,
    #hud_char.folded .hud-chips,
    #hud_char.folded .hud-status { display: none; }

    /* minimap and monsters: under the card on the right */
    #hud_right {
        right: 8px;
        top: calc(var(--hud-card-bottom, 100px) + 6px);
        /* beside the view switcher */
        width: min(240px, calc(100vw - 222px));
        gap: 6px;
    }
    #hud_right .hud-panel { padding: 6px 8px; }
    #hud_map .hud-head { margin-bottom: 4px; gap: 6px; align-items: center; cursor: pointer; }
    #hud_map .hud-title { margin-right: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    #hud_mon_badge { white-space: nowrap; }
    .hud-fold-ico { display: inline; color: var(--hud-dim); }
    .hud-fold-ico::before { content: "\25B4"; }
    #hud_right.folded .hud-fold-ico::before { content: "\25BE"; }
    #hud_right.folded #hud_map .hud-head { margin-bottom: 0; }
    #hud_right.folded #hud_map_canvas,
    #hud_right.folded #hud_map .hud-btnrow,
    #hud_right.folded #hud_mons { display: none !important; }
    #hud_map_canvas { height: 140px; }
    .hud-btnrow { margin-top: 6px; gap: 4px; }
    .hud-btnrow button { font-size: 11px; padding: 6px 2px; }
    .hud-btnrow .hud-key { display: none; }
    .hud-mon { font-size: 12px; padding: 3px 0; }

    /* hotbar: full width, two rows */
    #hud_bar {
        left: 8px;
        right: 8px;
        bottom: 8px;
        transform: none;
        padding: 6px;
        flex-wrap: wrap;
        justify-content: center;
        gap: 5px;
    }
    #hud_bar .hud-grp, #hud_bar .hud-slots { display: contents; }
    .hud-slot { width: 44px; height: 44px; border-radius: 7px; }
    .hud-slot .hud-icon { font-size: 18px; }
    .hud-slot small { font-size: 9px; margin-top: 2px; }
    .hud-slot .hud-count { top: 2px; right: 3px; font-size: 9px; }

    /* message log: full width above the hotbar, three lines */
    body.crawl3d-hud #message_pane {
        left: 8px;
        right: 8px;
        bottom: calc(var(--hud-bar-h, 120px) + 6px);
        width: auto;
        padding: 4px 8px;
        font-size: 12px;
    }
    body.crawl3d-hud #hud_log_head { margin-bottom: 0; }
    body.crawl3d-hud #messages_container { max-height: 4.5em !important; }
    body.crawl3d-hud #messages .game_message[data-turn]::before { min-width: 2.8em; font-size: 10px; }

    /* view switcher: small, top-left under the card */
    body.crawl3d-hud #three_toolbar.hud {
        left: 8px;
        right: auto;
        top: calc(var(--hud-card-bottom, 100px) + 6px);
        bottom: auto;
        padding: 3px;
        font-size: 11px;
    }
    #three_toolbar.hud button { padding: 5px 7px; }
    #three_toolbar.hud [data-act^=rot] { display: none !important; }

    /* pickers, the Keys drawer and the floor prompt sit above the log */
    #hud_picker { bottom: calc(var(--hud-bar-h, 120px) + 6px); max-width: calc(100vw - 16px); }
    /* above the log, which is where prompts ask their question */
    #hud_keys { bottom: calc(var(--hud-log-h, 200px) + 6px); }
    .ui-popup.crawl3d-spells { padding: 0 8px calc(var(--hud-bar-h, 120px) + 6px); }
    .ui-popup.crawl3d-spells .ui-popup-outer { max-width: calc(100vw - 16px); }
    #hud_floor.docked { bottom: calc(var(--hud-bar-h, 120px) + 96px); }
    #hud_aim {
        top: calc(var(--hud-card-bottom, 100px) + 44px);
        max-width: calc(100vw - 16px);
        white-space: normal;
        flex-wrap: wrap;
    }
    .hud-card { flex: 1 1 100%; }
    .hud-cards { max-height: 40vh; }
    body.crawl3d-hud .ui-popup.crawl3d-menu .ui-popup-outer { max-width: calc(100vw - 16px); padding: 10px 10px 8px; }
    body.crawl3d-hud .crawl3d-menu .menu { min-width: 0; }
    #hud_pickup .hud-pickup-card { flex-basis: 100%; max-width: none; }

    /* inventory sheet: a smaller paper doll over the bag */
    /* stock menus are at least 640px wide */
    body.crawl3d-hud .ui-popup .menu { min-width: 0; }
    body.crawl3d-hud .ui-popup.crawl3d-inv .ui-popup-outer {
        box-sizing: border-box;
        width: calc(100vw - 16px);
        padding: 10px 8px 8px;
    }
    #hud_inv .hud-head { flex-wrap: wrap; row-gap: 4px; }
    .hud-inv-body { gap: 10px; }
    .hud-inv-left { min-width: 0; padding: 10px 6px 8px; gap: 10px; }
    .hud-inv-doll {
        grid-template-columns: repeat(3, 52px);
        grid-template-rows: repeat(4, 52px);
        gap: 20px 18px;
        background-size: 76px 240px;
    }
    .hud-inv-slot { width: 52px; height: 52px; }
    .hud-inv-slot canvas { width: 40px; height: 40px; }
    .hud-inv-defs { flex-wrap: wrap; justify-content: center; }
    .hud-inv-bag { max-height: 30vh; }
    .hud-inv-info { white-space: normal; }
}

/* ------------------------------------------------------------------
   Character creation (newgame.js): the species / background / weapon
   screens and the random-combination prompt, as HUD cards. Not under
   body.crawl3d-hud: it comes before the game view, for everyone. */

.ui-popup.crawl3d-newgame .ui-popup-outer {
    box-sizing: border-box;
    width: min(980px, calc(100vw - 32px));
    max-height: calc(100dvh - 32px);
    margin: 16px;
    padding: 16px 18px 14px;
    background: rgba(14, 12, 10, 0.97);
    border: 1px solid var(--hud-border);
    border-radius: 12px;
    outline: none;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.7);
    color: var(--hud-text);
    font-family: var(--hud-sans);
}
.ui-popup.crawl3d-newgame .ui-popup-inner { flex: 1 1 auto; width: 100%; min-height: 0; max-height: none; }
.crawl3d-newgame .newgame-choice { flex: 1 1 auto; width: 100%; min-height: 0; }
.crawl3d-newgame .hud-menu-prefix { display: none; }
.crawl3d-newgame .ng-close {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 2;
    width: 30px;
    height: 30px;
    margin: 0;
    padding: 0;
    border-radius: 6px;
    font-size: 16px;
    line-height: 30px;
}
.crawl3d-newgame .ng-close:hover { background: #2c241a; }

/* header: "Welcome, Cap." in gold, the question under it */
.crawl3d-newgame .newgame-choice > .header {
    flex: 0 0 auto;
    flex-wrap: wrap;
    gap: 2px 10px;
    margin: 0;
    padding: 0 40px 10px 0;
    white-space: normal;
}
.crawl3d-newgame .newgame-choice > .ng-title { font: 18px var(--hud-serif); }
.crawl3d-newgame .ng-title span { color: var(--hud-gold); }
.crawl3d-newgame .ng-title > canvas { margin: 0; border-radius: 6px; background: #2a2118; }
.crawl3d-newgame .ng-title .ng-ask,
.crawl3d-newgame .ng-prompt,
.crawl3d-newgame .ng-prompt span { flex-basis: 100%; color: var(--hud-text); font: 13px var(--hud-sans); }
.crawl3d-newgame .newgame-choice > .ng-head-last { margin-bottom: 10px; border-bottom: 1px solid #3b3227; }
/* the stock chat bar means nothing offline; the HUD hides it in game too */
body:has(.ui-popup.crawl3d-newgame) #chat,
body:has(.ui-popup.crawl3d-newgame) #chat_hidden { display: none !important; }

/* the choices: the engine's columns, as cards */
.crawl3d-newgame .main-items {
    grid-template-columns: repeat(var(--ng-cols, 3), minmax(0, 1fr));
    gap: 6px 12px;
    padding: 8px 4px 4px 8px;
}
/* one column (the weapon screen): flow the cards instead of stretching them */
.crawl3d-newgame .main-items.ng-single { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.crawl3d-newgame .main-items.ng-single > * { grid-row: auto !important; grid-column: auto !important; }
.crawl3d-newgame .main-items > .ng-head {
    align-self: end;
    margin: 6px 0 2px;
    padding-bottom: 3px;
    border-bottom: 1px solid #3b3227;
    font: 12px var(--hud-serif);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.crawl3d-newgame .main-items > .ng-head::before { display: none; }
.crawl3d-newgame .main-items > .ng-head span { color: var(--hud-gold); }
.crawl3d-newgame .ng-card {
    position: relative;
    gap: 8px;
    min-width: 0;
    padding: 4px 10px 4px 4px;
    background: #1c1813;
    border: 1px solid #5a4e3c;
    border-radius: 8px;
    white-space: nowrap;
    cursor: pointer;
}
.crawl3d-newgame .ng-card > canvas { flex: 0 0 auto; border-radius: 5px; background: #2a2118; }
.crawl3d-newgame .ng-card-text { display: flex; flex-direction: column; flex: 1 1 auto; min-width: 0; }
.crawl3d-newgame .ng-card-text > span { margin: 0; overflow: hidden; text-overflow: ellipsis; }
.crawl3d-newgame .ng-card-name { color: var(--hud-text); font-size: 13px; }
.crawl3d-newgame .ng-card-note { color: var(--hud-dim); font-size: 11px; }
.crawl3d-newgame .ng-card .ng-key { position: absolute; top: -7px; left: -6px; min-width: 0; padding: 0 4px; font-size: 10px; }
.crawl3d-newgame .ng-card.ng-rec { border-color: #6b7a43; }
.crawl3d-newgame .ng-card.ng-rec .ng-card-note { color: #a9cf74; }
.crawl3d-newgame .ng-card.ng-off .ng-card-name { color: var(--hud-dim); }
.crawl3d-newgame .ng-card.ng-off > canvas { opacity: 0.6; }
.crawl3d-newgame .ng-card:hover,
.crawl3d-newgame .ng-card.selected {
    background: #262017;
    border-color: var(--hud-gold);
}
.crawl3d-newgame .ng-card.selected { box-shadow: inset 3px 0 0 var(--hud-gold), 0 0 10px rgba(255, 215, 122, 0.2); }

/* the selected choice's description */
.crawl3d-newgame .ng-info {
    flex: 0 0 auto;
    margin-top: 10px;
    padding: 8px 12px 10px;
    background: #15120e;
    border: 1px solid #3b3227;
    border-radius: 8px;
}
.crawl3d-newgame .ng-info-head { display: flex; align-items: center; gap: 10px; min-height: 22px; }
.crawl3d-newgame .ng-info-name { font: 15px var(--hud-serif); color: var(--hud-gold); }
.crawl3d-newgame .ng-choose,
.crawl3d-newgame .ng-extra,
.crawl3d-newgame .ng-combo-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    padding: 4px 10px 4px 5px;
    background: #1c1813;
    border: 1px solid #5a4e3c;
    border-radius: 8px;
    color: var(--hud-text);
    font: 12px var(--hud-sans);
    white-space: nowrap;
    cursor: pointer;
}
.crawl3d-newgame .ng-choose {
    display: none;
    margin-left: auto;
    padding: 6px 14px;
    background: var(--hud-gold);
    border-color: #f0d9a4;
    color: #1a140c;
    font-weight: 600;
}
.crawl3d-newgame.ng-touch .ng-choose.on { display: inline-flex; }
.crawl3d-newgame .descriptions {
    display: grid;
    margin: 4px 0 0;
    max-width: none;
    color: var(--hud-text);
    font: 13px/1.45 var(--hud-sans);
}
.crawl3d-newgame .descriptions > .pane { height: auto !important; white-space: normal; }

/* the extra choices (random, recommended, aptitudes, help...) as buttons */
.crawl3d-newgame .sub-items {
    display: flex;
    flex: 0 0 auto;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #3b3227;
}
.crawl3d-newgame .ng-extra span { margin: 0; color: var(--hud-text); white-space: nowrap; }
.crawl3d-newgame .ng-extra .ng-key { margin-right: 6px; }
.crawl3d-newgame .ng-extra:hover,
.crawl3d-newgame .ng-extra.selected,
.crawl3d-newgame .ng-combo-btn:hover { background: #2c241a; border-color: var(--hud-gold); }

/* "play this combination?" */
.ui-popup.crawl3d-ng-combo .ui-popup-outer { width: min(520px, calc(100vw - 32px)); }
.crawl3d-ng-combo .describe-generic { width: 100%; }
.crawl3d-ng-combo .header { padding-right: 40px; }
.crawl3d-ng-combo .header > span { font: 16px var(--hud-serif); white-space: normal; }
.crawl3d-ng-combo .header span { color: var(--hud-gold); }
.crawl3d-ng-combo .header > canvas { border-radius: 6px; background: #2a2118; }
.crawl3d-ng-combo .ng-combo-ask { color: var(--hud-text); font: 13px var(--hud-sans); }
.crawl3d-ng-combo .ng-combo-foot { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; padding-top: 10px; border-top: 1px solid #3b3227; }

@media (max-width: 720px) {
    .ui-popup.crawl3d-newgame .ui-popup-outer {
        width: calc(100vw - 16px);
        max-height: calc(100dvh - 16px);
        margin: 8px;
        padding: 12px 10px 10px;
    }
    .crawl3d-newgame .newgame-choice > .ng-title { font-size: 16px; }
    /* one flowing list: heads across, cards two to a row */
    .crawl3d-newgame .main-items {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 8px;
        padding-left: 6px;
    }
    .crawl3d-newgame .main-items.ng-single { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
    .crawl3d-newgame .main-items > * { grid-row: auto !important; grid-column: auto !important; }
    .crawl3d-newgame .main-items > .ng-head { grid-column: 1 / -1 !important; margin-top: 8px; }
    .crawl3d-newgame .ng-card { min-height: 42px; }
    .crawl3d-newgame .descriptions { max-height: 24vh; overflow-y: auto; font-size: 12px; }
    .crawl3d-newgame .sub-items { display: grid; grid-template-columns: 1fr 1fr; }
    .crawl3d-newgame .ng-extra { min-width: 0; min-height: 34px; padding-right: 6px; text-align: left; }
    .crawl3d-newgame .ng-extra > span { white-space: normal; line-height: 1.25; }
    .crawl3d-newgame .ng-extra .ng-key { flex: 0 0 auto; }
    .crawl3d-newgame .ng-combo-btn { min-height: 36px; }
}
