:root {
    color-scheme: dark;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #17212b;
    color: #f4f0e6;
}

* {
    box-sizing: border-box;
}

html,
body,
.atlas-app {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
}

body {
    background: #17212b;
}

.atlas-app {
    position: relative;
    isolation: isolate;
}

.map-canvas {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    background: #17212b;
    cursor: grab;
    touch-action: none;
    outline: none;
}

.label-canvas {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: block;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.map-canvas.is-dragging {
    cursor: grabbing;
}

.overlay-panel {
    position: absolute;
    z-index: 10;
    border: 1px solid rgba(236, 222, 190, 0.2);
    border-radius: 14px;
    background: rgba(27, 34, 40, 0.9);
    box-shadow: 0 12px 34px rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(10px);
}

.left-overlay-stack {
    position: absolute;
    z-index: 10;
    top: max(16px, env(safe-area-inset-top));
    left: max(16px, env(safe-area-inset-left));
    width: min(360px, calc(100vw - 32px));
    display: grid;
    gap: 12px;
}

.search-overlay-stack {
    position: absolute;
    z-index: 10;
    top: max(16px, env(safe-area-inset-top));
    right: max(16px, env(safe-area-inset-right));
    width: min(330px, calc(100vw - 32px));
    display: grid;
    gap: 12px;
    justify-items: end;
}

.timeline-overlay-stack {
    position: absolute;
    z-index: 10;
    bottom: max(16px, env(safe-area-inset-bottom));
    left: 50%;
    width: min(620px, calc(100vw - 32px));
    display: grid;
    justify-items: center;
    transform: translateX(-50%);
}

.left-overlay-stack > .overlay-panel,
.search-overlay-stack > .overlay-panel,
.timeline-overlay-stack > .overlay-panel {
    position: relative;
}

.map-tools,
.province-panel {
    width: 100%;
    padding: 16px;
}

.province-panel.has-owner-color {
    border-left: 4px solid var(--owner-color);
}

.panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.panel-header h1,
.panel-header h2 {
    margin: 0;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 1.35rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.province-title {
    display: flex;
    align-items: baseline;
    gap: 7px;
}

.province-capital-marker {
    color: #f3c95f;
    font-size: 0.82em;
    line-height: 1;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.65);
}

.panel-header p,
.interaction-hint {
    margin: 5px 0 0;
    color: #c6c0b3;
    font-size: 0.8rem;
}

.province-details {
    display: grid;
    gap: 7px;
    margin: 14px 0 0;
}

.province-details > div {
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 10px;
}

.province-details dt {
    color: #c6c0b3;
    font-size: 0.8rem;
}

.province-details dd {
    min-width: 0;
    margin: 0;
    overflow-wrap: anywhere;
}

.province-owner {
    display: flex;
    align-items: center;
    gap: 7px;
}

.owner-swatch {
    width: 13px;
    height: 13px;
    flex: 0 0 13px;
    border: 1px solid rgba(255, 255, 255, 0.45);
    border-radius: 4px;
    background: var(--owner-color);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
}

.province-source-history {
    margin-top: 14px;
    border-top: 1px solid rgba(236, 222, 190, 0.16);
    padding-top: 12px;
}

.province-source-history h3 {
    margin: 0 0 8px;
    color: #f4f0e6;
    font-size: 0.86rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.province-source-history ol {
    display: grid;
    gap: 7px;
    max-height: min(260px, calc(100vh - 460px));
    margin: 0;
    overflow-y: auto;
    padding: 0;
    list-style: none;
}

.source-history-row {
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 10px;
    border-radius: 8px;
    padding: 6px 0;
}

.source-history-date {
    color: #c6c0b3;
    font-size: 0.78rem;
    white-space: nowrap;
}

.source-history-fields {
    display: grid;
    gap: 3px;
    min-width: 0;
    font-size: 0.82rem;
}

.source-history-field {
    overflow-wrap: anywhere;
}

.source-history-field-name {
    color: #c6c0b3;
}

.search-panel {
    width: 100%;
    padding: 14px;
}

.country-focus-panel {
    width: 100%;
    padding: 14px;
    border-left: 4px solid var(--country-focus-color, rgba(236, 222, 190, 0.2));
}

.country-focus-summary {
    display: grid;
    gap: 7px;
    margin: 12px 0 0;
}

.country-focus-summary > div {
    display: grid;
    grid-template-columns: 78px minmax(0, 1fr);
    gap: 10px;
}

.country-focus-summary dt,
.country-focus-cultures h3 {
    color: #c6c0b3;
    font-size: 0.8rem;
}

.country-focus-summary dd {
    min-width: 0;
    margin: 0;
    overflow-wrap: anywhere;
}

.country-focus-cultures {
    margin-top: 14px;
    border-top: 1px solid rgba(236, 222, 190, 0.16);
    padding-top: 12px;
}

.country-focus-cultures h3 {
    margin: 0 0 8px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.country-focus-toggle {
    display: grid;
    justify-items: start;
    gap: 7px;
    margin: 0 0 12px;
    color: #d8d2c5;
    font-size: 0.82rem;
    line-height: 1.25;
    user-select: none;
}

.country-focus-toggle input {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
}

.country-focus-toggle-label {
    display: grid;
    grid-template-columns: 15px minmax(0, 1fr);
    align-items: center;
    gap: 8px;
}

.country-focus-toggle-slider {
    position: relative;
    width: 34px;
    height: 18px;
    flex: 0 0 34px;
    border: 1px solid rgba(236, 222, 190, 0.28);
    border-radius: 999px;
    background: rgba(13, 18, 22, 0.8);
    transition: background 140ms ease, border-color 140ms ease;
}

.country-focus-toggle-slider::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #c6c0b3;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
    transition: transform 140ms ease, background 140ms ease;
}

.country-focus-toggle input:checked ~ .country-focus-toggle-slider {
    border-color: rgba(217, 170, 71, 0.7);
    background: rgba(217, 170, 71, 0.28);
}

.country-focus-toggle input:checked ~ .country-focus-toggle-slider::after {
    transform: translateX(16px);
    background: #f0c663;
}

.country-focus-toggle input:focus-visible ~ .country-focus-toggle-slider {
    outline: 2px solid #f0c663;
    outline-offset: 2px;
}

.country-focus-toggle-swatch {
    width: 15px;
    height: 15px;
    flex: 0 0 15px;
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 4px;
    background:
        repeating-linear-gradient(
            135deg,
            #808580 0,
            #808580 4px,
            #666b66 4px,
            #666b66 8px
        );
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

.country-focus-cultures ol {
    display: grid;
    gap: 9px;
    max-height: min(620px, calc(100vh - 250px));
    margin: 0;
    overflow-y: auto;
    padding: 0;
    list-style: none;
}

.culture-group-legend-row {
    display: grid;
    gap: 5px;
}

.culture-group-legend-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    color: #f4f0e6;
    font-size: 0.86rem;
    font-weight: 600;
}

.culture-group-legend-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.culture-group-legend-cultures {
    display: grid;
    gap: 4px;
    margin: 0;
    padding: 0 0 0 12px;
    list-style: none;
}

.culture-legend-row {
    display: grid;
    grid-template-columns: 14px minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    font-size: 0.84rem;
}

.culture-legend-swatch {
    width: 14px;
    height: 14px;
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 4px;
    background: var(--culture-color);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

.culture-legend-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.culture-legend-count {
    color: #c6c0b3;
    font-variant-numeric: tabular-nums;
}

.search-input-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    margin-top: 12px;
    border: 1px solid rgba(236, 222, 190, 0.25);
    border-radius: 9px;
    padding: 0 10px;
    background: #20282d;
}

.search-input-wrap:focus-within {
    border-color: #eec462;
    box-shadow: 0 0 0 1px #eec462;
}

.search-input-wrap svg {
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
    fill: none;
    stroke: #c6c0b3;
    stroke-width: 1.8;
    stroke-linecap: round;
}

.search-input-wrap input {
    min-width: 0;
    width: 100%;
    border: 0;
    outline: 0;
    padding: 8px 0;
    background: transparent;
    color: inherit;
    font: inherit;
}

.search-results {
    display: grid;
    gap: 4px;
    max-height: min(420px, calc(100vh - 170px));
    margin: 8px 0 0;
    overflow-y: auto;
    padding: 0;
    list-style: none;
}

.search-result-button {
    width: 100%;
    min-height: 44px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    border-color: transparent;
    padding: 7px 9px;
    text-align: left;
}

.search-result-button strong,
.search-result-button small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.search-result-button small,
.search-message {
    color: #c6c0b3;
    font-size: 0.78rem;
}

.search-message {
    padding: 8px 4px 2px;
}

.timeline-panel {
    width: 100%;
    padding: 12px 16px 10px;
}

.timeline-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.timeline-header > div {
    display: flex;
    min-width: 0;
    align-items: baseline;
    gap: 10px;
}

#timeline-title {
    font-family: Georgia, "Times New Roman", serif;
    font-weight: 600;
}

#timeline-date-label {
    overflow: hidden;
    color: #eec462;
    font-size: 0.85rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.timeline-slider {
    width: 100%;
    margin: 9px 0 0;
    accent-color: #eec462;
    cursor: pointer;
}

.timeline-slider:disabled {
    cursor: wait;
    opacity: 0.6;
}

.timeline-endpoints {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    color: #c6c0b3;
    font-size: 0.72rem;
}

button {
    min-height: 36px;
    border: 1px solid rgba(236, 222, 190, 0.25);
    border-radius: 9px;
    background: rgba(241, 231, 207, 0.1);
    color: inherit;
    font: inherit;
    cursor: pointer;
}

button:hover {
    background: rgba(241, 231, 207, 0.18);
}

button:focus-visible {
    outline: 2px solid #eec462;
    outline-offset: 2px;
}

.map-mode-setting {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    margin-top: 10px;
}

.control-label {
    color: #c6c0b3;
    font-size: 0.8rem;
}

.map-mode-controls {
    display: grid;
    grid-template-columns: repeat(5, minmax(36px, 1fr));
    gap: 6px;
}

.map-mode-button {
    display: grid;
    min-width: 0;
    min-height: 38px;
    place-items: center;
    padding: 7px;
}

.map-mode-button svg {
    width: 21px;
    height: 21px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.map-mode-button[aria-pressed="true"] {
    border-color: rgba(238, 196, 98, 0.85);
    background: rgba(238, 196, 98, 0.22);
    color: #f6d784;
}

.map-mode-button:disabled {
    cursor: wait;
    opacity: 0.6;
}

.icon-button {
    min-width: 34px;
    min-height: 34px;
    padding: 0;
    font-size: 1.25rem;
    line-height: 1;
}

.navigation-controls {
    display: grid;
    grid-template-columns: 42px 1fr 42px;
    gap: 8px;
    margin-top: 10px;
}

.navigation-controls button:first-child,
.navigation-controls button:last-child {
    font-size: 1.25rem;
}

.secondary-action {
    width: 100%;
    margin-top: 10px;
}

.support-link {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    margin-top: 10px;
    border: 1px solid rgba(238, 196, 98, 0.55);
    border-radius: 9px;
    padding: 7px 10px;
    background: rgba(238, 196, 98, 0.16);
    color: #f6d784;
    font-size: 0.86rem;
    text-align: center;
    text-decoration: none;
}

.support-link:hover {
    background: rgba(238, 196, 98, 0.24);
}

.support-link:focus-visible {
    outline: 2px solid #eec462;
    outline-offset: 2px;
}

.restore-tools {
    justify-self: start;
    padding: 9px 13px;
}

.map-status {
    right: max(16px, env(safe-area-inset-right));
    bottom: max(16px, env(safe-area-inset-bottom));
    max-width: min(430px, calc(100vw - 32px));
    padding: 10px 14px;
    color: #d9d3c6;
    font-size: 0.82rem;
    transition: opacity 180ms ease;
}

.map-status.is-ready {
    opacity: 0;
    pointer-events: none;
}

.map-status.is-error,
.fatal-message {
    border-color: rgba(224, 100, 90, 0.65);
    color: #ffd6d2;
}

.fatal-message {
    top: 50%;
    left: 50%;
    padding: 16px 20px;
    transform: translate(-50%, -50%);
}

[hidden] {
    display: none !important;
}

@media (max-width: 600px) {
    .left-overlay-stack {
        top: max(10px, env(safe-area-inset-top));
        left: max(10px, env(safe-area-inset-left));
        width: min(330px, calc(100vw - 20px));
    }

    .map-tools,
    .province-panel {
        padding: 13px;
    }

    .interaction-hint {
        display: none;
    }

    .search-overlay-stack {
        top: auto;
        right: 10px;
        bottom: max(138px, calc(env(safe-area-inset-bottom) + 128px));
        width: min(330px, calc(100vw - 20px));
    }

    .timeline-overlay-stack {
        bottom: max(10px, env(safe-area-inset-bottom));
        width: calc(100vw - 20px);
    }

    .timeline-panel {
        padding: 10px 12px 8px;
    }

    .timeline-header > div {
        display: grid;
        gap: 2px;
    }

    .map-status {
        right: 10px;
        bottom: max(126px, calc(env(safe-area-inset-bottom) + 116px));
        left: 10px;
        max-width: none;
    }
}
