:root {
    --ocean:       #a8d0e6;
    --land:        #eef2f5;
    --land-border: #9fb3c8;
    --accent:      #f5ac16;
    --accent-dark: #d8930a;
    --primary:     #2563eb;
    --primary-dark:#1d4ed8;
    --panel-bg:    #f4f6f8;
    --card-bg:     #ffffff;
    --text:        #1f2933;
    --muted:       #6b7280;
    --border:      #d7dde3;
}

html, body {
    height: 100vh;
    height: 100dvh; /* accounts for mobile browser chrome */
    -webkit-text-size-adjust: 100%; /* stop iOS inflating text on rotate */
    text-size-adjust: 100%;
}

* {
    -webkit-tap-highlight-color: rgba(37, 99, 235, 0.15); /* tidy tap flash on touch */
}

body {
    display: flex;
    margin: 0;
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ---------- Map ---------- */
#map {
    flex: 1;
    background-color: var(--ocean);
    background-image: radial-gradient(circle at 30% 20%, #bfe0f0, var(--ocean));
    margin: 0;
    padding: 0;
    min-height: 0; /* let the map shrink to fit inside the flex layout */
    overflow: hidden;
}

#svg {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none; /* we handle pan/zoom/double-tap ourselves */
}

svg path {
    fill: var(--land);
    stroke: var(--land-border);
    stroke-width: 0.3;
    transition: fill 0.25s ease;
}

svg path:hover {
    fill: var(--accent);
    cursor: pointer;
}

/* Countries that already have a postcard (set by the PHP back-end) */
svg path.selected {
    fill: var(--accent);
}

svg path.selected:hover {
    fill: var(--accent-dark);
}

/* Temporary "focus" map (one sender's countries) — distinct pink so it never
   reads as the normal gold all-postcards map. */
svg path.focus { fill: #ec4899; }
svg path.focus:hover { fill: #db2777; }

/* ---------- Form panel ---------- */
#form-container {
    flex: 0.4;
    box-sizing: border-box;
    padding: 28px 24px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    overflow-y: auto;
    background-color: var(--panel-bg);
    border-left: 1px solid var(--border);
    box-shadow: -6px 0 18px rgba(0, 0, 0, 0.06);
}

#form-container label {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    margin-bottom: 6px;
    display: block;
}

input[type="text"] {
    width: 100%;
    padding: 11px 12px;
    box-sizing: border-box;
    font-size: 0.95rem;
    color: var(--text);
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input[type="text"]::placeholder {
    color: #aab2bd;
}

input[type="text"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18);
}

/* ---------- Sender autocomplete ---------- */
.autocomplete-wrapper {
    position: relative;
}

.autocomplete-list {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 20;
    margin: 0;
    padding: 4px;
    list-style: none;
    max-height: 190px;     /* scrollable once the list is taller than this */
    overflow-y: auto;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
}

.autocomplete-list.hidden {
    display: none;
}

.autocomplete-item {
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 0.92rem;
    cursor: pointer;
}

.autocomplete-item:hover,
.autocomplete-item.active {
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary-dark);
}

/* ---------- Sender chips (email-style recipients) ---------- */
.chips-input {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding: 7px 8px;
    box-sizing: border-box;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: text;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.chips-input:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18);
}

/* The inner entry inherits the global input look — strip it back to bare. */
.chips-input input[type="text"] {
    flex: 1;
    width: auto;
    min-width: 130px;
    border: none;
    border-radius: 0;
    padding: 5px 4px;
    background: transparent;
}

.chips-input input[type="text"]:focus {
    outline: none;
    border: none;
    box-shadow: none;
}

.sender-chip {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    max-width: 100%;
    background: rgba(37, 99, 235, 0.12);
    border: 1px solid rgba(37, 99, 235, 0.3);
    color: var(--primary-dark);
    border-radius: 999px;
    padding: 3px 4px 3px 12px;
    font-size: 0.88rem;
    font-weight: 600;
    line-height: 1.3;
}

.sender-chip-x {
    border: none;
    background: transparent;
    color: inherit;
    font-size: 1.05rem;
    line-height: 1;
    padding: 2px 7px;
    border-radius: 50%;
    cursor: pointer;
}

.sender-chip-x:hover {
    background: rgba(37, 99, 235, 0.18);
}

/* ---------- Post-submit banner (?added / ?dup) ---------- */
.form-banner {
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.92rem;
    font-weight: 600;
    transition: opacity 0.6s ease;
}

.form-banner.ok {
    background: #dcfce7;
    color: #14532d;
    border: 1px solid #86efac;
}

.form-banner.dup {
    background: #fef3c7;
    color: #713f12;
    border: 1px solid #fcd34d;
}

.form-banner.gone {
    opacity: 0;
}

.submit-button:disabled {
    opacity: 0.65;
    cursor: default;
}

.submit-button {
    margin-top: 6px;
    padding: 12px 20px;
    background-color: var(--primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    transition: background-color 0.2s ease, transform 0.05s ease, box-shadow 0.2s ease;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.25);
}

.submit-button:hover {
    background-color: var(--primary-dark);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}

.submit-button:active {
    transform: translateY(1px);
}

/* ---------- Phones / narrow screens: stack map above form ---------- */
@media (max-width: 768px) {
    body {
        flex-direction: column;
    }

    #map {
        flex: none;
        height: 55vh;
        height: 55dvh;
    }

    /* View-only: no form below, so let the map fill the screen and
       center itself vertically (preserveAspectRatio xMidYMid meet). */
    body.view-only #map {
        height: 100vh;
        height: 100dvh;
    }

    #form-container {
        flex: 1;
        border-left: none;
        border-top: 1px solid var(--border);
        box-shadow: 0 -6px 18px rgba(0, 0, 0, 0.06);
        /* keep clear of the iOS home-bar / notch */
        padding-bottom: calc(28px + env(safe-area-inset-bottom));
    }

    /* 16px+ stops iOS Safari auto-zooming when a field gets focus */
    input[type="text"] {
        font-size: 16px;
        padding: 13px 12px;
    }

    .submit-button {
        padding: 14px 20px; /* comfier touch target */
    }
}

/* ============================================================
   Portal homepage (index.php) + Leaderboard (leaderboard.php)
   + map navigation overlays
   ============================================================ */
:root {
    --ink:         #0f2440;
    --sky-1:       #1e3a8a;
    --sky-2:       #2563eb;
    --sky-3:       #38bdf8;
    --gold:        #f5ac16;
    --gold-2:      #f6c453;
    --shadow-sm:   0 2px 8px rgba(15, 36, 64, 0.08);
    --shadow-md:   0 10px 28px rgba(15, 36, 64, 0.12);
    --shadow-lg:   0 22px 48px rgba(15, 36, 64, 0.20);
}

/* ---------- Map navigation overlays (postcard.php) ---------- */
.top-nav {
    position: absolute;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 50;
    display: flex;
    gap: 4px;
    padding: 6px;
    background: rgba(255, 255, 255, 0.86);
    border: 1px solid rgba(255, 255, 255, 0.6);
    border-radius: 999px;
    box-shadow: var(--shadow-md);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.top-nav a {
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--ink);
    padding: 8px 16px;
    border-radius: 999px;
    white-space: nowrap;
    transition: background 0.15s ease, color 0.15s ease;
}

.top-nav a:hover {
    background: rgba(37, 99, 235, 0.12);
    color: var(--primary-dark);
}

/* In-flow variant (leaderboard hero) — same pill, not floating over a map */
.top-nav.static {
    position: static;
    transform: none;
    display: flex;
    width: max-content;     /* size to its links… */
    max-width: 100%;
    margin: 0 auto 18px;    /* …then center the pill */
}

/* "Only a map" view: a single discreet home button, nothing else */
.map-home {
    position: absolute;
    top: 16px;
    left: 16px;
    z-index: 50;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px 10px 14px;
    text-decoration: none;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--ink);
    background: rgba(255, 255, 255, 0.82);
    border: 1px solid rgba(255, 255, 255, 0.6);
    border-radius: 999px;
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    opacity: 0.7;
    transition: opacity 0.2s ease, box-shadow 0.2s ease, transform 0.05s ease;
}

.map-home:hover { opacity: 1; box-shadow: var(--shadow-md); }
.map-home:active { transform: translateY(1px); }

/* Narrow phones: keep the floating nav inside the viewport and clear the notch */
@media (max-width: 480px) {
    .top-nav {
        top: calc(10px + env(safe-area-inset-top));
        max-width: calc(100vw - 20px);
        gap: 2px;
        padding: 4px;
        flex-wrap: nowrap;
    }
    .top-nav a {
        font-size: 0.78rem;
        padding: 8px 10px;
    }
    .map-home {
        top: calc(10px + env(safe-area-inset-top));
        left: calc(10px + env(safe-area-inset-left));
        opacity: 0.92; /* hover doesn't exist on touch, so don't hide it */
    }
}

/* Focus-map banner: floats at the bottom so it clears the top nav pill */
.focus-banner {
    position: absolute;
    bottom: calc(18px + env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 14px;
    max-width: calc(100vw - 24px);
    padding: 10px 12px 10px 18px;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.6);
    border-radius: 999px;
    box-shadow: var(--shadow-md);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    font-size: 0.9rem;
}

.focus-label { color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.focus-label b { color: #db2777; }

.focus-clear {
    flex: none;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.85rem;
    color: #fff;
    background: #ec4899;
    padding: 7px 14px;
    border-radius: 999px;
    transition: background 0.15s ease;
}
.focus-clear:hover { background: #db2777; }

/* ---------- View Map search (floating, collapsible) ---------- */
.map-search {
    position: absolute;
    top: 72px;               /* clears the centred top-nav pill on any width */
    left: 16px;
    z-index: 60;
    width: 330px;
    max-width: calc(100vw - 32px);
    background: var(--card-bg);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
}

.map-search-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    border: none;
    background: transparent;
    cursor: pointer;
    font: inherit;
    font-weight: 700;
    font-size: 0.98rem;
    color: var(--ink);
    padding: 14px 18px;
}

.ms-caret { color: var(--muted); transition: transform 0.2s ease; }
.map-search.collapsed .ms-caret { transform: rotate(-90deg); }

.map-search-body { padding: 0 18px 18px; }
.map-search.collapsed .map-search-body { display: none; }

/* Long result lists scroll inside the card rather than overflowing the screen */
.map-search .search-results { max-height: 38vh; overflow-y: auto; }
.map-search .result-list { grid-template-columns: 1fr; }

.map-clear {
    margin-top: 14px;
    border: none;
    cursor: pointer;
    font: inherit;
    font-weight: 600;
    font-size: 0.85rem;
    color: #fff;
    background: #ec4899;
    padding: 9px 16px;
    border-radius: 999px;
    transition: background 0.15s ease;
}
.map-clear:hover { background: #db2777; }
.map-clear.hidden { display: none; }

@media (max-width: 560px) {
    .map-search {
        top: calc(64px + env(safe-area-inset-top));
        left: 12px;
        right: 12px;
        width: auto;
        max-width: none;
    }
}

/* Read-only map: hide the entry form so the map fills the screen.
   (Inputs stay in the DOM so script.js's selectCountry() never hits null.) */
body.view-only #form-container { display: none; }

/* ---------- Shared portal shell ---------- */
body.home,
body.board {
    display: block;
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    color: var(--ink);
    background:
        radial-gradient(1200px 600px at 80% -10%, rgba(56, 189, 248, 0.35), transparent 60%),
        linear-gradient(180deg, var(--sky-1) 0%, var(--sky-2) 30%, #9fc6ec 62%, var(--panel-bg) 100%);
    background-attachment: fixed;
}

.portal {
    max-width: 1040px;
    margin: 0 auto;
    padding: 40px 22px 56px;
    box-sizing: border-box;
}

/* ---------- Homepage hero ---------- */
.hero {
    text-align: center;
    color: #fff;
    padding: 36px 16px 30px;
}

.hero-badge {
    display: inline-block;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 7px 16px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.35);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    margin-bottom: 18px;
}

.hero h1 {
    margin: 0 0 12px;
    font-size: clamp(2.1rem, 5.5vw, 3.4rem);
    line-height: 1.05;
    letter-spacing: -0.03em;
    text-shadow: 0 4px 24px rgba(15, 36, 64, 0.35);
}

.hero p {
    margin: 0 auto;
    max-width: 540px;
    font-size: 1.08rem;
    line-height: 1.5;
    color: rgba(255, 255, 255, 0.9);
}

.hero-stats {
    margin-top: 26px;
    display: flex;
    justify-content: center;
    gap: 14px;
    flex-wrap: wrap;
}

.chip {
    min-width: 104px;
    padding: 14px 22px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.16);
    border: 1px solid rgba(255, 255, 255, 0.3);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: #fff;
}

.chip b { display: block; font-size: 1.8rem; line-height: 1; }
.chip span { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.07em; opacity: 0.85; }

/* ---------- Portal cards ---------- */
.home-cards {
    margin-top: 36px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 22px;
}

.home-card {
    position: relative;
    display: flex;
    flex-direction: column;
    text-decoration: none;
    color: var(--ink);
    background: var(--card-bg);
    border-radius: 20px;
    padding: 30px 26px 26px;
    box-shadow: var(--shadow-md);
    overflow: hidden;
    isolation: isolate;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.home-card::before {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 6px;
    background: var(--card-accent, var(--primary));
}

.home-card::after {
    content: "";
    position: absolute;
    z-index: -1;
    top: -40%;
    right: -30%;
    width: 220px;
    height: 220px;
    border-radius: 50%;
    background: var(--card-accent, var(--primary));
    opacity: 0.07;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.home-card:hover {
    transform: translateY(-6px);
    box-shadow: var(--shadow-lg);
}

.home-card:hover::after { transform: scale(1.35); opacity: 0.12; }

.card-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 58px;
    height: 58px;
    font-size: 1.9rem;
    border-radius: 16px;
    background: color-mix(in srgb, var(--card-accent, var(--primary)) 14%, #fff);
    margin-bottom: 18px;
}

.home-card h2 { margin: 0 0 8px; font-size: 1.3rem; letter-spacing: -0.01em; }
.home-card p { margin: 0; color: var(--muted); font-size: 0.95rem; line-height: 1.55; }

.card-go {
    margin-top: 20px;
    font-weight: 700;
    font-size: 0.92rem;
    color: var(--card-accent, var(--primary));
}

.card-go .arrow { display: inline-block; transition: transform 0.2s ease; }
.home-card:hover .card-go .arrow { transform: translateX(5px); }

.card-map        { --card-accent: #0ea5a4; }
.card-add        { --card-accent: #f5ac16; }
.card-board      { --card-accent: #7c3aed; }

.home-footer {
    margin-top: 40px;
    text-align: center;
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.85rem;
}

/* ---------- Leaderboard ---------- */
.board-hero { color: #fff; padding: 12px 4px 24px; }

.board-back {
    display: inline-block;
    margin-bottom: 16px;
    text-decoration: none;
    color: rgba(255, 255, 255, 0.92);
    font-weight: 600;
    font-size: 0.9rem;
    padding: 7px 14px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.16);
    border: 1px solid rgba(255, 255, 255, 0.3);
    transition: background 0.15s ease;
}

.board-back:hover { background: rgba(255, 255, 255, 0.28); }

.board-hero h1 {
    margin: 0 0 6px;
    font-size: clamp(1.9rem, 4.5vw, 2.7rem);
    letter-spacing: -0.02em;
    text-shadow: 0 4px 24px rgba(15, 36, 64, 0.35);
}

.board-hero p { margin: 0; color: rgba(255, 255, 255, 0.9); font-size: 1.02rem; }

.stat-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}

.stat-box {
    position: relative;
    background: var(--card-bg);
    border-radius: 16px;
    padding: 22px 20px;
    text-align: center;
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.stat-box::before {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 5px;
    background: linear-gradient(90deg, var(--sky-2), var(--sky-3));
}

.stat-ico { font-size: 1.5rem; }
.stat-box b { display: block; font-size: 2.1rem; line-height: 1.1; color: var(--sky-1); }
.stat-lbl { font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

/* ---------- Leaderboard search ---------- */
.search-panel {
    background: var(--card-bg);
    border-radius: 18px;
    padding: 22px 24px 24px;
    box-shadow: var(--shadow-md);
    margin-bottom: 28px;
}

.search-title { margin: 0 0 16px; font-size: 1.12rem; letter-spacing: -0.01em; }

.search-tabs {
    display: inline-flex;
    gap: 2px;
    padding: 4px;
    margin-bottom: 14px;
    background: var(--panel-bg);
    border-radius: 999px;
}

.search-tab {
    border: none;
    background: transparent;
    cursor: pointer;
    font: inherit;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--muted);
    padding: 8px 18px;
    border-radius: 999px;
    transition: background 0.15s ease, color 0.15s ease;
}

.search-tab.active {
    background: var(--card-bg);
    color: var(--ink);
    box-shadow: var(--shadow-sm);
}

.search-hint { margin: 12px 2px 0; color: var(--muted); font-size: 0.88rem; }

.search-results { margin-top: 18px; }

.result-head {
    font-weight: 700;
    font-size: 1.02rem;
    color: var(--ink);
    margin-bottom: 14px;
}

.result-head--row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.map-btn {
    flex: none;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.85rem;
    color: #fff;
    background: var(--primary);
    padding: 8px 14px;
    border-radius: 999px;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.25);
    transition: background 0.15s ease, box-shadow 0.15s ease;
}
.map-btn:hover { background: var(--primary-dark); box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35); }

.result-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr));
    gap: 10px;
}

.result-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 11px 14px;
    background: var(--panel-bg);
    border-radius: 10px;
    font-size: 0.95rem;
}

.result-list .r-main { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.r-badge {
    flex: none;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--primary-dark);
    background: rgba(37, 99, 235, 0.1);
    padding: 3px 9px;
    border-radius: 999px;
}

.search-empty { color: var(--muted); font-size: 0.95rem; margin: 0; }

/* Special notes for a searched country (View Map, by-country mode) */
.result-notes {
    margin: 0 0 14px;
    padding: 12px 14px;
    border-radius: 10px;
    background: rgba(37, 99, 235, 0.07);
    border: 1px solid rgba(37, 99, 235, 0.18);
}
.result-notes-h {
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--primary-dark);
    margin-bottom: 8px;
}
.note-row {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 6px 0;
}
.note-row + .note-row { border-top: 1px solid rgba(37, 99, 235, 0.14); }
.note-place { font-weight: 600; color: var(--ink); }
.note-people { display: flex; flex-direction: column; gap: 1px; }
.note-by { font-size: 0.82rem; color: var(--muted); }

.board-grid {
    display: grid;
    /* min() keeps a single column from overflowing a ~320px phone */
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
    gap: 22px;
    margin-bottom: 28px;
}

.board-panel {
    background: var(--card-bg);
    border-radius: 18px;
    padding: 24px 26px;
    box-shadow: var(--shadow-md);
}

.board-panel h2 {
    margin: 0 0 18px;
    font-size: 1.12rem;
    letter-spacing: -0.01em;
}

.rank-list { list-style: none; margin: 0; padding: 0; counter-reset: rank; }
.rank-item { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.rank-item:last-child { margin-bottom: 0; }

.rank-medal {
    flex: none;
    width: 30px;
    text-align: center;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--muted);
}

.rank-body { flex: 1; min-width: 0; }

.rank-label {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    font-size: 0.94rem;
    font-weight: 500;
    margin-bottom: 6px;
}

.rank-label .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-label .count { color: var(--muted); font-weight: 700; flex: none; }

.rank-track { height: 9px; border-radius: 999px; background: var(--panel-bg); overflow: hidden; }
.rank-bar { height: 100%; border-radius: 999px; min-width: 6px; background: linear-gradient(90deg, var(--gold), var(--gold-2)); }
.rank-bar.sender { background: linear-gradient(90deg, var(--sky-2), var(--sky-3)); }

table.cards {
    width: 100%;
    border-collapse: collapse;
    background: var(--card-bg);
    border-radius: 18px;
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

table.cards th,
table.cards td {
    text-align: left;
    padding: 13px 18px;
    font-size: 0.93rem;
}

table.cards th {
    background: var(--ink);
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 0.72rem;
}

.cards-pager {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-top: 16px;
}

.pager-status {
    color: var(--muted);
    font-size: 0.9rem;
    font-variant-numeric: tabular-nums;
    margin: 0 4px;
}

.pager-btn {
    border: 1px solid var(--border);
    background: var(--card-bg);
    color: var(--ink);
    cursor: pointer;
    font: inherit;
    font-weight: 600;
    font-size: 0.9rem;
    padding: 8px 16px;
    border-radius: 999px;
    transition: background 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

.pager-btn:hover:not(:disabled) { box-shadow: var(--shadow-sm); }

.pager-btn:disabled { opacity: 0.4; cursor: default; }

.pager-btn.ghost {
    margin-left: auto;
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.25);
}

.pager-btn.ghost:hover { background: var(--primary-dark); }

table.cards tbody tr { border-top: 1px solid var(--border); }
table.cards tbody tr:nth-child(even) { background: #fafbfd; }
table.cards tbody tr:hover { background: rgba(37, 99, 235, 0.06); }
table.cards td.idcol { color: var(--muted); font-variant-numeric: tabular-nums; width: 48px; }

/* Special note on a card (e.g. the exact place within the country) */
.card-note {
    display: inline-block;
    margin-left: 8px;
    padding: 2px 9px;
    border-radius: 999px;
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary-dark);
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
    vertical-align: middle;
}

.board-section-title { color: #fff; margin: 0 0 16px; font-size: 1.15rem; text-shadow: 0 4px 24px rgba(15, 36, 64, 0.35); }

/* Let a wide card table scroll sideways instead of breaking the layout */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 18px;
    box-shadow: var(--shadow-md);
}
.table-wrap table.cards { box-shadow: none; }
.table-wrap table.cards th,
.table-wrap table.cards td { white-space: nowrap; }
.table-wrap table.cards td:nth-child(3) { white-space: normal; } /* sender names can wrap */

@media (max-width: 600px) {
    table.cards th, table.cards td { padding: 11px 12px; font-size: 0.88rem; }
    .portal { padding: 28px 16px 44px; }
    .home-cards { gap: 16px; margin-top: 26px; }
    .home-card { padding: 24px 22px 22px; }
    .stat-row { gap: 12px; }
    .hero { padding: 24px 8px 22px; }
}

/* ============================================================
   Login page (login.php)
   ============================================================ */
body.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 24px;
    box-sizing: border-box;
    background: linear-gradient(160deg, var(--sky-1) 0%, var(--sky-2) 55%, var(--sky-3) 100%);
}

.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--card-bg);
    border-radius: 18px;
    padding: 34px 30px 26px;
    box-shadow: 0 20px 50px rgba(15, 36, 64, 0.28);
    text-align: center;
}

.login-brand {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--sky-2);
    margin-bottom: 18px;
}

.login-card h1 {
    margin: 0 0 6px;
    font-size: 1.5rem;
    color: var(--ink);
}

.login-sub {
    margin: 0 0 22px;
    color: var(--muted);
    font-size: 0.95rem;
}

.login-card form { margin: 0; }

.login-card input[type="password"] {
    width: 100%;
    box-sizing: border-box;
    padding: 13px 14px;
    font-size: 16px;               /* no iOS zoom */
    color: var(--text);
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 12px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.login-card input[type="password"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18);
}

.login-primary {
    width: 100%;
    padding: 13px;
    border: none;
    border-radius: 10px;
    background: var(--primary);
    color: #fff;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
    transition: background 0.15s ease, box-shadow 0.15s ease;
}
.login-primary:hover { background: var(--primary-dark); box-shadow: 0 4px 14px rgba(37, 99, 235, 0.4); }

.login-guest {
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
}

.login-secondary {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: transparent;
    color: var(--muted);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}
.login-secondary:hover { background: var(--panel-bg); color: var(--ink); }

.login-error {
    background: #fee2e2;
    color: #7f1d1d;
    border: 1px solid #fca5a5;
    border-radius: 8px;
    padding: 9px 12px;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 14px;
}

.login-note {
    margin: 14px 0 0;
    font-size: 0.82rem;
    color: var(--muted);
}

/* Sign-in / sign-out link sits apart from the section links in the nav pill. */
.top-nav .nav-auth {
    margin-left: 4px;
    opacity: 0.85;
}
