.offline-controls {
    position: fixed;
    top: max(12px, env(safe-area-inset-top));
    right: max(14px, env(safe-area-inset-right));
    z-index: 3000;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px;
    border: 1px solid rgba(255, 255, 255, .42);
    border-radius: 999px;
    background: rgba(255, 255, 255, .88);
    box-shadow: 0 8px 26px rgba(8, 20, 29, .16);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
}

.offline-control {
    display: inline-grid;
    min-width: 42px;
    width: 42px;
    height: 42px;
    padding: 0;
    place-items: center;
    border: 0;
    border-radius: 50%;
    color: var(--nav-link, #385d7c);
    background: transparent;
    font: 700 .72rem/1 Inter, system-ui, sans-serif;
    letter-spacing: .06em;
    text-decoration: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background-color .18s ease, color .18s ease;
}

.offline-control:hover {
    color: var(--blue-dark, #253f56);
    background: rgba(56, 93, 124, .1);
}

.offline-theme {
    font-size: 1.2rem;
}

.offline-control:focus-visible,
.legal-dialog button:focus-visible,
.maintenance-links button:focus-visible {
    outline: 3px solid var(--gold, #b49450);
    outline-offset: 3px;
}

body.dark .offline-controls {
    border-color: rgba(255, 255, 255, .18);
    background: rgba(29, 38, 48, .9);
}

body.dark .offline-control {
    color: var(--blue-deep, #c8d8e8);
}

body.dark .offline-control:hover {
    color: #fff;
    background: rgba(255, 255, 255, .1);
}

.legal-dialog {
    position: fixed;
    inset: 0;
    margin: auto;
    width: min(960px, calc(100vw - 28px));
    height: min(860px, calc(100vh - 40px));
    height: min(860px, calc(100dvh - 40px));
    max-width: none;
    max-height: none;
    padding: 0;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, .42);
    border-radius: 18px;
    color: #263e55;
    background: #faf8f4;
    box-shadow: 0 28px 100px rgba(0, 0, 0, .35);
}

.legal-dialog::backdrop {
    background: rgba(8, 17, 26, .66);
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
}

.legal-dialog-header {
    position: relative;
    z-index: 1;
    display: flex;
    min-height: 58px;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 8px 12px 8px 20px;
    border-bottom: 1px solid rgba(37, 63, 86, .12);
    background: rgba(250, 248, 244, .96);
}

.legal-dialog-header h2 {
    margin: 0;
    color: #253f56;
    font: 600 1rem/1.3 Inter, system-ui, sans-serif;
}

.legal-dialog-close {
    display: grid;
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    place-items: center;
    border: 1px solid rgba(37, 63, 86, .14);
    border-radius: 50%;
    color: #253f56;
    background: #fff;
    font: 400 1.5rem/1 Inter, system-ui, sans-serif;
    cursor: pointer;
}

.legal-dialog-content {
    display: block;
    width: 100%;
    height: calc(100% - 58px);
    overflow: auto;
    overscroll-behavior: contain;
    padding: clamp(10px, 2vw, 22px);
    color: #263e55;
    background: #faf8f4;
    -webkit-overflow-scrolling: touch;
}

.legal-dialog-content > main {
    min-height: 0;
    padding-top: 0;
}

.legal-dialog-content .container {
    width: 100%;
    max-width: 100%;
    padding-right: 0;
    padding-left: 0;
}

.legal-dialog-loading,
.legal-dialog-error {
    display: grid;
    min-height: 180px;
    place-items: center;
    color: #506476;
    text-align: center;
}

.legal-dialog-error a {
    color: var(--blue-deep, #385d7c);
    text-underline-offset: 3px;
}

.maintenance-links button.legal-link {
    padding: 0;
    border: 0;
    color: rgba(255, 255, 255, .76);
    background: transparent;
    font: inherit;
    text-decoration: underline;
    text-underline-offset: 5px;
    cursor: pointer;
}

.maintenance-links button.legal-link:hover {
    color: #fff;
}

body.dark .legal-dialog {
    border-color: rgba(255, 255, 255, .15);
    color: #dce2e8;
    background: #171e26;
}

body.dark .legal-dialog-header {
    border-color: rgba(255, 255, 255, .1);
    background: rgba(23, 30, 38, .97);
}

body.dark .legal-dialog-header h2,
body.dark .legal-dialog-close {
    color: #dce2e8;
}

body.dark .legal-dialog-close {
    border-color: rgba(255, 255, 255, .16);
    background: #253545;
}

body.dark .legal-dialog-content {
    color: #dce2e8;
    background: #171e26;
}

body.dark .legal-dialog-loading,
body.dark .legal-dialog-error {
    color: #b7c4d1;
}

@media (max-width: 600px) {
    .offline-controls {
        top: max(9px, env(safe-area-inset-top));
        right: max(10px, env(safe-area-inset-right));
    }

    .offline-control {
        min-width: 40px;
        width: 40px;
        height: 40px;
    }

    .legal-dialog {
        width: calc(100vw - 16px);
        height: calc(100vh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        border-radius: 14px;
    }

    .legal-dialog-header {
        min-height: 54px;
        padding-left: 14px;
    }

.legal-dialog-content {
        height: calc(100% - 54px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .offline-control {
        transition-duration: .01ms;
    }
}
