:root {
    --bg: #0b1020;
    --panel: #121a30;
    --panel-soft: #1a2442;
    --line: #2e3b66;
    --text: #e8ecff;
    --muted: #aab5d9;
    --accent: #66d9ff;
    --accent-2: #9b8cff;
    --ok: #43d193;
    --warn: #ffb86c;
    --danger: #ff6b81;
    --radius: 14px;
    --shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    background: radial-gradient(circle at 20% 10%, #182646, var(--bg));
    color: var(--text);
    font-family: Inter, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 8px;
    border-bottom: 1px solid var(--line);
    background: rgba(11, 16, 32, 0.88);
    backdrop-filter: blur(4px);
    position: sticky;
    top: 0;
    z-index: 999;
}

.brand {
    font-weight: 700;
    letter-spacing: 0.3px;
}

.topnav {
    display: flex;
    align-items: center;
    gap: 12px;
}

.welcome {
    color: var(--muted);
}

.btn,
button {
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--panel-soft);
    color: var(--text);
    padding: 7px 11px;
    cursor: pointer;
    transition: transform 0.12s ease, background 0.12s ease;
}

.btn:hover,
button:hover {
    background: #27325e;
}

.btn:active,
button:active {
    transform: translateY(1px);
}

.btn.primary {
    background: linear-gradient(120deg, var(--accent-2), var(--accent));
    color: #080c1a;
    border-color: transparent;
    font-weight: 700;
}


.btn.small {
    font-size: 0.84rem;
    padding: 5px 9px;
}

.flash-wrap {
    display: grid;
    gap: 8px;
    margin-bottom: 10px;
}

.flash {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 8px 10px;
    background: var(--panel);
}

.flash.success {
    border-color: color-mix(in srgb, var(--ok) 65%, var(--line));
}

.flash.error {
    border-color: color-mix(in srgb, var(--danger) 65%, var(--line));
}

.login-shell {
    min-height: 70vh;
    display: grid;
    place-items: center;
}

.login-card {
    width: min(420px, 94vw);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px;
}

.subtle {
    color: var(--muted);
}

.stack {
    display: grid;
    gap: 10px;
}

label {
    display: grid;
    gap: 6px;
    font-size: 0.92rem;
    color: var(--muted);
}

input,
textarea,
select {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 6px 8px;
    background: #0f1730;
    color: var(--text);
    width: 100%;
    min-width: 0;
}

.mapper-layout {
    display: flex;
    flex-direction: row;
    gap: 4px;
    height: calc(100vh - 1.2em);
}

.panel {
    background: var(--panel);
    overflow: auto;
}

.panel.left {
    flex: 0 0 minmax(230px, 280px);
    min-width: 230px;
    max-width: 280px;
}

.panel.right {
    flex: 0 0 minmax(260px, 320px);
    min-width: 260px;
    max-width: 320px;
    border-radius: 10px;
    padding:  8px;
}

.panel.hidden {
    display: none;
}

.panel details {
    border: 1px solid #2a3760;
    border-bottom-right-radius: 8px;
    border-bottom-left-radius: 8px;
    margin-bottom: 8px;
    background: rgba(255, 255, 255, 0.02);
}

.panel summary {
    cursor: pointer;
    padding: 8px 10px;
    font-weight: 600;
}

.tools-grid,
.ops-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 8px;
}

.tool-btn.active {
    border-color: var(--accent);
    background-color: color-mix(in srgb, var(--accent) 15%, var(--panel-soft));
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent);
}

.layers-box {
    padding: 8px;
}

#layers-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 6px;
}

.layer-item {
    border: 1px solid #2a3760;
    border-radius: 10px;
    padding: 0;
    overflow: hidden;
}

.layer-strip {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    min-height: 34px;
    background: rgba(255, 255, 255, 0.02);
}

.layer-strip.active {
    border-left: 3px solid var(--accent);
    background: color-mix(in srgb, var(--accent) 15%, var(--panel-soft));
}

.layer-icons {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0 6px;
}

.layer-icon,
.layer-icon-btn {
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    font-size: 0.9rem;
}

.layer-icon {
    background: rgba(255, 255, 255, 0.04);
}

.layer-icon-btn {
    border: 1px solid transparent;
    background: rgba(255, 255, 255, 0.06);
    cursor: pointer;
    padding: 0;
}

.layer-icon-btn:hover {
    background: rgba(255, 255, 255, 0.14);
}

.layer-name-btn {
    flex: 1;
    min-width: 0;
    border: none;
    background: transparent;
    text-align: right;
    padding: 0 10px;
    color: var(--text);
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
}

.layer-actions {
    margin-top: 9px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.map-stage {
    flex: 1;
    min-width: 240px;
    overflow: hidden;
    position: relative;
}

#map,
#shared-map {
    width: 100%;
    height: 100%;
    min-height: 340px;
    background: #111a32;
}

.notice-box {
    position: absolute;
    right: 10px;
    bottom: 10px;
    max-width: min(350px, 70%);
    max-height: 45%;
    overflow: auto;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: rgba(18, 26, 48, 0.95);
    padding: 10px;
    box-shadow: var(--shadow);
}

.draw-hint {
    position: absolute;
    left: 50%;
    top: 12px;
    color: #888;
    transform: translateX(-50%);
    background: rgba(18, 26, 48, 0.92);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 6px 11px;
    font-size: 0.86rem;
}

.shape-label {
    background: rgba(10, 16, 30, 0.8);
    color: var(--text);
    border: 1px solid #3d4f86;
    border-radius: 999px;
    padding: 3px 8px;
    font-size: 0.76rem;
}

.vertex-handle {
    color: #e2e9ff;
    font-size: 14px;
    text-shadow: 0 0 4px #000;
    transform: translate(-7px, -7px);
}

.arrow-head {
    color: #ffb86c;
    font-size: 17px;
    text-shadow: 0 0 4px #000;
    transform: translate(-8px, -8px);
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.arrow-head span {
    transform-origin: center;
}

.hidden {
    display: none !important;
}

.changes-list {
    list-style: none;
    padding: 0;
    margin: 10px 0;
    display: grid;
    gap: 6px;
}

.changes-list li {
    border: 1px dashed #3a4b7e;
    border-radius: 8px;
    padding: 6px 8px;
    color: var(--muted);
}

.changes-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

dialog {
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--panel);
    color: var(--text);
    /* width: min(340px, 94vw); */
}

dialog::backdrop {
    background: rgba(0, 0, 0, 0.5);
}

.dialog-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.export-preview-shell {
    width: min(980px, 96vw - 4em -  6px);
}

.export-preview-frame {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #0a0f1f;
    overflow: auto;
    /* max-height: min(72vh, 760px); */
}

#export-preview-image {
    display: block;
    width: 100%;
    height: auto;
    min-height: 200px;
    max-height: 50vh;
    object-fit: contain;
}

.share-layout {
    height: calc(100vh - 100px);
    display: grid;
    grid-template-rows: auto 1fr;
    gap: 10px;
}

.share-layout.fullscreen {
    height: 100vh;
    grid-template-rows: 1fr;
}

.share-header.hidden {
    display: none;
}

body.fullscreen-share {
    overflow: hidden;
}

body.fullscreen-share .topbar {
    display: none;
}

body.fullscreen-share main {
    height: 100vh;
}

body.fullscreen-share .share-layout {
    gap: 0;
    height: 100vh;
}

body.fullscreen-share .share-layout.fullscreen {
    height: 100vh;
}

body.fullscreen-share #shared-map {
    min-height: 0;
    height: 100vh;
}

.admin-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    align-items: start;
    padding: 12px;
}

.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-shadow: var(--shadow);
}

.card h2 {
    margin: 0;
    line-height: 1.1;
}

#notice-input {
    min-height: 120px;
    resize: vertical;
}

.preview-box,
.list {
    margin-top: 0;
    border: 1px solid #2a3760;
    border-radius: 10px;
    padding: 10px;
    min-height: 80px;
}

.list {
    list-style: none;
    display: grid;
    gap: 8px;
}

.admin-form {
    display: grid;
    gap: 8px;
    align-items: end;
}

.admin-form--users {
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1.4fr) auto auto;
}

.admin-form--snapshot {
    grid-template-columns: minmax(0, 1fr) auto;
}

.admin-form--layer {
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) auto auto;
}

.admin-form label,
.permissions-toolbar {
    align-items: center;
}

.admin-form label {
    display: inline-flex;
    gap: 6px;
    white-space: nowrap;
}

.admin-form label input[type="checkbox"] {
    width: auto;
}

.admin-form .btn {
    width: fit-content;
}

.permissions-toolbar {
    display: grid;
    margin-top: 0;
}

.permissions-toolbar select {
    max-width: 18rem;
}

.list li {
    border: 1px solid #2a3760;
    border-radius: 8px;
    padding: 8px;
    min-width: 0;
    display: grid;
    gap: 8px;
}

.mini-grid {
    display: grid;
    gap: 6px;
}

.permissions-list {
    display: grid;
    gap: 8px;
}

.button-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.share-link-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    border: 1px solid #2a3760;
    border-radius: 8px;
    padding: 7px 8px;
    background: rgba(255, 255, 255, 0.02);
}

.share-link-row code {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.permission-row {
    border: 1px solid #2a3760;
    border-radius: 8px;
    padding: 8px;
    display: grid;
    gap: 8px;
}

.permission-controls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

@media (max-width: 1320px) {
    .admin-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 980px) {
    .admin-grid {
        grid-template-columns: 1fr;
    }

    .admin-form--users,
    .admin-form--layer,
    .admin-form--snapshot {
        grid-template-columns: 1fr;
    }

    .permissions-toolbar select {
        max-width: none;
    }
}

@media (max-width: 1080px) {
    .mapper-layout {
        flex-direction: row;
    }

    .panel.left {
        flex: 0 0 minmax(200px, 260px);
        min-width: 200px;
        max-width: 260px;
    }

    .panel.right {
        position: fixed;
        right: 12px;
        bottom: 12px;
        flex: none;
        width: min(360px, calc(100vw - 24px));
        max-height: 55vh;
        z-index: 900;
    }
}
