* { box-sizing: border-box; }

.hidden { display: none !important; }

:root {
    --topbar-h: 56px;
    --bg: #f3f4f6;
    --surface: #ffffff;
    --surface-2: #f9fafb;
    --text: #1f2937;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --topbar: #111827;
    --topbar-text: #f9fafb;
    --nav-muted: #d1d5db;
    --you-bg: #dbeafe;
    --you-border: #93c5fd;
    --flash-start: #fef9c3;
    --list-hover-bg: #eff6ff;
    --list-hover-border: #93c5fd;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0b1220;
        --surface: #111827;
        --surface-2: #1f2937;
        --text: #e5e7eb;
        --text-muted: #9ca3af;
        --border: #374151;
        --accent: #60a5fa;
        --accent-hover: #3b82f6;
        --topbar: #0b1220;
        --you-bg: #1e3a5f;
        --you-border: #3b82f6;
        --flash-start: #422006;
        --list-hover-bg: #1e3a5f;
        --list-hover-border: #3b82f6;
    }
}

body, html {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color: var(--text);
    background: var(--bg);
}

#topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: auto;
    min-height: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-top: env(safe-area-inset-top, 0px);
    padding-right: calc(16px + env(safe-area-inset-right, 0px));
    padding-bottom: 0;
    padding-left: calc(16px + env(safe-area-inset-left, 0px));
    background: var(--topbar);
    color: var(--topbar-text);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

#topbar nav {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.nav-btn {
    color: var(--nav-muted);
    text-decoration: none;
    padding: 8px 14px;
    border-radius: 8px;
    font-weight: 500;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    transition: background 0.15s ease, transform 0.12s ease;
    -webkit-tap-highlight-color: transparent;
}

@media (hover: hover) {
    .nav-btn:hover { background: rgba(255,255,255,0.08); }
}
.nav-btn:active { transform: scale(0.97); }
.nav-btn.active { background: var(--accent); color: white; }

.nav-btn:focus-visible,
#team-display button:focus-visible,
.card button:focus-visible,
#create-team-form button:focus-visible,
#team-list li:focus-visible,
#scoreboard-list li:focus-visible,
#scoreboard-team-pois li:focus-visible,
#scoreboard-team-firsts li:focus-visible,
.poi-sheet-claim:focus-visible,
.poi-sheet-maps:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

#team-display {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    min-width: 0;
    flex-shrink: 1;
}

#team-label {
    font-weight: 600;
    max-width: 38vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#team-display button,
.card button,
#create-team-form button {
    background: var(--accent);
    color: white;
    border: none;
    padding: 10px 16px;
    min-height: 44px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.15s ease, transform 0.12s ease;
}

@media (hover: hover) {
    #team-display button:hover,
    .card button:hover { background: var(--accent-hover); transform: translateY(-1px); }
}

#team-display button:active,
.card button:active,
#create-team-form button:active { transform: scale(0.97); }

main {
    position: absolute;
    top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
    left: 0;
    right: 0;
    bottom: 0;
}

.view {
    width: 100%;
    height: 100%;
    overflow: auto;
}

.view.hidden { display: none; }

#map {
    height: 100%;
    width: 100%;
}

#view-admin {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 24px 16px;
}

.scoreboard-wrap {
    max-width: 720px;
    margin: 24px auto;
    padding: 24px;
    background: var(--surface);
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.scoreboard-wrap h1 {
    margin: 0 0 16px;
    font-size: 28px;
}

#scoreboard-list {
    list-style: none;
    padding: 0;
    margin: 0;
    counter-reset: rank;
}

#scoreboard-list li {
    counter-increment: rank;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-radius: 8px;
    background: var(--surface-2);
    margin-bottom: 8px;
    font-size: 16px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
    -webkit-tap-highlight-color: transparent;
}

#scoreboard-list li:active {
    transform: scale(0.98);
}

#scoreboard-list li.you {
    background: var(--you-bg);
    border-color: var(--you-border);
}

#scoreboard-list li.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent);
}

#scoreboard-list li::before {
    content: counter(rank);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    margin-right: 12px;
    font-weight: 700;
    font-size: 14px;
    color: var(--text-muted);
}

#scoreboard-list li:nth-child(-n+3)::before {
    border-radius: 50%;
    color: #fff;
    font-size: 13px;
    box-shadow: inset 0 -2px 4px rgba(0,0,0,0.18), 0 1px 3px rgba(0,0,0,0.25);
}

#scoreboard-list li:nth-child(1)::before {
    background: linear-gradient(160deg, #fde68a 0%, #f5b301 55%, #d4920a 100%);
    color: #5a3e00;
}

#scoreboard-list li:nth-child(2)::before {
    background: linear-gradient(160deg, #f1f5f9 0%, #cbd5e1 55%, #94a3b8 100%);
    color: #334155;
}

#scoreboard-list li:nth-child(3)::before {
    background: linear-gradient(160deg, #f0c08a 0%, #cd7f32 60%, #a25e1f 100%);
    color: #3d2206;
}

#scoreboard-list li.scoreboard-skeleton {
    cursor: default;
    pointer-events: none;
}

#scoreboard-list li.scoreboard-skeleton::before {
    content: none;
}

#scoreboard-list li.scoreboard-skeleton .sk-bar,
#scoreboard-list li.scoreboard-skeleton .sk-pill {
    height: 14px;
    border-radius: 6px;
    background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%);
    background-size: 400px 100%;
    animation: skShimmer 1.2s ease-in-out infinite;
}

#scoreboard-list li.scoreboard-skeleton .sk-bar {
    flex: 1;
    max-width: 55%;
}

#scoreboard-list li.scoreboard-skeleton .sk-pill {
    width: 32px;
}

@keyframes skShimmer {
    0%   { background-position: -200px 0; }
    100% { background-position: 200px 0; }
}

#scoreboard-list .name { flex: 1; font-weight: 600; }
#scoreboard-list .score { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--accent); }

#scoreboard-list li.flash { animation: flash 1s ease; }
@keyframes flash {
    0%   { background: var(--flash-start); }
    100% { background: var(--surface-2); }
}

.scoreboard-team-detail {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.scoreboard-team-detail h2 {
    margin: 0 0 12px;
    font-size: 1.125rem;
    font-weight: 700;
}

#scoreboard-team-pois,
#scoreboard-team-firsts {
    list-style: none;
    padding: 0;
    margin: 0;
}

#scoreboard-team-firsts-section {
    margin-top: 16px;
}

#scoreboard-team-firsts-title {
    margin: 0 0 8px;
    font-size: 0.8125rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

#scoreboard-team-firsts li .small {
    margin-left: auto;
    padding-left: 8px;
    white-space: nowrap;
}

.poi-letter {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.5rem;
    margin-right: 8px;
    font-weight: 800;
    font-size: 0.9375rem;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
}

#scoreboard-team-pois li,
#scoreboard-team-firsts li {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: 10px 12px;
    margin-bottom: 6px;
    border-radius: 8px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    font-weight: 500;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.15s ease, transform 0.12s ease;
}

@media (hover: hover) {
    #scoreboard-team-pois li:hover,
    #scoreboard-team-firsts li:hover {
        background: var(--list-hover-bg);
        border-color: var(--list-hover-border);
    }
}

#scoreboard-team-pois li:active,
#scoreboard-team-firsts li:active {
    transform: scale(0.98);
}

.muted { color: var(--text-muted); }
.small { font-size: 13px; }

.team-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 7px;
    flex-shrink: 0;
    vertical-align: middle;
    border: 1.5px solid rgba(0,0,0,0.12);
}


.overlay {
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, 0.6);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
    overscroll-behavior: contain;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.22s ease, visibility 0.22s ease;
}

.overlay.hidden { display: none; }

.overlay.is-open {
    opacity: 1;
    visibility: visible;
}

.card {
    background: var(--surface);
    color: var(--text);
    border-radius: 12px;
    padding: 24px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.25);
}

.overlay .card {
    transform: translateY(12px) scale(0.98);
    opacity: 0;
    transition: transform 0.26s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.2s ease;
}

.overlay.is-open .card {
    transform: none;
    opacity: 1;
}

.card h2 {
    margin: 0 0 12px;
    font-size: 20px;
}

#team-list {
    list-style: none;
    padding: 0;
    margin: 0 0 16px;
    max-height: 240px;
    overflow-y: auto;
}

#team-list li {
    padding: 10px 12px;
    min-height: 48px;
    align-items: center;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    border: 1px solid var(--border);
    margin-bottom: 6px;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.15s ease, transform 0.12s ease;
}

@media (hover: hover) {
    #team-list li:hover { background: var(--list-hover-bg); border-color: var(--list-hover-border); }
}
#team-list li:active { transform: scale(0.98); }

#admin-team-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

#admin-team-list li.admin-team-row {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 48px;
    padding: 10px 12px;
    margin-bottom: 6px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-2);
}

#admin-team-list .name {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 0;
    font-weight: 500;
}

#admin-team-list .score {
    font-variant-numeric: tabular-nums;
}

.card button.btn-danger {
    background: #dc2626;
    min-height: 36px;
    padding: 6px 12px;
}

@media (hover: hover) {
    .card button.btn-danger:hover { background: #b91c1c; }
}

#create-team-form {
    display: flex;
    gap: 8px;
}

#create-team-form input {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 16px;
    background: var(--surface);
    color: var(--text);
}

#toast {
    position: fixed;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%) translateY(12px);
    background: #1f2937;
    color: white;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 14px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.25);
    z-index: 3000;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.25s cubic-bezier(0.32, 0.72, 0, 1), visibility 0.2s ease;
}

#toast.toast-show {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

/* POI bottom sheet (replaces Leaflet popup) */
.poi-sheet {
    position: fixed;
    inset: 0;
    z-index: 1500;
    pointer-events: none;
}

.poi-sheet:not(.hidden) {
    pointer-events: auto;
}

.poi-sheet-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    opacity: 0;
    transition: opacity 0.25s ease;
}

.poi-sheet:not(.hidden) .poi-sheet-backdrop {
    opacity: 1;
}

.poi-sheet-panel {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: min(85vh, 520px);
    padding: 8px 20px calc(20px + env(safe-area-inset-bottom, 0px));
    background: var(--surface);
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -8px 40px rgba(15, 23, 42, 0.18);
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.poi-sheet:not(.hidden) .poi-sheet-panel {
    transform: translateY(0);
}

.poi-sheet-handle {
    width: 40px;
    height: 4px;
    margin: 4px auto 16px;
    border-radius: 999px;
    background: var(--border);
}

.poi-sheet-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: var(--surface-2);
    color: var(--text);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.12s ease, transform 0.12s ease;
}

.poi-sheet-close:active {
    background: var(--border);
    transform: scale(0.97);
}

.team-picker-card {
    position: relative;
}

.card button.team-picker-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    min-height: 0;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-muted);
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.12s ease, background 0.12s ease, transform 0.12s ease;
}

@media (hover: hover) {
    .card button.team-picker-close:hover {
        background: var(--surface-2);
        color: var(--text);
        transform: none;
    }
}

.card button.team-picker-close:active {
    background: var(--border);
    transform: scale(0.97);
}

.poi-sheet-label {
    margin: 0 0 4px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--accent);
}

#poi-sheet-title {
    margin: 0 36px 12px 0;
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.25;
    color: var(--text);
}

.poi-sheet-desc {
    margin: 0 0 20px;
    font-size: 1rem;
    line-height: 1.5;
    color: var(--text-muted);
}

.poi-sheet-maps {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 44px;
    margin: 0 0 12px;
    padding: 10px 16px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface-2);
    color: var(--accent);
    font-size: 1rem;
    font-weight: 600;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.12s ease, transform 0.12s ease;
}

.poi-sheet-maps:active {
    transform: scale(0.98);
    background: var(--border);
}

.poi-sheet-claim {
    width: 100%;
    min-height: 52px;
    padding: 14px 20px;
    border: none;
    border-radius: 14px;
    background: linear-gradient(180deg, #22c55e 0%, #16a34a 100%);
    color: #fff;
    font-size: 1.0625rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(22, 163, 74, 0.35);
    transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
    -webkit-tap-highlight-color: transparent;
}

.poi-sheet-claim:active:not(:disabled) {
    transform: scale(0.98);
    box-shadow: 0 2px 8px rgba(22, 163, 74, 0.3);
}

.poi-sheet-claim:disabled {
    opacity: 0.65;
    cursor: default;
    box-shadow: none;
}

@media (max-width: 380px) {
    .nav-btn {
        padding: 8px 10px;
    }

    #team-display {
        gap: 6px;
    }
}

@media (min-width: 640px) {
    .poi-sheet-panel {
        left: 50%;
        right: auto;
        bottom: 24px;
        width: min(420px, calc(100% - 32px));
        max-height: 70vh;
        margin-left: calc(min(420px, calc(100% - 32px)) / -2);
        border-radius: 20px;
        padding-bottom: 24px;
    }

    .poi-sheet-handle {
        display: none;
    }
}

.beer-celebrate {
    position: fixed;
    inset: 0;
    z-index: 4000;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

.beer {
    position: absolute;
    font-size: 64px;
    line-height: 1;
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.3));
    will-change: transform, opacity;
}

.beer-left  { animation: beerLeft  1.1s cubic-bezier(0.2,0.7,0.2,1) forwards; }
.beer-right { animation: beerRight 1.1s cubic-bezier(0.2,0.7,0.2,1) forwards; }

@keyframes beerLeft {
    0%   { transform: translate(-8px, 60px) scale(0.3) rotate(-28deg); opacity: 0; }
    35%  { transform: translate(-46px, 0)  scale(1)   rotate(-24deg); opacity: 1; }
    50%  { transform: translate(-26px, 0)  scale(1)   rotate(-6deg); }
    62%  { transform: translate(-42px, 0)  scale(1)   rotate(-18deg); }
    100% { transform: translate(-50px, -70px) scale(1) rotate(-20deg); opacity: 0; }
}

@keyframes beerRight {
    0%   { transform: translate(8px, 60px) scale(0.3) rotate(28deg); opacity: 0; }
    35%  { transform: translate(46px, 0)  scale(1)   rotate(24deg); opacity: 1; }
    50%  { transform: translate(26px, 0)  scale(1)   rotate(6deg); }
    62%  { transform: translate(42px, 0)  scale(1)   rotate(18deg); }
    100% { transform: translate(50px, -70px) scale(1) rotate(20deg); opacity: 0; }
}

.beer-spark {
    position: absolute;
    font-size: 30px;
    opacity: 0;
    transform: scale(0.2);
    animation: beerSpark 0.5s ease-out 0.5s forwards;
}

@keyframes beerSpark {
    0%   { opacity: 0; transform: scale(0.2); }
    30%  { opacity: 1; transform: scale(1.2); }
    100% { opacity: 0; transform: scale(1.6) translateY(-10px); }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}
