/* Dungeon Generator: the Encounter Builder's palette and panels, with the map editor's own pieces. */
.dungeon-generator {
    --dungeon-bg: #122027;
    --dungeon-surface: #0e171c;
    --dungeon-surface-2: #17262d;
    --dungeon-border: #31454d;
    --dungeon-text: #f2c080;
    --dungeon-muted: #b6cbd0;
    --dungeon-accent: #e7bf8f;
    --dungeon-accent-rgb: 231, 191, 143;
    --dungeon-danger: #d85f5f;
    --dungeon-link: #e7bf8f;
    max-width: 1480px;
    margin: 0 auto;
    padding: 24px 16px 56px;
    color: var(--dungeon-text);
}

.dungeon-generator h2,
.dungeon-generator h3,
.dungeon-generator p {
    margin-top: 0;
}

.dungeon-generator h2 {
    font-size: 1.05rem;
    margin-bottom: 14px;
}

.dungeon-generator h3 {
    font-size: 0.95rem;
    margin-bottom: 10px;
}

.dungeon-header,
.dungeon-panel {
    background: var(--dungeon-surface);
    border: 1px solid rgba(242, 192, 128, 0.16);
    border-radius: 8px;
}

.dungeon-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px 20px;
    padding: 16px 20px;
    margin-bottom: 18px;
}

/* The dungeon's name heads the page, centred above its controls, with how its saving stands at its right. The empty
   first column balances the status, so the name sits in the middle of the header. */
.dungeon-title-row {
    display: grid;
    flex: 1 0 100%;
    grid-template-columns: minmax(0, 1fr) minmax(0, 3fr) minmax(0, 1fr);
    align-items: center;
    gap: 8px 14px;
}

.dungeon-title-row::before {
    content: "";
}

.dungeon-title-row .dungeon-save-status {
    justify-self: end;
}

.dungeon-title-input {
    min-width: 0;
    width: 100%;
    border: 1px solid transparent;
    text-align: center;
    border-radius: 6px;
    padding: 4px 8px;
    color: #fff1cf;
    background: transparent;
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1.25;
}

.dungeon-title-input::placeholder {
    color: rgba(242, 192, 128, 0.55);
}

.dungeon-title-input:hover {
    border-color: var(--dungeon-border);
}

.dungeon-title-input:focus {
    outline: none;
    border-color: var(--dungeon-accent);
    background: var(--dungeon-bg);
}

.dungeon-save-status {
    white-space: normal;
}

.dungeon-save-status.is-error {
    border-color: rgba(216, 95, 95, 0.6);
    color: #ffd2d2;
    background: rgba(216, 95, 95, 0.12);
}

.dungeon-note,
.dungeon-empty,
.dungeon-card-summary {
    color: var(--dungeon-muted);
}

.dungeon-note {
    font-size: 0.86rem;
    margin: 10px 0 0;
}

.dungeon-note a,
.dungeon-history-item a,
.dungeon-card-actions a,
.dungeon-key a {
    color: var(--dungeon-link);
}

.dungeon-header-actions,
.dungeon-section-heading,
.dungeon-map-actions,
.dungeon-size-controls,
.dungeon-dialog-actions,
.dungeon-history-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.dungeon-section-heading {
    justify-content: space-between;
    margin-bottom: 12px;
}

.dungeon-size-controls {
    flex-wrap: wrap;
    align-items: flex-end;
}

.dungeon-field--inline {
    margin-top: 0;
}

.dungeon-field--inline input {
    width: 92px;
}

.dungeon-size-times {
    color: var(--dungeon-muted);
    padding-bottom: 9px;
}

.dungeon-size-controls .dungeon-note {
    margin: 0 0 10px;
}

.dungeon-floor-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-width: 0;
}

.dungeon-floor-tab {
    min-height: 36px;
    padding: 6px 12px;
    border: 1px solid var(--dungeon-border);
    border-radius: 6px;
    background: var(--dungeon-bg);
    color: #f7dfbf;
    font-weight: 700;
    font-size: 0.86rem;
}

.dungeon-floor-tab[aria-selected="true"] {
    border-color: var(--dungeon-accent);
    background: rgba(var(--dungeon-accent-rgb), 0.16);
    color: #fff4df;
}

.dungeon-floor-tab--add {
    border-style: dashed;
    color: var(--dungeon-text);
}

.dungeon-full-width {
    width: 100%;
    margin-top: 12px;
}

.dungeon-link {
    color: var(--dungeon-link);
    margin-right: auto;
}

.dungeon-dialog {
    width: min(560px, calc(100vw - 32px));
    border: 1px solid rgba(242, 192, 128, 0.35);
    border-radius: 8px;
    background: var(--dungeon-surface);
    color: var(--dungeon-text);
    padding: 20px;
}

.dungeon-dialog--wide {
    width: min(760px, calc(100vw - 32px));
    max-height: calc(100vh - 48px);
    overflow-y: auto;
}

.dungeon-rows {
    display: grid;
    gap: 6px;
    margin-top: 10px;
}

.dungeon-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    border: 1px solid rgba(182, 203, 208, 0.12);
    border-radius: 6px;
    background: rgba(18, 32, 39, 0.72);
    padding: 6px 10px;
}

.dungeon-row.is-replacing {
    border-color: var(--dungeon-accent);
}

.dungeon-row-name {
    flex: 1 1 200px;
    min-width: 0;
    color: #fff1cf;
    overflow-wrap: anywhere;
}

.dungeon-row-name a {
    color: var(--dungeon-link);
}

.dungeon-row .dungeon-row-count {
    width: 72px;
    min-height: 34px;
    border: 1px solid var(--dungeon-border);
    border-radius: 6px;
    background: var(--dungeon-bg);
    color: #f7dfbf;
    padding: 4px 8px;
}

.dungeon-row .dungeon-field--check {
    margin-top: 0;
}

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

.dungeon-picker {
    border-top: 1px solid rgba(182, 203, 208, 0.12);
    margin-top: 14px;
    padding-top: 12px;
}

.dungeon-picker-search,
.dungeon-picker-create {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.dungeon-picker-create {
    margin-top: 10px;
}

.dungeon-picker-search select,
.dungeon-picker-search input,
.dungeon-picker-create input {
    min-height: 36px;
    border: 1px solid var(--dungeon-border);
    border-radius: 6px;
    background: var(--dungeon-bg);
    color: #f7dfbf;
    padding: 6px 10px;
}

.dungeon-picker-search input,
.dungeon-picker-create input {
    flex: 1 1 220px;
}

.dungeon-picker .dungeon-link {
    display: inline-block;
    margin-top: 8px;
}

.dungeon-dialog::backdrop {
    background: rgba(5, 10, 12, 0.72);
}

.dungeon-dialog h2 {
    font-size: 1.05rem;
    margin-bottom: 8px;
}

.dungeon-dialog-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
    margin-top: 16px;
}

.dungeon-section-heading h2 {
    margin-bottom: 0;
}

.dungeon-layout {
    display: grid;
    grid-template-columns: 300px minmax(0, 1fr);
    gap: 18px;
}

.dungeon-panel {
    padding: 18px;
    margin-bottom: 18px;
}

.dungeon-sidebar {
    align-self: start;
    position: sticky;
    top: 14px;
    max-height: calc(100vh - 28px);
    overflow-y: auto;
}

.dungeon-sidebar,
.dungeon-history-list {
    scrollbar-color: var(--dungeon-border) transparent;
    scrollbar-width: thin;
}

.dungeon-sidebar section + section {
    border-top: 1px solid rgba(182, 203, 208, 0.12);
    margin-top: 16px;
    padding-top: 16px;
}

.dungeon-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    margin-top: 10px;
}

.dungeon-field span {
    color: var(--dungeon-muted);
    font-size: 0.78rem;
    text-transform: uppercase;
}

.dungeon-field input,
.dungeon-field select,
.dungeon-field textarea {
    width: 100%;
    min-height: 40px;
    border: 1px solid var(--dungeon-border);
    border-radius: 6px;
    background: var(--dungeon-bg);
    color: #f7dfbf;
    padding: 8px 10px;
}

.dungeon-field input:disabled,
.dungeon-field select:disabled,
.dungeon-field textarea:disabled {
    background: #20272c;
    border-color: rgba(182, 203, 208, 0.18);
    color: #83969b;
    cursor: not-allowed;
}

.dungeon-field textarea {
    min-height: 88px;
    resize: vertical;
}

.dungeon-field input:focus,
.dungeon-field select:focus,
.dungeon-field textarea:focus {
    border-color: var(--dungeon-accent);
    outline: 2px solid rgba(var(--dungeon-accent-rgb), 0.24);
    outline-offset: 0;
}

.dungeon-field--check {
    flex-direction: row;
    align-items: center;
    gap: 8px;
}

.dungeon-field--check input {
    width: auto;
    min-height: 0;
    accent-color: var(--dungeon-accent);
}

.dungeon-generator input[type="number"] {
    appearance: textfield;
    -moz-appearance: textfield;
}

.dungeon-generator input[type="number"]::-webkit-outer-spin-button,
.dungeon-generator input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.dungeon-btn,
.dungeon-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: 6px;
    border: 1px solid var(--dungeon-border);
    min-height: 40px;
    padding: 8px 12px;
    font-weight: 700;
    color: #fff4df;
    background: var(--dungeon-surface-2);
}

.dungeon-btn:disabled,
.dungeon-icon-btn:disabled {
    cursor: not-allowed;
    opacity: 0.58;
}

/* The site's buttons (.btn-buy, .btn-close-dnd) are the shared component layer's (tool_components.css); here only their width. */
.dungeon-generator :is(.btn-buy, .btn-close-dnd) {
    width: auto;
    margin-top: 0;
}

.dungeon-generator .dungeon-icon-btn {
    flex: 0 0 40px;
    width: 40px;
    padding: 0;
}

.dungeon-header-actions .dungeon-btn {
    white-space: nowrap;
}

/* A free plan's limits (web/dungeon_plans.py), on a row of their own under the header's controls; once its week's
   dungeons are used up, in the colours of a warning. */
.dungeon-plan-note {
    flex: 1 0 100%;
    margin: 0;
    border: 1px solid rgba(242, 192, 128, 0.35);
    border-radius: 8px;
    background: rgba(242, 192, 128, 0.08);
    color: var(--dungeon-text);
    padding: 10px 16px;
    font-size: 1rem;
    line-height: 1.5;
    text-align: center;
}

.dungeon-plan-note.is-used-up {
    border-color: rgba(216, 95, 95, 0.7);
    background: rgba(216, 95, 95, 0.16);
    color: #ffe0e0;
}

.dungeon-plan-note a {
    color: var(--dungeon-link);
    font-weight: 700;
}

/* What the plan does not allow stays in sight, greyed out; a press tells why. */
.dungeon-generator .is-locked {
    opacity: 0.45;
    cursor: not-allowed;
}

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

.dungeon-tool-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.dungeon-tool,
.dungeon-swatch {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    padding: 8px 10px;
    border: 1px solid var(--dungeon-border);
    border-radius: 6px;
    background: var(--dungeon-bg);
    color: #f7dfbf;
    font-size: 0.88rem;
    text-align: left;
}

.dungeon-tool:hover,
.dungeon-swatch:hover {
    border-color: var(--dungeon-accent);
}

.dungeon-tool[aria-pressed="true"],
.dungeon-swatch[aria-checked="true"] {
    border-color: var(--dungeon-accent);
    background: rgba(var(--dungeon-accent-rgb), 0.16);
    color: #fff4df;
}

.dungeon-tool i {
    width: 16px;
    text-align: center;
}

.dungeon-tool span {
    white-space: nowrap;
}

.dungeon-tool-grid .dungeon-tool {
    font-size: 0.84rem;
    padding-inline: 8px;
}

.dungeon-swatches {
    display: grid;
    gap: 6px;
}

/* The Place palette in the groups of Solasta's gadget library. */
.dungeon-placeables {
    display: grid;
    gap: 10px;
}

/* A long name (Teleport destination) wraps inside its button rather than spilling out of it. */
.dungeon-placeables .dungeon-tool span {
    white-space: normal;
    line-height: 1.15;
    overflow-wrap: break-word;
    min-width: 0;
}

.dungeon-palette-heading {
    margin: 0 0 6px;
    color: var(--dungeon-muted);
    font-size: 0.74rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

/* The room library: ready-made rooms by group, each with its plan. */
.dungeon-room-library {
    display: grid;
    gap: 8px;
}

.dungeon-template-group summary {
    cursor: pointer;
    color: #f7dfbf;
    font-size: 0.88rem;
    padding: 4px 0;
}

.dungeon-template-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 8px;
}

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

.dungeon-template canvas {
    max-width: 100%;
    height: auto;
    border-radius: 3px;
}

.dungeon-template:hover,
.dungeon-template[aria-pressed="true"] {
    border-color: var(--dungeon-accent);
}

.dungeon-template[aria-pressed="true"] {
    background: rgba(var(--dungeon-accent-rgb), 0.16);
}

.dungeon-size-pair {
    display: flex;
    align-items: center;
    gap: 6px;
}

.dungeon-size-pair input {
    min-width: 0;
    flex: 1 1 0;
}

.dungeon-shift {
    display: flex;
    gap: 6px;
}

/* What the game sets on a floor by itself: a switch for each part, and a button that makes its pieces the author's. */
.dungeon-auto {
    margin: 10px 0 0;
    border: 0;
    padding: 0;
    min-width: 0;
}

.dungeon-auto legend {
    margin: 0;
    color: var(--dungeon-muted);
    font-size: 0.78rem;
    text-transform: uppercase;
}

.dungeon-generator .dungeon-auto-part {
    margin-top: 6px;
    white-space: nowrap;
}

.dungeon-auto-count {
    text-transform: none;
}

.dungeon-auto-edit {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
}

.dungeon-auto-edit span {
    flex-basis: 100%;
    color: var(--dungeon-muted);
    font-size: 0.78rem;
    text-transform: uppercase;
}

.dungeon-toggle {
    gap: 4px;
    cursor: pointer;
}

.dungeon-toggle input {
    margin: 0;
}

/* Why the ghost on the map cannot go where it is (Solasta's red caption). */
.dungeon-map-caption {
    margin: 8px 0 0;
    border: 1px solid rgba(216, 95, 95, 0.4);
    border-radius: 6px;
    background: rgba(216, 95, 95, 0.14);
    color: #ffd8d8;
    padding: 6px 10px;
    font-size: 0.86rem;
}

.dungeon-form-heading {
    margin: 12px 0 0;
    color: #f7dfbf;
}

.dungeon-small-btn.is-active {
    border-color: var(--dungeon-accent);
    background: rgba(var(--dungeon-accent-rgb), 0.2);
}

.dungeon-swatch-chip {
    flex: 0 0 22px;
    width: 22px;
    height: 22px;
    border-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.5);
}

.dungeon-summary {
    display: grid;
    gap: 8px;
    margin: 0;
}

.dungeon-summary div,
.dungeon-history-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    border: 1px solid rgba(182, 203, 208, 0.12);
    border-radius: 6px;
    background: rgba(18, 32, 39, 0.72);
    padding: 10px;
}

.dungeon-summary dt,
.dungeon-summary dd {
    margin: 0;
}

.dungeon-summary dt {
    color: var(--dungeon-muted);
}

.dungeon-summary dd {
    color: #fff1cf;
    font-weight: 700;
}

.dungeon-warnings {
    display: grid;
    gap: 8px;
    margin-top: 12px;
}

.dungeon-warning,
.dungeon-error {
    border-radius: 6px;
    padding: 10px;
    font-size: 0.88rem;
}

.dungeon-warning {
    background: rgba(242, 192, 128, 0.1);
    border: 1px solid rgba(242, 192, 128, 0.35);
    color: #f7dfbf;
}

.dungeon-error {
    background: rgba(216, 95, 95, 0.14);
    border: 1px solid rgba(216, 95, 95, 0.4);
    color: #ffd8d8;
}

.dungeon-pill {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    border: 1px solid rgba(242, 192, 128, 0.35);
    border-radius: 6px;
    padding: 2px 8px;
    color: #f7dfbf;
    background: rgba(242, 192, 128, 0.1);
    font-size: 0.75rem;
    line-height: 1.2;
    white-space: nowrap;
}

.dungeon-canvas-wrap {
    overflow: auto;
    max-height: 78vh;
    border: 1px solid var(--dungeon-border);
    border-radius: 6px;
    background: #0a1114;
}

/* Under the map while a piece is held (a room from the library, a moved or copied placement) or a target is picked. */
.dungeon-held-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

/* A touch screen's right button: on while pressed. */
.dungeon-touch-only {
    display: none;
}

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

@media (any-pointer: coarse) {
    .dungeon-touch-only {
        display: inline-flex;
    }
}

/* The pointer's cell: with no hover (a touch screen) it would only ever tell the last touch. */
@media (hover: none) {
    #dungeon-cursor {
        display: none;
    }
}

/* The sidebar's sheet header and the Tools button that opens it show only where the sidebar is a sheet (narrow
   screens, below). */
.dungeon-sheet-header,
.dungeon-sheet-only {
    display: none;
}

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

#dungeon-canvas {
    display: block;
    margin: 0 auto;
    touch-action: none;
    cursor: crosshair;
}

.dungeon-inspector-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 12px;
}

.dungeon-inspector-grid .dungeon-field--wide {
    grid-column: 1 / -1;
}

.dungeon-inspector-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 14px;
}

.dungeon-search {
    display: grid;
    grid-template-columns: 180px minmax(200px, 1fr) 96px 96px auto;
    align-items: end;
    gap: 10px;
    margin-bottom: 16px;
}

.dungeon-search .dungeon-field {
    margin-top: 0;
}

.dungeon-card-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

.dungeon-monster-card {
    display: flex;
    flex-direction: column;
    min-width: 0;
    border: 1px solid var(--dungeon-border);
    border-radius: 8px;
    background: rgba(6, 15, 19, 0.55);
    overflow: hidden;
}

.dungeon-monster-card.is-armed {
    border-color: var(--dungeon-accent);
    box-shadow: 0 0 0 2px rgba(var(--dungeon-accent-rgb), 0.28);
}

.dungeon-monster-card__image {
    aspect-ratio: 16 / 10;
    display: block;
    width: 100%;
    object-fit: cover;
}

.dungeon-monster-card__body {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
}

.dungeon-monster-card h3 {
    margin: 0;
    font-size: 0.95rem;
    color: #fff1cf;
    overflow-wrap: anywhere;
}

.dungeon-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.dungeon-card-summary {
    font-size: 0.84rem;
    line-height: 1.4;
    overflow-wrap: anywhere;
    margin: 0;
}

.dungeon-card-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: auto;
}

.dungeon-card-actions .dungeon-btn {
    flex: 1 1 auto;
    min-height: 36px;
    text-transform: none;
}

.dungeon-load-more-wrap {
    display: flex;
    justify-content: center;
    margin-top: 16px;
}

.dungeon-accordion-toggle,
.dungeon-collapsible-toggle {
    align-items: center;
    background: transparent;
    border: 0;
    color: var(--dungeon-text);
    display: flex;
    gap: 14px;
    justify-content: space-between;
    padding: 0;
    text-align: left;
    width: 100%;
}

.dungeon-accordion-toggle i,
.dungeon-collapsible-toggle i {
    color: #f7dfbf;
    transition: transform 140ms ease;
}

.dungeon-accordion-toggle[aria-expanded="true"] i,
.dungeon-collapsible-toggle[aria-expanded="true"] i {
    transform: rotate(180deg);
}

/* Each part of the sidebar folds away under its heading. */
.dungeon-generator .dungeon-collapsible-heading {
    margin: 0;
}

.dungeon-collapsible-toggle {
    font: inherit;
    font-weight: 700;
}

.dungeon-collapsible-toggle:focus-visible {
    outline: 2px solid var(--dungeon-accent);
    outline-offset: 3px;
    border-radius: 4px;
}

.dungeon-collapsible-body {
    margin-top: 14px;
}

.dungeon-accordion-title,
.dungeon-accordion-subtitle {
    display: block;
}

.dungeon-accordion-title {
    font-size: 1.05rem;
    font-weight: 700;
}

.dungeon-accordion-subtitle {
    color: var(--dungeon-muted);
    font-size: 0.86rem;
    margin-top: 3px;
}

.dungeon-generate-body {
    border-top: 1px solid rgba(182, 203, 208, 0.12);
    margin-top: 14px;
    padding-top: 4px;
}

.dungeon-generate-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 12px;
}

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

.dungeon-key-entry {
    border: 1px solid rgba(182, 203, 208, 0.12);
    border-radius: 6px;
    background: rgba(18, 32, 39, 0.72);
    padding: 12px;
    cursor: pointer;
}

.dungeon-key-entry.is-selected {
    border-color: var(--dungeon-accent);
}

.dungeon-key-entry h3 {
    color: #fff1cf;
    margin-bottom: 6px;
}

.dungeon-key-entry ul {
    margin: 6px 0 0;
    padding-left: 18px;
    color: var(--dungeon-muted);
    font-size: 0.88rem;
}

.dungeon-read-aloud {
    border-left: 3px solid var(--dungeon-text);
    padding: 4px 0 4px 10px;
    color: #f7dfbf;
    font-style: italic;
    white-space: pre-line;
    margin: 6px 0;
}

.dungeon-link-form {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) auto;
    gap: 10px;
    align-items: end;
}

.dungeon-history-list {
    display: grid;
    gap: 10px;
    max-height: 340px;
    overflow-y: auto;
    margin-bottom: 10px;
}

.dungeon-history-list .dungeon-history-item {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
}

.dungeon-history-title {
    font-weight: 700;
    color: #fff1cf;
    overflow-wrap: anywhere;
}

.dungeon-history-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    color: var(--dungeon-muted);
    font-size: 0.86rem;
}

.dungeon-history-actions .dungeon-btn {
    min-height: 34px;
    padding: 6px 10px;
}

.dungeon-toast {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 1050;
    max-width: min(420px, calc(100vw - 40px));
    border: 1px solid var(--dungeon-border);
    border-radius: 8px;
    background: #0b1519;
    color: #f8e4c0;
    padding: 12px 14px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.32);
    opacity: 0;
    pointer-events: none;
    transform: translateY(8px);
    transition: opacity 160ms ease, transform 160ms ease;
}

.dungeon-toast.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.dungeon-toast.dungeon-error {
    background: #2a1416;
}

/* Over the whole page while a random dungeon is generated: the Monster Generator's loading overlay (its spinner and
   its lines that pop in, monster_generator4.css .loading-overlay), above the tools sheet and the toast. */
.dungeon-generating {
    position: fixed;
    inset: 0;
    z-index: 1500;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    padding: 16px;
    background-color: rgba(0, 0, 0, 0.7);
}

.dungeon-generating[hidden] {
    display: none;
}

.dungeon-generating__spinner {
    width: 60px;
    height: 60px;
    border: 5px solid rgba(231, 191, 143, 0.3);
    border-top-color: #e7bf8f;
    border-radius: 50%;
    animation: dungeon-generating-spin 1.5s linear infinite;
}

.dungeon-generating__message {
    max-width: 32rem;
    margin: 0;
    color: #e7bf8f;
    font-size: 1.2rem;
    font-style: italic;
    font-weight: bold;
    text-align: center;
    animation: dungeon-generating-pop 0.5s ease-out forwards;
}

body.dungeon-is-generating {
    overflow: hidden;
}

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

@keyframes dungeon-generating-pop {
    0% {
        opacity: 0;
        transform: scale(0.3) translateY(20px);
    }
    50% {
        transform: scale(1.1) translateY(-5px);
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@media (prefers-reduced-motion: reduce) {
    .dungeon-generating__spinner {
        animation-duration: 4s;
    }

    .dungeon-generating__message {
        animation: none;
    }
}

/* The printed sheet of the Battlemap Generator (battlemap/app_export.js): a white A4 page, built off screen and captured
   for its PDF. The dungeon's own PDF is drawn by dungeon_pdf_export.js and uses none of this. */
.dungeon-print-host {
    position: fixed;
    left: -10000px;
    top: 0;
}

.dungeon-print-sheet {
    width: 718px;
    padding: 0;
    background: #ffffff;
    color: #1d1a16;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 12px;
    line-height: 1.45;
}

.dungeon-print-sheet h1 {
    font-size: 24px;
    margin: 0 0 4px;
    color: #1d1a16;
}

.dungeon-print-sheet h2 {
    font-size: 16px;
    margin: 18px 0 8px;
    border-bottom: 2px solid #7a1f1f;
    padding-bottom: 3px;
    color: #7a1f1f;
}

.dungeon-print-sheet p {
    margin: 0 0 6px;
}

.dungeon-print-meta {
    color: #5b5148;
    font-style: italic;
}

.dungeon-print-map img {
    display: block;
    width: 100%;
    height: auto;
    border: 1px solid #1d1a16;
}

.dungeon-print-entry {
    margin-bottom: 12px;
}

.dungeon-print-notes {
    white-space: pre-line;
}

.dungeon-print-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
    margin-top: 6px;
    color: #5b5148;
}

.dungeon-print-roster {
    width: 100%;
    border-collapse: collapse;
}

.dungeon-print-roster th,
.dungeon-print-roster td {
    border-bottom: 1px solid #d8cdb8;
    padding: 4px 6px;
    text-align: left;
}

@media (max-width: 1180px) {
    .dungeon-layout {
        grid-template-columns: 260px minmax(0, 1fr);
    }

    .dungeon-card-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .dungeon-search {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* Phones and upright tablets: one column with the map first; the sidebar is a sheet that slides up over the lower
   part of the screen from the Tools button, so the map stays in sight while a tool is chosen. */
@media (max-width: 920px) {
    .dungeon-header {
        align-items: stretch;
        flex-direction: column;
    }

    .dungeon-header-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }

    .dungeon-header-actions .dungeon-btn {
        flex: 1 1 0;
        min-width: max-content;
    }

    .dungeon-layout {
        grid-template-columns: minmax(0, 1fr);
    }

    .dungeon-sidebar {
        position: fixed;
        top: auto;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: 1040;
        max-height: min(60vh, 620px);
        margin: 0;
        padding-top: 0;
        border-radius: 14px 14px 0 0;
        overflow-y: auto;
        overscroll-behavior: contain;
        box-shadow: 0 -18px 48px rgba(0, 0, 0, 0.5);
        transform: translateY(100%);
        visibility: hidden;
        transition: transform 200ms ease, visibility 0s linear 200ms;
    }

    .dungeon-sidebar.is-open {
        transform: none;
        visibility: visible;
        transition: transform 200ms ease;
    }

    .dungeon-sheet-header {
        position: sticky;
        top: 0;
        z-index: 1;
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin: 0 -18px 12px;
        padding: 10px 18px;
        border-bottom: 1px solid rgba(182, 203, 208, 0.12);
        background: var(--dungeon-surface);
        color: #f7dfbf;
        font-size: 1.05rem;
        font-weight: 700;
    }

    .dungeon-sheet-only {
        display: inline-flex;
    }

    /* In the sheet the saved maps leave room for the tools below them. */
    .dungeon-sidebar .dungeon-history-list {
        max-height: 190px;
    }

    .dungeon-section-heading {
        flex-wrap: wrap;
        gap: 10px;
    }

    .dungeon-map-actions {
        flex-wrap: wrap;
        gap: 8px;
    }

    .dungeon-card-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .dungeon-link-form {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .dungeon-generator {
        padding-inline: 10px;
    }

    .dungeon-header,
    .dungeon-panel {
        padding: 12px;
    }

    .dungeon-sheet-header {
        margin-inline: -12px;
        padding-inline: 12px;
    }

    .dungeon-title-input {
        font-size: 1.3rem;
    }

    .dungeon-card-grid,
    .dungeon-search,
    .dungeon-inspector-grid,
    .dungeon-history-item,
    .dungeon-title-row {
        grid-template-columns: 1fr;
    }

    .dungeon-title-row::before {
        display: none;
    }

    .dungeon-title-row .dungeon-save-status {
        justify-self: center;
    }
}

/* ==================================================================================================================
   The Dungeon Generator page's editor layout (templates/web/dungeon_generator.html, dungeon_editor_shell.js).
   Everything below is scoped to .dungeon-page, which only that page carries: the Battlemap Generator shares the rules
   above and keeps them. The shell sets data-layout ("desktop" from 1200 px, "tablet" from 768 px, "phone" below that
   and on a landscape phone) and data-orient on the root; the sizes below are the shell's (DESKTOP_MIN_WIDTH ...).
   ================================================================================================================== */

.dungeon-generator.dungeon-page {
    --dungeon-rail-width: 76px;
    --dungeon-flyout-width: 276px;
    --dungeon-side-width: 348px;
    --dungeon-surface-line: rgba(242, 192, 128, 0.16);
    max-width: none;
    padding: 12px 12px 24px;
}

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

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

.dungeon-page .dungeon-header--slim {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 6px 16px;
    margin-bottom: 10px;
    padding: 8px 14px;
}

.dungeon-page .dungeon-header--slim .dungeon-title-row {
    display: flex;
    flex: initial;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.dungeon-page .dungeon-header--slim .dungeon-title-row::before {
    display: none;
}

.dungeon-page .dungeon-header--slim .dungeon-title-input {
    flex: 1 1 auto;
    text-align: left;
    font-size: 1.3rem;
    min-height: 40px;
}

.dungeon-page .dungeon-header--slim .dungeon-title-row .dungeon-save-status {
    flex: 0 1 auto;
    min-width: 0;
    white-space: normal;
}

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

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

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

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

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

.dungeon-page .dungeon-note.is-error {
    color: #ffd2d2;
}

.dungeon-page .dungeon-header--slim .dungeon-header-actions {
    gap: 8px;
}

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

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

.dungeon-page .dungeon-more {
    display: none;
    position: relative;
}

.dungeon-page .dungeon-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;
    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);
}

.dungeon-page .dungeon-more-panel .dungeon-btn {
    width: 100%;
    min-height: 44px;
    justify-content: flex-start;
}

.dungeon-page .dungeon-more-panel .dungeon-size-controls {
    flex-wrap: wrap;
    padding-top: 8px;
    border-top: 1px solid rgba(182, 203, 208, 0.12);
}

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

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

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

.dungeon-page .dungeon-editor {
    position: relative;
    display: flex;
    gap: 10px;
    height: var(--dungeon-editor-height, 720px);
    min-height: 0;
}

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

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

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

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

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

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

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

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

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

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

.dungeon-page .dungeon-flyout-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 8px 8px 14px;
    border-bottom: 1px solid rgba(182, 203, 208, 0.12);
}

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

.dungeon-page .dungeon-flyout-modes {
    display: none;
}

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

.dungeon-page .dungeon-flyout:not([data-panel="paint"]):not([data-panel="ground"]) .dungeon-brush-field {
    display: none;
}

.dungeon-page .dungeon-swatches {
    grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
    margin-top: 10px;
}

.dungeon-page .dungeon-swatch {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 6px;
    font-size: 0.74rem;
    line-height: 1.15;
    text-align: center;
}

.dungeon-page .dungeon-swatch .dungeon-swatch-chip {
    flex: none;
    width: 100%;
    height: 40px;
}

.dungeon-page .dungeon-palette-group {
    margin-top: 6px;
}

.dungeon-page .dungeon-palette-group .dungeon-tool-grid {
    grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
}

.dungeon-page .dungeon-placeables .dungeon-tool {
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    min-height: 62px;
    padding: 6px 4px;
    font-size: 0.72rem;
    text-align: center;
}

.dungeon-page .dungeon-room-library {
    margin-top: 10px;
}

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

.dungeon-page .dungeon-map-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    border-bottom: 1px solid rgba(182, 203, 208, 0.12);
}

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

.dungeon-page .dungeon-floor-tab {
    flex: none;
    white-space: nowrap;
}

.dungeon-page .dungeon-map-actions {
    flex: none;
    gap: 6px;
}

.dungeon-page .dungeon-map-actions .dungeon-icon-btn {
    flex: 0 0 38px;
    width: 38px;
    min-height: 38px;
}

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

.dungeon-page .dungeon-toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 38px;
    padding: 0 10px;
    border: 1px solid var(--dungeon-border);
    border-radius: 6px;
    background: var(--dungeon-bg);
    color: #f7dfbf;
    font-size: 0.8rem;
    font-weight: 700;
    white-space: nowrap;
}

.dungeon-page .dungeon-toggle input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    opacity: 0;
    cursor: pointer;
}

.dungeon-page .dungeon-toggle:has(input:checked) {
    border-color: var(--dungeon-accent);
    background: rgba(var(--dungeon-accent-rgb), 0.16);
    color: #fff4df;
}

.dungeon-page .dungeon-toggle:has(input:focus-visible) {
    outline: 2px solid var(--dungeon-accent);
    outline-offset: 2px;
}

.dungeon-page .dungeon-canvas-wrap {
    flex: 1 1 0;
    min-height: 0;
    max-height: none;
    border: 0;
    border-radius: 0;
    overscroll-behavior: contain;
}

.dungeon-page .dungeon-statusbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 10px;
    border-top: 1px solid rgba(182, 203, 208, 0.12);
    min-height: 34px;
}

.dungeon-page .dungeon-statusbar .dungeon-map-caption {
    flex: 1 1 auto;
    margin: 0;
}

.dungeon-page .dungeon-statusbar .dungeon-held-actions {
    flex: none;
    margin: 0;
}

.dungeon-page .dungeon-statusbar .dungeon-btn {
    min-height: 34px;
    padding: 4px 12px;
}

.dungeon-page .dungeon-chip,
.dungeon-page .dungeon-peek,
.dungeon-page .dungeon-phonebar,
.dungeon-page .dungeon-scrim,
.dungeon-page .dungeon-flyout-modes {
    display: none;
}

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

.dungeon-page .dungeon-side-header {
    display: flex;
    align-items: stretch;
    border-bottom: 1px solid rgba(182, 203, 208, 0.12);
}

.dungeon-page .dungeon-side-tabs {
    display: flex;
    flex: 1 1 0;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
}

.dungeon-page .dungeon-side-tab {
    flex: 1 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 62px;
    min-height: 54px;
    padding: 6px 8px;
    border: 0;
    border-bottom: 3px solid transparent;
    background: transparent;
    color: var(--dungeon-muted);
    font-size: 0.72rem;
    font-weight: 700;
}

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

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

.dungeon-page .dungeon-side-tab[aria-selected="true"] {
    border-bottom-color: var(--dungeon-accent);
    color: #fff4df;
}

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

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

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

.dungeon-page .dungeon-section-heading--spaced {
    margin-top: 22px;
}

.dungeon-page .dungeon-side .dungeon-search {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-bottom: 8px;
}

.dungeon-page .dungeon-side .dungeon-search .dungeon-field:nth-child(1),
.dungeon-page .dungeon-side .dungeon-search .dungeon-search-query,
.dungeon-page .dungeon-side .dungeon-search .dungeon-btn,
.dungeon-page .dungeon-side .dungeon-search .dungeon-field-error {
    grid-column: 1 / -1;
}

.dungeon-page .dungeon-field-error {
    margin: 0;
    padding: 6px 10px;
    border: 1px solid rgba(216, 95, 95, 0.4);
    border-radius: 6px;
    background: rgba(216, 95, 95, 0.14);
    color: #ffd8d8;
    font-size: 0.84rem;
}

.dungeon-page .dungeon-field input[aria-invalid="true"] {
    border-color: var(--dungeon-danger);
}

.dungeon-page .dungeon-side .dungeon-card-grid {
    grid-template-columns: minmax(0, 1fr);
}

.dungeon-page .dungeon-create-monster {
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid rgba(182, 203, 208, 0.12);
}

.dungeon-page .dungeon-side .dungeon-history-list {
    max-height: none;
    overflow: visible;
}

.dungeon-page .dungeon-side-panel > .dungeon-section-heading:first-child h2,
.dungeon-page #dungeon-inspector h2 {
    font-size: 1.05rem;
}

.dungeon-page .dungeon-side .dungeon-collapsible + .dungeon-collapsible {
    border-top: 1px solid rgba(182, 203, 208, 0.12);
    margin-top: 16px;
    padding-top: 16px;
}

.dungeon-page .dungeon-auto-part span {
    text-transform: none;
    font-size: 0.86rem;
}

.dungeon-page .dungeon-auto legend {
    float: none;
    width: auto;
    padding: 0;
    font-size: 0.78rem;
    line-height: 1.3;
}

/* Windows of the page: confirmation and keyboard shortcuts */
.dungeon-page .dungeon-dialog p {
    color: var(--dungeon-muted);
}

.dungeon-page .dungeon-shortcuts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 4px 28px;
}

.dungeon-page .dungeon-shortcuts h3 {
    margin: 14px 0 6px;
    color: #fff1cf;
}

.dungeon-page .dungeon-shortcuts dl {
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr);
    gap: 6px 14px;
    margin: 0;
    align-items: baseline;
}

.dungeon-page .dungeon-shortcuts dt,
.dungeon-page .dungeon-shortcuts dd {
    margin: 0;
}

.dungeon-page .dungeon-shortcuts dd {
    color: var(--dungeon-muted);
    font-size: 0.88rem;
}

.dungeon-page .dungeon-shortcuts kbd {
    display: inline-block;
    min-width: 24px;
    padding: 1px 7px;
    border: 1px solid var(--dungeon-border);
    border-bottom-width: 2px;
    border-radius: 5px;
    background: var(--dungeon-bg);
    color: #fff4df;
    font: inherit;
    font-size: 0.8rem;
    text-align: center;
}

.dungeon-page .dungeon-plan-detail {
    margin-right: 0;
}

/* --- The map's toolbar gives up its words before it wraps -------------------------------------------------------- */

@container (max-width: 760px) {
    .dungeon-page .dungeon-toggle span {
        display: none;
    }

    .dungeon-page .dungeon-toggle {
        width: 38px;
        justify-content: center;
        padding: 0;
    }
}

@container (max-width: 560px) {
    .dungeon-page .dungeon-map-actions {
        gap: 4px;
    }

    .dungeon-page .dungeon-map-actions .dungeon-icon-btn,
    .dungeon-page .dungeon-toggle {
        flex-basis: 34px;
        width: 34px;
        min-height: 34px;
    }
}

/* --- Full screen: the page's own filling when the browser's is not there, and the browser's -------------------- */

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

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

/* --- Tablet: the right column is a drawer ------------------------------------------------------------------------ */

.dungeon-page .dungeon-tablet-only {
    display: none;
}

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

.dungeon-page[data-layout="desktop"] .dungeon-desktop-only {
    display: inline-flex;
}

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

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

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

.dungeon-page[data-layout="tablet"] .dungeon-header--slim .dungeon-header-actions,
.dungeon-page[data-layout="phone"] .dungeon-header--slim .dungeon-header-actions {
    grid-column: 2;
}

.dungeon-page[data-layout="tablet"] .dungeon-rail,
.dungeon-page[data-layout="tablet"] .dungeon-rail-title {
    --dungeon-rail-width: 58px;
}

.dungeon-page[data-layout="tablet"] {
    --dungeon-rail-width: 58px;
    --dungeon-flyout-width: 252px;
}

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

/* Only the tool in use, or the one whose options are open, keeps its label on a tablet. */
.dungeon-page[data-layout="tablet"] .dungeon-rail .dungeon-tool span {
    display: none;
}

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

.dungeon-page[data-layout="tablet"] .dungeon-side,
.dungeon-page[data-layout="phone"] .dungeon-side {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 1045;
    width: min(420px, 92vw);
    flex: none;
    border-radius: 14px 0 0 14px;
    box-shadow: -18px 0 48px rgba(0, 0, 0, 0.5);
    transform: translateX(105%);
    visibility: hidden;
    transition: transform 200ms ease, visibility 0s linear 200ms;
}

.dungeon-page[data-side-open="true"] .dungeon-side {
    transform: none;
    visibility: visible;
    transition: transform 200ms ease;
}

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

.dungeon-page .dungeon-scrim {
    position: fixed;
    inset: 0;
    z-index: 1040;
    background: rgba(5, 10, 12, 0.55);
}

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

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

.dungeon-page[data-layout="phone"] {
    padding: 6px 0 0;
}

.dungeon-page[data-layout="phone"] .dungeon-header--slim {
    margin: 0 6px 6px;
    padding: 6px 8px;
    gap: 6px 8px;
}

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

.dungeon-page[data-layout="phone"] .dungeon-header--slim .dungeon-title-row .dungeon-save-status {
    font-size: 0.66rem;
}

.dungeon-page[data-layout="phone"] .dungeon-header--slim .dungeon-title-row .dungeon-save-status.is-error {
    max-width: 9em;
    white-space: normal;
    font-size: 0.6rem;
}

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

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

.dungeon-page[data-layout="phone"] .dungeon-plan-detail {
    display: none;
}

.dungeon-page[data-layout="phone"] .dungeon-header--slim .dungeon-plan-note {
    padding: 4px 8px;
    font-size: 0.76rem;
}

.dungeon-page[data-layout="phone"] .dungeon-editor {
    flex-direction: column;
    gap: 0;
}

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

.dungeon-page[data-layout="phone"] .dungeon-stage {
    border-radius: 0;
    border-left: 0;
    border-right: 0;
}

.dungeon-page[data-layout="phone"] .dungeon-phonebar {
    display: flex;
    flex: 0 0 auto;
    gap: 4px;
    padding: 4px 6px;
    background: var(--dungeon-surface);
    border-top: 1px solid var(--dungeon-surface-line);
}

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

/* The toolbar floats over the map: the floors at its top left, the view controls at its right edge. It lies above the map
   sheet's edge handles (z-index 4, dungeon_draw.css): the view panel opens over the map's right edge, and a tap on one of
   its buttons must not land on the handle under it. */
.dungeon-page[data-layout="phone"] .dungeon-map-toolbar {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: block;
    padding: 0;
    border: 0;
    pointer-events: none;
}

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

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

.dungeon-page[data-layout="phone"] .dungeon-map-actions {
    position: absolute;
    top: 6px;
    right: 6px;
    display: grid;
    gap: 6px;
    max-height: calc(100% - 12px);
    overflow-y: auto;
    padding: 3px;
    border: 1px solid var(--dungeon-surface-line);
    border-radius: 10px;
    background: rgba(14, 23, 28, 0.88);
    pointer-events: auto;
    scrollbar-width: none;
}

.dungeon-page[data-layout="phone"] .dungeon-map-actions .dungeon-icon-btn,
.dungeon-page[data-layout="phone"] .dungeon-toggle {
    flex: none;
    width: 44px;
    min-height: 44px;
    justify-content: center;
    padding: 0;
}

.dungeon-page[data-layout="phone"] .dungeon-toggle span,
.dungeon-page[data-layout="phone"] .dungeon-desktop-only,
.dungeon-page[data-layout="phone"] #dungeon-side-toggle {
    display: none;
}

.dungeon-page[data-layout="phone"] .dungeon-touch-only {
    display: inline-flex;
}

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

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

.dungeon-page[data-layout="phone"] .dungeon-statusbar .dungeon-map-caption {
    position: absolute;
    top: 58px;
    left: 8px;
    right: 66px;
    z-index: 3;
}

.dungeon-page[data-layout="phone"] .dungeon-statusbar .dungeon-held-actions {
    position: absolute;
    left: 8px;
    bottom: 60px;
    z-index: 4;
    gap: 6px;
}

.dungeon-page[data-layout="phone"] .dungeon-statusbar .dungeon-btn {
    min-height: 44px;
    background-color: #151f25;
}

.dungeon-page[data-layout="phone"] .dungeon-chip {
    position: absolute;
    left: 8px;
    bottom: 8px;
    z-index: 4;
    display: flex;
    max-width: calc(100% - 76px);
    border: 1px solid var(--dungeon-accent);
    border-radius: 22px;
    background: rgba(14, 38, 38, 0.95);
    color: #fff4df;
    overflow: hidden;
}

.dungeon-page[data-layout="phone"] .dungeon-chip[hidden] {
    display: none;
}

.dungeon-page[data-layout="phone"] .dungeon-chip button {
    min-height: 44px;
    border: 0;
    background: transparent;
    color: inherit;
    font-size: 0.86rem;
    font-weight: 700;
}

.dungeon-page[data-layout="phone"] .dungeon-chip-label {
    min-width: 0;
    padding: 0 6px 0 16px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dungeon-page[data-layout="phone"] .dungeon-chip-clear {
    flex: none;
    width: 44px;
}

.dungeon-page[data-layout="phone"] .dungeon-peek {
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: 8px;
    z-index: 5;
    display: grid;
    gap: 8px;
    padding: 10px;
    border: 1px solid rgba(242, 192, 128, 0.35);
    border-radius: 12px;
    background: rgba(14, 23, 28, 0.97);
    box-shadow: 0 10px 32px rgba(0, 0, 0, 0.5);
}

.dungeon-page[data-layout="phone"] .dungeon-peek[hidden] {
    display: none;
}

.dungeon-page .dungeon-peek-name {
    color: #fff1cf;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dungeon-page .dungeon-peek-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.dungeon-page .dungeon-peek-actions .dungeon-btn {
    min-height: 48px;
    padding: 6px 8px;
    font-size: 0.8rem;
}

/* The tool options are the half-height sheet over the map; the right column the full-height one. */
.dungeon-page[data-layout="phone"] .dungeon-flyout {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1045;
    flex: none;
    width: auto;
    height: 52dvh;
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -18px 48px rgba(0, 0, 0, 0.5);
}

.dungeon-page[data-layout="phone"] .dungeon-flyout[data-group="draw"] .dungeon-flyout-modes {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    padding: 8px 12px 0;
}

.dungeon-page .dungeon-mode {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 54px;
    border: 1px solid var(--dungeon-border);
    border-radius: 6px;
    background: var(--dungeon-bg);
    color: #f7dfbf;
    font-size: 0.74rem;
}

.dungeon-page .dungeon-mode[aria-pressed="true"] {
    border-color: var(--dungeon-accent);
    background: rgba(var(--dungeon-accent-rgb), 0.16);
    color: #fff4df;
}

.dungeon-page[data-layout="phone"] .dungeon-side {
    top: 0;
    width: 100%;
    border-radius: 0;
    border: 0;
}

.dungeon-page[data-layout="phone"] .dungeon-toast {
    right: 12px;
    bottom: 72px;
    left: 12px;
    max-width: none;
}

/* A phone held sideways: the tool bar is a rail at the left edge, so the map keeps the height. */
.dungeon-page[data-layout="phone"][data-orient="landscape"] .dungeon-editor {
    flex-direction: row;
}

.dungeon-page[data-layout="phone"][data-orient="landscape"] .dungeon-phonebar {
    order: -1;
    flex-direction: column;
    flex: 0 0 64px;
    padding: 4px;
    border-top: 0;
    border-right: 1px solid var(--dungeon-surface-line);
    overflow-y: auto;
}

.dungeon-page[data-layout="phone"][data-orient="landscape"] .dungeon-phonebar .dungeon-tool {
    flex: 1 0 44px;
    min-height: 44px;
    padding: 2px;
}

.dungeon-page[data-layout="phone"][data-orient="landscape"] .dungeon-phonebar .dungeon-tool span {
    font-size: 0.62rem;
}

.dungeon-page[data-layout="phone"][data-orient="landscape"] .dungeon-flyout {
    top: 0;
    right: auto;
    left: 70px;
    width: min(400px, 58vw);
    height: auto;
    border-radius: 0 14px 14px 0;
}

.dungeon-page[data-layout="phone"][data-orient="landscape"] .dungeon-side {
    left: auto;
    width: min(480px, 66vw);
    border-radius: 14px 0 0 14px;
}

.dungeon-page[data-layout="phone"][data-orient="landscape"] .dungeon-map-actions {
    grid-auto-flow: column;
    grid-template-rows: repeat(5, 44px);
}

.dungeon-page[data-layout="phone"][data-orient="landscape"] .dungeon-floor-tabs {
    max-width: calc(100% - 128px);
}

.dungeon-page[data-layout="phone"][data-orient="landscape"] .dungeon-statusbar .dungeon-map-caption {
    right: 128px;
}

.dungeon-page[data-layout="phone"][data-orient="landscape"] .dungeon-toast {
    left: 76px;
    bottom: 12px;
}

.dungeon-page[data-layout="phone"][data-orient="landscape"] .dungeon-statusbar .dungeon-held-actions {
    bottom: 60px;
}

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

@media (any-pointer: coarse) {
    .dungeon-page .dungeon-btn,
    .dungeon-page .dungeon-icon-btn,
    .dungeon-page .dungeon-floor-tab,
    .dungeon-page .dungeon-small-btn,
    .dungeon-page .dungeon-card-actions .dungeon-btn,
    .dungeon-page .dungeon-history-actions .dungeon-btn,
    .dungeon-page .dungeon-statusbar .dungeon-btn,
    .dungeon-page .dungeon-toggle,
    .dungeon-page .dungeon-field input,
    .dungeon-page .dungeon-field select,
    .dungeon-page .dungeon-tool,
    .dungeon-page .dungeon-swatch,
    .dungeon-page .dungeon-row .dungeon-row-count,
    .dungeon-page .dungeon-picker-search select,
    .dungeon-page .dungeon-picker-search input,
    .dungeon-page .dungeon-picker-create input {
        min-height: 44px;
    }

    .dungeon-page .dungeon-generator .dungeon-small-btn,
    .dungeon-page .dungeon-generator .dungeon-icon-btn {
        min-height: 44px;
    }

    .dungeon-page .dungeon-map-actions .dungeon-icon-btn {
        flex-basis: 44px;
        width: 44px;
    }

    .dungeon-page .dungeon-toggle {
        min-width: 44px;
    }

    .dungeon-page .dungeon-generator .dungeon-icon-btn,
    .dungeon-page .dungeon-icon-btn {
        flex-basis: 44px;
        min-width: 44px;
    }

    .dungeon-page .dungeon-collapsible-toggle,
    .dungeon-page .dungeon-accordion-toggle,
    .dungeon-page .dungeon-side-tab,
    .dungeon-page .dungeon-template-group summary {
        min-height: 44px;
    }

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

    .dungeon-page .dungeon-field--check input,
    .dungeon-page .dungeon-auto-part input[type="checkbox"] {
        width: 24px;
        height: 24px;
    }

    .dungeon-page .dungeon-swatch .dungeon-swatch-chip {
        height: 44px;
    }

    .dungeon-page .dungeon-size-controls .dungeon-field input {
        min-height: 44px;
    }

    .dungeon-page .dungeon-key-entry,
    .dungeon-page .dungeon-key-entry li {
        min-height: 40px;
    }

    .dungeon-page .dungeon-key-entry li {
        padding: 6px 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .dungeon-page .dungeon-side,
    .dungeon-page[data-side-open="true"] .dungeon-side {
        transition: none;
    }
}

/* The title's pill keeps to one line, except when it tells of a problem (the offline text is a sentence). */
.dungeon-page .dungeon-header--slim .dungeon-title-row .dungeon-save-status {
    white-space: nowrap;
}

.dungeon-page .dungeon-header--slim .dungeon-title-row .dungeon-save-status.is-error {
    white-space: normal;
    max-width: 26em;
}

.dungeon-page #dungeon-shortcuts-dialog {
    width: min(920px, calc(100vw - 32px));
}

.dungeon-page .dungeon-shortcuts dl {
    grid-template-columns: minmax(120px, max-content) minmax(0, 1fr);
}

/* On a phone the floors and the view controls float over the map's corners: the map sits clear of them. */
.dungeon-page[data-layout="phone"] .dungeon-canvas-wrap {
    padding: 54px 58px 8px 8px;
}

.dungeon-page[data-layout="phone"][data-orient="landscape"] .dungeon-canvas-wrap {
    padding-right: 114px;
}

.dungeon-page[data-layout="phone"] #dungeon-canvas {
    margin: 0;
}

.dungeon-page .dungeon-header--slim .dungeon-title-input {
    width: auto;
    min-width: 0;
}

/* A phone held sideways has little height: the card of what is selected is one row, clear of the view controls. */
.dungeon-page[data-layout="phone"][data-orient="landscape"] .dungeon-peek {
    right: 128px;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
}

.dungeon-page[data-layout="phone"][data-orient="landscape"] .dungeon-peek-actions {
    grid-template-columns: repeat(3, 110px);
}

/* On a tablet the options of a tool slide over the map's left side, so the map's toolbar keeps its room. */
.dungeon-page[data-layout="tablet"] .dungeon-flyout {
    position: absolute;
    top: 0;
    bottom: 0;
    left: calc(var(--dungeon-rail-width) + 10px);
    z-index: 30;
    box-shadow: 14px 0 36px rgba(0, 0, 0, 0.45);
}

/* While a tablet's flyout lies over the map's left side, the map's frame leaves that side free (the map scrolls in it), so
   the squares under the flyout can still be reached: a stamp or a stroke there needs no closing of the tool's options. */
.dungeon-page[data-layout="tablet"]:has(.dungeon-flyout:not([hidden])) .dungeon-canvas-wrap {
    padding-left: calc(var(--dungeon-flyout-width) + 10px);
}

/* The page's own rules above are more specific than the touch minimum: touch gets its 44 px here as well. */
@media (any-pointer: coarse) {
    .dungeon-page .dungeon-map-actions .dungeon-icon-btn,
    .dungeon-page .dungeon-map-actions .dungeon-toggle,
    .dungeon-page .dungeon-header--slim .dungeon-btn,
    .dungeon-page .dungeon-header--slim .dungeon-icon-btn,
    .dungeon-page .dungeon-statusbar .dungeon-btn,
    .dungeon-page .dungeon-more-panel .dungeon-btn {
        min-height: 44px;
    }

    .dungeon-page .dungeon-plan-note a {
        display: inline-block;
        padding: 12px 4px;
        margin: -12px 0;
    }
}

/* ==================================================================================================================
   One screen: the page is exactly one viewport tall (header, map, bar), docks to the top of the screen with one swipe,
   and the map takes all the room that is left.
   ================================================================================================================== */

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

/* The top of the page is a resting place too. Without it the editor's snap point is the only one, and on a short screen
   it lies within "proximity" of position 0: the page docks to the editor about half a second after it loads and the
   banner is never seen. With both, a fresh load rests at the top and one swipe docks the editor. */
html.dungeon-snap body > .custom-navbar {
    scroll-snap-align: start;
}

.dungeon-generator.dungeon-page {
    /* The map sheet (below): the plain panel it lies on, its frame, and the room round it for its edge handles. */
    --dungeon-sheet-desk: #0a1114;
    --dungeon-sheet-edge: #d9b98a;
    --dungeon-sheet-gutter: 18px;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    height: 100vh;
    height: 100dvh;
    min-height: 420px;
    scroll-snap-align: start;
    scroll-margin-top: 0;
}

.dungeon-page .dungeon-header--slim {
    flex: none;
}

.dungeon-page .dungeon-editor {
    flex: 1 1 0;
    height: auto;
}

/* The map is a sheet lying on the panel: the panel round it is plain (nothing outside the sheet looks like map), the
   sheet has a light frame and a shadow, and the padding leaves room for its edge handles (dungeon_map_sheet.js). */
.dungeon-page .dungeon-canvas-wrap {
    display: flex;
    position: relative;
    padding: var(--dungeon-sheet-gutter);
    background: var(--dungeon-sheet-desk);
}

.dungeon-page #dungeon-canvas {
    flex: none;
    margin: auto;
    box-shadow: 0 0 0 2px var(--dungeon-sheet-edge), 0 12px 32px rgba(0, 0, 0, 0.6);
}

.dungeon-page[data-layout="phone"] #dungeon-canvas {
    margin: auto;
}

/* --- The view popover -------------------------------------------------------------------------------------------- */

.dungeon-page .dungeon-phone-only,
.dungeon-page .dungeon-view-label {
    display: none;
}

.dungeon-page[data-layout="phone"] .dungeon-phone-only {
    display: block;
    position: relative;
}

.dungeon-page .dungeon-view-panel {
    position: absolute;
    top: 0;
    right: calc(100% + 8px);
    z-index: 40;
    display: grid;
    gap: 6px;
    width: max-content;
    max-width: calc(100vw - 90px);
    padding: 8px;
    border: 1px solid rgba(242, 192, 128, 0.35);
    border-radius: 10px;
    background: var(--dungeon-surface);
    box-shadow: 0 14px 40px rgba(0, 0, 0, 0.55);
}

/* A landscape phone is shorter than the panel: it is laid on the screen beside the tool bar, from its top, and scrolls
   when the screen is still too short for it (it opens from the view button, which sits at the foot of the screen). */
.dungeon-page[data-layout="phone"][data-orient="landscape"] .dungeon-view-panel {
    position: fixed;
    top: 8px;
    right: 66px;
    max-height: calc(100dvh - 16px);
    overflow-y: auto;
    overscroll-behavior: contain;
}

.dungeon-page .dungeon-view-panel .dungeon-icon-btn,
.dungeon-page .dungeon-view-panel .dungeon-toggle {
    flex: none;
    width: auto;
    min-width: 44px;
    min-height: 44px;
    justify-content: flex-start;
    gap: 10px;
    padding: 0 14px;
    border-radius: 22px;
}

.dungeon-page .dungeon-view-panel .dungeon-view-label,
.dungeon-page .dungeon-view-panel .dungeon-toggle span {
    display: inline;
}

/* --- Phone: the tool bar is fixed to the screen's edge while any of the editor shows ----------------------------- */

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

.dungeon-page[data-layout="phone"] .dungeon-header--slim {
    margin: 0;
    border-radius: 0;
    border-width: 0 0 1px;
}

.dungeon-page[data-layout="phone"] .dungeon-editor {
    padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px));
}

.dungeon-page[data-layout="phone"] .dungeon-phonebar {
    display: none;
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1030;
    padding: 4px 6px calc(4px + env(safe-area-inset-bottom, 0px));
}

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

.dungeon-page[data-layout="phone"] .dungeon-toast {
    bottom: calc(76px + env(safe-area-inset-bottom, 0px));
}

/* Landscape phone: the bar is a rail fixed to the left edge, under the header; the header is one slim line. */
.dungeon-page[data-layout="phone"][data-orient="landscape"] .dungeon-editor {
    padding-bottom: 0;
    padding-left: calc(64px + env(safe-area-inset-left, 0px));
}

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

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

.dungeon-page[data-layout="phone"][data-orient="landscape"] .dungeon-header--slim .dungeon-header-actions {
    grid-column: 3;
}

.dungeon-page[data-layout="phone"][data-orient="landscape"] .dungeon-header--slim .dungeon-plan-note {
    grid-column: 2;
    grid-row: 1;
    position: relative;
    max-width: 9.5em;
    margin: 0;
    padding: 2px 8px;
    overflow: hidden;
    border-radius: 14px;
    font-size: 0.66rem;
    line-height: 1.3;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
}

.dungeon-page[data-layout="phone"][data-orient="landscape"] .dungeon-header--slim .dungeon-plan-note.is-expanded {
    position: absolute;
    top: calc(100% + 4px);
    right: 8px;
    z-index: 1060;
    width: min(420px, 80vw);
    max-width: none;
    overflow: visible;
    background: var(--dungeon-surface);
    border-radius: 8px;
    white-space: normal;
}

.dungeon-page[data-layout="phone"][data-orient="landscape"] .dungeon-header--slim .dungeon-plan-note.is-expanded .dungeon-plan-detail {
    display: inline;
}

.dungeon-page[data-layout="phone"][data-orient="landscape"] .dungeon-header--slim .dungeon-btn,
.dungeon-page[data-layout="phone"][data-orient="landscape"] .dungeon-header--slim .dungeon-icon-btn {
    min-height: 40px;
}

.dungeon-page[data-layout="phone"][data-orient="landscape"] .dungeon-header--slim .dungeon-title-input {
    min-height: 40px;
}

.dungeon-page[data-layout="phone"][data-orient="landscape"] .dungeon-header--slim .dungeon-plan-note {
    display: flex;
    align-items: center;
    min-height: 40px;
}

.dungeon-page[data-layout="phone"][data-orient="landscape"] .dungeon-map-actions {
    grid-auto-flow: row;
    grid-template-rows: none;
}

.dungeon-page[data-layout="phone"][data-orient="landscape"] .dungeon-canvas-wrap {
    padding-right: 58px;
}

.dungeon-page[data-layout="phone"][data-orient="landscape"] .dungeon-floor-tabs {
    max-width: calc(100% - 70px);
}

.dungeon-page[data-layout="phone"][data-orient="landscape"] .dungeon-statusbar .dungeon-map-caption {
    right: 66px;
}

.dungeon-page[data-layout="phone"][data-orient="landscape"] .dungeon-peek {
    right: 66px;
}

.dungeon-page[data-layout="phone"][data-orient="landscape"] .dungeon-flyout {
    left: calc(70px + env(safe-area-inset-left, 0px));
}

/* The title's pill is a dot on a phone: green when saved, amber while changes wait, red on a problem. */
.dungeon-page[data-layout="phone"] .dungeon-header--slim .dungeon-title-row .dungeon-save-status,
.dungeon-page[data-layout="phone"] .dungeon-header--slim .dungeon-title-row .dungeon-save-status.is-error {
    flex: none;
    width: 14px;
    min-width: 14px;
    height: 14px;
    min-height: 14px;
    max-width: 14px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: #e0a23a;
    font-size: 0;
    overflow: hidden;
}

.dungeon-page[data-layout="phone"] .dungeon-header--slim .dungeon-title-row .dungeon-save-status.is-saved {
    background: #3fbf8f;
}

.dungeon-page[data-layout="phone"] .dungeon-header--slim .dungeon-title-row .dungeon-save-status.is-error {
    background: var(--dungeon-danger);
}

.dungeon-page.is-fullscreen {
    height: 100%;
}

.dungeon-page[data-layout="phone"][data-orient="landscape"] .dungeon-header--slim .dungeon-plan-note strong {
    margin-right: 0.35em;
}

/* The view popover opens leftwards out of the cluster: the cluster must not clip it. */
.dungeon-page[data-layout="phone"] .dungeon-map-actions {
    overflow: visible;
}

.dungeon-page[data-layout="phone"] .dungeon-view-panel .dungeon-icon-btn,
.dungeon-page[data-layout="phone"] .dungeon-view-panel .dungeon-toggle {
    width: auto;
    min-width: 0;
    height: 44px;
    padding: 0 16px;
    justify-content: flex-start;
    white-space: nowrap;
    text-transform: none;
}

/* --- The overlay, hints on touch screens, the key's entries and the chips (dungeon_generator.js) ----------------------- */

/* What lies on the map (the pointer's square, the selection, a piece being placed) is drawn on a canvas of its own over
   the map's: the script gives it the map's size and place in the frame, and it never takes the pointer. */
.dungeon-overlay-canvas {
    position: absolute;
    left: 0;
    top: 0;
    pointer-events: none;
}

/* What a field means in full is its tooltip where a pointer can hover; a touch screen has no tooltips and shows it as a
   line under the field instead. */
.dungeon-field-hint {
    display: none;
    color: var(--dungeon-muted);
    font-size: 0.78rem;
    line-height: 1.3;
}

@media (any-pointer: coarse) {
    .dungeon-field-hint {
        display: block;
    }

    .dungeon-field--check {
        flex-wrap: wrap;
    }

    .dungeon-field--check .dungeon-field-hint {
        flex: 0 0 100%;
    }

    /* A button that shares a row of the form with a field made taller by its hint keeps its own height. */
    .dungeon-inspector-grid > .dungeon-btn {
        align-self: start;
    }
}

/* The Map Key's entries are buttons to the keyboard too. */
.dungeon-key [data-key-type] {
    cursor: pointer;
}

.dungeon-key [data-key-type]:focus-visible {
    outline: 2px solid var(--dungeon-accent);
    outline-offset: 2px;
}

/* A swatch's chip is a small canvas, cropped to the chip. */
.dungeon-swatch-chip {
    overflow: hidden;
}

.dungeon-generator .dungeon-swatch-chip canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
    object-fit: cover;
}
