*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg: #f4f1ec;
    --ocean: #dceefb;
    --land: #f2efe9;
    --land-hover: #e6e0d4;
    --land-selected: #d4cfc5;
    --border: #c8c0b4;
    --graticule: rgba(0,0,0,0.06);
    --text: #2c2c2c;
    --text-muted: #777;
    --panel-bg: #fff;
    --panel-border: rgba(0,0,0,0.08);
    --toolbar-bg: rgba(255,255,255,0.92);
    --accent: #c8943e;
    --accent-soft: rgba(200,148,62,0.15);
    --btn-text: #555;
    --btn-hover: rgba(0,0,0,0.04);
    --btn-active-bg: var(--accent-soft);
    --btn-active-text: #a07530;
    --tissot-stroke: rgba(200,80,60,0.4);
    --tissot-fill: rgba(200,80,60,0.06);
    --country-label: rgba(60,55,50,0.55);
    --strip-bg: rgba(255,255,255,0.88);
    --strip-item: rgba(0,0,0,0.04);
    --strip-active: var(--accent);
    --truesize-fill: rgba(200,148,62,0.25);
    --truesize-stroke: #c8943e;
    --kbd-bg: rgba(0,0,0,0.06);
    --kbd-border: rgba(0,0,0,0.12);
}

[data-theme="dark"] {
    --bg: #0d1117;
    --ocean: #0d1926;
    --land: #1e2530;
    --land-hover: #2a3340;
    --land-selected: #343e4d;
    --border: #333d4a;
    --graticule: rgba(255,255,255,0.04);
    --text: #d0d4db;
    --text-muted: #7d8590;
    --panel-bg: rgba(22,27,34,0.95);
    --panel-border: rgba(255,255,255,0.06);
    --toolbar-bg: rgba(22,27,34,0.88);
    --accent: #d4a04a;
    --accent-soft: rgba(212,160,74,0.12);
    --btn-text: #8b929a;
    --btn-hover: rgba(255,255,255,0.05);
    --btn-active-bg: var(--accent-soft);
    --btn-active-text: #d4a04a;
    --tissot-stroke: rgba(230,90,70,0.4);
    --tissot-fill: rgba(230,90,70,0.06);
    --country-label: rgba(160,166,175,0.45);
    --strip-bg: rgba(13,17,23,0.92);
    --strip-item: rgba(255,255,255,0.04);
    --strip-active: #d4a04a;
    --truesize-fill: rgba(212,160,74,0.2);
    --truesize-stroke: #d4a04a;
    --kbd-bg: rgba(255,255,255,0.06);
    --kbd-border: rgba(255,255,255,0.1);
}

html, body {
    width: 100%; height: 100%;
    overflow: hidden;
    background: var(--ocean);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

#map {
    position: absolute;
    inset: 0;
    width: 100%; height: 100%;
    cursor: grab;
}
#map:active { cursor: grabbing; }

.hidden { display: none !important; }

/* ---- Top bar ---- */
#topbar {
    position: absolute;
    top: 12px; left: 12px; right: 12px;
    display: flex;
    gap: 8px;
    z-index: 30;
    pointer-events: none;
}
#topbar > * { pointer-events: auto; }

#search-box {
    position: relative;
    flex: 0 0 280px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 14px;
    background: var(--toolbar-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
#search-box svg { flex-shrink: 0; color: var(--text-muted); }
#search {
    flex: 1;
    padding: 9px 0;
    border: none;
    background: transparent;
    font: inherit;
    font-size: 13px;
    color: var(--text);
    outline: none;
}
#search::placeholder { color: var(--text-muted); }

#search-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0; right: 0;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    max-height: 280px;
    overflow-y: auto;
    z-index: 31;
}
.result-item {
    padding: 9px 14px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.1s;
}
.result-item:hover { background: var(--btn-hover); }
.result-item:first-child { border-radius: 10px 10px 0 0; }
.result-item:last-child { border-radius: 0 0 10px 10px; }
.result-type {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-left: 6px;
}

#tools {
    display: flex;
    gap: 0;
    background: var(--toolbar-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    overflow: hidden;
}
#tools button {
    padding: 9px 12px;
    border: none;
    border-right: 1px solid var(--panel-border);
    background: transparent;
    color: var(--btn-text);
    font: inherit;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
}
#tools button:last-child { border-right: none; }
#tools button:hover { background: var(--btn-hover); }
#tools button.active {
    background: var(--btn-active-bg);
    color: var(--btn-active-text);
}
#tools button.active svg { stroke: var(--btn-active-text); }

/* ---- Info panel ---- */
#info-panel {
    position: absolute;
    top: 64px; left: 12px;
    width: 260px;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.1);
    padding: 16px;
    z-index: 25;
}
#info-close {
    position: absolute;
    top: 8px; right: 10px;
    border: none; background: none;
    font-size: 16px; cursor: pointer;
    color: var(--text-muted);
    line-height: 1;
}
#info-panel h2 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 10px;
    padding-right: 20px;
}
#info-details {
    font-size: 12px;
    line-height: 1.8;
    color: var(--text-muted);
}
.info-row {
    display: flex;
    justify-content: space-between;
    padding: 1px 0;
}
.info-label { color: var(--text); font-weight: 500; }
#info-drag-btn {
    display: block;
    width: 100%;
    margin-top: 10px;
    padding: 7px;
    border: 1px solid var(--accent);
    border-radius: 6px;
    background: var(--accent-soft);
    color: var(--accent);
    font: inherit;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}
#info-drag-btn:hover { background: var(--accent); color: #fff; }

/* ---- Tooltip ---- */
#tooltip {
    position: absolute;
    padding: 4px 8px;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    color: var(--text);
    border-radius: 5px;
    font-size: 11px;
    font-weight: 500;
    pointer-events: none;
    z-index: 40;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* ---- Projection strip ---- */
#proj-strip {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    z-index: 30;
    background: var(--strip-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--panel-border);
    padding: 8px 0;
}
#proj-scroll {
    display: flex;
    gap: 6px;
    padding: 0 12px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
#proj-scroll::-webkit-scrollbar { display: none; }

.proj-item {
    flex: 0 0 auto;
    padding: 6px 14px;
    border-radius: 7px;
    background: var(--strip-item);
    border: 1.5px solid transparent;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    scroll-snap-align: start;
    transition: all 0.2s;
    white-space: nowrap;
    user-select: none;
    -webkit-user-select: none;
}
.proj-item:hover {
    color: var(--text);
    background: var(--btn-hover);
}
.proj-item.active {
    border-color: var(--strip-active);
    color: var(--strip-active);
    background: var(--accent-soft);
    font-weight: 600;
}
.proj-item .proj-num {
    display: inline-block;
    width: 14px;
    height: 14px;
    line-height: 14px;
    text-align: center;
    border-radius: 3px;
    background: var(--kbd-bg);
    border: 1px solid var(--kbd-border);
    font-size: 9px;
    font-weight: 600;
    margin-right: 5px;
    vertical-align: 1px;
    color: var(--text-muted);
}
.proj-item.active .proj-num {
    background: var(--accent-soft);
    border-color: var(--strip-active);
    color: var(--strip-active);
}

/* ---- Projection info card ---- */
#proj-card {
    position: absolute;
    bottom: 56px; left: 12px;
    width: 320px;
    max-width: calc(100vw - 24px);
    z-index: 29;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.12);
    overflow: hidden;
    transition: opacity 0.2s, transform 0.2s;
}
#proj-card.hidden {
    display: block !important;
    opacity: 0;
    transform: translateY(8px);
    pointer-events: none;
}
#proj-card:not(.hidden) {
    opacity: 1;
    transform: translateY(0);
}
#proj-card-inner { padding: 14px 16px; }
#proj-card-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}
.badge-conformal { background: #e8f0fe; color: #1a73e8; }
.badge-equal-area { background: #e6f4ea; color: #1e8e3e; }
.badge-compromise { background: #fef7e0; color: #b06e00; }
.badge-perspective { background: #fce8e6; color: #d93025; }
.badge-polyhedral { background: #f3e8fd; color: #8430ce; }
[data-theme="dark"] .badge-conformal { background: rgba(26,115,232,0.15); color: #58a6ff; }
[data-theme="dark"] .badge-equal-area { background: rgba(30,142,62,0.15); color: #56d364; }
[data-theme="dark"] .badge-compromise { background: rgba(176,110,0,0.15); color: #d4a04a; }
[data-theme="dark"] .badge-perspective { background: rgba(217,48,37,0.15); color: #f47067; }
[data-theme="dark"] .badge-polyhedral { background: rgba(132,48,206,0.15); color: #bc8cff; }

#proj-card-name {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 4px;
}
#proj-card-desc {
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-muted);
    margin-bottom: 8px;
}
#proj-card-props {
    display: flex;
    gap: 12px;
    font-size: 11px;
    color: var(--text-muted);
}
.prop-item { display: flex; flex-direction: column; gap: 1px; }
.prop-label { font-size: 9px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); }
.prop-value { font-weight: 600; color: var(--text); font-size: 11px; }

/* ---- About overlay ---- */
#about-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
}
#about-box {
    width: 420px;
    max-width: 90vw;
    max-height: 80vh;
    overflow-y: auto;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    padding: 24px;
    position: relative;
}
#about-close {
    position: absolute;
    top: 12px; right: 14px;
    border: none; background: none;
    font-size: 18px; cursor: pointer;
    color: var(--text-muted);
}
#about-box h2 { font-size: 17px; font-weight: 600; margin-bottom: 12px; }
#about-box p {
    font-size: 13px; line-height: 1.65;
    color: var(--text-muted); margin-bottom: 10px;
}
#about-box em { color: var(--text); font-style: italic; }
#about-box hr { border: none; border-top: 1px solid var(--panel-border); margin: 14px 0; }
.credit { font-size: 11px; color: var(--text-muted); }
.credit a { color: var(--accent); text-decoration: none; }
.shortcuts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 16px;
    margin: 12px 0;
    font-size: 12px;
    color: var(--text-muted);
}
kbd {
    display: inline-block;
    padding: 1px 5px;
    border-radius: 3px;
    background: var(--kbd-bg);
    border: 1px solid var(--kbd-border);
    font-family: inherit;
    font-size: 10px;
    font-weight: 600;
    min-width: 18px;
    text-align: center;
}

/* ---- True-size bar ---- */
#truesize-bar {
    position: absolute;
    top: 56px; left: 50%;
    transform: translateX(-50%);
    z-index: 35;
    background: var(--panel-bg);
    border: 1px solid var(--accent);
    border-radius: 8px;
    padding: 8px 16px;
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.1);
    white-space: nowrap;
}
#truesize-exit {
    padding: 4px 10px;
    border: 1px solid var(--panel-border);
    border-radius: 5px;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 11px;
    cursor: pointer;
}
#truesize-exit:hover { background: var(--btn-hover); }

/* ---- Scale bar ---- */
#scale-bar {
    position: absolute;
    bottom: 52px; right: 14px;
    z-index: 15;
}
#scale-line {
    height: 2px;
    background: var(--text-muted);
    min-width: 40px;
    border-left: 2px solid var(--text-muted);
    border-right: 2px solid var(--text-muted);
    box-sizing: content-box;
    padding-top: 5px;
}
#scale-label {
    font-size: 9px;
    color: var(--text-muted);
    text-align: center;
    display: block;
    margin-top: 1px;
}

/* ---- Responsive ---- */
@media (max-width: 640px) {
    #search-box { flex: 0 0 160px; }
    #tools button { padding: 8px 10px; min-width: 34px; }
    #info-panel { width: calc(100% - 24px); top: auto; bottom: 56px; left: 12px; }
    #proj-card { width: calc(100% - 24px); }
    #truesize-bar { font-size: 11px; padding: 6px 12px; }
    .shortcuts { grid-template-columns: 1fr; }
}
