/* --- 1. THEME VARIABLES --- */
:root {
    /* This is the FALLBACK theme (your current dark theme) */
    --app-bg-color: #1a1a1a;
    --app-bg-image: linear-gradient(rgba(120, 120, 120, 0.05) 1px, transparent 1px), linear-gradient(90deg, rgba(120, 120, 120, 0.05) 1px, transparent 1px);
    --app-bg-size: 30px 30px;
    --card-bg-color: rgba(40, 40, 40, 0.6);
    --card-border-color: rgba(255, 255, 255, 0.1);
    --text-primary-color: #f0f0f0;
    --text-secondary-color: #999;
    --divider-color: #444;
    --input-bg-color: rgba(50, 50, 50, 0.8);
    --primary-accent-color: #fc5200;
    --primary-accent-color-rgb: 252, 82, 0;
    --secondary-accent-color: #00aaff;
    --progress-color: #39d353;
    --button-raised-bg: var(--primary-accent-color);
    --button-raised-text: #ffffff;
    --button-subtle-bg: #555;
    --success-color: #28a745;
}

body.light-theme {
    /* Light Theme Overrides */
    --app-bg-color: #f0f2f5;
    --card-bg-color: rgba(255, 255, 255, 0.5);
    --card-border-color: rgba(255, 255, 255, 0.2);
    --text-primary-color: #202124;
    --text-secondary-color: #5f6368;
    --divider-color: #dadce0;
    --input-bg-color: rgba(220, 220, 220, 0.7);
    --progress-color: #2ea043;
    --button-raised-bg: var(--secondary-accent-color);
    --button-subtle-bg: #e8eaed;
}

/* --- 2. BASE & BACKGROUND --- */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--app-bg-color);
    color: var(--text-primary-color);
    margin: 0;
    padding: 40px 20px;
    /* Themes will update these variables */
    background-image: var(--app-bg-image);
    background-size: var(--app-bg-size);
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: fixed;
    box-sizing: border-box;
    transition: background-image 0.5s ease, background-color 0.5s ease;
}

/* --- 3. MAIN LAYOUT & CARD --- */

.container {
    background: var(--card-bg-color);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--card-border-color);
    border-radius: 16px;
    padding: 30px;
    width: 90%;
    max-width: 600px;
    text-align: center;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    margin: 0 auto;
    position: relative;
    transition: background-color 0.5s ease, border-color 0.5s ease;
}
h1, h2 {
    color: var(--primary-accent-color);
}
h3 {
    text-align: left;
    margin-top: 20px;
    margin-bottom: 10px;
    border-bottom: 1px solid var(--divider-color);
    padding-bottom: 5px;
}
p, label {
    color: var(--text-secondary-color);
}
hr.divider {
    margin: 30px 0;
    border: 0;
    border-top: 1px solid var(--divider-color);
}
#challenge-icon-container {
    width: 80px;
    height: 80px;
    margin: 0 auto 20px auto;
}
#challenge-icon-container img,
#challenge-icon-container svg {
    width: 100%;
    height: 100%;
    object-fit: cover;
    fill: var(--primary-accent-color);
}

/* --- 4. FORMS & BUTTONS --- */
.form-group {
    display: flex;
    flex-direction: column;
    text-align: left;
    gap: 5px;
    margin-bottom: 20px;
}
input[type="text"], input[type="email"], select, button {
    background: var(--input-bg-color);
    color: var(--text-primary-color);
    border: 1px solid var(--divider-color);
    border-radius: 6px;
    padding: 10px;
    font-size: 1em;
    font-family: inherit;
    box-sizing: border-box;
}
button {
    cursor: pointer;
    background-color: var(--primary-accent-color);
    color: white;
    font-weight: bold;
    border: none;
    transition: background-color 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
button:hover {
    filter: brightness(1.1);
}
button:disabled {
    background-color: var(--button-subtle-bg);
    cursor: not-allowed;
}
button svg {
    width: 1.2em;
    height: 1.2em;
    fill: currentColor;
}
.hidden { display: none !important; }
.save-btn { background-color: var(--success-color); }

.google-btn {
    width: 240px;
    height: 40px;
    background-color: #fff;
    color: #444;
    border-radius: 5px;
    border: 1px solid #dadce0;
    box-shadow: 0 1px 3px 0 rgba(0,0,0,.20);
    font-family: 'Roboto', sans-serif;
    font-weight: 500;
    font-size: 14px;
}
.google-btn:hover { background-color: #f8f9fa; }
.strava-connect-link {
    display: inline-block;
    margin: 10px 0;
    line-height: 0;
}
.strava-connect-link img {
    height: 48px;
    transition: transform 0.2s ease;
}
.strava-connect-link:hover img {
    transform: scale(1.02);
}
input[type="checkbox"] {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    display: inline-block;
    width: 20px;
    height: 20px;
    background-color: var(--input-bg-color);
    border: 2px solid var(--divider-color);
    border-radius: 4px;
    cursor: pointer;
    position: relative;
    vertical-align: middle;
    transition: background-color 0.2s, border-color 0.2s;
    flex-shrink: 0;
}
input[type="checkbox"]:checked {
    background-color: var(--primary-accent-color);
    border-color: var(--primary-accent-color);
}
input[type="checkbox"]:checked::after {
    content: '✔';
    font-size: 14px;
    color: white;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    line-height: 1;
}
input[type="checkbox"]:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(var(--primary-accent-color-rgb), 0.5);
}
.public-toggle {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    margin-top: 20px;
    margin-bottom: 0;
}
.public-toggle label {
    margin-bottom: 0;
    cursor: pointer;
}
.public-toggle input[type="checkbox"] {
    margin-right: 10px;
}


/* --- 5. MAP & STATS --- */
.map-container { margin: 20px 0; }
#progress-map path { fill: none; stroke-width: 10; }
#path-track { stroke: var(--divider-color); }
#path-progress { stroke: var(--progress-color); transition: stroke-dashoffset 1s ease-in-out; }
.milestone circle { fill: var(--button-subtle-bg, #555); stroke: var(--card-bg-color); stroke-width: 2; }
.milestone text { fill: var(--text-secondary-color); font-size: 12px; text-anchor: middle; }
.milestone.unlocked circle { fill: var(--secondary-accent-color); }
.milestone.unlocked text { fill: var(--text-primary-color); font-weight: bold; }
.stats { margin-top: 15px; }

    /*
    * PROGRESS MAP & FOG OF WAR STYLES
    */

/* The container that holds the map image */
#progress-map-container {
    position: relative;
    width: 100%;
    /* We let the SVG's viewBox define the aspect ratio.
      This container just holds it.
    */
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    border-radius: 12px;
    overflow: hidden;
}

/* The SVG element itself (the "glass" on top) */
#progress-map {
    display: block; /* Removes bottom space */
    width: 100%;
    /* height: 100%; <-- THIS LINE IS REMOVED (THE FIX) */
    /* Make the SVG background transparent so we see the map image */
    background-color: transparent;
}

/* The grey track (the full path) */
#path-track {
    fill: none;
    stroke: rgba(255, 255, 255, 0.2); /* Faint white */
    stroke-width: 4px; /* Thin */
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* The user's progress path (colored) */
#path-progress {
    fill: none;
    stroke: var(--progress-color, #ffdd57);
    stroke-width: 10px; /* <-- INCREASED */
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: stroke-dashoffset 1s ease-out;
}

/* The "fog of war" rectangle */
#fog-of-war {
    fill: #222; /* Dark grey */
    opacity: 0.99; /* Very dense */
    /* x, y, width, height are set by JS */
}

/* The path inside the mask that "clears" the fog */
#fog-mask-path {
    fill: none;
    stroke: black; /* This BLACK stroke conceals the fog */
    stroke-width: 50px; /* <-- INCREASED (This is the reveal range) */
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: stroke-dashoffset 1s ease-out;
}

/* The rect inside the mask */
#fog-mask > rect {
    fill: white; /* This WHITE rect reveals the fog */
    /* x, y, width, height are set by JS */
}

/* --- NEW MILESTONE STYLES --- */
.milestone circle {
    r: 12px; /* Larger radius */
    fill: rgba(255, 255, 255, 0.4); /* Locked milestone */
    stroke: white;
    stroke-width: 2px;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5));
    transition: all 0.3s ease; /* Added transition */
}

.milestone.unlocked circle {
    fill: var(--primary-accent-color, #ffdd57); /* Unlocked color */
    stroke: white;
}

.milestone text {
    font-size: 18px; /* <-- INCREASED */
    font-weight: 600;
    fill: white;
    text-anchor: middle;
    stroke: black; /* Thin outline for legibility */
    stroke-width: 0.4px;
    paint-order: stroke; /* Draw stroke behind fill */
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.8));
    transform: translateY(-18px); /* <-- Adjusted */
}

/* --- 6. ACTIVITY LOG --- */
#activity-log-section { margin-top: 30px; }
.controls-grid { display: flex; flex-wrap: wrap; gap: 15px; align-items: flex-end; margin-bottom: 20px; }
.controls-grid .form-group { flex-grow: 1; margin-bottom: 0; }
.activity-list {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--divider-color);
    border-radius: 8px;
    margin-top: 10px;
    padding: 10px;
}
.empty-list-message {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-secondary-color);
    font-style: italic;
}
.activity-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 8px;
    background-color: rgba(40, 50, 60, 0.7);
}
.activity-item:last-child { margin-bottom: 0; }
.activity-item:nth-child(4n+2) { background-color: rgba(40, 60, 50, 0.7); }
.activity-item:nth-child(4n+3) { background-color: rgba(60, 50, 40, 0.7); }
.activity-item:nth-child(4n+4) { background-color: rgba(50, 40, 60, 0.7); }
body.light-theme .activity-item:nth-child(4n+1) { background-color: rgba(210, 225, 240, 0.7); }
body.light-theme .activity-item:nth-child(4n+2) { background-color: rgba(210, 240, 225, 0.7); }
body.light-theme .activity-item:nth-child(4n+3) { background-color: rgba(240, 225, 210, 0.7); }
body.light-theme .activity-item:nth-child(4n+4) { background-color: rgba(225, 210, 240, 0.7); }

.activity-selector, .icon-placeholder {
    flex-shrink: 0;
}
.icon-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
}
.icon-placeholder svg {
    width: 1.5em;
    height: 1.5em;
    fill: currentColor;
    color: var(--text-secondary-color);
    display: block;
}
.activity-info {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    overflow: hidden;
    text-align: left;
}
.activity-text {
    display: flex;
    flex-direction: column;
}
.activity-info strong {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    color: var(--text-primary-color);
    margin-bottom: 4px;
}
.activity-info span {
    display: flex;
    align-items: center;
    font-size: 0.9em;
    color: var(--text-secondary-color);
    white-space: nowrap;
}
.activity-assign { flex-shrink: 0; width: 200px; display: flex; flex-direction: column; gap: 5px; text-align: left; }
.activity-assign label { font-size: 0.8em; margin-bottom: -2px; }
.activity-assign-dropdown { width: 100%; padding: 4px 8px; font-size: 0.9em; }
#sync-btn, #save-all-btn { margin-top: 20px; }
#sync-btn.synced { background-color: #555; color: #aaa; font-size: 0.8em; font-weight: normal; padding: 5px 10px; }


/* --- 7. MODALS (LEADERBOARD, FRIENDS, PROFILE) --- */
.top-controls { display: flex; gap: 15px; align-items: flex-end; margin-bottom: 20px; }
.top-controls .form-group { flex-grow: 1; margin-bottom: 0; }
.top-controls button { flex-shrink: 0; }

#profile-icon {
    position: fixed;
    top: 20px;
    left: 20px;
    width: 50px;
    height: 50px;
    background: var(--card-bg-color);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--card-border-color);
    border-radius: 50%;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    z-index: 100;
    cursor: pointer;
    padding: 0;
}
#profile-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
#theme-toggle-btn {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    background: var(--card-bg-color);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--card-border-color);
    border-radius: 50%;
    color: var(--text-secondary-color);
    z-index: 100;
    padding: 8px;
}
#theme-toggle-btn i {
    font-size: 24px;
    cursor: pointer;
}
.icon-on { display: none; }
.icon-off { display: inline-block; }
body.light-theme .icon-on { display: inline-block; }
body.light-theme .icon-off { display: none; }

#friends-btn, .profile-modal-btn {
    background-color: var(--button-subtle-bg);
    color: var(--text-primary-color);
    font-weight: normal;
}
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}
.modal-content {
    background: var(--card-bg-color);
    padding: 30px;
    border-radius: 16px;
    border: 1px solid var(--card-border-color);
    width: 90%;
    max-width: 500px;
    position: relative;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    gap: 15px;
}
.modal-close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--text-secondary-color);
    cursor: pointer;
}
#leaderboard-list { list-style: none; padding: 0; margin: 0; overflow-y: auto; }
.leaderboard-item { display: flex; align-items: center; padding: 10px; border-bottom: 1px solid var(--divider-color); }
.leaderboard-item:last-child { border-bottom: none; }
.leaderboard-item .rank { font-size: 1.2em; font-weight: bold; color: var(--text-secondary-color); width: 40px; text-align: left; }
.leaderboard-item .avatar { width: 40px; height: 40px; border-radius: 50%; margin-right: 15px; }
.leaderboard-item .name { flex-grow: 1; text-align: left; }
.leaderboard-item .distance { font-weight: bold; color: var(--primary-accent-color); }
.leaderboard-item.friend-highlight .avatar {
    border: 3px solid var(--primary-accent-color);
    box-shadow: 0 0 10px var(--primary-accent-color);
}
.peer-marker circle { stroke-width: 2; stroke: rgba(255, 255, 255, 0.7); fill: #333; }
.peer-marker.friend-highlight circle {
    stroke: var(--primary-accent-color);
    stroke-width: 3;
    filter: drop-shadow(0 0 3px var(--primary-accent-color));
}
.private-warning {
    font-size: 0.8em;
    font-style: italic;
    color: var(--text-secondary-color);
    margin-left: 8px;
    cursor: pointer;
    text-decoration: underline;
}
.private-warning:hover {
    color: var(--text-primary-color);
}
.friend-code-container {
    display: flex;
    gap: 10px;
}
.friend-code-container input {
    flex-grow: 1;
}
.friend-code-container button {
    flex-shrink: 0;
    padding-left: 12px;
    padding-right: 12px;
}
.requests-list {
    border-top: 1px solid var(--divider-color);
    margin-top: 10px;
    padding-top: 10px;
    text-align: left;
}
.request-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    border-radius: 6px;
}
.request-item:nth-child(odd) {
    background-color: rgba(0,0,0,0.1);
}
body.light-theme .request-item:nth-child(odd) {
    background-color: rgba(0,0,0,0.05);
}
.request-item-info {
    font-size: 0.9em;
}
.request-item-actions button {
    font-size: 0.8em;
    padding: 5px 10px;
    margin-left: 5px;
}
.request-item-actions .accept-btn {
    background-color: var(--success-color);
}
.request-item-actions .decline-btn {
    background-color: var(--button-subtle-bg);
    color: var(--text-secondary-color);
}
#profile-modal button {
    width: 100%;
}
.logout-btn-modal {
    background: none;
    border: 1px solid var(--divider-color);
    color: var(--text-secondary-color);
}
.logout-btn-modal svg {
    width: 1.2em;
    height: 1.2em;
    fill: currentColor;
}


/* --- 8. FOOTER & TOAST --- */
.app-footer {
    background: var(--card-bg-color);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--card-border-color);
    border-radius: 16px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    width: 90%;
    max-width: 600px;
    margin: 20px auto 0 auto;
    padding: 15px;
    box-sizing: border-box;
    text-align: center;
}
.app-footer a {
    color: var(--text-secondary-color);
    font-size: 0.9em;
    text-decoration: none;
    transition: color 0.2s ease;
}
.app-footer a:hover {
    color: var(--text-primary-color);
    text-decoration: underline;
}
#toast {
    visibility: hidden;
    min-width: 250px;
    background: var(--card-bg-color);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--card-border-color);
    color: var(--text-primary-color);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    text-align: center;
    border-radius: 12px;
    padding: 16px;
    position: fixed;
    z-index: 1001;
    left: 50%;
    transform: translateX(-50%);
    bottom: 30px;
}
#toast.show {
    visibility: visible;
    -webkit-animation: fadein 0.5s, fadeout 0.5s 2.5s;
    animation: fadein 0.5s, fadeout 0.5s 2.5s;
}
@-webkit-keyframes fadein { from {bottom: 0; opacity: 0;} to {bottom: 30px; opacity: 1;} }
@keyframes fadein { from {bottom: 0; opacity: 0;} to {bottom: 30px; opacity: 1;} }
@-webkit-keyframes fadeout { from {bottom: 30px; opacity: 1;} to {bottom: 0; opacity: 0;} }
@keyframes fadeout { from {bottom: 30px; opacity: 1;} to {bottom: 0; opacity: 0;} }

/* --- 9. MOBILE RESPONSIVE STYLES --- */
@media (max-width: 600px) {
    body { padding-top: 60px; padding-left: 15px; padding-right: 15px; }
    .container { padding: 20px; }

    #challenge-icon-container {
        position: absolute;
        width: 80px;
        height: 80px;
        top: -40px;
        right: 20px;
        background: var(--card-bg-color);
        border: 1px solid var(--card-border-color);
        border-radius: 50%;
        padding: 12px;
        box-sizing: border-box;
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
    }
    #challenge-icon-container::before {
        content: '';
        position: absolute;
        width: 0;
        height: 0;
        bottom: -11px;
        left: 50%;
        transform: translateX(-50%);
        border-left: 10px solid transparent;
        border-right: 10px solid transparent;
        border-top: 10px solid var(--card-border-color);
    }
    #challenge-icon-container::after {
        content: '';
        position: absolute;
        width: 0;
        height: 0;
        bottom: -10px;
        left: 50%;
        transform: translateX(-50%);
        border-left: 10px solid transparent;
        border-right: 10px solid transparent;
        border-top: 10px solid var(--card-bg-color);
    }

    .controls-grid { grid-template-columns: 1fr; gap: 10px; }
    .activity-item { flex-direction: column; align-items: flex-start; gap: 15px; }
    .activity-assign { width: 100%; border-top: 1px solid var(--divider-color); padding-top: 15px; }
    .app-footer { display: none; }
}
