:root {
    --accent: #ff6b35;
    --accent-gradient: linear-gradient(135deg, #ff6b35, #ff3d68);
    --bg: #f7f7f8;
    --surface: #ffffff;
    --surface-alt: rgba(255, 255, 255, 0.86);
    --text: #1a1a1a;
    --text-muted: #6b7280;
    --border: rgba(0, 0, 0, 0.08);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.16);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.22);
    --radius-pill: 999px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #121214;
        --surface: #1c1c1f;
        --surface-alt: rgba(28, 28, 31, 0.86);
        --text: #f3f3f4;
        --text-muted: #9a9aa1;
        --border: rgba(255, 255, 255, 0.1);
        --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.4);
        --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.5);
        --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.6);
    }
}

* {
    box-sizing: border-box;
}

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

.page {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

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

.topbar {
    position: sticky;
    top: 0;
    z-index: 1200;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    padding-top: calc(10px + env(safe-area-inset-top, 0px));
    background: var(--surface-alt);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border);
}

.logo {
    /* Logo.png is a 1275x1700 (3:4) portrait that fills its full frame —
       a square box would crop real content (crown/beard), not just margin. */
    height: 44px;
    width: 33px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.topbar-text {
    flex: 1;
    min-width: 0;
}

.topbar-text h1 {
    margin: 0;
    font-size: 18px;
    font-weight: 800;
    line-height: 1.15;
    letter-spacing: -0.01em;
}

.tagline {
    margin: 1px 0 0;
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.finds-dropdown-wrap {
    position: relative;
    flex-shrink: 0;
}

.finds-badge {
    flex-shrink: 0;
    font-size: 13px;
    font-weight: 700;
    padding: 6px 12px;
    border-radius: var(--radius-pill);
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    white-space: nowrap;
    cursor: pointer;
    font-family: inherit;
    transition: transform 0.1s ease;
}

.finds-badge:active {
    transform: scale(0.95);
}

.finds-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: min(300px, 80vw);
    max-height: 60vh;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    opacity: 0;
    transform: translateY(-6px) scale(0.97);
    pointer-events: none;
    transition: opacity 0.16s ease, transform 0.16s ease;
    transform-origin: top right;
    z-index: 1300;
}

.finds-dropdown.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.finds-dropdown-header {
    padding: 12px 14px;
    font-size: 12px;
    font-weight: 700;
    border-bottom: 1px solid var(--border);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.finds-dropdown-list {
    overflow-y: auto;
}

.finds-dropdown-empty {
    padding: 20px 14px;
    text-align: center;
    font-size: 13px;
    color: var(--text-muted);
}

.finds-dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 14px;
    border: none;
    border-bottom: 1px solid var(--border);
    background: none;
    color: var(--text);
    font-family: inherit;
    font-size: 13px;
    text-align: left;
    cursor: pointer;
    transition: background 0.1s ease;
}

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

.finds-dropdown-item:active {
    background: var(--bg);
}

.finds-dropdown-item-icon {
    font-size: 16px;
    flex-shrink: 0;
}

.finds-dropdown-item-text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.series-switcher-list {
    max-height: 180px;
    overflow-y: auto;
    border-bottom: 1px solid var(--border);
}

.series-switch-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 14px;
    border: none;
    border-bottom: 1px solid var(--border);
    background: none;
    color: var(--text);
    font-family: inherit;
    font-size: 13px;
    text-align: left;
    cursor: pointer;
    transition: background 0.1s ease;
}

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

.series-switch-item:active {
    background: var(--bg);
}

.series-switch-item.active {
    background: var(--accent-bg, rgba(255, 107, 53, 0.1));
    box-shadow: inset 3px 0 0 var(--accent, #ff6b35);
}

.series-switch-thumb {
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    font-size: 14px;
}

.series-switch-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.series-switch-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
}

.series-switch-count {
    flex-shrink: 0;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
}

.account-icon-btn {
    position: relative;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    text-decoration: none;
}

.account-icon-btn:active {
    transform: scale(0.95);
}

.account-icon-dot {
    position: absolute;
    top: 1px;
    right: 1px;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #34c759;
    border: 2px solid var(--surface-alt);
}

.account-status {
    font-size: 12px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.account-status strong {
    color: var(--text);
}

.account-signin-btn {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    background: var(--bg);
    color: var(--text);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.account-signin-btn:active {
    transform: scale(0.98);
}

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

.content {
    position: relative;
    flex: 1 1 auto;
    min-height: 0; /* CRITICAL for Leaflet inside flex */
}

#map {
    width: 100%;
    height: 100%;
    min-height: 300px; /* safety fallback */
    background: var(--bg);
}

/* ================= STATUS TOAST ================= */

.status-toast {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1100;
    max-width: calc(100% - 32px);
    padding: 8px 16px;
    border-radius: var(--radius-pill);
    background: rgba(20, 20, 22, 0.88);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    box-shadow: var(--shadow-md);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ================= PRIMARY FAB ("I found a sticker") ================= */

.fab-primary {
    position: absolute;
    left: 50%;
    bottom: calc(20px + var(--safe-bottom));
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 24px;
    border: none;
    border-radius: var(--radius-pill);
    background: var(--accent-gradient);
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.fab-primary-icon {
    font-size: 18px;
}

.fab-primary:active {
    transform: translateX(-50%) scale(0.96);
    box-shadow: var(--shadow-md);
}

/* ================= SECONDARY FAB MENU (hints / seed) ================= */

.fab-menu-wrap {
    position: absolute;
    right: 16px;
    bottom: calc(20px + var(--safe-bottom));
    z-index: 1000;
}

.fab-toggle {
    width: 52px;
    height: 52px;
    border: none;
    border-radius: 50%;
    background: var(--surface);
    color: var(--text);
    font-size: 22px;
    font-weight: 700;
    box-shadow: var(--shadow-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.12s ease;
}

.fab-toggle:active {
    transform: scale(0.94);
}

.fab-toggle-glyph {
    transform: translateY(-2px);
}

/* Stacked directly above the "⋯" toggle, like the locate-me control in most
   map apps. Pure navigation — no zone restriction, unlike the primary
   "I found a sticker" FAB. */
.fab-locate {
    position: absolute;
    bottom: 62px;
    right: 0;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.12s ease;
}

.fab-locate:active {
    transform: scale(0.92);
}

.fab-menu {
    position: absolute;
    bottom: 116px;
    right: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    opacity: 0;
    transform: translateY(10px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.16s ease, transform 0.16s ease;
    transform-origin: bottom right;
}

.fab-menu.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.fab-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border: none;
    border-radius: var(--radius-pill);
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
    box-shadow: var(--shadow-md);
    white-space: nowrap;
    cursor: pointer;
    transition: transform 0.1s ease;
}

.fab-menu-item:active {
    transform: scale(0.96);
}

.fab-menu-icon {
    font-size: 16px;
}

/* ================= STICKER DETAIL MODAL ================= */

.sticker-modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.sticker-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
}

.sticker-modal-card {
    position: relative;
    width: min(420px, 100%);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.sticker-modal-close {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 1;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: rgba(20, 20, 22, 0.55);
    color: #fff;
    font-size: 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sticker-modal-image-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
}

.sticker-modal-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.sticker-modal-image-empty {
    font-size: 13px;
    color: var(--text-muted);
    display: none;
}

.sticker-modal-info {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sticker-modal-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font-size: 13px;
}

.sticker-modal-row strong {
    color: var(--text-muted);
    font-weight: 600;
}

.sticker-modal-row span {
    text-align: right;
    color: var(--text);
}

/* ================= ACCOUNT PAGE ================= */

.topbar-back {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    color: var(--text);
    text-decoration: none;
    font-size: 18px;
}

.account-content {
    flex: 1 1 auto;
    max-width: 560px;
    width: 100%;
    margin: 0 auto;
    padding: 16px;
    padding-bottom: calc(16px + var(--safe-bottom));
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.account-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 16px;
}

.account-panel h2 {
    margin: 0 0 12px;
    font-size: 15px;
    font-weight: 700;
}

.account-hint {
    margin: 0 0 12px;
    font-size: 13px;
    color: var(--text-muted);
}

.account-primary-btn {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: var(--radius-pill);
    background: var(--accent-gradient);
    color: #fff;
    font-family: inherit;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}

.account-primary-btn:active {
    transform: scale(0.98);
}

.series-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.series-form label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
}

.series-form-hint {
    font-weight: 400;
}

.series-form input[type="text"],
.series-form textarea {
    font-family: inherit;
    font-size: 14px;
    font-weight: 400;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    resize: vertical;
}

.series-form input[type="file"] {
    font-size: 13px;
    color: var(--text-muted);
}

.series-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.series-list-empty {
    padding: 16px;
    text-align: center;
    font-size: 13px;
    color: var(--text-muted);
}

.series-card {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg);
    cursor: pointer;
    text-align: left;
    font-family: inherit;
}

.series-card:active {
    transform: scale(0.99);
}

.series-card-thumb {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    border-radius: 10px;
    overflow: hidden;
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.series-card-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.series-card-info {
    flex: 1;
    min-width: 0;
}

.series-card-name {
    font-size: 14px;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.series-card-meta {
    margin-top: 2px;
    font-size: 12px;
    color: var(--text-muted);
}

.series-modal-name {
    margin: 0;
    font-size: 17px;
    font-weight: 800;
}

.series-modal-description {
    margin: 4px 0 4px;
    font-size: 13px;
    color: var(--text-muted);
}

.series-modal-invite {
    margin-top: 8px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.series-modal-invite label {
    display: block;
    margin-bottom: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
}

.series-invite-row {
    display: flex;
    gap: 8px;
}

.series-invite-row input {
    flex: 1;
    min-width: 0;
    font-family: inherit;
    font-size: 12px;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
}

.series-invite-row button {
    flex-shrink: 0;
    padding: 8px 14px;
    border: none;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-family: inherit;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}

/* ================= DESKTOP ================= */

@media (min-width: 700px) {
    .logo {
        height: 52px;
        width: 39px;
    }

    .topbar-text h1 {
        font-size: 20px;
    }

    .fab-primary {
        padding: 15px 28px;
        font-size: 16px;
    }
}
