:root {
    --page-bg: #0c100d;
    --panel-bg: #121711;
    --panel-soft: rgba(17, 23, 17, 0.9);
    --text: #f6f1e7;
    --muted: #9ca597;
    --line: #3a4438;
    --accent: #e8c86c;
}

* { box-sizing: border-box; }

.world-map-icon-sprite {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

html,
body {
    min-height: 100%;
    margin: 0;
}

body {
    color: var(--text);
    background:
        linear-gradient(rgba(232, 200, 108, 0.025) 1px, transparent 1px),
        linear-gradient(90deg, rgba(232, 200, 108, 0.025) 1px, transparent 1px),
        var(--page-bg);
    background-size: 24px 24px;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 1rem;
    line-height: 1.5;
}

button,
input,
textarea,
select {
    font-family: inherit;
}

.world-map-page {
    width: min(calc(100% - 1rem), 76rem);
    margin: 0 auto;
    padding: 0.5rem 0;
}

.world-map-heading {
    display: flex;
    gap: 0.75rem 1.25rem;
    align-items: baseline;
    justify-content: flex-end;
    width: min(100%, calc(100dvh - 7rem));
    margin: 0 auto 0.5rem;
}

.world-map-heading h1 {
    margin: 0;
    color: var(--accent);
    font-size: 1.5rem;
    line-height: 1.2;
    text-align: right;
}

.world-map-stage {
    position: relative;
    width: min(100%, calc(100dvh - 7rem));
    aspect-ratio: 1;
    margin: 0 auto;
    border: 1px solid var(--line);
    background: #0a0d0a;
    overflow: hidden;
    touch-action: none;
    cursor: default;
    user-select: none;
}

.world-map-stage.is-dragging { cursor: grabbing; }

.world-map-tiles {
    position: absolute;
    inset: 0;
    overflow: hidden;
}

.world-map-kingdoms,
.world-map-markers {
    position: absolute;
    z-index: 3;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
    pointer-events: none;
}

.world-map-kingdom {
    fill: color-mix(in srgb, var(--kingdom-colour) 9%, transparent);
    stroke: var(--kingdom-colour);
    stroke-width: 2;
    vector-effect: non-scaling-stroke;
    pointer-events: none;
}

.world-map-kingdom.is-draft {
    stroke-dasharray: 7 5;
    fill: color-mix(in srgb, var(--kingdom-colour) 6%, transparent);
}

.world-map-kingdom-name {
    fill: var(--accent);
    stroke: rgba(6, 8, 6, 0.94);
    stroke-width: 3px;
    paint-order: stroke fill;
    font-family: "OpenMine CZ", monospace;
    font-size: clamp(18px, 2.2vw, 28px);
    font-weight: 700;
    text-anchor: middle;
    dominant-baseline: central;
    cursor: pointer;
    pointer-events: auto;
}

.world-map-markers { z-index: 4; }

.world-map-marker {
    position: absolute;
    display: block;
    width: 20px;
    height: 20px;
    padding: 0;
    border: 0;
    color: var(--accent);
    background: transparent;
    transform: translate(-10px, -10px);
    cursor: pointer;
    pointer-events: auto;
}

.world-map-marker-icon {
    display: block;
    width: 20px;
    height: 20px;
    overflow: visible;
    fill: rgba(8, 11, 8, 0.88);
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2;
    filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.9));
}

.world-map-marker > span {
    position: absolute;
    top: 50%;
    left: 100%;
    max-width: min(14rem, 40vw);
    margin-left: 0.48rem;
    padding: 0.18rem 0.35rem;
    overflow: hidden;
    border: 1px solid rgba(232, 200, 108, 0.42);
    color: var(--accent);
    background: rgba(8, 11, 8, 0.82);
    font-family: "OpenMine CZ", monospace;
    font-size: clamp(0.85rem, 1.4vw, 1rem);
    line-height: 1.1;
    text-overflow: ellipsis;
    white-space: nowrap;
    opacity: 0;
    transform: translate(-0.25rem, -50%);
    transition: opacity 120ms ease, transform 120ms ease;
    pointer-events: none;
}

.world-map-marker.shows-label > span,
.world-map-marker:is(:hover, :focus-visible) > span {
    opacity: 1;
    transform: translate(0, -50%);
}

.world-map-marker:is(:hover, :focus-visible) { color: var(--text); }
.world-map-marker.is-draft { opacity: 0.72; }

.world-map-vertex-handle,
.world-map-centre-handle {
    fill: #11160f;
    stroke: var(--accent);
    stroke-width: 3;
    vector-effect: non-scaling-stroke;
    cursor: move;
    pointer-events: auto;
}

.world-map-centre-handle {
    fill: var(--accent);
    stroke: #11160f;
}

.world-map-scale {
    position: absolute;
    z-index: 5;
    top: 0.65rem;
    left: 0.65rem;
    display: grid;
    gap: 0.18rem;
    justify-items: start;
    padding: 0.35rem 0.45rem;
    border: 1px solid rgba(232, 200, 108, 0.38);
    background: rgba(8, 11, 8, 0.72);
    color: var(--text);
    pointer-events: none;
}

.world-map-scale > span {
    display: block;
    height: 7px;
    min-width: 28px;
    border: solid var(--accent);
    border-width: 0 1px 1px;
}

.world-map-scale small {
    color: var(--muted);
    font-family: "OpenMine CZ", monospace;
    font-size: 0.9rem;
    white-space: nowrap;
}

.world-map-controls-hint {
    color: var(--muted);
    font-size: 0.78rem;
    line-height: 1.3;
}

.world-map-controls-touch { display: none; }

.world-map-admin-tools {
    position: absolute;
    z-index: 6;
    top: 0.65rem;
    right: 0.65rem;
    max-width: min(23rem, calc(100% - 9rem));
    padding: 0.35rem;
    border: 1px solid var(--line);
    background: rgba(8, 11, 8, 0.86);
}

.world-map-admin-tools > div {
    display: flex;
    gap: 0.35rem;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
}

.world-map-admin-tools button,
.world-map-feature-dialog button {
    min-height: 2rem;
    border: 1px solid #586254;
    padding: 0.35rem 0.55rem;
    color: var(--text);
    background: #151a14;
    font-size: 1rem;
    cursor: pointer;
}

.world-map-admin-tools button:is(:hover, :focus-visible),
.world-map-feature-dialog button:is(:hover, :focus-visible) {
    border-color: var(--accent);
    color: var(--accent);
}

.world-map-admin-mode small {
    flex: 1 1 11rem;
    color: var(--accent);
    font-size: 0.8rem;
    line-height: 1.3;
}

.world-map-stage[data-annotation-mode] { cursor: crosshair; }
.world-map-stage[data-annotation-mode="edit-kingdom"] { cursor: default; }

.world-map-tile {
    position: absolute;
    display: block;
    max-width: none;
    image-rendering: pixelated;
    opacity: 0;
    pointer-events: none;
    user-select: none;
    transition: opacity 100ms linear;
    will-change: left, top, width, height, opacity;
}

.world-map-tile.is-loaded { opacity: 1; }
.world-map-tile.is-zoom-pending { opacity: 0; }
.world-map-tile.is-stale { z-index: 0; }
.world-map-tile:not(.is-stale) { z-index: 1; }

.world-map-loader {
    position: absolute;
    inset: 0;
    display: grid;
    gap: 0.65rem;
    place-content: center;
    place-items: center;
    background: rgba(10, 13, 10, 0.94);
    z-index: 10;
    transition: opacity 160ms ease;
}

.world-map-loader.is-hidden {
    opacity: 0;
    pointer-events: none;
}

.world-map-loader img {
    width: clamp(3rem, 10vw, 5.5rem);
    aspect-ratio: 1;
    object-fit: contain;
}

.world-map-loader strong {
    color: var(--accent);
    font-size: 1rem;
}

.world-map-footer {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    justify-content: space-between;
    width: min(100%, calc(100dvh - 7rem));
    margin: 0.5rem auto 0;
}

.world-map-catalog-admin {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    justify-content: flex-end;
    width: min(100%, calc(100dvh - 7rem));
    margin: 0.5rem auto 0;
}

.world-map-catalog-admin > small {
    margin-left: auto;
    color: var(--muted);
    font-size: 0.7rem;
    opacity: 0.8;
}

.world-map-footer-navigation {
    display: flex;
    flex: 1 1 24rem;
    gap: 0.65rem;
    align-items: center;
    min-width: 0;
}

.world-map-footer > span {
    color: var(--muted);
    font-size: 0.75rem;
}

.world-map-error {
    width: min(100%, 42rem);
    margin: 3rem auto;
    padding: 1rem;
    border: 1px solid var(--line);
    color: var(--accent);
    background: var(--panel-bg);
    text-align: center;
}

.world-map-feature-dialog {
    width: min(calc(100% - 1.5rem), 34rem);
    max-height: min(88dvh, 42rem);
    padding: 1rem;
    border: 1px solid var(--accent);
    color: var(--text);
    background: var(--panel-bg);
}

.world-map-feature-dialog::backdrop { background: rgba(0, 0, 0, 0.76); }

.world-map-feature-heading {
    display: flex;
    gap: 1rem;
    align-items: start;
    justify-content: space-between;
}

.world-map-feature-heading h2 {
    margin: 0 0 0.8rem;
    color: var(--accent);
    font-size: 1.25rem;
}

.world-map-feature-heading button {
    width: 2rem;
    min-width: 2rem;
    padding: 0;
    font-size: 1.2rem;
}

.world-map-feature-description {
    margin: 0 0 1rem;
    white-space: pre-wrap;
    font-size: 1rem;
    line-height: 1.5;
}

.world-map-feature-edit {
    display: block;
    margin-left: auto;
}

.world-map-feature-form {
    display: grid;
    gap: 0.8rem;
}

.world-map-feature-form[hidden] { display: none; }
.world-map-feature-form [hidden] { display: none; }

.world-map-feature-form fieldset {
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}

.world-map-feature-form fieldset > legend {
    margin-bottom: 0.3rem;
    color: var(--muted);
    font-size: 0.85rem;
}

.world-map-marker-options {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.4rem;
}

.world-map-marker-options label {
    display: block;
    cursor: pointer;
}

.world-map-marker-options input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.world-map-marker-options label > span {
    display: grid;
    min-height: 3.7rem;
    gap: 0.18rem;
    place-content: center;
    place-items: center;
    border: 1px solid var(--line);
    color: var(--muted);
    background: #090c09;
}

.world-map-marker-options svg {
    width: 1.4rem;
    height: 1.4rem;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2;
}

.world-map-marker-options small { font-size: 0.76rem; }

.world-map-marker-options input:is(:checked, :focus-visible) + span {
    border-color: var(--accent);
    color: var(--accent);
}

.world-map-feature-form label {
    display: grid;
    gap: 0.3rem;
    color: var(--muted);
    font-size: 0.85rem;
}

.world-map-feature-form :is(input, textarea) {
    width: 100%;
    border: 1px solid var(--line);
    padding: 0.6rem;
    color: var(--text);
    background: #090c09;
    font: inherit;
}

.world-map-feature-form input[type="color"] {
    width: 4.25rem;
    height: 2.5rem;
    padding: 0.2rem;
    cursor: pointer;
}

.world-map-feature-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    flex-wrap: wrap;
}

.world-map-feature-actions [data-map-feature-delete] { margin-right: auto; }

@media (max-width: 700px) {
    .world-map-page { width: calc(100% - 0.5rem); }
    .world-map-heading,
    .world-map-stage,
    .world-map-footer { width: 100%; }
    .world-map-catalog-admin { width: 100%; }
    .world-map-heading { align-items: end; }
    .world-map-footer .download-command { font-size: 0.85rem; }
    .world-map-scale { top: 0.4rem; left: 0.4rem; }
    .world-map-footer-navigation { gap: 0.4rem; }
    .world-map-controls-hint { font-size: 0.7rem; }
    .world-map-controls-desktop { display: none; }
    .world-map-controls-touch { display: inline; }
    .world-map-admin-tools {
        top: 0.4rem;
        right: 0.4rem;
        max-width: calc(100% - 8rem);
    }
    .world-map-admin-tools button { font-size: 0.85rem; }
}
