/* Map Generator: a map-first application on the site's dark palette. The tool uses the whole window; the map is the
 * page, the tools sit in a sidebar that becomes a bottom sheet (or a drawer on a phone held sideways) on small screens,
 * and the parts that float on the map are small, glassy and kept to its edges. */
.map-generator {
    --mg-bg: #0f1b21;
    --mg-surface: #13232a;
    --mg-surface-2: #1a2e37;
    --mg-raised: #223a45;
    --mg-border: #2c454f;
    --mg-hairline: rgba(255, 255, 255, 0.07);
    --mg-text: #e6eef0;
    --mg-strong: #fff6e4;
    --mg-muted: #a1b8be;
    /* The site's own palette (styles9.css .btn-buy / the tools' .btn-close-dnd): gold on dark navy. */
    --mg-gold: #e7bf8f;
    --mg-gold-ink: #152734;
    --mg-cream: #f6e6c9;
    --mg-accent: #e7bf8f;
    --mg-accent-rgb: 231, 191, 143;
    --mg-accent-hover: #f6e6c9;
    --mg-accent-ink: #152734;
    --mg-danger: #e06b6b;
    --mg-link: #e7bf8f;
    --mg-glass: rgba(13, 24, 29, 0.84);
    --mg-shadow: 0 8px 28px rgba(0, 0, 0, 0.38);
    --mg-side: clamp(320px, 24vw, 400px);
    --mg-gutter: clamp(12px, 1.4vw, 24px);
    --mg-bar: 56px;
    --mg-touch: 40px;
    --mg-radius: 10px;
    /* One screen tall (as the Dungeon and Battlemap generators are): header, bar and body share the window, and the body's
       sidebar and map each scroll or fit inside their own share. */
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    min-height: 520px;
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 0;
    color: var(--mg-text);
    background: var(--mg-bg);
}

.map-generator *,
.map-generator *::before,
.map-generator *::after {
    box-sizing: border-box;
}

/* The page is the tool: the hero above it keeps its picture but gives the map the room. */
.jumbo.site-jumbo:has(~ .main-content .map-generator) {
    min-height: clamp(120px, 11vw, 170px);
}

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

.map-generator [hidden] {
    display: none !important;
}

.map-generator .visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}

.map-generator :focus-visible {
    outline: 2px solid var(--mg-link);
    outline-offset: 2px;
}

.mg-fatal {
    padding: 12px 16px;
    margin: 12px var(--mg-gutter);
    border: 1px solid var(--mg-danger);
    border-radius: var(--mg-radius);
    background: rgba(224, 107, 107, 0.12);
    color: #ffd2d2;
}

/* --- Header ------------------------------------------------------------------------------------------------------ */

.mg-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 16px;
    padding: 10px var(--mg-gutter);
    background: var(--mg-surface);
    border-top: 1px solid var(--mg-hairline);
    border-bottom: 1px solid var(--mg-border);
}

.mg-title-row {
    display: flex;
    flex: 1 1 280px;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.map-generator .mg-title-input {
    flex: 1 1 auto;
    max-width: 560px;
    min-width: 0;
    min-height: var(--mg-touch);
    padding: 4px 12px;
    font-family: "Raleway", sans-serif;
    font-size: 1.2rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    color: var(--mg-strong);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    text-overflow: ellipsis;
}

.map-generator .mg-title-input:hover {
    border-color: var(--mg-border);
}

.map-generator .mg-title-input:focus {
    background: var(--mg-bg);
    border-color: var(--mg-gold);
    outline: none;
}

.mg-title-input::placeholder {
    color: var(--mg-muted);
    opacity: 0.8;
}

.mg-pill {
    flex: none;
    padding: 3px 10px;
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--mg-gold);
    background: rgba(242, 192, 128, 0.12);
    border: 1px solid rgba(242, 192, 128, 0.32);
    border-radius: 999px;
    white-space: nowrap;
}

/* The map's actions (undo, redo, new, export, save) sit on a bar over the map that stays in view as the page scrolls. */
.mg-toolbar {
    position: sticky;
    top: 0;
    z-index: 30;
    padding: 6px var(--mg-gutter);
    background: var(--mg-surface);
    border-bottom: 1px solid var(--mg-border);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.28);
}

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

/* On a wide screen the header is laid out as the Dungeon Generator's: the map's name centred on a line of its own, then
   what the plan allows; the actions are on the bar under it. */
@media (min-width: 900px) {
    .mg-title-row {
        flex: 1 0 100%;
        justify-content: center;
    }

    .map-generator .mg-title-input {
        max-width: 720px;
        font-size: 1.6rem;
        text-align: center;
    }

    .mg-header-actions {
        justify-content: flex-end;
    }
}

/* What a free plan allows, told as plainly as the Dungeon Generator tells it. */
.mg-plan-note {
    flex: 1 0 100%;
    margin: 0;
    padding: 10px 16px;
    font-size: 1rem;
    line-height: 1.5;
    text-align: center;
    color: var(--mg-text);
    background: rgba(242, 192, 128, 0.08);
    border: 1px solid rgba(242, 192, 128, 0.35);
    border-radius: 8px;
}

.mg-plan-note strong {
    color: var(--mg-gold);
}

/* A subscriber's note is quiet: what the plan gives, not an offer. */
.mg-plan-note.is-plan {
    padding: 6px 16px;
    font-size: 0.9rem;
    color: var(--mg-muted);
    background: none;
    border-color: var(--mg-border);
}

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

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

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

/* --- Buttons and fields ------------------------------------------------------------------------------------------ */

/* Text buttons wear the site's classes (btn btn-buy / btn btn-secondary btn-close-dnd, see dom.js button()); .mg-btn
   only lays their content out. Their colours, type and size are the shared component layer's (tool_components.css). */
.mg-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    max-width: 100%;
}

.map-generator :is(.btn-buy, .btn-close-dnd) {
    margin-top: 0;
    width: auto;
}

/* Icon-only buttons (undo, dice, zoom ...) in the same gold-on-navy, round. */
.mg-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: var(--mg-touch);
    min-height: var(--mg-touch);
    padding: 0;
    color: #e7bf8f;
    background: #151f25;
    border: 1px solid rgba(231, 191, 143, 0.55);
    border-radius: 50%;
    cursor: pointer;
    transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
}

.mg-icon-btn-small {
    width: 32px;
    min-height: 32px;
}

.mg-icon-btn:hover:not(:disabled) {
    color: #151f25;
    background: #e7bf8f;
    border-color: #e7bf8f;
}

.mg-btn:disabled,
.mg-icon-btn:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.mg-btn-small {
    min-height: 34px;
    padding: 4px 12px;
    font-size: 0.84rem;
}

.map-generator .mg-block {
    width: 100%;
}

/* A plain section card (the same frame as the collapsible groups). */
.mg-card {
    display: grid;
    gap: 10px;
    margin-bottom: 12px;
    padding: 14px;
    background: var(--mg-surface);
    border: 1px solid var(--mg-border);
    border-radius: var(--mg-radius);
}

.mg-danger {
    color: #ffb3b3;
}

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

/* The fields' colours, edges, arrows and focus are the shared component layer's (tool_components.css); here only their size. */
.map-generator input[type="text"],
.map-generator input[type="number"],
.map-generator select,
.map-generator textarea {
    width: 100%;
    min-width: 0;
    min-height: var(--mg-touch);
    padding: 6px 10px;
    font: inherit;
    font-size: 0.92rem;
}

.map-generator input[type="color"] {
    width: 44px;
    height: var(--mg-touch);
}

.map-generator input[type="range"] {
    width: 100%;
    min-width: 0;
    accent-color: var(--mg-accent);
}

.mg-field,
.mg-select {
    display: grid;
    gap: 4px;
    min-width: 0;
    margin-bottom: 10px;
}

.mg-field-label,
.mg-select label,
.mg-range-label,
.mg-inline-field span {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--mg-muted);
}

.mg-range {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 2px 8px;
    margin-bottom: 8px;
}

.mg-range input {
    grid-column: 1 / -1;
}

.mg-range-value {
    font-size: 0.82rem;
    font-variant-numeric: tabular-nums;
    color: var(--mg-strong);
}

.mg-check {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 32px;
}

.mg-check input {
    flex: none;
    width: 18px;
    height: 18px;
    accent-color: var(--mg-accent);
}

.mg-inline-field {
    display: inline-flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.mg-hint {
    display: block;
    margin: 2px 0 6px;
    font-size: 0.8rem;
    color: var(--mg-muted);
}

.mg-empty {
    color: var(--mg-muted);
    font-size: 0.9rem;
}

.mg-link {
    padding: 0;
    font: inherit;
    color: var(--mg-link);
    background: none;
    border: 0;
    text-decoration: underline;
    cursor: pointer;
}

/* --- Body: sidebar and stage ------------------------------------------------------------------------------------- */

.mg-body {
    position: relative;
    display: grid;
    flex: 1 1 0;
    grid-template-columns: var(--mg-side) minmax(0, 1fr);
    min-height: 0;
}

/* The header and the bar keep their own height; only the body gives way. */
.mg-fatal,
.mg-header,
.mg-toolbar {
    flex: none;
}

.mg-sidebar {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    background: var(--mg-surface);
    border-right: 1px solid var(--mg-border);
    overflow: hidden;
}

.mg-sheet-header {
    display: none;
}

.mg-tabs {
    display: flex;
    flex: none;
    border-bottom: 1px solid var(--mg-border);
}

.mg-tab {
    display: flex;
    flex: 1 1 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 0;
    min-height: 56px;
    padding: 8px 2px 6px;
    font: inherit;
    font-size: 0.74rem;
    font-weight: 600;
    color: var(--mg-muted);
    background: none;
    border: 0;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    transition: color 120ms ease, background-color 120ms ease;
}

.mg-tab span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

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

.mg-tab:hover {
    color: var(--mg-text);
    background: rgba(255, 255, 255, 0.03);
}

.mg-tab[aria-selected="true"] {
    color: var(--mg-gold);
    border-bottom-color: var(--mg-gold);
    background: var(--mg-surface-2);
}

.mg-panels {
    flex: 1 1 auto;
    min-height: 0;
    padding: 14px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
}

.mg-panel {
    min-width: 0;
}

.mg-group {
    margin-bottom: 12px;
    border: 1px solid var(--mg-border);
    border-radius: var(--mg-radius);
    background: rgba(26, 46, 55, 0.55);
}

.mg-group > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 11px 14px;
    font-weight: 700;
    color: var(--mg-gold);
    cursor: pointer;
    list-style: none;
}

.mg-group > summary::-webkit-details-marker {
    display: none;
}

.mg-group > summary::after {
    content: "\f078";
    font-family: "Font Awesome 6 Free", sans-serif;
    font-weight: 900;
    font-size: 0.74rem;
    color: var(--mg-muted);
}

.mg-group[open] > summary::after {
    content: "\f077";
}

.mg-group > :not(summary) {
    max-width: calc(100% - 28px);
    margin-right: 14px;
    margin-left: 14px;
}

.mg-group > :last-child {
    margin-bottom: 14px;
}

.mg-seed-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.mg-seed-row label {
    font-weight: 700;
}

.mg-card .mg-seed-row {
    margin-bottom: 0;
}

.mg-stale {
    color: var(--mg-gold);
}

.mg-summary ul,
.mg-list {
    margin: 0 0 10px;
    padding: 0;
    list-style: none;
}

.mg-summary h3 {
    font-size: 0.95rem;
}

.mg-summary li {
    font-size: 0.86rem;
    color: var(--mg-muted);
}

.mg-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 8px 0;
}

.mg-layer {
    display: grid;
    grid-template-columns: 22px minmax(0, 1fr);
    align-items: start;
    column-gap: 8px;
    padding: 4px 0;
    border-bottom: 1px solid var(--mg-hairline);
}

.mg-layer > i {
    margin-top: 8px;
    color: var(--mg-muted);
    text-align: center;
}

.mg-layer .mg-range {
    display: none;
    grid-column: 2;
}

.mg-layer.is-on .mg-range {
    display: grid;
}

.mg-layer.is-on > i {
    color: var(--mg-gold);
}

.mg-feature {
    display: grid;
    grid-template-columns: 22px minmax(0, 1fr);
    align-items: center;
    column-gap: 8px;
}

.mg-feature > i {
    color: var(--mg-muted);
    text-align: center;
}

.mg-list li {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--mg-hairline);
    font-size: 0.88rem;
}

.mg-list li > span:not(.mg-year):not(.mg-hint) {
    color: var(--mg-muted);
}

.mg-war-sides {
    flex-basis: 100%;
}

.mg-events-list li {
    flex-wrap: nowrap;
    align-items: flex-start;
}

.mg-events-list li > span:nth-child(2) {
    flex: 1 1 auto;
    min-width: 0;
}

.mg-year {
    flex: none;
    min-width: 62px;
    color: var(--mg-gold);
    font-variant-numeric: tabular-nums;
}

.mg-saved {
    justify-content: space-between;
}

.mg-saved > div:first-child {
    display: grid;
    min-width: 0;
}

.mg-saved .mg-actions {
    margin: 0;
}

.mg-saved.is-open {
    background: rgba(var(--mg-accent-rgb), 0.1);
}

/* Inspector cards */
.mg-card {
    margin-bottom: 12px;
    padding: 14px;
    background: var(--mg-surface-2);
    border: 1px solid var(--mg-border);
    border-radius: var(--mg-radius);
}

.mg-card > header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}

.mg-card h3 {
    margin: 0;
    min-width: 0;
    font-size: 1.02rem;
    color: var(--mg-strong);
    overflow-wrap: anywhere;
}

.mg-card-kind {
    flex: none;
    font-size: 0.74rem;
    font-weight: 600;
    color: var(--mg-gold);
}

.mg-facts {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 3px 12px;
    margin: 0 0 8px;
    font-size: 0.88rem;
}

.mg-facts dt {
    color: var(--mg-muted);
    font-weight: 400;
}

.mg-facts dd {
    margin: 0;
    color: var(--mg-strong);
    overflow-wrap: anywhere;
}

.mg-rename {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
}

.mg-rename > input {
    flex: 1 1 0;
    min-width: 0;
}

.mg-rename > .mg-btn {
    flex: none;
}

.mg-editors {
    display: grid;
    gap: 8px;
    margin-bottom: 8px;
}

.mg-events ul {
    margin: 6px 0 0;
    padding: 0;
    list-style: none;
    font-size: 0.84rem;
    color: var(--mg-muted);
}

.mg-events li {
    padding: 3px 0;
}

.mg-pin-icons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.mg-pin-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--mg-touch);
    height: var(--mg-touch);
    color: var(--mg-strong);
    background: var(--mg-bg);
    border: 1px solid var(--mg-border);
    border-radius: 8px;
    cursor: pointer;
}

.mg-pin-icon[aria-checked="true"] {
    color: var(--mg-gold-ink);
    background: var(--mg-gold);
    border-color: var(--mg-gold);
}

/* --- Stage ------------------------------------------------------------------------------------------------------- */

.mg-stage {
    position: relative;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background: var(--mg-bg);
}

.mg-viewport {
    position: absolute;
    inset: 0;
    touch-action: none;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.mg-viewport:active {
    cursor: grabbing;
}

.mg-gl,
.mg-overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.mg-overlay {
    pointer-events: none;
}

/* The parts that float on the map share one glass look. */
.mg-modes,
.mg-tools,
.mg-tool-options,
.mg-breadcrumb,
.mg-camera .mg-icon-btn,
.mg-camera .mg-segmented,
.mg-legend,
.mg-tip,
.mg-chip,
.mg-busy {
    background: var(--mg-glass);
    border: 1px solid var(--mg-border);
    box-shadow: var(--mg-shadow);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}

/* Top left: the map's modes, the way back out of a zoomed region, and the tools with their options. */
.mg-top {
    position: absolute;
    top: 12px;
    left: 12px;
    right: 72px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    pointer-events: none;
}

.mg-top > *,
.mg-toolbox > * {
    pointer-events: auto;
}

.mg-toolbox {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    max-width: 100%;
    max-height: calc(100dvh - 190px);
    pointer-events: none;
}

.mg-modes {
    position: relative;
    display: flex;
    gap: 2px;
    max-width: 100%;
    padding: 3px;
    border-radius: 12px;
}

.mg-mode-list {
    display: flex;
    flex: 1 1 auto;
    gap: 2px;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
}

.mg-mode-list::-webkit-scrollbar {
    display: none;
}

/* The one button that opens the modes as a list: only on a phone held sideways (below). */
.mg-modes-toggle {
    display: none;
}

.mg-mode {
    display: flex;
    flex: none;
    align-items: center;
    gap: 7px;
    min-height: max(38px, var(--mg-touch));
    padding: 0 12px;
    font: inherit;
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--mg-muted);
    background: none;
    border: 0;
    border-radius: 9px;
    cursor: pointer;
    transition: color 120ms ease, background-color 120ms ease;
}

.mg-mode i {
    font-size: 0.95rem;
}

.mg-mode:hover {
    color: var(--mg-strong);
    background: rgba(255, 255, 255, 0.07);
}

.mg-mode[aria-pressed="true"] {
    color: var(--mg-gold-ink);
    background: var(--mg-gold);
}

/* Too narrow for the modes' names: their icons alone. */
.mg-modes[data-compact="true"] .mg-mode {
    min-width: var(--mg-touch);
    justify-content: center;
    padding: 0 11px;
}

.mg-modes[data-compact="true"] .mg-mode span {
    display: none;
}

/* Where only icons fit, the mode on show keeps its name. */
.mg-modes[data-compact="true"] .mg-mode[aria-pressed="true"] span {
    display: inline;
}

.mg-breadcrumb {
    display: flex;
    align-items: center;
    gap: 6px;
    max-width: 100%;
    padding: 2px 12px;
    border-radius: 999px;
    font-size: 0.88rem;
}

.mg-crumb {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 30px;
    padding: 0 4px;
    font: inherit;
    font-weight: 600;
    color: var(--mg-link);
    background: none;
    border: 0;
    cursor: pointer;
}

.mg-crumb-current {
    color: var(--mg-strong);
    cursor: default;
}

.mg-crumb-sep {
    color: var(--mg-muted);
}

.mg-tools {
    display: flex;
    flex: none;
    flex-direction: column;
    gap: 2px;
    width: 72px;
    max-height: 100%;
    padding: 4px;
    overflow-y: auto;
    border-radius: 12px;
    scrollbar-width: none;
}

.mg-tools::-webkit-scrollbar {
    display: none;
}

.mg-tool {
    position: relative;
    display: flex;
    flex: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 50px;
    padding: 4px 2px;
    font: inherit;
    font-size: 0.64rem;
    font-weight: 600;
    color: var(--mg-muted);
    background: none;
    border: 0;
    border-radius: 9px;
    cursor: pointer;
    transition: color 120ms ease, background-color 120ms ease;
}

.mg-tool span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mg-tool i {
    font-size: 1.05rem;
}

.mg-tool:hover {
    color: var(--mg-strong);
    background: rgba(255, 255, 255, 0.07);
}

.mg-tool[aria-pressed="true"] {
    color: var(--mg-gold-ink);
    background: var(--mg-gold);
}

.mg-tool-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 230px;
    max-width: calc(100vw - 150px);
    max-height: 100%;
    padding: 10px 12px;
    overflow-y: auto;
    border-radius: 12px;
    font-size: 0.86rem;
}

.mg-tool-options[data-bare="true"] {
    display: none;
}

.mg-tool-options .mg-range,
.mg-tool-options .mg-select,
.mg-tool-options .mg-inline-field,
.mg-tool-options .mg-check {
    width: 100%;
    margin: 0;
}

.mg-tool-options input[type="text"],
.mg-tool-options select {
    min-height: 34px;
}

.mg-segmented {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.mg-seg {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 34px;
    padding: 4px 10px;
    font: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--mg-strong);
    background: var(--mg-surface-2);
    border: 1px solid var(--mg-border);
    border-radius: 8px;
    cursor: pointer;
}

.mg-seg:hover {
    border-color: rgba(242, 192, 128, 0.55);
}

.mg-seg[aria-pressed="true"] {
    color: var(--mg-gold-ink);
    background: var(--mg-gold);
    border-color: var(--mg-gold);
}

.mg-tool-options .mg-segmented .mg-seg {
    flex: 1 1 30%;
    padding: 4px 6px;
}

/* Top right: the camera. */
.mg-camera {
    position: absolute;
    top: 12px;
    right: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: stretch;
    width: 48px;
}

.mg-camera .mg-segmented {
    flex-direction: column;
    flex-wrap: nowrap;
    gap: 2px;
    padding: 3px;
    border-radius: 12px;
}

.mg-camera .mg-seg {
    flex-direction: column;
    gap: 2px;
    min-height: 44px;
    padding: 4px 2px;
    font-size: 0.6rem;
    line-height: 1.1;
    text-align: center;
    background: none;
    border-color: transparent;
    color: var(--mg-muted);
}

.mg-camera .mg-seg[aria-pressed="true"] {
    color: var(--mg-gold-ink);
    background: var(--mg-gold);
}

.mg-camera .mg-icon-btn {
    width: 48px;
    border-radius: 12px;
}

.mg-relief-only {
    display: none;
    flex-direction: column;
    gap: 6px;
}

.mg-camera[data-mode="relief"] .mg-relief-only {
    display: flex;
}

/* Bottom left (or right, wherever less land lies under it, see map_stage.js): what the colours mean. One panel with a header
   that folds it to a single line, and a body that scrolls inside the room it is given. */
.mg-legend {
    position: absolute;
    left: 12px;
    bottom: 12px;
    display: flex;
    flex-direction: column;
    width: 236px;
    max-width: min(280px, calc(100% - 84px));
    max-height: min(46%, 320px);
    font-size: 0.76rem;
    border-radius: 12px;
    overflow: hidden;
}

.mg-legend[data-corner="right"] {
    right: 12px;
    bottom: var(--mg-legend-lift, 12px);
    left: auto;
}

.mg-legend-head {
    display: flex;
    flex: none;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-height: 36px;
    padding: 6px 12px;
    font: inherit;
    font-weight: 700;
    color: var(--mg-gold);
    text-align: left;
    background: none;
    border: 0;
    cursor: pointer;
}

.mg-legend-title {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    font-size: 0.84rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mg-legend-mode {
    margin-left: 6px;
    font-weight: 500;
    color: var(--mg-muted);
}

.mg-legend-head .fa-chevron-down {
    flex: none;
    font-size: 0.7rem;
    color: var(--mg-muted);
    transition: transform 160ms ease;
}

.mg-legend[data-collapsed="true"] .fa-chevron-down {
    transform: rotate(180deg);
}

.mg-legend[data-collapsed="true"] .mg-legend-body {
    display: none;
}

.mg-legend-body {
    display: grid;
    flex: 1 1 auto;
    gap: 8px;
    min-height: 0;
    padding: 2px 12px 10px;
    overflow-y: auto;
    border-top: 1px solid var(--mg-hairline);
}

.mg-legend h3 {
    margin: 0 0 4px;
    font-size: 0.84rem;
    font-weight: 700;
    color: var(--mg-gold);
}

.mg-legend-block > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    cursor: pointer;
    list-style: none;
}

.mg-legend-block > summary::-webkit-details-marker {
    display: none;
}

.mg-legend-block > summary::after {
    content: "\f077";
    font-family: "Font Awesome 6 Free", sans-serif;
    font-weight: 900;
    font-size: 0.66rem;
    color: var(--mg-muted);
}

.mg-legend-block:not([open]) > summary::after {
    content: "\f078";
}

.mg-legend-block > summary h3 {
    margin: 0;
}

.mg-legend-hint {
    margin: 4px 0 6px;
    color: var(--mg-muted);
    line-height: 1.35;
}

.mg-gradient-bar {
    height: 10px;
    border-radius: 5px;
    border: 1px solid rgba(255, 255, 255, 0.25);
}

.mg-gradient-ticks {
    position: relative;
    height: 16px;
    margin-bottom: 2px;
}

.mg-gradient-ticks span {
    position: absolute;
    top: 2px;
    transform: translateX(-50%);
    white-space: nowrap;
    color: var(--mg-muted);
}

.mg-gradient-ticks span:first-child {
    transform: none;
}

.mg-gradient-ticks span:last-child {
    transform: translateX(-100%);
}

.mg-classes {
    margin: 0;
    padding: 0;
    list-style: none;
}

.mg-classes li {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 1px 0;
    color: var(--mg-strong);
}

.mg-swatch {
    flex: none;
    width: 14px;
    height: 14px;
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 3px;
}

.mg-swatch.is-hatched {
    background: repeating-linear-gradient(45deg, #fff 0 3px, #111 3px 6px) !important;
}

/* Bottom: a quiet tip that can be dismissed, the cell under the pointer, the chip that opens the details. */
.mg-tip {
    position: absolute;
    bottom: 12px;
    left: 50%;
    display: none;
    align-items: center;
    gap: 6px;
    max-width: calc(100% - 560px);
    padding: 3px 4px 3px 14px;
    transform: translateX(-50%);
    border-radius: 999px;
    font-size: 0.8rem;
    color: var(--mg-muted);
}

.mg-tip-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mg-tip .mg-icon-btn {
    flex: none;
    width: 28px;
    min-height: 28px;
    color: var(--mg-muted);
    background: none;
    border-color: transparent;
}

.mg-hover {
    position: absolute;
    right: 12px;
    bottom: 12px;
    max-width: calc(100% - 24px);
    padding: 3px 10px;
    font-size: 0.78rem;
    color: var(--mg-strong);
    background: var(--mg-glass);
    border-radius: 8px;
    pointer-events: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mg-hover:empty {
    display: none;
}

/* The hint stands above the cell under the pointer, never under it. */
.mg-stage:has(.mg-hover:not(:empty)) .mg-tip {
    bottom: 44px;
}

.mg-chip {
    position: absolute;
    left: 50%;
    bottom: 56px;
    display: none;
    align-items: center;
    gap: 10px;
    max-width: calc(100% - 24px);
    padding: 6px 8px 6px 14px;
    transform: translateX(-50%);
    border-radius: 999px;
}

.mg-chip-text {
    overflow: hidden;
    font-weight: 600;
    color: var(--mg-strong);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mg-busy {
    position: absolute;
    left: 50%;
    bottom: 14px;
    display: none;
    align-items: center;
    gap: 10px;
    max-width: calc(100% - 24px);
    padding: 8px 16px;
    transform: translateX(-50%);
    color: var(--mg-strong);
    border-radius: 999px;
    font-size: 0.9rem;
}

.mg-busy[data-phase="pending"],
.mg-busy[data-phase="working"],
.mg-busy[data-phase="error"] {
    display: flex;
}

/* Nothing generated yet: the stage waits for the user to ask for a world; the map's own tools stay out of the way. The card
   stands in the middle of the stage, like every other window of the site. */
.mg-busy[data-first="true"][data-phase="idle"] {
    display: flex;
}

.mg-busy[data-first="true"][data-phase="idle"],
.mg-busy[data-first="true"][data-phase="working"],
.mg-busy[data-first="true"][data-phase="pending"] {
    top: 50%;
    bottom: auto;
    padding: 22px 28px;
    border-radius: 16px;
    transform: translate(-50%, -50%);
    text-align: center;
}

.mg-busy[data-first="true"][data-phase="idle"] {
    flex-direction: column;
    gap: 6px;
    width: min(380px, calc(100% - 32px));
}

.mg-empty-mark {
    display: grid;
    place-items: center;
    width: 56px;
    height: 56px;
    margin-bottom: 6px;
    font-size: 1.5rem;
    color: var(--mg-gold);
    background: rgba(242, 192, 128, 0.1);
    border: 1px solid rgba(242, 192, 128, 0.3);
    border-radius: 50%;
}

.mg-empty-title {
    margin: 0;
    font-family: "Raleway", sans-serif;
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--mg-strong);
}

.mg-empty-text {
    margin: 4px 0 0;
    color: var(--mg-muted);
    line-height: 1.45;
}

/* On a short screen the card is tighter, so its button clears the fold under the hero. */
@media (max-height: 960px) {
    .mg-busy[data-first="true"][data-phase="idle"] {
        padding: 12px 22px 14px;
    }

    .mg-busy[data-first="true"][data-phase="idle"] .mg-empty-mark {
        display: none;
    }
}

.mg-stage:has(.mg-busy[data-first="true"]) .mg-top,
.mg-stage:has(.mg-busy[data-first="true"]) .mg-camera,
.mg-stage:has(.mg-busy[data-first="true"]) .mg-legend,
.mg-stage:has(.mg-busy[data-first="true"]) .mg-tip,
.mg-stage:has(.mg-busy[data-phase="working"]) .mg-tip,
.mg-stage:has(.mg-busy[data-phase="pending"]) .mg-tip,
.mg-stage:has(.mg-busy[data-phase="error"]) .mg-tip {
    display: none;
}

.mg-busy[data-phase="error"] {
    flex-wrap: wrap;
    justify-content: center;
    border-color: var(--mg-danger);
    border-radius: 14px;
}

.mg-spinner {
    flex: none;
    width: 18px;
    height: 18px;
    border: 3px solid rgba(242, 192, 128, 0.3);
    border-top-color: var(--mg-gold);
    border-radius: 50%;
    animation: mg-spin 0.9s linear infinite;
}

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

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

.mg-toast.is-visible {
    opacity: 1;
    transform: none;
}

.mg-toast.is-error {
    border-color: var(--mg-danger);
    color: #ffd2d2;
}

/* The tip only where there is a mouse and room for it. */
@media (min-width: 1200px) and (any-pointer: fine) {
    .mg-tip {
        display: flex;
    }
}

/* A pointer that hovers gets the names of the tools. */
@media (any-pointer: fine) {
    .mg-tool::after {
        content: attr(aria-label);
        position: absolute;
        left: calc(100% + 10px);
        top: 50%;
        padding: 4px 9px;
        font-size: 0.78rem;
        color: var(--mg-strong);
        background: #0b1519;
        border: 1px solid var(--mg-border);
        border-radius: 6px;
        opacity: 0;
        pointer-events: none;
        transform: translateY(-50%);
        transition: opacity 120ms ease;
        white-space: nowrap;
    }

    .mg-tool:hover::after {
        opacity: 1;
    }
}

/* --- Tablets and phones: the sidebar is a sheet over the map's lower part ------------------------------------------ */

@media (max-width: 899px) {
    /* The tool is exactly one screen: a compact header, then the map with its bar of tabs at the bottom. */
    .map-generator {
        --mg-gutter: 10px;
        display: flex;
        flex-direction: column;
        height: 100dvh;
        min-height: 0;
    }

    .mg-header {
        flex: none;
        padding: 8px 10px;
        gap: 6px;
    }

    .mg-plan-note {
        padding: 6px 10px;
        font-size: 0.88rem;
        line-height: 1.35;
    }

    .map-generator .mg-title-input {
        font-size: 1.05rem;
    }

    .mg-toolbar {
        flex: none;
        padding: 6px 10px;
    }

    .mg-header-actions {
        width: 100%;
        flex-wrap: nowrap;
        justify-content: space-between;
        gap: 6px;
    }

    .mg-header-actions .mg-btn span {
        display: none;
    }

    .mg-header-actions .mg-btn,
    .mg-header-actions .mg-icon-btn {
        flex: 1 1 0;
        min-width: 0;
        min-height: var(--mg-touch);
        padding: 0 8px;
    }

    .mg-header-actions #mg-save {
        flex: 2 1 0;
    }

    .mg-header-actions #mg-save span {
        display: inline;
    }

    .mg-body {
        display: block;
        flex: 1 1 auto;
        min-height: 0;
        height: auto;
    }

    .mg-stage {
        height: 100%;
    }

    /* The controls on the map: modes along the top, tools in a row along the bottom (above the tabs), the camera
       a slim column at the right; the map is framed between them. */
    .mg-top {
        top: 8px;
        right: 8px;
        bottom: calc(var(--mg-bar) + 8px);
        left: 8px;
    }

    .mg-toolbox {
        flex-direction: column-reverse;
        align-items: stretch;
        width: 100%;
        max-height: none;
        margin-top: auto;
    }

    .mg-tools {
        flex-direction: row;
        width: auto;
        max-width: 100%;
        overflow-x: auto;
        overflow-y: hidden;
    }

    .mg-tool {
        flex: 1 0 44px;
        min-height: 44px;
    }

    .mg-tool span {
        display: none;
    }

    /* The camera is a row under the modes (below the breadcrumb when there is one), so it never covers the map. */
    .mg-camera {
        top: 60px;
        right: 8px;
        flex-flow: row wrap;
        justify-content: flex-end;
        width: auto;
        max-width: calc(100% - 16px);
    }

    .mg-stage:has(#mg-breadcrumb:not([hidden])) .mg-camera {
        top: 104px;
    }

    .mg-camera .mg-segmented,
    .mg-relief-only {
        flex-direction: row;
    }

    .mg-camera .mg-seg {
        width: 48px;
        min-height: 40px;
    }

    .mg-camera .mg-icon-btn {
        width: 40px;
        min-height: 40px;
    }

    .mg-modes {
        width: 100%;
        justify-content: space-between;
    }

    /* On a small screen the modes keep their full names and the bar scrolls sideways (a touch screen has no hover for names). */
    .mg-modes {
        justify-content: flex-start;
    }

    .mg-mode-list {
        scroll-snap-type: x proximity;
    }

    .mg-mode {
        flex: none;
        min-height: var(--mg-touch);
        padding: 0 12px;
        scroll-snap-align: start;
    }

    .mg-modes[data-compact="true"] .mg-mode span,
    .mg-mode span {
        display: inline;
    }

    .mg-sidebar {
        position: absolute;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: 6;
        max-height: 100%;
        background: var(--mg-surface);
        border-top: 1px solid var(--mg-border);
        border-right: 0;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.45);
    }

    .mg-sheet-header {
        display: none;
        align-items: center;
        justify-content: space-between;
        order: 0;
        padding: 6px 10px 0 16px;
        font-weight: 700;
        color: var(--mg-gold);
    }

    .map-generator[data-sheet="open"] .mg-sheet-header {
        display: flex;
    }

    .mg-panels {
        order: 1;
        display: none;
        max-height: min(52dvh, 560px);
    }

    .map-generator[data-sheet="open"] .mg-panels {
        display: block;
    }

    .mg-tabs {
        order: 2;
        height: var(--mg-bar);
        border-top: 1px solid var(--mg-border);
        border-bottom: 0;
    }

    .mg-tab {
        min-height: 0;
        border-bottom: 0;
        border-top: 3px solid transparent;
    }

    .mg-tab[aria-selected="true"] {
        border-top-color: var(--mg-gold);
    }

    .map-generator[data-sheet="closed"] .mg-tab[aria-selected="true"] {
        border-top-color: transparent;
        background: none;
        color: var(--mg-muted);
    }

    .mg-chip {
        display: flex;
        bottom: calc(var(--mg-bar) + 52px);
    }

    .mg-chip[hidden] {
        display: none;
    }

    .mg-busy {
        bottom: calc(var(--mg-bar) + 12px);
    }

    .mg-legend {
        bottom: calc(var(--mg-bar) + 68px);
        width: 220px;
        max-height: 30%;
    }

    .mg-hover {
        display: none;
    }

    .mg-orient {
        bottom: calc(var(--mg-bar) + 72px);
    }

    .map-generator[data-sheet="open"] .mg-chip,
    .map-generator[data-sheet="open"] .mg-legend {
        display: none;
    }

    .mg-toast {
        right: 12px;
        bottom: 78px;
        left: 12px;
        max-width: none;
    }
}

/* A phone held sideways: one compact header row, the sheet a drawer at the left with its tabs under it, the modes and
   the camera along the top of the map and the tools in a two-column block at its left, so the map keeps its height. */
@media (max-width: 899px) and (orientation: landscape) and (max-height: 560px) {
    .map-generator {
        --mg-bar: 48px;
    }

    /* The map is what matters here: the title, the plan and the actions share one row above it. */
    .map-generator {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-rows: auto minmax(0, 1fr);
    }

    .mg-fatal {
        grid-column: 1 / -1;
    }

    .mg-header {
        flex: 1 1 0;
        flex-wrap: nowrap;
        min-width: 0;
        padding: 4px 8px;
        gap: 2px 8px;
        border-bottom: 0;
    }

    .mg-title-row {
        flex: 0 1 220px;
    }

    .map-generator .mg-title-input {
        min-height: 40px;
    }

    .mg-toolbar {
        flex: none;
        padding: 4px 8px;
        border-bottom: 0;
        box-shadow: none;
    }

    .mg-header-actions {
        flex: none;
        width: auto;
    }

    .mg-header-actions .mg-btn,
    .mg-header-actions .mg-icon-btn {
        flex: none;
        width: 44px;
        min-height: var(--mg-touch);
        padding: 0;
    }

    .mg-header-actions #mg-save {
        flex: none;
        width: auto;
        padding: 0 14px;
    }

    .mg-body {
        grid-column: 1 / -1;
        min-height: 0;
        border-top: 1px solid var(--mg-border);
    }

    .mg-plan-note {
        flex: 1 1 0;
        min-width: 0;
        overflow: hidden;
        padding: 4px 8px;
        font-size: 0.72rem;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .mg-sidebar {
        right: auto;
        width: min(360px, 48vw);
        border-radius: 0 16px 0 0;
    }

    .mg-panels {
        max-height: calc(100dvh - 60px - var(--mg-bar) - 40px);
    }

    .mg-tab span {
        display: none;
    }

    /* The camera buttons take the right of the top row; the modes are one button that opens them as a list. */
    .mg-modes {
        width: auto;
    }

    .mg-modes-toggle {
        display: flex;
        align-items: center;
        gap: 8px;
        min-height: var(--mg-touch);
        padding: 0 12px;
        font: inherit;
        font-size: 0.84rem;
        font-weight: 700;
        color: var(--mg-gold-ink);
        background: var(--mg-gold);
        border: 0;
        border-radius: 9px;
        cursor: pointer;
    }

    .mg-modes-toggle .fa-chevron-down {
        font-size: 0.7rem;
    }

    .mg-modes[data-open="true"] .fa-chevron-down {
        transform: rotate(180deg);
    }

    .mg-mode-list {
        position: absolute;
        top: calc(100% + 6px);
        left: 0;
        z-index: 8;
        display: none;
        flex-direction: column;
        width: max-content;
        min-width: 100%;
        max-height: calc(100dvh - 130px);
        padding: 3px;
        overflow: hidden auto;
        background: var(--mg-glass);
        border: 1px solid var(--mg-border);
        border-radius: 12px;
        box-shadow: var(--mg-shadow);
    }

    .mg-modes[data-open="true"] .mg-mode-list {
        display: flex;
    }

    .map-generator[data-sheet="closed"] .mg-modes {
        max-width: calc(100% - 340px);
    }

    /* The modes in the open list show their names whatever the room (they are stacked, not side by side). */
    .mg-modes[data-compact] .mg-mode span {
        display: inline;
    }

    .map-generator[data-sheet="open"] .mg-top {
        left: calc(min(360px, 48vw) + 12px);
    }

    .mg-toolbox {
        flex-direction: row;
        align-items: flex-start;
        width: auto;
        margin-top: 0;
    }

    .mg-tools {
        display: grid;
        grid-auto-flow: column;
        grid-template-rows: repeat(4, 44px);
        gap: 2px;
        width: auto;
        overflow: visible;
    }

    .mg-tools .mg-tool {
        width: 44px;
        min-height: 44px;
    }

    .mg-camera,
    .mg-stage:has(#mg-breadcrumb:not([hidden])) .mg-camera {
        top: 8px;
        max-width: calc(100% - 360px);
    }

    /* With the drawer open the modes take the top row of what is left, and the camera goes under them. */
    .map-generator[data-sheet="open"] .mg-camera {
        top: 60px;
        max-width: calc(100% - min(360px, 48vw) - 120px);
    }

    .mg-chip {
        bottom: calc(var(--mg-bar) + 10px);
        left: calc(min(360px, 48vw) + 12px);
        transform: none;
    }

    .mg-legend {
        left: auto;
        right: 8px;
        bottom: 8px;
    }

    .mg-orient {
        right: auto;
        bottom: 8px;
        left: calc(100% - 90px);
        flex-direction: row;
        align-items: flex-end;
    }
}

@media (any-pointer: coarse) {
    .map-generator {
        --mg-touch: 44px;
    }

    .mg-tool {
        min-height: 52px;
    }

    .mg-hover {
        display: none;
    }

    .map-generator input[type="range"] {
        min-height: 40px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .mg-spinner,
    .mg-btn.is-busy::after {
        animation-duration: 3s;
    }

    .mg-toast,
    .mg-btn,
    .mg-icon-btn,
    .mg-mode,
    .mg-tool,
    .mg-tab {
        transition: none;
    }
}

/* --- Language model sections, features and peoples, lore text ---------------------------------------------------- */

.mg-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 6px 0 10px;
}

.mg-chip-example {
    max-width: 100%;
    padding: 5px 12px;
    font: inherit;
    font-size: 0.8rem;
    line-height: 1.3;
    text-align: left;
    color: var(--mg-link);
    background: var(--mg-bg);
    border: 1px solid var(--mg-border);
    border-radius: 14px;
    cursor: pointer;
}

.mg-chip-example:hover {
    border-color: var(--mg-link);
}

.mg-ai-progress {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin: 10px 0;
    font-size: 0.86rem;
    color: var(--mg-gold);
}

.mg-ai-error {
    color: #ffb3b3;
}

.mg-name-ai .mg-btn {
    margin-bottom: 4px;
}

.mg-world-list {
    margin: 0 0 8px;
}

.mg-world-row {
    align-items: flex-start;
    flex-wrap: nowrap !important;
}

.mg-world-fields {
    display: grid;
    flex: 1 1 auto;
    gap: 2px;
    min-width: 0;
}

.mg-world-row .mg-field,
.mg-world-row .mg-select {
    margin-bottom: 4px;
}

.mg-lore-text {
    display: block;
    flex-basis: 100%;
    margin: 0 0 8px;
    font-size: 0.86rem;
    font-style: italic;
    color: #e8dcc4 !important;
}

.mg-world-name {
    margin: 0 0 4px;
    font-family: "Raleway", sans-serif;
    font-size: 1.1rem;
    color: var(--mg-strong);
}

/* --- Phones: every tool is in view (icons; the names are in each button's label) ------------------------------------ */

@media (max-width: 599px) {
    .mg-tool span {
        display: none;
    }

    .mg-tool {
        min-height: 44px;
    }
}


/* --- The map has the keyboard ---------------------------------------------------------------------------------------- */

.mg-viewport:focus {
    outline: none;
}

.mg-viewport:focus-visible,
.mg-viewport:focus {
    box-shadow: inset 0 0 0 2px rgba(231, 191, 143, 0.75);
}

.mg-viewport:focus:not(:focus-visible) {
    box-shadow: inset 0 0 0 2px rgba(231, 191, 143, 0.28);
}

.mg-shortcuts {
    position: absolute;
    top: 12px;
    right: 72px;
    z-index: 8;
    width: min(340px, calc(100% - 96px));
    padding: 12px 14px;
    background: var(--mg-glass);
    border: 1px solid var(--mg-border);
    border-radius: 12px;
    box-shadow: var(--mg-shadow);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}

.mg-shortcuts-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.mg-shortcuts h3 {
    margin: 0;
    font-size: 0.95rem;
    color: var(--mg-gold);
}

.mg-shortcut-list {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 6px 12px;
    margin: 6px 0 0;
    font-size: 0.82rem;
}

.mg-shortcut-list dt {
    font-weight: 700;
    color: var(--mg-strong);
    white-space: nowrap;
}

.mg-shortcut-list dd {
    margin: 0;
    color: var(--mg-muted);
}

/* --- Compass and scale bar ---------------------------------------------------------------------------------------------- */

.mg-orient {
    position: absolute;
    right: 12px;
    bottom: 44px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    pointer-events: none;
}

.mg-compass {
    width: 52px;
    height: 52px;
    transition: transform 120ms linear;
}

.mg-compass svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.55));
}

.mg-compass-ring {
    fill: var(--mg-glass);
    stroke: var(--mg-gold);
    stroke-width: 1.5;
}

.mg-compass-north {
    fill: var(--mg-gold);
}

.mg-compass-north-dark {
    fill: #b58a55;
}

.mg-compass-south {
    fill: #a1b8be;
}

.mg-compass-south-dark {
    fill: #667d84;
}

.mg-compass-letter {
    font: 700 9px "Cinzel", Georgia, serif;
    fill: #fff6e4;
    paint-order: stroke;
    stroke: #0f1b21;
    stroke-width: 2px;
}

.mg-scale {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    padding: 3px 8px 5px;
    font-size: 0.74rem;
    font-weight: 600;
    color: var(--mg-strong);
    background: var(--mg-glass);
    border-radius: 8px;
}

.mg-scale-bar {
    display: block;
    height: 6px;
    border: 2px solid var(--mg-strong);
    border-top: 0;
}

/* --- A message with a button, the export window, the history's filters ---------------------------------------------- */

.mg-toast.has-action {
    display: flex;
    align-items: center;
    gap: 12px;
    pointer-events: auto;
}

.mg-toast-action {
    flex: none;
}

.mg-export {
    width: min(460px, calc(100vw - 24px));
    max-height: calc(100dvh - 24px);
    padding: 18px 20px;
    overflow-y: auto;
    color: var(--mg-text);
    background: var(--mg-surface);
    border: 1px solid var(--mg-border);
    border-radius: 14px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
}

.mg-export::backdrop {
    background: rgba(5, 10, 13, 0.7);
}

.mg-export-title {
    margin: 0 0 12px;
    font-family: "Raleway", sans-serif;
    font-size: 1.2rem;
    color: var(--mg-strong);
}

.mg-export .mg-select,
.mg-export .mg-hint {
    margin-bottom: 10px;
}

.mg-export-progress {
    display: block;
    width: 100%;
    height: 10px;
    margin: 4px 0 8px;
    accent-color: var(--mg-gold);
}

.mg-export-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 6px;
}

.map-generator input[type="search"].mg-history-filter {
    width: 100%;
    min-height: var(--mg-touch);
    margin-bottom: 8px;
    padding: 6px 12px;
    color: var(--mg-text);
    background: var(--mg-bg);
    border: 1px solid var(--mg-border);
    border-radius: 8px;
}

.map-generator input[type="search"].mg-history-filter:focus {
    border-color: var(--mg-gold);
    outline: none;
}

.mg-era > .mg-list,
.mg-era > .mg-lore-text {
    margin-top: 6px;
}

/* --- Touch screens: every control is at least 40 px each way --------------------------------------------------------- */

@media (any-pointer: coarse), (max-width: 899px) {
    .map-generator input[type="range"] {
        min-height: 40px;
    }

    .mg-icon-btn-small {
        width: var(--mg-touch);
        min-height: var(--mg-touch);
    }

    .mg-btn-small,
    .mg-chip-example {
        min-height: var(--mg-touch);
    }
}

/* One swipe from the banner brings the tool to the top of the screen, as on the other generators. The page scrolls in
   the body, so both it and the document carry the snap. */
html:has(#mg-app),
html:has(#mg-app) body {
    scroll-snap-type: y proximity;
}

/* The top of the page is a resting place too (the site's navbar is the first element of the body): a fresh load shows the
   banner, and one deliberate scroll docks the tool. With the tool as the only snap point it lies within "proximity" of the
   top on a short screen and the page would dock by itself. */
html:has(#mg-app) body > .custom-navbar {
    scroll-snap-align: start;
}

#mg-app {
    scroll-snap-align: start;
}

/* The confirmation dialog (dom.js confirmDialog) is the export window's, narrower; its main action warns. */
.mg-confirm {
    width: min(400px, calc(100vw - 24px));
}

.mg-confirm .mg-hint {
    font-size: 0.92rem;
    color: var(--mg-text);
}

.mg-btn-danger.btn-buy {
    color: #fff;
    background: var(--mg-danger);
    border-color: var(--mg-danger);
}
