.hexmap-app {
    display: flex;
    gap: 12px;
    height: calc(100vh - 190px);
    min-height: 420px;
}

/* Bootstrap's display utilities are !important and would otherwise beat the hidden attribute. */
.hexmap-app [hidden] { display: none !important; }

.hexmap-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.hexmap-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    min-height: 31px;
}

.hexmap-toolbar label {
    font-size: 0.8rem;
    color: var(--bs-secondary-color);
    margin: 0;
}

.hexmap-toolbar .form-select {
    width: auto;
}

.hexmap-svg {
    flex: 1;
    width: 100%;
    background: #23262b;
    border: 1px solid var(--bs-border-color);
    border-radius: 4px;
    cursor: grab;
    touch-action: none;
    user-select: none;
}

.hexmap-svg.tool-paint { cursor: crosshair; }
.hexmap-svg.panning { cursor: grabbing; }

.hexmap-side {
    width: 340px;
    flex-shrink: 0;
    overflow-y: auto;
    font-size: 0.875rem;
}

.hexmap-side section {
    border: 1px solid var(--bs-border-color);
    border-radius: 4px;
    padding: 10px 12px;
    margin-bottom: 10px;
    background: var(--bs-body-bg);
}

.hexmap-side h2 {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 0 0 8px;
}

.hexmap-side dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; }
.hexmap-side dt { font-weight: 500; color: var(--bs-secondary-color); }
.hexmap-side dd { margin: 0; }
.hexmap-side .field { margin-bottom: 8px; }
.hexmap-side .field > label { display: block; font-weight: 500; color: var(--bs-secondary-color); margin-bottom: 2px; }
.hexmap-side .check-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 3px; }
.hexmap-side .check-row .extra { color: var(--bs-secondary-color); font-size: 0.8rem; }
.hexmap-side .check-row .warn { color: var(--pfkm-warn-text); font-size: 0.8rem; flex-basis: 100%; padding-left: 20px; }
.hexmap-side .check-row input[type="text"] { flex: 1; min-width: 80px; }

.hex-actions { border-top: 1px solid var(--bs-border-color); margin-top: 12px; padding-top: 10px; }
.hex-actions .summary { margin-bottom: 8px; color: var(--bs-secondary-color); }
.hex-actions .action-row { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.hex-actions .action-row .extra { color: var(--bs-secondary-color); font-size: 0.8rem; }
.hex-actions details { margin-top: 6px; font-size: 0.8rem; color: var(--bs-secondary-color); }
.hex-actions details summary { cursor: pointer; }
.hex-actions .blocked { margin-top: 3px; }

.swatch {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 3px;
    border: 1px solid var(--pfkm-swatch-border);
    vertical-align: -2px;
    margin-right: 5px;
}

.legend-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 8px; }
.legend-grid code { color: var(--bs-body-color); font-weight: 600; }

/* --- hexes --- */
.hex .terrain { stroke: #3a3a3a; stroke-width: 1; }
.hex .terrain.fog { fill: #33373d; stroke: #454a52; }
/* The two tint variables are set on the svg by the map's settings sliders; unset, the values here apply. */
.hex .terrain:not(.fog) { fill-opacity: var(--pfkm-terrain-tint, 1); }
.hex .owner { opacity: 0.45; pointer-events: none; }
.hex .unexplored { fill: #000; opacity: var(--pfkm-unexplored-tint, 0.4); pointer-events: none; }
.hex .hidden-mark { fill: none; stroke: #a21caf; stroke-width: 2; stroke-dasharray: 3 3; pointer-events: none; }
.hex .status { fill: none; stroke-width: 2.5; pointer-events: none; }
.hex .status.dashed { stroke-dasharray: 5 3; }
.hex text { pointer-events: none; text-anchor: middle; font-family: system-ui, sans-serif; }
.hex .coord { font-size: 7px; fill: rgba(0, 0, 0, 0.55); }
.hex .terrain.fog ~ .coord { fill: rgba(255, 255, 255, 0.3); }
.hex .settlement { font-size: 9px; font-weight: 700; fill: #111; paint-order: stroke; stroke: #fff; stroke-width: 2.5px; }
.hex .features { font-size: 8px; font-style: italic; fill: #0b3d91; paint-order: stroke; stroke: rgba(255, 255, 255, 0.7); stroke-width: 2px; }
.hex .improvements { font-size: 8px; font-weight: 700; fill: #3b1f00; paint-order: stroke; stroke: rgba(255, 255, 255, 0.7); stroke-width: 2px; }
.hex.painting .terrain { stroke: #f59e0b; stroke-width: 3; }

.cursor { fill: none; stroke: #fff; stroke-width: 3; pointer-events: none; filter: drop-shadow(0 0 2px #000); }

/* --- background picture: terrain becomes a tint over it; fogged hexes stay solid and cover it --- */
.hexmap-svg image.background { pointer-events: none; }
.hide-background image.background { display: none; }
.has-background:not(.hide-background) .hex .terrain:not(.fog) { fill-opacity: var(--pfkm-terrain-tint, 0.3); stroke: rgba(0, 0, 0, 0.5); }
.has-background:not(.hide-background).hide-terrain .hex .terrain:not(.fog) { fill-opacity: 0; }
.has-background:not(.hide-background) .hex .terrain:not(.fog) ~ .coord {
    fill: rgba(255, 255, 255, 0.85);
    paint-order: stroke;
    stroke: rgba(0, 0, 0, 0.6);
    stroke-width: 1.5px;
}
.hexmap-background .calibration { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.hexmap-background .calibration label { font-size: 0.8rem; color: var(--bs-secondary-color); margin: 0; }

/* --- icons placed by the GM (Font Awesome or RPG Awesome glyphs in a foreignObject) --- */
.icons, .icons * { pointer-events: none; }
.tool-icon .map-icon, .tool-icon .map-icon * { pointer-events: all; cursor: move; }
.hexmap-svg.tool-icon { cursor: crosshair; }
.hide-icons .icons { display: none; }
.map-icon foreignObject { overflow: visible; }
.map-icon .glyph {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    filter: drop-shadow(0 0 1px #fff) drop-shadow(0 0 1px #fff);
}
.map-icon .ring { fill: transparent; stroke: none; }
.map-icon.selected .ring { stroke: #fff; stroke-width: 1.5; stroke-dasharray: 3 2; filter: drop-shadow(0 0 1px #000); }
.map-icon.secret { opacity: 0.55; }
.map-icon .label {
    text-anchor: middle;
    font: 600 7px system-ui, sans-serif;
    fill: #111;
    paint-order: stroke;
    stroke: rgba(255, 255, 255, 0.85);
    stroke-width: 2px;
}

.icon-preview { width: 30px; flex-shrink: 0; text-align: center; font-size: 22px; line-height: 1; }
.hexmap-side .form-control-color { width: 38px; flex-shrink: 0; }
.icon-palette {
    display: grid;
    grid-template-columns: repeat(auto-fill, 30px);
    gap: 3px;
    max-height: 168px;
    overflow-y: auto;
    padding: 4px;
    border: 1px solid var(--bs-border-color);
    border-radius: 4px;
}
.icon-palette button {
    width: 30px;
    height: 30px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 4px;
    background: none;
    font-size: 16px;
    line-height: 1;
    color: var(--bs-body-color);
}
.icon-palette button:hover { border-color: var(--bs-primary); background: var(--pfkm-hover-bg); }
.icon-palette span { grid-column: 1 / -1; }

/* --- drawing layer: freehand lines anyone can add; they take the pointer only while erasing --- */
.drawings path { fill: none; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.tool-erase .drawings path.stroke { pointer-events: stroke; }
.hexmap-svg.tool-draw { cursor: crosshair; }
.hexmap-svg.tool-erase { cursor: cell; }
.hide-drawings .drawings { display: none; }
.hexmap-toolbar .form-control-color { width: 38px; }

/* --- layer toggles (classes on the svg) --- */
.hide-terrain .hex .terrain:not(.fog) { fill: #efeadb !important; fill-opacity: 1; }

/* --- settings modal: sits to the right, clear of most of the map, so changes can be watched --- */
@media (min-width: 576px) {
    #hexmap-settings .modal-dialog { margin-right: 1rem; }
}
.hexmap-settings { font-size: 0.875rem; }
.hexmap-settings h3 { font-size: 0.95rem; font-weight: 600; margin-bottom: 8px; }
.hexmap-settings .check-row { margin-bottom: 3px; }
.hexmap-settings .tint-row { margin-bottom: 6px; }
.hexmap-settings .tint-row label { margin-bottom: 0; }
.hide-status .hex .status,
.hide-ownership .hex .owner,
.hide-features .hex .features,
.hide-improvements .hex .improvements,
.hide-settlements .hex .settlement,
.hide-coordinates .hex .coord,
.hide-fog .hex .unexplored,
.hide-fog .hex .hidden-mark { display: none; }

@media (max-width: 900px) {
    .hexmap-app { flex-direction: column; height: auto; }
    .hexmap-svg { height: 60vh; flex: none; }
    .hexmap-side { width: 100%; }
}
