/* ============================================================
   Берёзка Карта — Dark Green Theme
   ============================================================ */

:root {
    --bg-primary: #0a0a0a;
    --bg-secondary: #141414;
    --bg-card: #1a1a1a;
    --bg-input: #222222;
    --green: #4caf50;
    --green-bright: #66bb6a;
    --green-dark: #2e7d32;
    --green-glow: rgba(76, 175, 80, 0.25);
    --text: #e0e0e0;
    --text-muted: #888;
    --border: #2a2a2a;
    --red: #ef5350;
    --country-default: #1e1e1e;
    --country-visited: #4caf50;
    --country-hover: #2a2a2a;
    --country-stroke: #333;
    --ocean: #0d1117;
}

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

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text);
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

/* ============================================================
   Screens
   ============================================================ */
.screen {
    display: none;
    position: absolute;
    inset: 0;
    flex-direction: column;
}
.screen.active {
    display: flex;
}

/* ============================================================
   Loading Screen
   ============================================================ */
#screen-loading {
    align-items: center;
    justify-content: center;
    gap: 16px;
}
.loader {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--green);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader-text {
    color: var(--text-muted);
    font-size: 14px;
}

/* ============================================================
   Auth Screen
   ============================================================ */
#screen-auth {
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: var(--bg-primary);
}
.auth-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 32px 28px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 0 40px rgba(76, 175, 80, 0.06);
}
.auth-logo {
    text-align: center;
    margin-bottom: 24px;
}
.auth-logo h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--green);
    margin-bottom: 4px;
}
.auth-logo p {
    font-size: 13px;
    color: var(--text-muted);
}
.auth-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    background: var(--bg-input);
    border-radius: 10px;
    padding: 3px;
}
.auth-tab {
    flex: 1;
    padding: 10px 0;
    text-align: center;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    border: none;
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}
.auth-tab.active {
    background: var(--green-dark);
    color: #fff;
}
.auth-input {
    width: 100%;
    padding: 12px 14px;
    margin-bottom: 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-input);
    color: var(--text);
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s;
}
.auth-input:focus {
    border-color: var(--green);
}
.auth-input::placeholder {
    color: #555;
}
.auth-btn {
    width: 100%;
    padding: 13px;
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--green-dark), var(--green));
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
    margin-top: 4px;
}
.auth-btn:active {
    opacity: 0.8;
}
.auth-error {
    color: var(--red);
    font-size: 13px;
    text-align: center;
    margin-top: 10px;
    min-height: 18px;
}

/* ============================================================
   Header
   ============================================================ */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 10;
}
.header-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--green);
}
.header-nav {
    display: flex;
    gap: 4px;
}
.nav-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}
.nav-btn.active, .nav-btn:hover {
    background: var(--green-glow);
    color: var(--green);
}

/* ============================================================
   Stats Bar
   ============================================================ */
.stats-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.stats-count {
    font-size: 14px;
    color: var(--text);
    font-weight: 500;
}
.stats-count span {
    color: var(--green);
    font-weight: 700;
}
.country-tooltip {
    font-size: 13px;
    color: var(--text-muted);
    max-width: 50%;
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============================================================
   Map Container
   ============================================================ */
.map-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: var(--ocean);
    touch-action: none;
}
.map-container svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}
.map-container svg .country {
    fill: var(--country-default);
    stroke: var(--country-stroke);
    stroke-width: 0.5;
    cursor: pointer;
    transition: fill 0.15s;
}
.map-container svg .country:hover {
    fill: var(--country-hover);
}
.map-container svg .country.visited {
    fill: var(--country-visited);
}
.map-container svg .country.visited:hover {
    fill: var(--green-bright);
}
.map-container svg .country.other-visited {
    fill: #1a8a5e;
}

/* Zoom controls */
.zoom-controls {
    position: absolute;
    bottom: 20px;
    right: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 5;
}
.zoom-btn {
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-card);
    color: var(--text);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}
.zoom-btn:active {
    background: var(--green-dark);
    color: #fff;
}

/* Country list button */
.list-btn {
    position: absolute;
    bottom: 20px;
    left: 16px;
    height: 40px;
    padding: 0 16px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-card);
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    z-index: 5;
}
.list-btn:active {
    background: var(--green-dark);
    color: #fff;
}

/* ============================================================
   Country List Modal
   ============================================================ */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    z-index: 100;
    align-items: flex-end;
    justify-content: center;
}
.modal-overlay.active {
    display: flex;
}
.modal {
    background: var(--bg-card);
    border-radius: 16px 16px 0 0;
    width: 100%;
    max-width: 500px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.25s ease;
}
@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
}
.modal-close {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 8px;
    background: var(--bg-input);
    color: var(--text);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-search {
    padding: 12px 20px;
    flex-shrink: 0;
}
.modal-search input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-input);
    color: var(--text);
    font-size: 14px;
    outline: none;
}
.modal-search input:focus {
    border-color: var(--green);
}
.modal-search input::placeholder {
    color: #555;
}
.modal-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
    -webkit-overflow-scrolling: touch;
}
.modal-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    cursor: pointer;
    transition: background 0.15s;
}
.modal-list-item:active {
    background: var(--bg-input);
}
.modal-list-item .name {
    font-size: 14px;
}
.modal-list-item .check {
    width: 22px;
    height: 22px;
    border: 2px solid var(--border);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: transparent;
    flex-shrink: 0;
    transition: all 0.15s;
}
.modal-list-item.checked .check {
    background: var(--green);
    border-color: var(--green);
    color: #fff;
}

/* ============================================================
   Search Screen
   ============================================================ */
.search-panel {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    -webkit-overflow-scrolling: touch;
}
.search-row {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}
.search-input {
    flex: 1;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-input);
    color: var(--text);
    font-size: 15px;
    outline: none;
}
.search-input:focus {
    border-color: var(--green);
}
.search-input::placeholder {
    color: #555;
}
.search-go {
    padding: 12px 20px;
    border: none;
    border-radius: 10px;
    background: var(--green-dark);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}
.search-go:active {
    opacity: 0.8;
}
.search-result {
    padding: 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    text-align: center;
}
.search-result h3 {
    font-size: 16px;
    margin-bottom: 4px;
}
.search-result p {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 14px;
}
.search-result .open-map-btn {
    padding: 10px 24px;
    border: none;
    border-radius: 8px;
    background: var(--green-dark);
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
}
.search-result .open-map-btn:active {
    opacity: 0.8;
}
.search-msg {
    color: var(--text-muted);
    font-size: 14px;
    text-align: center;
    padding: 40px 0;
}
.search-error {
    color: var(--red);
    font-size: 14px;
    text-align: center;
    padding: 40px 0;
}

/* ============================================================
   View Map Screen (other user)
   ============================================================ */
.view-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.back-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: var(--bg-input);
    color: var(--text);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.back-btn:active {
    background: var(--green-dark);
    color: #fff;
}
.view-header-info h2 {
    font-size: 16px;
    font-weight: 600;
}
.view-header-info p {
    font-size: 12px;
    color: var(--text-muted);
}

/* ============================================================
   Settings Screen
   ============================================================ */
.settings-panel {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    -webkit-overflow-scrolling: touch;
}
.settings-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 16px;
    overflow: hidden;
}
.settings-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
}
.settings-item + .settings-item {
    border-top: 1px solid var(--border);
}
.settings-label {
    font-size: 15px;
}
.settings-desc {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}
/* Toggle switch */
.toggle {
    position: relative;
    width: 48px;
    height: 28px;
    flex-shrink: 0;
}
.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}
.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--bg-input);
    border-radius: 14px;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.2s;
}
.toggle-slider::before {
    content: '';
    position: absolute;
    width: 22px;
    height: 22px;
    left: 2px;
    top: 2px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: all 0.2s;
}
.toggle input:checked + .toggle-slider {
    background: var(--green-dark);
    border-color: var(--green);
}
.toggle input:checked + .toggle-slider::before {
    transform: translateX(20px);
    background: var(--green-bright);
}
.logout-btn {
    width: 100%;
    padding: 14px;
    border: 1px solid var(--red);
    border-radius: 12px;
    background: transparent;
    color: var(--red);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}
.logout-btn:active {
    background: var(--red);
    color: #fff;
}
.settings-user {
    text-align: center;
    padding: 20px;
    margin-bottom: 16px;
}
.settings-avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--green-dark);
    color: #fff;
    font-size: 28px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 10px;
}
.settings-username {
    font-size: 18px;
    font-weight: 600;
}

/* ============================================================
   Scrollbar
   ============================================================ */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ============================================================
   Mobile Responsive
   ============================================================ */
@media (max-width: 480px) {
    .auth-card {
        padding: 24px 20px;
        border-radius: 12px;
    }
    .auth-logo h1 {
        font-size: 20px;
    }
    .header {
        padding: 10px 12px;
    }
    .header-title {
        font-size: 16px;
    }
    .stats-bar {
        padding: 8px 12px;
    }
    .zoom-controls {
        bottom: 16px;
        right: 12px;
    }
    .zoom-btn {
        width: 36px;
        height: 36px;
        font-size: 18px;
    }
    .list-btn {
        bottom: 16px;
        left: 12px;
        height: 36px;
        padding: 0 12px;
        font-size: 12px;
    }
}

/* Safe area for notched phones */
@supports (padding-top: env(safe-area-inset-top)) {
    .header {
        padding-top: calc(12px + env(safe-area-inset-top));
    }
    .zoom-controls {
        bottom: calc(20px + env(safe-area-inset-bottom));
    }
    .list-btn {
        bottom: calc(20px + env(safe-area-inset-bottom));
    }
}
