* {
    box-sizing: border-box;
}

:root {
    --brand: #0BAB9E;
    --brand-light: #E6F4F4;
    --brand-soft: #9DD8D5;
    --ink: #2C2F31;
}

html,
body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    width: 100%;
    overflow-x: hidden;
    font-family: Arial, sans-serif;
    background: var(--brand-light);
    color: var(--ink);
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    padding: clamp(8px, 2vw, 20px);
}

button,
input {
    font: inherit;
}

button {
    border: 0;
    border-radius: 8px;
    background: var(--brand);
    color: white;
    cursor: pointer;
    font-weight: 700;
    transition: transform 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

.top-bar button,
.bottom-buttons button,
.secondary-page button {
    background: var(--brand);
}

.top-bar .sign-in {
    background: var(--brand-soft);
    color: var(--ink);
}

.top-bar .logout {
    background: #dc2626;
    color: white;
}

.top-bar .logout:hover {
    background: #b91c1c;
    color: white;
}

.is-hidden {
    display: none !important;
}

button:hover {
    background: var(--brand-soft);
    color: var(--ink);
    box-shadow: 0 6px 16px rgba(11, 171, 158, 0.22);
    transform: translateY(-1px);
}

button:active {
    transform: translateY(0);
}

/* ==================== TOP BAR ==================== */

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    width: min(100%, 1080px);
    margin: 0 auto 12px;
    padding: 10px;
    background: white;
    border: 1px solid var(--brand-soft);
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(44, 47, 49, 0.08);
}

.brand-logo {
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
    width: 50px;
    height: 50px;
}

.brand-logo img {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.auth-buttons {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    width: min(100%, 360px);
    min-width: 0;
}

.top-bar button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 8px 10px;
    font-size: 0.86rem;
    line-height: 1;
    white-space: nowrap;
    text-align: center;
}

.coins-label {
    font-weight: 700;
}

/* ==================== MAP ==================== */

#map {
    width: min(100%, 1080px);
    height: min(62vh, 560px);
    min-height: 360px;
    margin: 0 auto 14px;
    border: 2px solid var(--ink);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 10px 28px rgba(44, 47, 49, 0.18);
}

.leaflet-control-zoom a {
    color: var(--ink);
}

.leaflet-control-zoom a:hover {
    background: var(--brand-light);
    color: var(--ink);
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
    color: var(--ink);
}

.map-pin {
    background: transparent;
    border: 0;
}

.map-pin span {
    display: block;
}

.waypoint-pin span {
    width: 26px;
    height: 26px;
    position: relative;
    border: 3px solid white;
    border-radius: 50% 50% 50% 0;
    background: var(--brand);
    box-shadow: 0 3px 10px rgba(44, 47, 49, 0.3);
    transform: rotate(-45deg);
}

.waypoint-pin span::after {
    content: "";
    position: absolute;
    top: 6px;
    left: 6px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--brand-light);
}

.user-pin span {
    width: 22px;
    height: 22px;
    border: 3px solid white;
    border-radius: 50%;
    background: var(--brand);
    box-shadow: 0 0 0 5px rgba(157, 216, 213, 0.5), 0 3px 10px rgba(44, 47, 49, 0.25);
}

/* ==================== BUTTONS + LEADERBOARD ==================== */

.bottom-section {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    width: min(100%, 1080px);
    margin: 0 auto;
}

.bottom-buttons {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

.bottom-buttons button {
    width: 100%;
    min-height: 48px;
    padding: 10px 12px;
    font-size: 0.9rem;
    letter-spacing: 0;
    white-space: normal;
}

.leaderboard {
    width: 100%;
    background: white;
    border: 1px solid var(--brand-soft);
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 2px 8px rgba(44, 47, 49, 0.08);
    overflow-x: hidden;
}

.leaderboard h3 {
    margin: 0 0 10px;
    text-align: center;
    color: var(--ink);
    font-size: 1.05rem;
}

.leaderboard table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    font-size: 0.88rem;
}

.leaderboard .rank-col {
    width: 34px;
}

.leaderboard .points-col {
    width: 86px;
}

.leaderboard th {
    text-align: left;
    padding: 7px 6px;
    border-bottom: 2px solid var(--brand-soft);
    color: var(--ink);
    font-size: 0.68rem;
    text-transform: uppercase;
    white-space: nowrap;
}

.leaderboard td {
    padding: 8px 6px;
    overflow-wrap: anywhere;
}

.leaderboard th:first-child,
.leaderboard td:first-child {
    width: 34px;
}

.leaderboard th:last-child,
.leaderboard td:last-child {
    width: 86px;
    text-align: right;
}

.leaderboard th:nth-child(2),
.leaderboard td:nth-child(2) {
    padding-right: 14px;
}

.leaderboard tbody tr:nth-child(even) {
    background-color: var(--brand-light);
}

.leaderboard tbody tr.top1 {
    background-color: var(--brand-soft);
    font-weight: 700;
}

.leaderboard tbody tr:hover {
    background-color: var(--brand-light);
}

.home-panels { display: grid; gap: 10px; min-width: 0; }

.rules-open { overflow: hidden; }

.rules-modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(5, 12, 18, 0.78);
    backdrop-filter: blur(8px);
}

.rules-modal.is-hidden { display: none; }
.rules-step.is-hidden { display: none; }

.rules-modal-card {
    width: min(100%, 560px);
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    padding: 28px;
    border-radius: 20px;
    background: #fff;
    color: #182026;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
}

.rules-modal-card h2 { margin: 0 0 18px; }
.rules-content { line-height: 1.55; }
.rules-content h3 { margin: 22px 0 10px; }
.rules-content h3:first-child { margin-top: 0; }
.rules-content p { margin: 0 0 14px; }
.rules-content ul { padding-left: 22px; }
.rules-content li { margin-bottom: 8px; }

.rules-step-count {
    display: block;
    margin-bottom: 6px;
    color: #66727a;
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.rules-consent {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 22px 0 16px;
    font-weight: 700;
    cursor: pointer;
}

.rules-consent input { margin-top: 3px; }
.rules-modal-card button { width: 100%; }
.rules-modal-card button:disabled { cursor: not-allowed; opacity: 0.45; }

.rules-actions { display: grid; grid-template-columns: 0.45fr 1fr; gap: 10px; }
.rules-modal-card .rules-secondary-button { background: #e8edef; color: #182026; }
.home-achievements {
    padding: 12px;
    border: 1px solid var(--brand-soft);
    border-radius: 12px;
    background: white;
    box-shadow: 0 2px 8px rgba(44, 47, 49, 0.08);
}
.home-panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.home-panel-heading h3 { margin: 0; font-size: 1.05rem; }
.home-panel-heading a { color: var(--brand); font-size: 0.8rem; font-weight: 800; text-decoration: none; }
#home-achievements-list { display: grid; gap: 8px; margin-top: 10px; }
.home-achievement {
    display: grid;
    grid-template-columns: 52px 1fr;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border: 1px solid var(--brand-soft);
    border-radius: 9px;
    background: var(--brand-light);
}
.home-achievement-medal { width: 52px; height: 52px; border-radius: 50%; object-fit: cover; }
.home-achievement span { display: block; margin-bottom: 3px; color: #667174; font-size: 0.66rem; font-weight: 800; text-transform: uppercase; }
.home-achievement strong { display: block; font-size: 0.88rem; line-height: 1.2; }
.home-achievement small { display: block; margin-top: 4px; color: #596164; font-size: 0.68rem; font-weight: 700; }
.achievement-progress {
    width: 100%;
    height: 7px;
    margin-top: 7px;
    overflow: hidden;
    border-radius: 999px;
    background: #d9e2e2;
}
.achievement-progress i {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--brand);
    transition: width 0.35s ease;
}
.home-achievement:nth-child(1) .achievement-progress i { background: #c9824b; }
.home-achievement:nth-child(2) .achievement-progress i { background: #aeb8c2; }
.home-achievement:nth-child(3) .achievement-progress i { background: #e7b416; }
.home-achievement.is-locked { opacity: 0.68; }
.home-achievement.is-locked > div { filter: grayscale(1); opacity: 0.72; }
.home-achievement.is-unlocked { border-left: 4px solid var(--brand); }

/* ==================== SECONDARY PAGES ==================== */

.secondary-page {
    width: min(100%, 680px);
    margin: 0 auto;
    padding: 20px;
    background: white;
    border: 1px solid var(--brand-soft);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(44, 47, 49, 0.1);
}

.secondary-page h1 {
    margin: 0 0 18px;
    font-size: clamp(1.6rem, 6vw, 2.4rem);
}

.secondary-page form {
    display: grid;
    gap: 12px;
    margin-bottom: 16px;
}

.secondary-page input {
    width: 100%;
    min-height: 46px;
    padding: 11px 12px;
    border: 1px solid var(--brand-soft);
    border-radius: 8px;
    background: var(--brand-light);
    color: var(--ink);
    font-size: 1rem;
}

.secondary-page button {
    min-height: 46px;
    padding: 11px 14px;
}

.form-message {
    min-height: 22px;
    margin: 0 0 10px;
    color: #b91c1c;
}

.form-message.success {
    color: #15803d;
}

.auth-switch {
    margin: 0;
    color: var(--ink);
}

.secondary-page a {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
    margin-top: 10px;
    color: var(--brand);
    font-weight: 700;
    text-decoration: none;
}

.secondary-page a:hover {
    text-decoration: underline;
}

.secondary-page ul {
    margin: 0;
    padding-left: 20px;
}

.quest-item {
    position: relative;
    border-bottom: 1px solid var(--brand-soft);
    padding: 14px 0;
}

.quest-item.quest-locked { opacity: 0.62; }
.quest-item.quest-complete { border-left: 4px solid var(--brand); padding-left: 12px; }
.quest-status {
    float: right;
    padding: 4px 8px;
    border-radius: 999px;
    background: var(--brand-light);
    color: var(--ink);
    font-size: 0.75rem;
    font-weight: 800;
    text-transform: uppercase;
}
.complete-quest { display: block; margin-top: 12px; }
.complete-quest:disabled { cursor: not-allowed; filter: grayscale(1); opacity: 0.55; }

.quest-submission {
    clear: both;
    display: grid;
    gap: 12px;
    margin-top: 14px;
    padding: 14px;
    border-radius: 10px;
    background: var(--brand-light);
}
.quest-submission label { display: grid; gap: 6px; font-weight: 700; }
.quest-submission label span { font-weight: 500; line-height: 1.4; }
.quest-submission input { background: white; }
.quest-submission small { color: #596164; }
.extra-challenge-card {
    margin: 14px 0;
    padding: 16px;
    border: 1px solid var(--brand-soft);
    border-radius: 10px;
    background: var(--brand-light);
}
.extra-challenge-card h2 { margin: 8px 0; font-size: 1.1rem; }
.extra-challenge-card p { margin: 0; line-height: 1.45; }
.extra-challenge-card strong { display: block; margin-top: 10px; }
.extra-challenge-card.extra-complete { border-left: 4px solid var(--brand); }
.extra-challenge-card.extra-locked { filter: grayscale(1); opacity: 0.58; }
.extra-submission {
    display: grid;
    gap: 10px;
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--brand-soft);
}
.extra-submission label { display: grid; gap: 6px; font-weight: 700; }
.extra-submission input { background: white; }
.extra-submission button:disabled { opacity: 0.55; cursor: wait; }
.optional-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 999px;
    background: var(--brand);
    color: white;
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
}

#achievements-list { display: grid; gap: 12px; padding: 0; list-style: none; }
.achievement-item {
    display: grid;
    grid-template-columns: 86px 1fr;
    align-items: center;
    gap: 14px;
    padding: 16px;
    border: 1px solid var(--brand-soft);
    border-radius: 10px;
    background: var(--brand-light);
}
.achievement-item strong { display: block; margin: 3px 0 8px; font-size: 1.05rem; }
.achievement-item p { margin: 0; line-height: 1.4; }
.achievement-locked { filter: grayscale(1); opacity: 0.58; }
.achievement-unlocked { border-left: 5px solid var(--brand); }
.achievement-medal {
    width: 86px;
    height: 86px;
    border-radius: 50%;
    object-fit: cover;
    box-shadow: 0 4px 12px rgba(44, 47, 49, 0.18);
}
.medal-bronze { filter: sepia(0.78) saturate(0.9) hue-rotate(335deg) brightness(1.02) contrast(0.9); }
.medal-silver { filter: grayscale(1) brightness(1.12) contrast(0.9); }
.medal-gold { filter: saturate(1.08) contrast(1.03); }
.achievement-tier {
    color: #6b7477;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}
.achievement-state {
    float: right;
    padding: 3px 7px;
    border-radius: 999px;
    background: var(--brand);
    color: white;
    font-size: 0.7rem;
    font-weight: 800;
    text-transform: uppercase;
}

@media (max-width: 420px) {
    .achievement-item { grid-template-columns: 68px 1fr; gap: 10px; padding: 12px; }
    .achievement-medal { width: 68px; height: 68px; }
}

.quest-item h3 {
    margin: 0 0 6px;
}

.quest-item p {
    margin: 0 0 8px;
    line-height: 1.45;
    white-space: pre-line;
}

.quest-item:last-child {
    border-bottom: none;
}

/* ==================== RESPONSIVE ==================== */

@media (min-width: 700px) {
    .top-bar {
        padding: 12px 14px;
    }

    .auth-buttons {
        display: flex;
        justify-content: flex-end;
        width: auto;
    }

    .brand-logo {
        width: 56px;
        height: 56px;
    }

    .top-bar button {
        min-width: 110px;
    }

    .bottom-section {
        grid-template-columns: minmax(220px, 300px) minmax(0, 1fr);
        align-items: start;
    }

    .bottom-buttons button {
        min-height: 56px;
        font-size: 0.95rem;
    }

    .leaderboard {
        padding: 18px 20px;
    }

    .home-panels { grid-template-columns: repeat(2, minmax(0, 1fr)); }

    .home-achievements { padding: 18px; }

    .leaderboard table {
        font-size: 1rem;
    }
}

@media (max-width: 699px) {
    body {
        padding: 8px;
    }

    .top-bar {
        gap: 8px;
        margin-bottom: 8px;
        padding: 8px;
        border-radius: 10px;
    }

    .brand-logo {
        width: 42px;
        height: 42px;
    }

    .auth-buttons {
        display: flex;
        flex: 1 1 auto;
        width: auto;
        justify-content: flex-end;
        gap: 6px;
    }

    .auth-buttons button {
        flex: 0 0 auto;
        min-width: 88px;
    }

    .top-bar button {
        min-height: 40px;
        padding: 7px 6px;
        font-size: clamp(0.66rem, 2.9vw, 0.82rem);
        border-radius: 8px;
    }

    #map {
        height: 54dvh;
        min-height: 310px;
        margin-bottom: 10px;
        border-radius: 10px;
    }

    .leaflet-control-zoom a {
        width: 36px;
        height: 36px;
        line-height: 36px;
    }

    .bottom-section {
        gap: 10px;
    }

    .bottom-buttons {
        gap: 8px;
    }

    .bottom-buttons button {
        min-height: 44px;
        padding: 9px 10px;
        font-size: 0.82rem;
        border-radius: 8px;
    }

    .leaderboard {
        padding: 10px;
        border-radius: 10px;
    }

    .leaderboard h3 {
        margin-bottom: 8px;
        font-size: 1rem;
        line-height: 1.2;
    }

    .leaderboard table {
        font-size: 0.8rem;
    }

    .leaderboard .rank-col {
        width: 24px;
    }

    .leaderboard .points-col {
        width: 72px;
    }

    .leaderboard th {
        padding: 6px 4px;
        font-size: 0.58rem;
    }

    .leaderboard td {
        padding: 7px 4px;
    }

    .leaderboard th:first-child,
    .leaderboard td:first-child {
        width: 24px;
    }

    .leaderboard th:last-child,
    .leaderboard td:last-child {
        width: 72px;
    }

    .leaderboard th:nth-child(2),
    .leaderboard td:nth-child(2) {
        padding-right: 16px;
    }

    .secondary-page {
        width: 100%;
        min-height: calc(100dvh - 16px);
        margin: 0 auto;
        padding: 18px;
        border-radius: 10px;
    }

    .secondary-page h1 {
        margin-bottom: 16px;
        line-height: 1.1;
    }

    .secondary-page input,
    .secondary-page button {
        min-height: 48px;
    }

    .secondary-page a {
        min-height: 44px;
    }
}

@media (max-width: 420px) {
    .top-bar {
        gap: 6px;
    }

    .brand-logo {
        width: 38px;
        height: 38px;
    }

    .auth-buttons {
        justify-content: flex-end;
        gap: 5px;
    }

    .auth-buttons button {
        min-width: 76px;
    }

    .top-bar button {
        min-height: 38px;
        padding: 7px 4px;
        font-size: clamp(0.6rem, 3vw, 0.76rem);
    }

    #map {
        height: 52dvh;
        min-height: 300px;
    }

    .top-bar,
    .leaderboard,
    .secondary-page {
        border-radius: 10px;
    }

    .bottom-buttons button {
        min-height: 42px;
        padding: 8px;
        font-size: 0.76rem;
    }

    .leaderboard table {
        font-size: 0.74rem;
    }

    .leaderboard th {
        padding: 6px 3px;
        font-size: 0.5rem;
    }

    .leaderboard td {
        padding: 7px 3px;
    }

    .leaderboard .rank-col {
        width: 20px;
    }

    .leaderboard .points-col {
        width: 68px;
    }

    .leaderboard th:first-child,
    .leaderboard td:first-child {
        width: 20px;
    }

    .leaderboard th:last-child,
    .leaderboard td:last-child {
        width: 68px;
    }

    .leaderboard th:nth-child(2),
    .leaderboard td:nth-child(2) {
        padding-right: 14px;
    }

    .secondary-page {
        padding: 16px;
    }
}

@media (max-width: 340px) {
    .brand-logo {
        width: 34px;
        height: 34px;
    }

    .top-bar button {
        min-height: 36px;
        font-size: 0.56rem;
    }

    .auth-buttons button {
        min-width: 66px;
    }

    .leaderboard h3 {
        font-size: 0.92rem;
    }

    .leaderboard .points-col,
    .leaderboard th:last-child,
    .leaderboard td:last-child {
        width: 62px;
    }
}
