/* The Battlemap Generator's editor layout (app_shell.js builds the DOM, app_layout.js drives it). It is the Dungeon Generator's
   layout (dungeon_generator.css, the part scoped to .dungeon-page) in this page's own classes, so that the two tools are one
   family and neither sheet depends on the other's edits. Everything is scoped to .bm-page, the page's root.

   The layout sets data-layout on the root: "desktop" from 1200 px, "tablet" from 768 px, "phone" below that and on a
   landscape phone (a coarse pointer on a screen no taller than 500 px); data-orient is "portrait" or "landscape". The widths
   are app_layout.js's: keep them together. The page is exactly one screen tall and docks to the top of it with one swipe. */

/* --- The root and the one-screen page ------------------------------------------------------------------------------------ */

.dungeon-generator.bm-page {
    --bm-rail-width: 76px;
    --bm-flyout-width: 276px;
    --bm-side-width: 348px;
    --bm-bar-height: 60px;
    --bm-line: rgba(242, 192, 128, 0.16);
    --bm-faint-line: rgba(182, 203, 208, 0.12);
    --bm-touch: 44px;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    max-width: none;
    height: 100vh;
    height: 100dvh;
    min-height: 420px;
    padding: 12px;
    scroll-snap-align: start;
    scroll-margin-top: 0;
}

.bm-page [hidden] {
    display: none !important;
}

html.bm-snap,
html.bm-snap body {
    scroll-snap-type: y proximity;
}

/* The top of the page is a resting place of its own, so that the hero is seen as it loads and one deliberate swipe is what docks the
   editor: with the editor as the only snap point, a short screen put it within the snap's reach of the top and the browser docked it
   at once. (The site's navbar is the first element of the body, at the very top.) */
html.bm-snap body > .custom-navbar {
    scroll-snap-align: start;
}

/* Not docked yet, on a touch screen: a cover over the map lets a finger scroll the page (the canvas keeps every touch for its tool)
   and holds the button that docks the editor. The button sits in the middle of the part of the map that is on screen. */
.bm-dock-cover {
    display: none;
}

@media (any-pointer: coarse) {
    .bm-page[data-editor-visible="false"]:not(.is-fullscreen) .bm-dock-cover {
        position: absolute;
        inset: 0;
        z-index: 2;
        display: block;
        background: rgba(8, 14, 17, 0.45);
        touch-action: pan-y;
    }

    .bm-page[data-editor-visible="false"] .bm-dock-cover .dungeon-btn {
        position: absolute;
        top: var(--bm-dock-cover-centre, 50%);
        left: 50%;
        transform: translate(-50%, -50%);
        min-height: 48px;
        padding-inline: 22px;
        white-space: nowrap;
    }
}

html.bm-fullscreen-lock,
html.bm-fullscreen-lock body {
    overflow: hidden;
}

.bm-page.is-fullscreen {
    position: fixed;
    inset: 0;
    z-index: 1060;
    overflow: hidden;
    background: #0b1519;
}

.bm-page h2 {
    margin-bottom: 10px;
}

/* --- The header: one slim row ------------------------------------------------------------------------------------------ */

.bm-header {
    display: grid;
    flex: none;
    /* Share and Clone on the left, the name in the middle, the rest of the controls on the right. */
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 6px 16px;
    margin-bottom: 10px;
    padding: 8px 14px;
    background: var(--dungeon-surface);
    border: 1px solid var(--bm-line);
    border-radius: 8px;
}

/* Where the header holds every control (from 1600 px) the buttons may not leave the name too little room: the row wraps, and the
   name keeps a width of its own. */
.bm-page[data-layout="desktop"][data-narrow="false"] .bm-header {
    display: flex;
    flex-wrap: wrap;
}

.bm-page[data-layout="desktop"][data-narrow="false"] .bm-title-row {
    flex: 1 1 240px;
}

.bm-page[data-layout="desktop"][data-narrow="false"] .bm-header-actions {
    margin-left: auto;
}

.bm-page[data-layout="desktop"][data-narrow="false"] .bm-header .bm-plan-note {
    flex: 1 0 100%;
}

.bm-header-start {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* The site's .btn-buy has a top margin of its own; in this row it would sit lower than its neighbours. */
.bm-header-start .btn-buy {
    margin: 0;
}

.bm-title-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-width: 0;
}

.bm-title-row .dungeon-title-input {
    flex: 1 1 auto;
    min-height: 40px;
    font-size: 1.3rem;
    text-align: center;
}

.bm-save-status {
    flex: 0 1 auto;
    min-width: 0;
    white-space: normal;
}

.bm-size-controls {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 6px;
}

.bm-size-controls .dungeon-field {
    flex-direction: row;
    align-items: center;
    gap: 6px;
    margin: 0;
}

.bm-size-controls .dungeon-field input {
    width: 68px;
    min-height: 38px;
}

.bm-size-controls .dungeon-size-times {
    padding: 0;
}

.bm-size-controls .dungeon-note {
    display: none;
    margin: 0;
}

.bm-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.bm-header .dungeon-btn {
    min-height: 38px;
    padding: 6px 12px;
    font-size: 0.82rem;
}

.bm-export-slot {
    display: contents;
}

.bm-header .bm-plan-note {
    grid-column: 1 / -1;
    padding: 6px 12px;
    font-size: 0.84rem;
    line-height: 1.4;
    text-align: left;
}

.bm-more {
    display: none;
    position: relative;
}

.bm-more-panel {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 1060;
    display: grid;
    gap: 8px;
    width: min(320px, calc(100vw - 24px));
    max-height: 70vh;
    max-height: 70dvh;
    overflow-y: auto;
    padding: 12px;
    border: 1px solid rgba(242, 192, 128, 0.35);
    border-radius: 10px;
    background: var(--dungeon-surface);
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.5);
}

.bm-more-panel .dungeon-btn,
.bm-more-panel .bm-menu-wrap {
    width: 100%;
}

.bm-more-panel .dungeon-btn {
    min-height: 44px;
    justify-content: flex-start;
}

.bm-more-panel .bm-size-controls {
    flex-wrap: wrap;
    padding-top: 8px;
    border-top: 1px solid var(--bm-faint-line);
}

.bm-more-panel .bm-size-controls .dungeon-note {
    display: block;
    flex-basis: 100%;
}

.bm-more-panel .bm-size-controls .dungeon-btn {
    width: auto;
}

.bm-more-panel .bm-plan-note {
    padding: 8px 10px;
    font-size: 0.8rem;
    line-height: 1.4;
    text-align: left;
}

/* --- The editor: rail, flyout, map, right column ----------------------------------------------------------------------- */

.bm-editor {
    position: relative;
    display: flex;
    flex: 1 1 0;
    gap: 10px;
    min-height: 0;
}

.bm-rail,
.bm-flyout,
.bm-stage,
.bm-side {
    min-height: 0;
    min-width: 0;
    background: var(--dungeon-surface);
    border: 1px solid var(--bm-line);
    border-radius: 8px;
}

.bm-rail,
.bm-flyout-body,
.bm-side-body,
.bm-more-panel {
    scrollbar-color: var(--dungeon-border) transparent;
    scrollbar-width: thin;
}

/* The tool rail */
.bm-rail {
    flex: 0 0 var(--bm-rail-width);
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 8px 6px;
    overflow-y: auto;
}

.bm-rail-group {
    display: grid;
    gap: 4px;
}

.bm-rail-title {
    color: var(--dungeon-muted);
    font-size: 0.62rem;
    letter-spacing: 0.08em;
    text-align: center;
    text-transform: uppercase;
}

.bm-rail-buttons {
    display: grid;
    gap: 4px;
}

.bm-rail .dungeon-tool,
.bm-phonebar .dungeon-tool,
.bm-flyout-modes .dungeon-tool {
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    min-height: 52px;
    padding: 6px 2px;
    font-size: 0.72rem;
    line-height: 1.1;
    text-align: center;
}

.bm-page .dungeon-tool i {
    width: auto;
    font-size: 1.1rem;
}

.bm-page .dungeon-tool span {
    min-width: 0;
    white-space: normal;
    overflow-wrap: anywhere;
}

.bm-page .dungeon-tool.is-open:not([aria-pressed="true"]) {
    box-shadow: inset 0 0 0 1px var(--dungeon-accent);
}

/* A touch screen has no pointer to hover with, yet keeps the last button it touched in :hover: that button would stay outlined like
   the lit one. Only a button that is really lit or open carries the accent there. */
@media (hover: none) {
    .bm-page .dungeon-tool:hover:not([aria-pressed="true"]):not(.is-open),
    .bm-page .dungeon-swatch:hover:not([aria-checked="true"]) {
        border-color: var(--dungeon-border);
    }
}

/* The options of a tool, beside the rail */
.bm-flyout {
    flex: 0 0 var(--bm-flyout-width);
    display: flex;
    flex-direction: column;
}

.bm-flyout-header,
.bm-side-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    border-bottom: 1px solid var(--bm-faint-line);
}

.bm-flyout-header {
    padding: 8px 8px 8px 14px;
}

.bm-flyout-header h2 {
    margin: 0;
    font-size: 1rem;
}

.bm-flyout-modes {
    display: none;
}

.bm-flyout-body {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    padding: 4px 12px 16px;
}

.bm-flyout-panel .bm-section-body > .dungeon-note:first-child {
    margin-top: 10px;
}

/* A picture to pick is a tile: its swatch above its name, a grid of them; never a column of full-width rows. */
.bm-flyout .dungeon-swatches,
.bm-side .dungeon-swatches,
.bm-new-dialog .dungeon-swatches {
    grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
    margin-top: 8px;
}

/* A list of swatches in titled groups (an area's floor): one title over each group's tiles. */
.bm-swatch-group + .bm-swatch-group {
    margin-top: 10px;
}

.bm-swatch-group-title {
    display: block;
    font-size: 0.78rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--dungeon-muted, #9fb0b4);
}

.bm-flyout .dungeon-swatch,
.bm-side .dungeon-swatch,
.bm-new-dialog .dungeon-swatch {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 6px;
    font-size: 0.74rem;
    line-height: 1.15;
    text-align: center;
}

.bm-flyout .dungeon-swatch .dungeon-swatch-chip,
.bm-side .dungeon-swatch .dungeon-swatch-chip,
.bm-new-dialog .dungeon-swatch .dungeon-swatch-chip {
    flex: none;
    width: 100%;
    height: 40px;
}

.bm-flyout .dungeon-swatch span:not(.dungeon-swatch-chip),
.bm-side .dungeon-swatch span:not(.dungeon-swatch-chip) {
    overflow-wrap: anywhere;
}

.bm-flyout .dungeon-swatch-chip--glyph {
    font-size: 1.1rem;
}

/* The inspector's one-line status of the tool: the chip stays small, in a line. */
.bm-tool-status .dungeon-swatch-chip,
.dungeon-readout .dungeon-swatch-chip {
    width: 22px;
    height: 22px;
}

/* The map */
.bm-stage {
    flex: 1 1 0;
    position: relative;
    display: flex;
    flex-direction: column;
    container-type: inline-size;
    overflow: hidden;
}

.bm-map-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
    padding: 6px 8px;
    border-bottom: 1px solid var(--bm-faint-line);
}

.bm-toolbar-left {
    order: 1;
    display: flex;
    flex: 1 1 280px;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.bm-level-tabs {
    flex: 1 1 0;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: thin;
    scrollbar-color: var(--dungeon-border) transparent;
}

.bm-level-tabs .dungeon-floor-tab {
    flex: none;
    min-height: 38px;
    padding-inline: 12px;
    white-space: nowrap;
}

.bm-level-tabs .dungeon-floor-tab:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.bm-toolbar-left > .dungeon-btn,
.bm-level-actions .dungeon-btn {
    flex: none;
    min-height: 38px;
    padding: 6px 12px;
    font-size: 0.8rem;
}

.bm-level-actions {
    display: flex;
    flex: none;
    flex-wrap: nowrap;
    gap: 8px;
}

.bm-toggles {
    order: 2;
    display: flex;
    flex: 0 1 auto;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.bm-map-actions {
    order: 3;
    display: flex;
    flex: none;
    align-items: center;
    gap: 6px;
    margin-left: auto;
}

.bm-map-actions .bm-tb-btn {
    flex: 0 0 38px;
    width: 38px;
    min-height: 38px;
    padding: 0;
}

.bm-map-actions .bm-tb-btn[aria-pressed="true"] {
    border-color: var(--dungeon-accent);
    background: rgba(var(--dungeon-accent-rgb), 0.22);
    color: #ffffff;
}

.bm-view-label {
    display: none;
}

.bm-view {
    position: relative;
}

.bm-compact-only,
.bm-tablet-only,
.bm-view {
    display: none;
}

/* The layers are chips with their words; below 1400 px of stage they take a row of their own under the tabs and the tools. */
.bm-toggles .bm-layer-face {
    min-height: 38px;
    padding: 4px 10px;
}

@container (max-width: 1399px) {
    .bm-toggles {
        order: 4;
        flex-basis: 100%;
    }
}

.bm-map-area {
    position: relative;
    display: flex;
    flex: 1 1 0;
    min-height: 0;
}

/* "Whole map" and "Full screen" in the map's top right corner, named and as big as a touch target, on a dark plate that stands out
   on any map. Elsewhere than on a desktop they live in the view popover (data-map-secondary), and the empty corner is not shown. */
.bm-map-corner {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 5;
    display: flex;
    gap: 8px;
}

/* A corner with no button to show (on a tablet or a phone outside the whole-map view) is not shown. */
.bm-map-corner:not(:has(> :not([hidden]))) {
    display: none;
}

.bm-map-corner .bm-tb-btn[hidden] {
    display: none;
}

/* The whole-map view (app_layout.js setMapOnly): the map alone over the whole browser window, above the page (and above the editor in
   full screen); the corner's way back stands where "Whole map" was. */
html.bm-map-only-lock,
html.bm-map-only-lock body {
    overflow: hidden;
}

.bm-page.is-map-only .bm-map-area {
    position: fixed;
    inset: 0;
    z-index: 1065;
    background: #0a1114;
}

.bm-page.is-map-only .bm-map-corner #bm-fit-btn {
    display: none;
}

.bm-map-corner .bm-tb-btn {
    display: inline-flex;
    flex: none;
    align-items: center;
    gap: 8px;
    width: auto;
    white-space: nowrap;
    min-height: var(--bm-touch);
    padding: 0 16px;
    font-size: 0.95rem;
    background: rgba(14, 23, 28, 0.94);
    border-color: var(--dungeon-accent);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.55);
}

.bm-map-corner .bm-tb-btn:hover:not(:disabled),
.bm-map-corner .bm-tb-btn:focus-visible {
    background: var(--dungeon-accent);
    color: #1a1208;
}

.bm-map-corner .bm-tb-btn[aria-pressed="true"] {
    background: rgba(var(--dungeon-accent-rgb), 0.3);
    color: #ffffff;
}

.bm-map-corner .bm-tb-btn:disabled {
    opacity: 0.55;
    border-color: var(--bm-line);
}

.bm-map-corner .bm-view-label {
    display: inline;
}

.bm-canvas-wrap {
    position: relative;
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
    background: #0a1114;
    overscroll-behavior: contain;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

/* The city plan: docked at the stage's left, in the width the map leaves empty (app_edit_city.js decides when), or the City
 * section of the Map tab. One list of districts, a line for each. */
.bm-city-dock {
    flex: 0 0 var(--bm-city-dock-width, 330px);
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--dungeon-surface);
    border-right: 1px solid var(--bm-line);
}

.bm-city-dock[hidden] {
    display: none;
}

.bm-city-dock-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border: 0;
    border-bottom: 1px solid var(--bm-faint-line);
    background: transparent;
    color: var(--tool-gold, #e7bf8f);
    font: inherit;
    font-weight: 300;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    text-align: left;
    cursor: pointer;
}

.bm-city-dock-toggle span {
    flex: 1 1 auto;
}

.bm-city-dock-toggle:hover,
.bm-city-dock-toggle:focus-visible {
    background: var(--tool-gold-soft, rgba(231, 191, 143, 0.14));
}

.bm-city-dock-body {
    flex: 1 1 0;
    min-height: 0;
    padding: 10px 12px 12px;
    overflow-y: auto;
    scrollbar-color: var(--dungeon-border) transparent;
    scrollbar-width: thin;
}

/* Folded: a narrow strip that holds only the toggle, its label running down. */
.bm-city-dock.is-folded {
    flex-basis: 44px;
}

.bm-city-dock.is-folded .bm-city-dock-body {
    display: none;
}

.bm-city-dock.is-folded .bm-city-dock-toggle {
    flex-direction: column;
    flex: 1 1 auto;
    padding: 12px 0;
    border-bottom: 0;
    justify-content: flex-start;
}

.bm-city-dock.is-folded .bm-city-dock-toggle span {
    flex: 0 0 auto;
    writing-mode: vertical-rl;
}

.bm-city-dock.is-folded .bm-city-dock-chevron {
    transform: rotate(180deg);
}

.bm-city-note {
    margin: 0 0 8px;
}

.bm-city-plan {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 6px;
    touch-action: manipulation;
}

.bm-city-districts {
    display: grid;
    gap: 2px;
    margin: 8px 0 0;
    padding: 0;
    list-style: none;
}

.bm-city-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
    width: 100%;
    min-height: 32px;
    padding: 5px 10px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--tool-cream, #f6e6c9);
    font: inherit;
    font-size: 0.9rem;
    text-align: left;
    cursor: pointer;
}

.bm-city-row:hover,
.bm-city-row:focus-visible {
    background: var(--tool-gold-soft, rgba(231, 191, 143, 0.14));
}

.bm-city-row.is-open {
    border-color: var(--tool-gold, #e7bf8f);
    background: var(--tool-gold-soft, rgba(231, 191, 143, 0.14));
    color: var(--tool-gold, #e7bf8f);
}

.bm-city-row-name {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bm-city-row-kind {
    flex: 0 0 auto;
    color: var(--tool-cream-muted, rgba(246, 230, 201, 0.72));
    font-size: 0.8rem;
}

.bm-city-row-mark {
    flex: 0 0 1em;
    font-size: 0.7rem;
    text-align: center;
}

.bm-city-row.is-new .bm-city-row-mark {
    opacity: 0.55;
}

.bm-city-row.is-locked {
    opacity: 0.7;
}

.bm-statusbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 34px;
    padding: 4px 10px;
    border-top: 1px solid var(--bm-faint-line);
}

.bm-statusbar .bm-status {
    flex: 1 1 auto;
    margin: 0;
}

.bm-statusbar .bm-cursor {
    display: none;
}

/* Notices sit at the top of the map, never over the bar, the chip or the strip at its foot. */
.bm-toasts {
    position: absolute;
    top: 10px;
    left: 50%;
    z-index: 6;
    display: grid;
    gap: 6px;
    width: max-content;
    max-width: min(420px, calc(100% - 20px));
    transform: translateX(-50%);
    pointer-events: none;
}

.bm-toast.dungeon-toast {
    position: static;
    max-width: none;
}

.bm-toast:not(.is-visible) {
    display: none;
}

.bm-chip,
.bm-peek,
.bm-hint,
.bm-phonebar,
.bm-scrim {
    display: none;
}

/* The right column */
.bm-side {
    flex: 0 0 var(--bm-side-width);
    display: flex;
    flex-direction: column;
}

/* The edge that resizes the right column (app_side_resize.js): on a desktop only, in the gap between the map and the column. A grip
   in its middle says it can be dragged; it turns gold under the pointer, while dragging and with the keyboard's focus. */
.bm-side-resize {
    display: none;
}

.bm-page[data-layout="desktop"] .bm-side {
    position: relative;
}

.bm-page[data-layout="desktop"] .bm-side-resize {
    position: absolute;
    top: 0;
    bottom: 0;
    left: -11px;
    z-index: 3;
    display: block;
    width: 12px;
    cursor: col-resize;
    touch-action: none;
}

.bm-page[data-layout="desktop"] .bm-side-resize::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 4px;
    width: 4px;
    height: 48px;
    border-radius: 2px;
    background: var(--bm-line);
    transform: translateY(-50%);
    transition: background-color 0.15s ease, height 0.15s ease;
}

.bm-page[data-layout="desktop"] .bm-side-resize:hover::after,
.bm-page[data-layout="desktop"] .bm-side-resize:focus-visible::after,
.bm-page.is-resizing-side .bm-side-resize::after {
    height: 96px;
    background: var(--dungeon-accent);
}

.bm-side-resize:focus-visible {
    outline: none;
}

/* While the edge is dragged the page neither selects text nor shows another cursor. */
.bm-page.is-resizing-side {
    cursor: col-resize;
    user-select: none;
    -webkit-user-select: none;
}

.bm-side-header {
    align-items: stretch;
    gap: 0;
}

.bm-side-tabs {
    display: flex;
    flex: 1 1 0;
    gap: 4px;
    min-width: 0;
    padding: 4px;
    overflow-x: auto;
    scrollbar-width: none;
}

/* A label that does not fit on a line (Place Characters & Monsters) goes on to the next, centred, inside its tab. */
.bm-side-tab span {
    max-width: 7.5em;
    overflow-wrap: anywhere;
    text-align: center;
    white-space: normal;
}

.bm-side-tab {
    /* the five tabs share the strip: a tab shrinks (its label wraps) before the strip would hide the first of them */
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 0;
    min-height: 54px;
    padding: 6px 4px;
    border: 1px solid var(--dungeon-accent);
    border-radius: 8px;
    background: transparent;
    color: var(--dungeon-muted);
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1.15;
}

.bm-side-tab i {
    font-size: 1.05rem;
}

.bm-side-tab:hover {
    color: #fff4df;
}

/* The site's tool theme (tool_components.css) draws a tab without a border; here every tab is a button with the gold border, and the chosen one
 * keeps the theme's gold fill. */
body.tool-ui .bm-side-tabs .bm-side-tab {
    border-color: var(--dungeon-accent);
    border-radius: 8px;
}

.bm-side-tab:focus-visible {
    outline: 2px solid var(--dungeon-accent);
    outline-offset: -2px;
}

.bm-side-close {
    display: none;
    flex: none;
    margin: 6px;
}

.bm-side-body {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    padding: 14px;
}

/* The Saved tab: the list takes the column's whole height and scrolls inside it; Refresh and Load more stay under it. */
.bm-side-panel[data-side-panel="saved"]:not([hidden]),
.bm-side-panel[data-side-panel="saved"] > .bm-section,
.bm-side-panel[data-side-panel="saved"] .bm-section-body {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.bm-side-panel[data-side-panel="saved"]:not([hidden]),
.bm-side-panel[data-side-panel="saved"] > .bm-section {
    height: 100%;
}

.bm-side-panel[data-side-panel="saved"] .bm-section-body:not([hidden]) {
    flex: 1 1 auto;
}

.bm-side-panel[data-side-panel="saved"] .dungeon-history-list {
    flex: 1 1 auto;
    min-height: 120px;
    max-height: none;
    overflow-y: auto;
    align-content: start;
}

.bm-side-panel[data-side-panel="saved"] .bm-section-body > .dungeon-btn {
    flex: none;
}

/* A saved map: its picture (a thumbnail the page draws and sends after a save; an icon until there is one), its name and facts. */
.dungeon-history-list .bm-history-item {
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 10px;
    align-items: start;
}

.bm-history-thumb {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 72px;
    height: 72px;
    overflow: hidden;
    border: 1px solid rgba(182, 203, 208, 0.18);
    border-radius: 6px;
    background: var(--dungeon-bg);
    color: var(--dungeon-border);
    font-size: 1.5rem;
}

.bm-history-thumb img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.bm-campaign-pill {
    display: inline-flex;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bm-history-body {
    display: grid;
    gap: 6px;
    min-width: 0;
}

.bm-history-item .dungeon-history-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.bm-inspector h2:first-child {
    font-size: 1.05rem;
    text-transform: uppercase;
}

/* The sections of a tab, each with its title. */
.bm-section + .bm-section {
    margin-top: 18px;
}

.bm-section-heading {
    margin: 0 0 8px;
    font-size: 0.95rem;
}

.bm-section-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    min-height: 36px;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--dungeon-text);
    font: inherit;
    font-weight: 700;
    text-align: left;
}

.bm-section-toggle i {
    transition: transform 0.15s ease;
}

.bm-section-toggle[aria-expanded="false"] i {
    transform: rotate(-90deg);
}

.bm-side-panel .bm-section-body > .dungeon-field:first-child {
    margin-top: 0;
}

.bm-section--flyout .bm-section-body > * + * {
    margin-top: 10px;
}

.bm-tool-inline {
    width: 100%;
    margin-bottom: 8px;
    justify-content: center;
}

.bm-side .dungeon-card-grid,
.bm-side .dungeon-asset-grid {
    grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
}

.bm-side .dungeon-asset-search {
    grid-template-columns: minmax(0, 1fr);
}

.bm-side .dungeon-token-list {
    grid-template-columns: minmax(0, 1fr);
}

.bm-hint {
    position: absolute;
    top: 64px;
    left: 8px;
    right: 66px;
    z-index: 5;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid var(--dungeon-accent);
    border-radius: 10px;
    background: rgba(14, 38, 38, 0.96);
    color: #fff4df;
    font-size: 0.86rem;
    line-height: 1.35;
}

.bm-hint-close {
    flex: none;
    min-height: 40px;
    padding: 0 14px;
    border: 1px solid var(--dungeon-accent);
    border-radius: 20px;
    background: transparent;
    color: #fff4df;
    font-weight: 700;
}

/* --- Full screen: the stage keeps the room, the header stays ------------------------------------------------------------ */

.bm-page.is-fullscreen {
    padding: 8px;
}

/* --- Tablet: the right column is a drawer, the flyout floats over the map ------------------------------------------------ */

.bm-page[data-layout="tablet"] .bm-rail,
.bm-page[data-layout="phone"] .bm-rail {
    --bm-rail-width: 64px;
}

.bm-page[data-layout="tablet"] .bm-rail .dungeon-tool span {
    display: none;
}

.bm-page[data-layout="tablet"] .bm-rail .dungeon-tool[aria-pressed="true"] span {
    display: block;
}

.bm-page[data-layout="tablet"] .bm-rail .dungeon-tool {
    min-height: 48px;
}

.bm-page[data-narrow="true"] .bm-more,
.bm-page[data-layout="tablet"] .bm-more,
.bm-page[data-layout="phone"] .bm-more {
    display: block;
}

.bm-page[data-layout="tablet"] .bm-header .bm-header-actions > [data-header-action],
.bm-page[data-layout="tablet"] .bm-header .bm-header-start > [data-header-action],
.bm-page[data-layout="phone"] .bm-header .bm-header-start > [data-header-action] {
    display: none;
}

.bm-page[data-layout="tablet"] .bm-header,
.bm-page[data-layout="phone"] .bm-header {
    grid-template-columns: auto minmax(0, 1fr) auto;
}

/* On a phone Share is its icon alone: the name needs the width. */
.bm-page[data-layout="phone"] .bm-header .bm-share-btn {
    width: 44px;
    min-height: 44px;
    padding: 0;
    justify-content: center;
}

.bm-page[data-layout="phone"] .bm-header .bm-share-btn span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
}

.bm-page[data-layout="tablet"] .bm-tablet-only,
.bm-page[data-layout="tablet"] .bm-compact-only,
.bm-page[data-layout="tablet"] .bm-view,
.bm-page[data-layout="phone"] .bm-compact-only,
.bm-page[data-layout="phone"] .bm-view {
    display: inline-flex;
}

.bm-page[data-layout="tablet"] .bm-view,
.bm-page[data-layout="phone"] .bm-view {
    display: block;
}

.bm-page[data-layout="tablet"] .bm-flyout {
    position: absolute;
    top: 0;
    bottom: 0;
    left: calc(var(--bm-rail-width) + 10px);
    z-index: 5;
    width: min(300px, calc(100% - var(--bm-rail-width) - 20px));
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.5);
}

.bm-page[data-layout="tablet"] .bm-side {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 7;
    width: min(380px, 92%);
    box-shadow: -12px 0 36px rgba(0, 0, 0, 0.5);
    transform: translateX(calc(100% + 16px));
    visibility: hidden;
    transition: transform 0.2s ease, visibility 0s linear 0.2s;
}

.bm-page[data-layout="tablet"][data-side-open="true"] .bm-side {
    transform: none;
    visibility: visible;
    transition: transform 0.2s ease;
}

.bm-page[data-layout="tablet"] .bm-side-close,
.bm-page[data-layout="phone"] .bm-side-close {
    display: inline-flex;
}

.bm-page[data-layout="tablet"] .bm-scrim {
    position: absolute;
    inset: 0;
    z-index: 6;
    background: rgba(5, 10, 12, 0.5);
    border-radius: 8px;
}

.bm-page[data-layout="tablet"] .bm-scrim:not([hidden]) {
    display: block;
}

/* The view popover: the layers, reroll, fit, full screen and measure of a screen too small to show them in the bar. */
.bm-view-panel {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 1060;
    display: grid;
    gap: 8px;
    width: min(300px, calc(100vw - 24px));
    max-height: min(70vh, 520px);
    overflow-y: auto;
    padding: 10px;
    border: 1px solid rgba(242, 192, 128, 0.35);
    border-radius: 10px;
    background: var(--dungeon-surface);
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.5);
}

.bm-view-panel .bm-toggles {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.bm-view-panel .bm-layer-toggle,
.bm-view-panel .bm-layer-face {
    width: 100%;
}

.bm-view-panel .bm-toggles .bm-layer-face > span {
    display: inline;
}

.bm-view-panel .bm-layer-face {
    min-height: 44px;
}

.bm-view-panel .dungeon-btn,
.bm-view-panel .bm-tb-btn {
    flex: none;
    width: 100%;
    min-height: 44px;
    justify-content: flex-start;
    padding: 6px 12px;
}

.bm-view-panel .bm-view-label {
    display: inline;
}

/* The popover sits inside the map's actions, whose icon buttons are a square 38-44 px (and on a touch screen or a phone a rule of
   higher weight makes them so): its own buttons are full-width rows with their names whatever the screen. */
.bm-page[data-layout] .bm-map-actions .bm-view-panel .bm-tb-btn {
    flex: none;
    width: 100%;
    justify-content: flex-start;
    padding: 6px 12px;
}

/* The tablet's button for the right column names itself: an icon alone did not say what it opens. */
.bm-page[data-layout="tablet"] .bm-map-actions .bm-side-toggle {
    flex-basis: auto;
    width: auto;
    padding-inline: 14px;
    gap: 8px;
}

.bm-page[data-layout="tablet"] .bm-map-actions .bm-side-toggle .bm-view-label {
    display: inline;
    font-size: 0.85rem;
    font-weight: 700;
}

.bm-view-panel .bm-level-actions {
    display: grid;
}

/* --- Phone: the map fills the screen; the tools are a bar at the thumb --------------------------------------------------- */

.dungeon-generator.bm-page[data-layout="phone"] {
    padding: 0;
    min-height: 0;
}

.bm-page[data-layout="phone"] .bm-header {
    grid-template-columns: auto minmax(0, 1fr) auto;
    margin: 0;
    padding: 6px 8px;
    gap: 4px 8px;
    border-width: 0 0 1px;
    border-radius: 0;
}

.bm-page[data-layout="phone"] .bm-header .bm-title-row .dungeon-title-input {
    padding: 2px 6px;
    font-size: 1.05rem;
}

.bm-page[data-layout="phone"] .bm-header .dungeon-btn,
.bm-page[data-layout="phone"] .bm-header .dungeon-icon-btn {
    min-height: 44px;
}

.bm-page[data-layout="phone"] .bm-header-actions > [data-header-action] {
    display: none;
}

.bm-page[data-layout="phone"] .bm-header-actions .dungeon-icon-btn {
    flex: 0 0 44px;
    width: 44px;
}

/* The save status is a dot: green saved, amber unsaved; its words are for screen readers. */
.bm-page[data-layout="phone"] .bm-save-status {
    flex: none;
    width: 12px;
    min-height: 12px;
    height: 12px;
    padding: 0;
    overflow: hidden;
    border-radius: 50%;
    border-color: transparent;
    background: var(--dungeon-accent);
    color: transparent;
    font-size: 0;
    text-indent: -9999px;
}

.bm-page[data-layout="phone"] .bm-save-status[data-state="dirty"] {
    background: #e7a64a;
}

.bm-page[data-layout="phone"] .bm-save-status[data-state="error"] {
    background: #e06b6b;
}

.bm-page[data-layout="phone"] .bm-save-status[data-state="saving"] {
    background: var(--dungeon-link);
}

.bm-page[data-layout="phone"] .bm-editor {
    flex-direction: column;
    gap: 0;
    padding-bottom: calc(var(--bm-bar-height) + env(safe-area-inset-bottom, 0px));
}

.bm-page[data-layout="phone"] .bm-rail {
    display: none;
}

.bm-page[data-layout="phone"] .bm-stage {
    flex: 1 1 0;
    border-width: 0;
    border-radius: 0;
}

.bm-page[data-layout="phone"] .bm-statusbar {
    display: none;
}

/* The toolbar floats over the map: the levels at its top left, the view controls at its right edge. */
.bm-page[data-layout="phone"] .bm-map-toolbar {
    position: absolute;
    inset: 0;
    z-index: 3;
    display: block;
    padding: 0;
    border: 0;
    pointer-events: none;
}

.bm-page[data-layout="phone"] .bm-toolbar-left {
    position: absolute;
    top: 6px;
    left: 6px;
    max-width: calc(100% - 66px);
    padding: 3px;
    border: 1px solid var(--bm-line);
    border-radius: 10px;
    background: rgba(14, 23, 28, 0.88);
    pointer-events: auto;
}

.bm-page[data-layout="phone"] .bm-level-tabs .dungeon-floor-tab {
    min-height: 40px;
    padding: 4px 10px;
    font-size: 0.8rem;
}

.bm-page[data-layout="phone"] .bm-map-actions {
    position: absolute;
    top: 6px;
    right: 6px;
    display: grid;
    gap: 6px;
    padding: 3px;
    border: 1px solid var(--bm-line);
    border-radius: 10px;
    background: rgba(14, 23, 28, 0.88);
    pointer-events: auto;
}

.bm-page[data-layout="phone"] .bm-map-actions .bm-tb-btn {
    flex: none;
    width: 44px;
    min-height: 44px;
}

.bm-page[data-layout="phone"] .bm-desktop-only {
    display: none;
}

.bm-page[data-layout="phone"] .bm-toasts {
    top: 58px;
    max-width: calc(100% - 76px);
}

.bm-page[data-layout="phone"] .bm-hint:not([hidden]),
.bm-page[data-layout="tablet"] .bm-hint:not([hidden]) {
    display: flex;
}

/* The bar: fixed to the screen's edge while any of the editor shows */
.bm-page[data-layout="phone"] .bm-phonebar {
    display: none;
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 900; /* under the site's cookie notice (1000), which a first visit must be able to answer */
    gap: 4px;
    padding: 4px 6px calc(4px + env(safe-area-inset-bottom, 0px));
    background: var(--dungeon-surface);
    border-top: 1px solid var(--bm-line);
}

.bm-page[data-layout="phone"][data-editor-visible="true"] .bm-phonebar {
    display: flex;
}

.bm-page[data-layout="phone"] .bm-phonebar .dungeon-tool {
    flex: 1 1 0;
    min-height: 52px;
}

/* What is armed, and what is selected, above the bar */
.bm-page[data-layout="phone"] .bm-chip:not([hidden]) {
    position: absolute;
    left: 8px;
    bottom: 8px;
    z-index: 4;
    display: flex;
    max-width: calc(100% - 16px);
    border: 1px solid var(--dungeon-accent);
    border-radius: 22px;
    background: rgba(14, 38, 38, 0.95);
    color: #fff4df;
    overflow: hidden;
}

.bm-chip button {
    min-height: 44px;
    border: 0;
    background: transparent;
    color: inherit;
    font-size: 0.86rem;
    font-weight: 700;
}

.bm-chip-label {
    min-width: 0;
    padding: 0 6px 0 16px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bm-chip-clear {
    flex: none;
    width: 44px;
}

.bm-page[data-layout="phone"] .bm-peek:not([hidden]) {
    position: absolute;
    right: 8px;
    bottom: 8px;
    left: 8px;
    z-index: 4;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 8px 8px 14px;
    border: 1px solid var(--bm-line);
    border-radius: 12px;
    background: rgba(14, 23, 28, 0.96);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.bm-peek-name {
    min-width: 0;
    overflow: hidden;
    color: #fff4df;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bm-peek-actions {
    display: flex;
    flex: none;
    gap: 6px;
}

.bm-peek .dungeon-btn {
    min-height: 44px;
    padding: 6px 14px;
}

/* The sheets: half the screen's height, over the map; the right column's is the whole screen */
.bm-page[data-layout="phone"] .bm-flyout {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1038; /* over the scrim (1035), under the right column's sheet (1040) */
    height: min(52dvh, 460px);
    border-width: 1px 0 0;
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -12px 36px rgba(0, 0, 0, 0.5);
}

.bm-page[data-layout="phone"] .bm-flyout-modes {
    display: flex;
    gap: 4px;
    padding: 6px 8px;
    overflow-x: auto;
    border-bottom: 1px solid var(--bm-faint-line);
    scrollbar-width: none;
}

.bm-page[data-layout="phone"] .bm-flyout-modes .dungeon-tool {
    flex: 1 0 64px;
    min-height: 48px;
}

.bm-page[data-layout="phone"] .bm-flyout-panel .bm-section-body > .dungeon-note:first-child {
    margin-top: 8px;
}

.bm-page[data-layout="phone"] .bm-side {
    position: fixed;
    top: var(--bm-header-bottom, 0px);
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1040;
    border-width: 1px 0 0;
    border-radius: 14px 14px 0 0;
    transform: translateY(105%);
    visibility: hidden;
    transition: transform 0.2s ease, visibility 0s linear 0.2s;
}

.bm-page[data-layout="phone"][data-side-open="true"] .bm-side {
    transform: none;
    visibility: visible;
    transition: transform 0.2s ease;
}

.bm-page[data-layout="phone"][data-side-open="true"][data-side-size="half"] .bm-side {
    top: auto;
    height: min(58dvh, 520px);
}

.bm-page[data-layout="phone"] .bm-scrim {
    position: fixed;
    inset: 0;
    z-index: 1035;
    background: rgba(5, 10, 12, 0.5);
}

.bm-page[data-layout="phone"] .bm-scrim:not([hidden]) {
    display: block;
}

/* A landscape phone: the bar is a rail at the left edge, under the header; sheets slide in at the sides */
.bm-page[data-layout="phone"][data-orient="landscape"] .bm-editor {
    padding-bottom: 0;
    padding-left: calc(64px + env(safe-area-inset-left, 0px));
}

.bm-page[data-layout="phone"][data-orient="landscape"][data-editor-visible="true"] .bm-phonebar {
    top: var(--bm-header-bottom, 0px);
    right: auto;
    bottom: 0;
    flex-direction: column;
    width: calc(64px + env(safe-area-inset-left, 0px));
    padding: 4px 4px 4px calc(4px + env(safe-area-inset-left, 0px));
    border-top: 0;
    border-right: 1px solid var(--bm-line);
}

.bm-page[data-layout="phone"][data-orient="landscape"] .bm-phonebar .dungeon-tool {
    min-height: 0;
    padding: 2px 0;
    /* the longest name ("Characters") must fit the narrow rail on one line */
    font-size: 0.62rem;
}

/* The Pan | Select button: both modes are named, the one in use is lit and the other dimmed. Side by side on the bottom bar, one over the
   other (no divider) on the narrow rail of a landscape phone. */
.bm-bar-modes {
    display: inline-flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0 4px;
}

.bm-bar-modes b {
    font-weight: 500;
    opacity: 0.55;
}

.bm-bar-modes b.is-on {
    font-weight: 700;
    opacity: 1;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.bm-bar-sep {
    font-style: normal;
    opacity: 0.4;
}

.bm-page[data-orient="landscape"] .bm-bar-modes {
    flex-direction: column;
    align-items: center;
}

.bm-page[data-orient="landscape"] .bm-bar-sep {
    display: none;
}

.bm-page[data-layout="phone"][data-orient="landscape"] .bm-header {
    grid-template-columns: auto minmax(0, 1fr) auto;
    padding: 2px 8px;
}

.bm-page[data-layout="phone"][data-orient="landscape"] .bm-flyout {
    top: 0;
    right: auto;
    width: min(340px, 60%);
    height: auto;
    border-width: 0 1px 0 0;
    border-radius: 0;
}

.bm-page[data-layout="phone"][data-orient="landscape"] .bm-side,
.bm-page[data-layout="phone"][data-orient="landscape"][data-side-open="true"][data-side-size="half"] .bm-side {
    top: var(--bm-header-bottom, 0px);
    left: auto;
    width: min(420px, 70%);
    height: auto;
    border-width: 0 0 0 1px;
    border-radius: 0;
    transform: translateX(105%);
}

.bm-page[data-layout="phone"][data-orient="landscape"][data-side-open="true"] .bm-side,
.bm-page[data-layout="phone"][data-orient="landscape"][data-side-open="true"][data-side-size="half"] .bm-side {
    transform: none;
}

/* --- Touch: every target is at least 40 px ------------------------------------------------------------------------------- */

@media (any-pointer: coarse) {
    .bm-page .dungeon-btn,
    .bm-page .dungeon-icon-btn,
    .bm-page .dungeon-small-btn,
    .bm-page .btn,
    .bm-page .dungeon-floor-tab,
    .bm-page .dungeon-swatch,
    .bm-page .dungeon-recent-item,
    .bm-page .bm-side-tab,
    .bm-page .bm-section-toggle,
    .bm-page .bm-layer-face,
    .bm-page .bm-tb-btn,
    .bm-page .dungeon-tool {
        min-height: 44px;
    }

    .bm-page .bm-map-actions .bm-tb-btn {
        flex-basis: 44px;
        width: 44px;
    }

    .bm-page .bm-size-controls .dungeon-field input,
    .bm-page .dungeon-field input:not([type="checkbox"]):not([type="range"]):not([type="color"]),
    .bm-page .dungeon-field select,
    .bm-page .dungeon-title-input {
        min-height: 44px;
    }

    .bm-page .dungeon-field--check {
        min-height: 44px;
        align-items: center;
    }

    .bm-page .dungeon-field input[type="checkbox"] {
        width: 22px;
        height: 22px;
    }

    .bm-page input[type="range"] {
        min-height: 44px;
    }

    .bm-page .dungeon-swatch {
        min-height: 72px;
    }

    .bm-page .dungeon-recent-item {
        min-height: 56px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .bm-page .bm-side,
    .bm-page .bm-section-toggle i {
        transition: none;
    }
}

/* --- The windows over the page ------------------------------------------------------------------------------------------- */

/* The Generate battlemap window: its parts sit in one scrolling body, with the buttons always in view below it. */
/* The site gives every window a top margin and a narrower frame; this one fills the screen it has on a phone and the dialog's own width above. */
#bm-random-modal {
    width: 100%;
    margin: 0;
}

#bm-random-modal .modal-content {
    margin-top: 0;
}

#bm-random-modal .modal-title {
    font-size: 1.15rem;
}

#bm-random-modal .modal-content > form {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0;
}

#bm-random-modal .modal-body {
    overflow-y: auto;
}

#bm-random-modal .modal-footer {
    justify-content: flex-end;
    gap: 14px;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid rgba(182, 203, 208, 0.18);
}

#bm-random-modal .modal-footer > * {
    margin: 0;
}

#bm-random-modal .modal-header {
    border-bottom: 1px solid rgba(182, 203, 208, 0.18);
}

#bm-random-modal .btn-close {
    opacity: 0.9;
}

#bm-random-modal .form-control,
#bm-random-modal .form-select {
    background-color: #0e171c;
    border-color: var(--dungeon-border, #31454d);
    color: #f7dfbf;
}

#bm-random-modal .form-control::placeholder {
    color: rgba(182, 203, 208, 0.75);
    opacity: 1;
}

#bm-random-modal .form-control:focus,
#bm-random-modal .form-select:focus {
    border-color: var(--dungeon-accent);
    box-shadow: 0 0 0 3px rgba(var(--dungeon-accent-rgb), 0.24);
}

/* What kind of place: a search box over groups of tiles, instead of one long list. */
.bm-kinds {
    display: grid;
    gap: 10px;
}

/* The window's body scrolls; the list of kinds does not scroll inside it, so no heading is ever cut in two. */
.bm-kinds-scroll {
    display: grid;
    gap: 12px;
}

.bm-kind-group h3 {
    margin: 0 0 6px;
    color: #b6cbd0;
    font-size: 0.74rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

/* The kinds of place are an accordion: each family's heading is a panel heading of the site's (upper case, light) and folds its tiles away. */
.bm-kind-accordion {
    --bs-accordion-bg: transparent;
    --bs-accordion-border-color: var(--dungeon-border);
    --bs-accordion-btn-bg: transparent;
    --bs-accordion-active-bg: transparent;
    --bs-accordion-active-color: var(--dungeon-text);
    --bs-accordion-btn-color: var(--dungeon-text);
    --bs-accordion-btn-focus-box-shadow: 0 0 0 0.2rem rgba(var(--dungeon-accent-rgb), 0.25);
    display: grid;
    gap: 8px;
}

.bm-kind-accordion .accordion-item {
    border: 1px solid var(--dungeon-border);
    border-radius: 8px;
    overflow: hidden;
    background: transparent;
}

.bm-kind-accordion .accordion-header {
    margin: 0;
}

.bm-kind-accordion .bm-kind-heading {
    justify-content: flex-start;
    padding: 10px 44px 10px 14px;
    font-size: 1rem;
    text-align: left;
}

.bm-kind-accordion .bm-kind-heading::after {
    position: absolute;
    right: 16px;
    margin-left: 0;
    filter: invert(1) brightness(1.6);
}

.bm-kind-accordion .bm-kind-heading {
    position: relative;
}

.bm-kind-accordion .accordion-body {
    padding: 10px;
}

.bm-kind-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
    gap: 6px;
}

.bm-kind {
    min-height: 44px;
    padding: 6px 10px;
    border: 1px solid #31454d;
    border-radius: 6px;
    background: #122027;
    color: #f7dfbf;
    font-size: 0.84rem;
    line-height: 1.2;
    text-align: left;
}

.bm-kind:hover {
    border-color: var(--dungeon-accent);
}

.bm-kind[aria-checked="true"] {
    border-color: var(--dungeon-accent);
    background: rgba(var(--dungeon-accent-rgb), 0.18);
    color: #fff4df;
}

.bm-kind:focus-visible {
    outline: 2px solid var(--dungeon-accent);
    outline-offset: 2px;
}

.bm-kinds-empty {
    margin: 0;
    color: #b6cbd0;
}

/* A window's frame (the gold-edged `.modal-content`, its title, close cross and footer) is the shared component layer's
   (tool_components.css `dialog.tool-dialog`); what stays here is the body of a window made of the page's own parts. */
.bm-page dialog.tool-dialog .bm-dialog-body {
    overflow: visible;
    padding-right: 0;
}

/* The New window: the title and the size first, the grounds scroll, Create stays in view. */
.bm-new-dialog:not(.tool-dialog) {
    max-height: calc(100dvh - 32px);
}

.bm-new-dialog:not(.tool-dialog)[open] {
    display: flex;
    flex-direction: column;
}

.bm-dialog-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding-right: 4px;
}

.bm-new-dialog .dungeon-dialog-actions {
    flex: none;
    gap: 14px;
    padding-top: 12px;
}

@media (max-width: 767.98px) {
    #bm-random-modal .modal-content {
        border-radius: 0;
    }

    .bm-page dialog.tool-dialog.bm-new-dialog {
        width: 100vw;
        max-width: 100vw;
        height: 100dvh;
        max-height: 100dvh;
        margin: 0;
    }

    .bm-page dialog.tool-dialog.bm-new-dialog .modal-content {
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }

    .bm-new-dialog .dungeon-dialog-actions {
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .bm-kinds-scroll {
        max-height: none;
        overflow: visible;
    }
}

/* What the map's floating strip keeps clear of at its foot: the phone's chip and peek card. */
.bm-page[data-layout="phone"][data-chip="true"] .bm-canvas-wrap,
.bm-page[data-layout="phone"][data-peek="true"] .bm-canvas-wrap {
    --bm-dock-inset: 56px;
}

.bm-dialog-body .dungeon-form-heading {
    margin-top: 18px;
}

/* The drawer waits beyond the editor's right edge: it must not widen the page. */
.bm-page[data-layout="tablet"] .bm-editor {
    overflow: hidden;
}

/* The line that tells how to end the wall or shape being drawn (path_hint.js): at the foot of the map, and at the top of a phone's
   map under the floating toolbar. It is emphasised the first time a wall is drawn in a browser. */
.bm-path-hint {
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: 10px;
    z-index: 5;
    margin: 0;
    padding: 6px 12px;
    font-size: 0.82rem;
    line-height: 1.35;
    color: #f7dfbf;
    text-align: center;
    background: rgba(14, 23, 28, 0.92);
    border: 1px solid var(--bm-faint-line, rgba(255, 255, 255, 0.14));
    border-radius: 8px;
    pointer-events: none;
}

.bm-path-hint[hidden] {
    display: none;
}

.bm-path-hint.is-emphasis {
    color: #1a1208;
    background: #e7bf8f;
    border-color: #fff1cf;
    font-weight: 600;
    animation: bm-path-hint-pulse 1.4s ease-out 2;
}

@keyframes bm-path-hint-pulse {
    from { box-shadow: 0 0 0 0 rgba(231, 191, 143, 0.85); }
    to { box-shadow: 0 0 0 16px rgba(231, 191, 143, 0); }
}

.bm-page[data-layout="phone"] .bm-path-hint {
    top: 58px;
    bottom: auto;
}

@media (prefers-reduced-motion: reduce) {
    .bm-path-hint.is-emphasis {
        animation: none;
    }
}

/* The Characters tab: the subtitle, the empty state and the picture picker (a grid of round portraits grouped by kind). */
.bm-panel-subtitle {
    margin: 0 0 8px;
}

.bm-empty-state {
    padding: 10px 12px;
    border: 1px dashed var(--bm-faint-line, rgba(255, 255, 255, 0.2));
    border-radius: 8px;
}

.bm-picker-field {
    grid-column: 1 / -1;
}

.bm-picker {
    display: grid;
    gap: 8px;
}

.bm-picker-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.bm-portrait-group h4 {
    margin: 4px 0;
    font-size: 0.8rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #f7dfbf;
}

.bm-portrait-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
    gap: 6px;
}

.bm-portrait {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-width: 0;
    padding: 3px;
    font-size: 0.7rem;
    line-height: 1.15;
    text-align: center;
    color: #f7dfbf;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 10px;
    cursor: pointer;
}

.bm-portrait img {
    width: 100%;
    max-width: 48px;
    aspect-ratio: 1;
    border-radius: 50%;
    object-fit: cover;
    background: #0a1114;
}

.bm-portrait .bm-portrait-name {
    display: -webkit-box;
    max-width: 100%;
    overflow: hidden;
    overflow-wrap: break-word;
    -webkit-hyphens: auto;
    hyphens: auto;
    text-transform: none;
    letter-spacing: 0;
    font-size: 0.7rem;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
}

.bm-portrait:hover {
    border-color: var(--dungeon-accent);
    background: rgba(var(--dungeon-accent-rgb), 0.1);
}

.bm-portrait:focus-visible {
    outline: 2px solid var(--dungeon-accent);
    outline-offset: 1px;
}

.bm-portrait[aria-pressed="true"] {
    border-color: var(--dungeon-accent);
    background: rgba(var(--dungeon-accent-rgb), 0.2);
}

/* A character of the map, as a row: a round thumbnail at the left, the name and the size beside it. */
.bm-char-row,
.bm-creature-row {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 52px;
    padding: 6px 10px;
    text-align: left;
    text-transform: none;
    letter-spacing: 0;
    color: #f7dfbf;
    background: var(--dungeon-bg);
    border: 1px solid var(--dungeon-border);
    border-radius: 8px;
    cursor: pointer;
}

.bm-char-row:hover,
.bm-creature-row:hover,
.bm-char-row[aria-checked="true"],
.bm-creature-row[aria-pressed="true"] {
    border-color: var(--dungeon-accent);
}

.bm-char-row[aria-checked="true"],
.bm-creature-row[aria-pressed="true"] {
    background: rgba(var(--dungeon-accent-rgb), 0.18);
}

.bm-char-chip,
.bm-creature-face {
    display: flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    background-size: cover;
    background-position: center;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.92);
}

.bm-char-text,
.bm-creature-text {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-width: 0;
}

.bm-char-name,
.bm-creature-name {
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.2;
    overflow-wrap: anywhere;
}

.bm-char-meta,
.bm-creature-detail {
    font-size: 0.74rem;
    line-height: 1.25;
    color: var(--dungeon-muted);
    overflow-wrap: anywhere;
}

.bm-char-list,
.bm-creature-list,
.bm-side .dungeon-token-list {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 6px;
}

.bm-portrait-name {
    text-transform: none;
    letter-spacing: 0;
}

@media (pointer: coarse) {
    .bm-portrait {
        min-height: 64px;
    }
}

/* A long single word ("Characters") breaks in two lines like "Door or window" does, with a hyphen, in the rail's narrow buttons. */
.bm-rail .dungeon-tool span {
    max-width: 100%;
    overflow-wrap: normal;
    word-break: normal;
    -webkit-hyphens: auto;
    hyphens: auto;
    hyphenate-limit-chars: 8 4 4;
}

/* The picker's places (tabs), the search of the creature tabs, and the disc of a creature that has no portrait yet. */
.bm-picker-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.bm-picker-tab {
    padding: 4px 10px;
    font-size: 0.78rem;
    color: #f7dfbf;
    background: transparent;
    border: 1px solid var(--bm-faint-line, rgba(255, 255, 255, 0.2));
    border-radius: 999px;
    cursor: pointer;
}

.bm-picker-tab[aria-selected="true"] {
    border-color: var(--dungeon-accent);
    background: rgba(var(--dungeon-accent-rgb), 0.2);
}

.bm-picker-search {
    display: flex;
    gap: 6px;
}

.bm-picker-search input {
    flex: 1 1 auto;
    min-width: 0;
}

.bm-portrait-disc {
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.92);
    background: #4f8fd6;
    border-radius: 50%;
}

.bm-portrait .bm-portrait-disc {
    width: 100%;
    max-width: 48px;
    aspect-ratio: 1;
    font-size: 1.2rem;
}

/* The cards of the Characters tab: the Assets tab's cards with a round picture (or the disc with the initial) in the thumbnail's place. */
.bm-creature-card .bm-card-face {
    display: block;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    object-fit: cover;
    font-size: 1.8rem;
    background-color: #4f8fd6;
}

.bm-creature-card .bm-card-face.bm-portrait-disc {
    display: flex;
}

.bm-creature-grid {
    margin-bottom: 8px;
}

.bm-picker-where a {
    color: var(--dungeon-accent);
    text-decoration: underline;
}

.bm-picture-change > summary {
    cursor: pointer;
    padding: 6px 0;
    color: #f7dfbf;
}

/* a card's detail line wraps (a long "Level 3 · Human · Fighter" is read whole) */
.bm-creature-card .dungeon-pill {
    white-space: normal;
    overflow-wrap: anywhere;
    text-align: left;
}

/* A titled group inside a section (the Walls panel's fortifications), set apart from the options above it. */
.bm-subgroup {
    display: grid;
    gap: 8px;
    margin-top: 6px;
    padding-top: 12px;
    border-top: 1px solid var(--bm-line);
}

.bm-subgroup-title {
    margin: 0;
    color: var(--dungeon-accent);
    font-size: 0.82rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

/* The context menu of the map (app_edit_menu.js): a right click or a long press on an item. It floats in the map, like the strip. */
.bm-context-menu {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 8;
    display: grid;
    min-width: 190px;
    padding: 4px;
    background: rgba(14, 23, 28, 0.97);
    border: 1px solid var(--dungeon-border);
    border-radius: 8px;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55);
}

.bm-context-item {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 40px;
    padding: 0 12px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: #fff4df;
    font-size: 0.9rem;
    text-align: left;
}

.bm-context-item i {
    width: 16px;
    color: var(--dungeon-accent);
    text-align: center;
}

.bm-context-item:hover,
.bm-context-item:focus-visible {
    background: rgba(var(--dungeon-accent-rgb), 0.2);
    outline: none;
}

.bm-context-item.is-danger,
.bm-context-item.is-danger i {
    color: #ff9d9d;
}

@media (any-pointer: coarse) {
    .bm-context-item {
        min-height: 48px;
    }
}

/* The level tabs of a phone scroll sideways (the open level is centred): the faded ends tell that more of them lie beyond. */
.bm-page[data-layout="phone"] .bm-level-tabs {
    scrollbar-width: none;
    -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 14px), transparent 100%);
    mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 14px), transparent 100%);
}

/* "On the map", the size and the count of a card of the Characters tab. */
.bm-on-map-tag {
    color: #9fe3a0;
    border-color: rgba(159, 227, 160, 0.6);
}

.bm-count-stepper {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
}

.bm-count-button {
    min-width: 32px;
    min-height: 32px;
    color: #f7dfbf;
    background: var(--dungeon-bg);
    border: 1px solid var(--dungeon-border);
    border-radius: 8px;
    cursor: pointer;
}

.bm-count-button:hover {
    border-color: var(--dungeon-accent);
}

.bm-count-stepper output {
    min-width: 3ch;
    text-align: center;
    font-weight: 600;
}

/* --- Ruin level: a segmented control left of Reroll (how far a generated ruin has fallen) --------------------------------- */

/* With the control the level tabs, the control and Reroll may not fit one row: the control (and Reroll) then drop to the next, and the
 * tabs keep their whole width (they scroll only when they alone are wider than the toolbar). */
.bm-page:not([data-layout="phone"]) .bm-toolbar-left {
    flex-wrap: wrap;
}

.bm-page:not([data-layout="phone"]) .bm-toolbar-left > .bm-level-tabs {
    flex: 1 1 auto;
}

.bm-condition {
    display: flex;
    flex: none;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.bm-condition[hidden] {
    display: none;
}

.bm-condition-label {
    color: #cfc3ad;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.bm-condition-level {
    min-height: 38px;
    padding: 6px 10px;
    color: #f7dfbf;
    background: var(--dungeon-bg);
    border: 1px solid var(--dungeon-border);
    border-radius: 0;
    font-size: 0.8rem;
    font-weight: 700;
    white-space: nowrap;
    cursor: pointer;
}

.bm-condition-label + .bm-condition-level {
    border-radius: 6px 0 0 6px;
}

.bm-condition-level:last-child {
    border-radius: 0 6px 6px 0;
}

.bm-condition-level + .bm-condition-level {
    margin-left: -1px;
}

.bm-condition-level:hover {
    border-color: var(--dungeon-accent);
}

.bm-condition-level[aria-pressed="true"] {
    position: relative;
    color: #fff4df;
    background: rgba(var(--dungeon-accent-rgb), 0.16);
    border-color: var(--dungeon-accent);
}

/* A condition change runs: the clicked segment shows a small spinner in place (the map stays visible), the others are off. */
.bm-condition-level:disabled {
    opacity: 0.6;
    cursor: progress;
}

.bm-condition-level.is-busy {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    opacity: 1;
}

.bm-condition-level.is-busy::after {
    content: "";
    flex: none;
    width: 12px;
    height: 12px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: bm-spin 0.8s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
    .bm-condition-level.is-busy::after {
        animation-duration: 2.4s;
    }
}

/* In the View panel (a tablet or phone) the control fills a row of its own. */
.bm-view-panel .bm-condition {
    flex-wrap: wrap;
    width: 100%;
}

.bm-view-panel .bm-condition-label {
    flex: 0 0 100%;
}

.bm-view-panel .bm-condition-level {
    flex: 1 1 0;
    min-height: 44px;
}

/* The Arrange | Play switch: two joined buttons, the one that is on lit. */
.bm-segmented {
    display: inline-flex;
    margin: 0 0 8px;
    border: 1px solid var(--dungeon-border);
    border-radius: 999px;
    overflow: hidden;
}

.bm-segment {
    min-height: 36px;
    padding: 4px 18px;
    color: #f7dfbf;
    background: transparent;
    border: 0;
    cursor: pointer;
}

.bm-segment[aria-checked="true"] {
    color: #0c1a14;
    background: var(--dungeon-accent);
    font-weight: 700;
}

.bm-segment:disabled {
    opacity: 0.5;
    cursor: default;
}

/* The encounter form's choices (Difficulty, Monsters, Where they stand) use the same pill; they sit in the Generate battlemap window, outside the
   page's root, so the colours carry their own fallbacks, and a long set of choices wraps instead of running off a phone's edge. */
.bm-segmented--wrap {
    display: flex;
    flex-wrap: wrap;
    width: fit-content;
    max-width: 100%;
    margin: 4px 0 0;
    border: 1px solid var(--dungeon-border, #31454d);
    border-radius: 20px;
}

.bm-segmented--wrap .bm-segment {
    flex: 1 1 auto;
    min-height: 38px;
    font-size: 0.9rem;
    color: #f7dfbf;
}

.bm-segmented--wrap .bm-segment + .bm-segment {
    border-left: 1px solid var(--dungeon-border, #31454d);
}

/* On a phone the choices stack, one to a row, each as wide as the form. */
@media (max-width: 575.98px) {
    .bm-segmented--wrap {
        display: grid;
        width: 100%;
    }

    .bm-segmented--wrap .bm-segment + .bm-segment {
        border-left: 0;
        border-top: 1px solid var(--dungeon-border, #31454d);
    }
}

.bm-segmented--wrap .bm-segment[aria-checked="true"] {
    color: #0c1a14;
    background: var(--dungeon-accent);
}

.bm-segmented--wrap .bm-segment:focus-visible {
    outline: 2px solid var(--dungeon-accent);
    outline-offset: -2px;
}

.bm-encounter-group {
    margin: 12px 0 0;
}

/* The party's numbers are typed (no spinners), in the page's input look. */
input.bm-number {
    width: 92px;
    min-height: 40px;
    padding: 8px 10px;
    color: #f7dfbf;
    background: var(--dungeon-bg, #122027);
    border: 1px solid var(--dungeon-border, #31454d);
    border-radius: 6px;
    -moz-appearance: textfield;
    appearance: textfield;
}

input.bm-number::-webkit-outer-spin-button,
input.bm-number::-webkit-inner-spin-button {
    margin: 0;
    -webkit-appearance: none;
}

input.bm-number:focus {
    border-color: var(--dungeon-accent);
    outline: 2px solid rgba(var(--dungeon-accent-rgb), 0.24);
}

/* --- The Characters panel's Sheet tab and the selected character's actions ---------------------------------------------- */

.bm-creature-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 0 0 10px;
}

.bm-creature-actions .dungeon-btn {
    margin: 0;
}

/* A switch that is on (Show path, Line of sight) is gold like the strip's button beside the character. */
body.tool-ui .bm-creature-actions .dungeon-small-btn[aria-pressed="true"] {
    border-color: var(--tool-gold);
    background: var(--tool-gold);
    color: var(--tool-ink);
}

body.tool-ui .bm-creature-actions .dungeon-small-btn[aria-pressed="true"] :is(i, span) {
    color: inherit;
}

.bm-sheet-name {
    margin: 0 0 2px;
    font-size: 1.1rem;
    color: #fff1cf;
}

.bm-sheet-abilities {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 4px;
    margin: 10px 0;
}

.bm-sheet-ability {
    display: grid;
    justify-items: center;
    padding: 6px 2px;
    background: var(--dungeon-bg);
    border: 1px solid var(--dungeon-border);
    border-radius: 6px;
    font-size: 0.78rem;
}

.bm-sheet-ability-label {
    color: var(--dungeon-muted);
    font-weight: 700;
    letter-spacing: 0.04em;
}

.bm-sheet-ability strong {
    font-size: 1rem;
    color: #fff1cf;
}

.bm-sheet-ability-mod {
    color: var(--dungeon-muted);
}

.bm-sheet-rows {
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr);
    gap: 3px 12px;
    margin: 0 0 10px;
    font-size: 0.9rem;
}

.bm-sheet-rows dt {
    color: var(--dungeon-muted);
    font-weight: 700;
}

.bm-sheet-rows dd {
    margin: 0;
    color: #f7dfbf;
    overflow-wrap: anywhere;
}

.bm-sheet-section h4 {
    margin: 12px 0 4px;
    font-size: 0.85rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--dungeon-text);
}

.bm-sheet-section p {
    margin: 0 0 6px;
    font-size: 0.88rem;
    color: #e6d7bf;
}

.bm-sheet-open {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 12px 0 0;
    text-decoration: none;
}
