:root {
    color-scheme: light;
    --ink: #0f172a;
    --ink-soft: #334155;
    --paper: #f4f7fb;
    --panel: #ffffff;
    --panel-soft: #f8fafc;
    --line: #e2e8f0;
    --line-strong: #cbd5e1;
    --primary: #1e3a5f;
    --primary-hover: #16304f;
    --accent: #0f766e;
    --accent-hover: #0d9488;
    --accent-ink: #ffffff;
    --accent-soft: #ccfbf1;
    --danger: #dc2626;
    --danger-soft: #fee2e2;
    --muted: #64748b;
    --ring: rgba(30, 58, 95, 0.28);
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 10px 30px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 24px 60px rgba(15, 23, 42, 0.14);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --aside-width: 400px;
    --font: "Source Sans 3", "Noto Sans Myanmar", sans-serif;
    --ease: 180ms ease;
}

* { box-sizing: border-box; }

html, body, #app, #login-gate {
    height: 100%;
    margin: 0;
}

body {
    font-family: var(--font);
    color: var(--ink);
    background: var(--paper);
    -webkit-font-smoothing: antialiased;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ——— Login ——— */

#login-gate {
    display: grid;
    place-items: center;
    padding: 28px 20px;
    background:
        radial-gradient(ellipse 80% 60% at 12% 18%, rgba(15, 118, 110, 0.16), transparent 55%),
        radial-gradient(ellipse 70% 50% at 88% 82%, rgba(30, 58, 95, 0.18), transparent 50%),
        linear-gradient(160deg, #eef4f8 0%, #f7fafc 45%, #e8eef5 100%);
    overflow: auto;
}

#login-gate[hidden] { display: none; }

.login-shell {
    width: min(100%, 920px);
    display: grid;
    grid-template-columns: 1.05fr 0.95fr;
    gap: 0;
    border: 1px solid rgba(226, 232, 240, 0.9);
    border-radius: 24px;
    overflow: hidden;
    background: var(--panel);
    box-shadow: var(--shadow-lg);
    animation: rise-in 420ms ease both;
}

.login-brand {
    position: relative;
    min-height: 420px;
    padding: 40px 36px;
    color: #e8f1f8;
    background: linear-gradient(145deg, #132a44 0%, #1e3a5f 48%, #0f766e 120%);
    display: flex;
    align-items: flex-end;
}

.login-brand-grid {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.06) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.06) 1px, transparent 1px);
    background-size: 36px 36px;
    mask-image: radial-gradient(ellipse 80% 70% at 40% 40%, #000 20%, transparent 75%);
    animation: grid-drift 18s linear infinite;
}

.login-brand-copy {
    position: relative;
    z-index: 1;
    max-width: 28ch;
}

.brand-mark {
    display: inline-flex;
    color: #5eead4;
    margin-bottom: 18px;
}

.brand-mark.compact {
    color: var(--accent);
    margin: 0;
    flex-shrink: 0;
}

.brand-name {
    margin: 0 0 10px;
    font-size: clamp(1.85rem, 3vw, 2.35rem);
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.1;
    color: #fff;
}

.brand-tagline {
    margin: 0;
    color: rgba(226, 241, 248, 0.82);
    font-size: 1rem;
    line-height: 1.45;
}

.login-card {
    padding: 40px 36px 32px;
    background: var(--panel);
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.login-card h1 {
    margin: 0 0 8px;
    font-size: 1.75rem;
    letter-spacing: -0.02em;
}

.login-card .hint { margin: 0 0 22px; }

.login-card button[type="submit"] {
    width: 100%;
    margin-top: 20px;
    padding: 12px 16px;
}

#login-status {
    min-height: 1.2em;
    margin: 14px 0 0;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--danger-soft);
    color: #991b1b;
    font-size: 0.92rem;
    font-weight: 500;
}

#login-status:empty {
    display: none;
    padding: 0;
    background: transparent;
}

@keyframes rise-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: none; }
}

@keyframes grid-drift {
    from { background-position: 0 0, 0 0; }
    to { background-position: 36px 36px, 36px 36px; }
}

/* ——— App shell ——— */

#app {
    display: grid;
    grid-template-columns: var(--aside-width) 1fr;
    background: var(--paper);
}

#app[hidden] { display: none; }

aside {
    overflow: auto;
    padding: 18px 16px 28px;
    background: var(--panel-soft);
    border-right: 1px solid var(--line);
    scrollbar-gutter: stable;
}

#map {
    min-height: 320px;
    background: #e8eef5;
}

.side-header {
    margin-bottom: 8px;
    padding: 4px 4px 14px;
}

.brand-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 10px;
}

.brand-row h1 {
    margin: 2px 0 0;
    font-size: 1.35rem;
    letter-spacing: -0.02em;
}

.eyebrow {
    margin: 0;
    color: var(--accent);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.auth-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 14px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--panel);
    box-shadow: var(--shadow-sm);
}

.auth-label {
    margin: 0;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}

.auth-name {
    margin: 2px 0 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--ink);
}

.panel {
    margin-top: 12px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--panel);
    box-shadow: var(--shadow-sm);
}

.panel h2,
.form-head h2 {
    margin: 0 0 10px;
    font-size: 0.95rem;
    letter-spacing: -0.01em;
}

h1, h2 { margin: 0 0 8px; }

h1 { font-size: 1.6rem; }

h2 { margin-top: 0; font-size: 1rem; }

.hint, #status, #credit, .route p, .coords {
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.4;
}

.hint.callout {
    margin: 10px 0 0;
    padding: 8px 10px;
    border-left: 3px solid var(--accent);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    background: var(--accent-soft);
    color: #115e59;
}

label {
    display: block;
    margin: 12px 0 5px;
    font-size: 0.8rem;
    font-weight: 650;
    color: var(--ink-soft);
}

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

input, select, textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: #fff;
    color: var(--ink);
    transition: border-color var(--ease), box-shadow var(--ease);
}

input:hover, select:hover, textarea:hover {
    border-color: #94a3b8;
}

input:focus, select:focus, textarea:focus, button:focus-visible {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--ring);
}

textarea { resize: vertical; min-height: 64px; }

.search-row, .actions, .lang-toggle {
    display: flex;
    gap: 8px;
}

.lang-toggle {
    padding: 4px;
    border-radius: var(--radius-md);
    background: var(--panel-soft);
    border: 1px solid var(--line);
}

.lang-toggle button {
    flex: 1;
    background: transparent;
    color: var(--ink-soft);
    box-shadow: none;
}

.lang-toggle button:hover {
    background: rgba(15, 118, 110, 0.08);
}

.lang-toggle button.active {
    background: var(--primary);
    color: #fff;
}

.maplibregl-marker:has(.region-label) { pointer-events: none; }

.region-label {
    font-family: "Noto Sans Myanmar", sans-serif;
    font-weight: 600;
    font-size: 13px;
    line-height: 1.2;
    color: #1e293b;
    white-space: nowrap;
    pointer-events: none;
    text-shadow:
        0 0 2px #f8fafc,
        1px 0 #f8fafc,
        -1px 0 #f8fafc,
        0 1px #f8fafc,
        0 -1px #f8fafc;
}

.region-label.major { font-size: 16px; }

.search-row input { flex: 1; }

button {
    border: 0;
    border-radius: var(--radius-sm);
    padding: 9px 13px;
    background: var(--primary);
    color: var(--accent-ink);
    font-weight: 650;
    cursor: pointer;
    transition: background var(--ease), transform var(--ease), opacity var(--ease), box-shadow var(--ease);
}

button:hover:not(:disabled) {
    background: var(--primary-hover);
}

button:active:not(:disabled) {
    transform: translateY(1px);
}

button.secondary {
    background: #eef2f7;
    color: var(--ink);
}

button.secondary:hover:not(:disabled) {
    background: #e2e8f0;
}

button.danger {
    background: var(--danger);
}

button.danger:hover:not(:disabled) {
    background: #b91c1c;
}

button:disabled {
    opacity: 0.5;
    cursor: default;
}

button.wide {
    width: 100%;
}

#results {
    list-style: none;
    margin: 8px 0 0;
    padding: 0;
}

#results li {
    padding: 10px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--ease);
}

#results li:hover,
#duplicates li:hover,
#nearby li:hover {
    background: #eef6f5;
}

#results small,
#duplicates small,
#nearby small {
    color: var(--muted);
}

#duplicates, #nearby, #edit-log-list, #token-list {
    list-style: none;
    margin: 8px 0 0;
    padding: 0;
}

#duplicates li, #nearby li, #edit-log-list li, #token-list li {
    padding: 10px;
    border-radius: var(--radius-sm);
}

#token-list li {
    display: flex;
    flex-direction: column;
    gap: 8px;
    border: 1px solid var(--line);
    margin-bottom: 8px;
    background: var(--panel-soft);
}

#token-list li.token-revoked {
    opacity: 0.6;
}

.token-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

.token-reveal {
    margin-top: 12px;
    padding: 12px;
    border: 1px dashed var(--accent);
    border-radius: var(--radius-md);
    background: var(--accent-soft);
}

.token-reveal code {
    display: block;
    margin: 8px 0;
    word-break: break-all;
    font-size: 0.82rem;
    color: var(--ink);
}

.token-usage code {
    font-size: 0.78rem;
    background: var(--panel-soft);
    padding: 1px 5px;
    border-radius: 4px;
}

#find-duplicates { margin-top: 10px; }

.form-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 4px;
}

.form-head h2 { margin: 0; }

#add-place {
    background: var(--accent);
}

#add-place:hover:not(:disabled) {
    background: var(--accent-hover);
}

#add-place.active {
    box-shadow: inset 0 0 0 2px #fff, 0 0 0 2px var(--accent);
}

.source-chip:not(:empty) {
    display: inline-block;
    margin: 8px 0 0;
    padding: 4px 8px;
    border-radius: 999px;
    background: #e0f2fe;
    color: #075985;
    font-size: 0.78rem;
    font-weight: 600;
}

#source-note:empty { display: none; }

.coord-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 8px;
}

.coord-fields label { margin-top: 0; }

#category-note { margin: 6px 0 0; }

details.extra {
    margin-top: 12px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--panel);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

details.extra summary {
    cursor: pointer;
    font-weight: 650;
    padding: 12px 14px;
    list-style: none;
    color: var(--ink);
    transition: background var(--ease);
}

details.extra summary::-webkit-details-marker { display: none; }

details.extra summary::after {
    content: "+";
    float: right;
    color: var(--muted);
    font-weight: 500;
}

details.extra[open] summary {
    border-bottom: 1px solid var(--line);
    background: var(--panel-soft);
}

details.extra[open] summary::after { content: "−"; }

details.extra h2 { display: none; }

details.extra section,
details.extra > ul {
    margin: 0;
    padding: 12px 14px 14px;
}

.pair-actions {
    display: flex;
    gap: 8px;
    margin-top: 6px;
}

.pair-actions button {
    padding: 4px 8px;
    font-size: 0.82rem;
}

.downloaded-label,
.road-label {
    max-width: 180px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: #1e293b;
    font-family: "Noto Sans Myanmar", "Source Sans 3", sans-serif;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    box-shadow: none;
    cursor: pointer;
    text-shadow:
        0 0 2px #f8fafc,
        1px 0 #f8fafc,
        -1px 0 #f8fafc,
        0 1px #f8fafc,
        0 -1px #f8fafc;
}

.downloaded-label.overture { color: #334155; }

.road-label { color: #475569; font-size: 11px; }

.downloaded-label.active,
.road-label.active {
    padding: 1px 6px;
    border: 1px solid var(--accent);
    border-radius: 4px;
    background: #fff;
    box-shadow: 0 0 0 2px var(--accent);
    text-shadow: none;
}

.place-pin, .draft-pin {
    position: relative;
    width: 16px;
    height: 16px;
    padding: 0;
    border: 2px solid #fff;
    border-radius: 50%;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.pin-label {
    position: absolute;
    left: 18px;
    top: 50%;
    transform: translateY(-50%);
    padding: 2px 7px;
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.3;
    white-space: nowrap;
    box-shadow: var(--shadow-sm);
    pointer-events: none;
}

.draft-pin {
    background: var(--accent);
    width: 18px;
    height: 18px;
    cursor: grab;
}

.maplibregl-marker:active .draft-pin { cursor: grabbing; }

.swatches {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 12px;
    margin-bottom: 10px;
}

.swatches label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin: 0;
}

.swatches input[type="color"] {
    width: 42px;
    height: 28px;
    padding: 2px;
    border: 1px solid var(--line);
    background: #fff;
    cursor: pointer;
}

#theme button { margin-top: 4px; }

#status {
    margin-top: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: #eff6ff;
    color: #1e3a5f;
    font-weight: 500;
}

#status:empty, #route-summary:empty { display: none; }

#credit {
    margin-top: 16px;
    padding: 0 4px;
    font-size: 0.78rem;
    line-height: 1.35;
}

.maplibregl-ctrl-group {
    border: 1px solid var(--line) !important;
    box-shadow: var(--shadow-sm) !important;
    border-radius: var(--radius-sm) !important;
    overflow: hidden;
}

/* ——— Responsive ——— */

@media (max-width: 960px) {
    .login-shell {
        grid-template-columns: 1fr;
        width: min(100%, 440px);
    }

    .login-brand {
        min-height: 180px;
        padding: 28px 24px;
    }

    .brand-name { font-size: 1.7rem; }
}

@media (max-width: 800px) {
    #app {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(42vh, auto) 58vh;
    }

    aside {
        border-right: 0;
        border-bottom: 1px solid var(--line);
        max-height: 48vh;
    }
}
