/* The Battlemap Generator page. Its design is the Dungeon Generator's (web/static/web/dungeon_generator.css, linked by the
   template): the page root carries `dungeon-generator battlemap-generator` and the markup uses the `dungeon-*` classes. This
   file adds only what the battlemap needs that the dungeon tool does not have. Class prefix bm-. */

.bm-canvas {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
    outline: none;
}

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

/* The layer toggles over the map: chips like the level tabs, lit (accent) while their layer shows. The checkbox stays in
   the page for the keyboard and screen readers; only its look is the chip's. */
.bm-layer-toggle {
    position: relative;
    display: inline-flex;
    margin: 0;
    cursor: pointer;
}

.bm-layer-input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
    pointer-events: none;
}

.bm-layer-face {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 34px;
    padding: 5px 11px;
    border: 1px solid var(--dungeon-border);
    border-radius: 6px;
    background: var(--dungeon-bg);
    color: var(--dungeon-muted);
    font-size: 0.82rem;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.bm-layer-face .fa-solid {
    font-size: 0.8rem;
    opacity: 0.55;
}

.bm-layer-toggle:hover .bm-layer-face {
    border-color: var(--dungeon-text);
    color: #f7dfbf;
}

.bm-layer-input:checked + .bm-layer-face {
    border-color: var(--dungeon-accent);
    background: rgba(var(--dungeon-accent-rgb), 0.16);
    color: #fff4df;
}

.bm-layer-input:checked + .bm-layer-face .fa-solid {
    color: var(--dungeon-link);
    opacity: 1;
}

.bm-layer-input:focus-visible + .bm-layer-face {
    outline: 2px solid var(--dungeon-accent);
    outline-offset: 2px;
}

.bm-status {
    margin: 8px 0 0;
}

/* The status line under the map: what the map is, and the square under the pointer (which tells nothing on a touch screen). */
.bm-status {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 4px 16px;
}

@media (hover: none) {
    .bm-status-cursor {
        display: none;
    }
}

/* --- Buttons the editor and the panels share -------------------------------------------------------------------------- */

.battlemap-generator .bm-block {
    width: 100%;
    margin-top: 0;
}

.battlemap-generator .bm-btn-small {
    min-height: 32px;
    padding: 4px 10px;
    font-size: 0.8rem;
}

.battlemap-generator .btn-close-dnd.bm-danger {
    border-color: var(--dungeon-danger);
    color: #ffb3b3;
}

.battlemap-generator .btn-close-dnd.bm-danger:hover,
.battlemap-generator .btn-close-dnd.bm-danger:focus {
    background-color: var(--dungeon-danger);
    color: #1b0d0d;
}

.battlemap-generator .btn.is-busy::after {
    content: "";
    width: 14px;
    height: 14px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: bm-spin 0.8s linear infinite;
}

@keyframes bm-spin {
    to {
        transform: rotate(360deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    .battlemap-generator .btn.is-busy::after {
        animation-duration: 2.4s;
    }
}

/* --- The Generate battlemap window -------------------------------------------------------------------------------------- */

/* The window's buttons are the shared component layer's (tool_components.css); only the spacing is the window's. */
#bm-random-modal .btn-close-dnd {
    width: auto;
    margin-top: 0;
}

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

/* --- Export window (app_export.js): the site's modal; the groups of downloads sit in rows ---------------------------------- */

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

.bm-menu-wrap {
    position: relative;
}

.bm-export-body {
    display: grid;
    gap: 10px;
}

.bm-export-body .dungeon-field,
.bm-export-body .dungeon-note,
.bm-export-body .dungeon-palette-heading {
    margin: 0;
}

.bm-export-body .bm-block {
    width: 100%;
}

/* --- Editor --- */
/* The map editor and the play features (app_editor.js and its modules). The page wears the Dungeon Generator's classes
   (dungeon_generator.css); only what that sheet has no counterpart for is here. */

/* The action strip: quick buttons floating over the map (rotate, duplicate, delete, finish a wall...). */
.bm-strip {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 4;
    display: flex;
    gap: 4px;
    padding: 4px;
    background: rgba(14, 23, 28, 0.94);
    border: 1px solid var(--dungeon-border);
    border-radius: 8px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
}

/* Beside a character (the Characters panel is not at hand): its few icon buttons stand in a column. */
.bm-strip.is-beside {
    flex-direction: column;
}

/* Named buttons (a desktop) in that column line up on the left, icon over icon. */
.bm-strip.is-beside .bm-strip-btn {
    justify-content: flex-start;
}

/* Strip buttons wear the site's own pill buttons (dungeon-btn); only their size and layout are set here. */
.bm-strip-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin: 0;
    padding: 0 10px;
}

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

.bm-strip.is-pop {
    animation: bm-strip-pop 0.35s ease-out;
}

@keyframes bm-strip-pop {
    from { box-shadow: 0 0 0 0 rgba(var(--dungeon-accent-rgb), 0.8); }
    to { box-shadow: 0 0 0 14px rgba(var(--dungeon-accent-rgb), 0); }
}

/* The Asset Catalog: smaller cards than the monster cards, each with a picture of its footprint. */
.dungeon-asset-search {
    grid-template-columns: minmax(200px, 1fr) minmax(180px, 280px);
}

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

.dungeon-asset-card[draggable="true"] {
    cursor: pointer;
    transition: border-color 0.12s, box-shadow 0.12s, background 0.12s;
}

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

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

.dungeon-asset-card.is-armed {
    background: rgba(var(--dungeon-accent-rgb), 0.18);
}

.dungeon-asset-thumb {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 88px;
    padding: 8px;
    background: repeating-conic-gradient(rgba(255, 255, 255, 0.04) 0% 25%, transparent 0% 50%) 0 0 / 16px 16px, #0a1114;
}

.dungeon-asset-thumb img {
    display: block;
    max-width: 100%;
    max-height: 72px;
    object-fit: contain;
}

.dungeon-asset-ph {
    display: block;
    border: 1px solid rgba(0, 0, 0, 0.55);
    border-radius: 5px;
}

.dungeon-asset-ph.is-round {
    border-radius: 50%;
}

.dungeon-armed {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    padding: 8px 10px;
    border: 1px solid var(--dungeon-accent);
    border-radius: 6px;
    background: rgba(var(--dungeon-accent-rgb), 0.12);
}

.dungeon-armed strong {
    margin-right: auto;
}

/* Recent assets: a row of small thumbnails in the sidebar. */
.dungeon-recent {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
}

.dungeon-recent-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-width: 0;
    padding: 4px;
    font-size: 0.72rem;
    color: #f7dfbf;
    background: var(--dungeon-bg);
    border: 1px solid var(--dungeon-border);
    border-radius: 6px;
}

.dungeon-recent-item .dungeon-asset-thumb {
    min-height: 44px;
    padding: 2px;
    background: none;
}

.dungeon-recent-item .dungeon-asset-thumb img {
    max-height: 40px;
}

.dungeon-recent-item span:last-child {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dungeon-recent-item.is-armed,
.dungeon-recent-item:hover {
    border-color: var(--dungeon-accent);
}

/* Snapping and the small button rows of the sidebar sections. */
.dungeon-snap {
    display: grid;
    gap: 8px;
}

.dungeon-snap-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.dungeon-snap-buttons .dungeon-btn {
    flex: 1 1 auto;
}

.battlemap-generator .dungeon-section-body .dungeon-field,
.battlemap-generator .dungeon-collapsible-body .dungeon-field {
    margin-top: 8px;
}

.dungeon-swatch-chip--glyph {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    background: var(--dungeon-surface-2);
    color: #f7dfbf;
}

.dungeon-btn.is-danger {
    border-color: rgba(216, 95, 95, 0.55);
}

.dungeon-readout strong {
    color: #fff1cf;
    font-weight: 600;
}

/* The Play panel: the token list and the form under it. */
.dungeon-token-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 6px;
    margin-top: 14px;
}

.dungeon-shortcuts {
    display: grid;
    gap: 10px;
}

.dungeon-shortcuts h4 {
    margin: 0 0 4px;
    font-size: 0.78rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--dungeon-muted);
}

.dungeon-shortcuts dl {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 3px 12px;
    margin: 0;
    font-size: 0.84rem;
}

.dungeon-shortcuts dd {
    margin: 0;
}

.dungeon-shortcuts kbd {
    padding: 1px 6px;
    color: #fff1cf;
    background: var(--dungeon-bg);
    border: 1px solid var(--dungeon-border);
    border-radius: 4px;
}

.dungeon-help {
    max-width: min(560px, 94vw);
    max-height: 86vh;
    overflow: auto;
}

@media (any-pointer: coarse) {
    .dungeon-recent-item {
        min-height: 56px;
    }
}

@media (max-width: 640px) {
    .dungeon-asset-search {
        grid-template-columns: minmax(0, 1fr);
    }
}

.dungeon-help {
    padding: 20px;
    color: var(--dungeon-text);
    background: var(--dungeon-surface);
    border: 1px solid rgba(242, 192, 128, 0.3);
    border-radius: 8px;
}

.dungeon-help::backdrop {
    background: rgba(0, 0, 0, 0.6);
}

.dungeon-help h2 {
    margin-bottom: 12px;
}

/* The Level section: a hint for each stairway that leads nowhere. */
.dungeon-level-hints {
    display: grid;
    gap: 10px;
    margin: 6px 0 0;
    padding: 0;
    list-style: none;
}

.dungeon-level-hint {
    padding: 8px 10px;
    font-size: 0.84rem;
    border: 1px solid rgba(216, 95, 95, 0.4);
    border-radius: 6px;
    background: rgba(216, 95, 95, 0.1);
}

/* --- The New window: the grounds a map can start as, in groups ---------------------------------------------------------- */

.bm-new-grounds {
    display: grid;
    gap: 12px;
    margin-top: 8px;
}

.bm-new-group .dungeon-swatches {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 6px;
    margin-top: 4px;
}

/* --- The Inspector with nothing selected: what the active tool is set to now ------------------------------------------- */

.bm-tool-status {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 8px 0 0;
    color: #f7dfbf;
}

.dungeon-readout strong .dungeon-swatch-chip {
    display: inline-block;
    vertical-align: middle;
}

/* The Nature tool's presets: picture tiles (a tree, a bush, a boulder) on a patch of green above their names, two to a row so that
   the names never break inside a word. */
.bm-flyout .dungeon-swatches.bm-nature-presets {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
}

.bm-nature-heading {
    display: block;
    margin-top: 12px;
    font-weight: 600;
}

.bm-page .bm-flyout .dungeon-swatch.bm-nature-preset span {
    overflow-wrap: normal;
    hyphens: auto;
}

.bm-nature-presets .dungeon-asset-thumb {
    min-height: 56px;
    padding: 2px;
    border-radius: 4px;
    background: radial-gradient(circle, #5f7a3f 0%, #3d5228 100%);
}

.bm-nature-presets .dungeon-asset-thumb img {
    max-height: 52px;
}

/* The Bridge tool's styles: a picture of each (drawn by the renderer's own bridge code) above its name, two to a row. */
.bm-flyout .bm-bridge-styles {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.bm-bridge-thumb {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 4px;
}

.bm-bridge-style span {
    overflow-wrap: normal;
    hyphens: auto;
}

/* The Place palette's browse view: ready-made things and categories as picture tiles under plain headings (app_edit_palette.js,
 * app_edit_prefab_tiles.js; the headings are data/palette.json). */
.bm-palette-section {
    margin-bottom: 14px;
}

.bm-palette-title {
    margin: 0 0 6px;
    font-size: 0.95rem;
    font-weight: 700;
    color: #f7dfbf;
}

.bm-palette-heading {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.bm-palette-heading .bm-palette-title {
    margin: 0;
}

.bm-ready-grid,
.bm-category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
    gap: 8px;
}

.bm-ready-tile {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    background: var(--dungeon-bg);
    border: 1px solid var(--dungeon-border);
    border-radius: 8px;
    transition: border-color 0.12s, background 0.12s;
}

.bm-ready-tile:hover,
.bm-ready-tile.is-armed {
    border-color: var(--dungeon-accent);
}

.bm-ready-tile.is-armed {
    background: rgba(var(--dungeon-accent-rgb), 0.18);
}

.bm-ready-pick,
.bm-category-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-width: 0;
    padding: 6px;
    font: inherit;
    color: #f7dfbf;
    text-align: center;
    cursor: pointer;
    background: none;
    border: 0;
}

.bm-ready-pick {
    flex: 1;
}

.bm-ready-pick strong,
.bm-category-tile strong {
    font-size: 0.82rem;
    line-height: 1.15;
}

.bm-ready-frame,
.bm-category-frame {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 88px;
    overflow: hidden;
    background: #11211a;
    border-radius: 6px;
}

.bm-ready-picture {
    display: block;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.bm-category-frame .dungeon-asset-thumb {
    min-height: 0;
    padding: 4px;
    background: none;
}

.bm-category-frame .dungeon-asset-thumb img {
    max-height: 76px;
}

.bm-ready-missing {
    color: #c9b79b;
}

.bm-ready-sizes {
    display: flex;
    border-top: 1px solid var(--dungeon-border);
}

.bm-ready-size {
    flex: 1;
    padding: 5px 2px;
    font: inherit;
    font-size: 0.7rem;
    color: #f7dfbf;
    cursor: pointer;
    background: none;
    border: 0;
}

/* A size the plan does not build wears a lock (greyed by the page's .is-locked); pressing it says why. */
.bm-ready-size {
    white-space: nowrap;
}

.bm-ready-size .fa-lock {
    margin-left: 2px;
    font-size: 0.7em;
}

.bm-ready-size + .bm-ready-size {
    border-left: 1px solid var(--dungeon-border);
}

.bm-ready-size:hover,
.bm-ready-size.is-on {
    background: rgba(var(--dungeon-accent-rgb), 0.28);
}

.bm-category-tile {
    background: var(--dungeon-bg);
    border: 1px solid var(--dungeon-border);
    border-radius: 8px;
}

.bm-category-tile:hover,
.bm-ready-pick:focus-visible,
.bm-category-tile:focus-visible {
    border-color: var(--dungeon-accent);
    outline: 2px solid var(--dungeon-accent);
    outline-offset: -2px;
}

.bm-armed-options {
    display: inline-flex;
    gap: 4px;
}

.bm-armed-options .is-on {
    background: rgba(var(--dungeon-accent-rgb), 0.4);
}

@media (any-pointer: coarse) {
    .bm-ready-size {
        min-height: 40px;
        font-size: 0.78rem;
    }

    .bm-ready-pick,
    .bm-category-tile {
        min-height: 44px;
    }
}

/* The Area inspector's list of the squares painted over a floor: one material per line. */
.bm-painted-line {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* The Share window: the switch, and the link with its Copy button. */
.bm-share-body {
    display: grid;
    gap: 12px;
}

/* A switch (the Share window's, the encounter's): its colours are the shared component layer's (tool_components.css), dark and gold-edged, gold when on. */
.bm-switch {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-left: 0;
    color: var(--tool-cream, #f6e6c9);
}

.bm-switch .form-check-input {
    flex: none;
    margin: 0;
}

.bm-share-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.bm-share-row .btn {
    margin-top: 0;
}

.bm-share-link {
    flex: 1 1 240px;
    min-width: 0;
}

/* The plan window: the site's sign-up card (styles9.css .bigass-register-card) with the reason under its line, Close below it. */
.bm-plan-dialog {
    width: min(620px, calc(100vw - 24px));
}

.bm-plan-dialog .bigass-register-card {
    margin-bottom: 12px;
}

.bm-plan-dialog .bigass-register-card .card-title {
    font-size: clamp(1.4rem, 4.5vw, 2rem);
}

.bm-plan-dialog .bm-plan-reason,
.bm-plan-dialog .bm-plan-kept {
    margin: 0 0 14px;
    font-size: 0.9rem;
}

.bm-plan-dialog .bm-plan-actions {
    justify-content: center;
}

/* The generating cover is a manual popover (so it stands above an open dialog); the popover's own box rules give way to the cover's. */
.dungeon-generating[popover] {
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    border: 0;
    overflow: hidden;
}
