/* ============================================================
   Flags of the World — Main Stylesheet
   Design: Dark premium, glassmorphism, blue-purple glow
   Color-matched to reference screenshots (pixel-sampled)
   ============================================================ */

/* --- CSS Variables --- */
:root {
    /* Background — avg RGB(15,20,40) from hero, RGB(20,21,34) from index */
    --bg-primary: #0a0e1c;
    --bg-deeper: #060912;
    /* Cards — slightly lighter than background */
    --bg-card: rgba(18, 24, 44, 0.5);
    --bg-card-hover: rgba(28, 36, 60, 0.7);
    /* Borders — very subtle, screenshot shows edge ~RGB(6,13,24) */
    --border-card: rgba(255, 255, 255, 0.05);
    --border-card-hover: rgba(76, 168, 226, 0.3);
    /* Text — bright near-white, sampled RGB(233,234,242) to RGB(250,250,252) */
    --text-primary: #eaecf2;
    --text-secondary: #8a90a8;
    --text-muted: #525a70;
    /* Accent — cyan-blue from screenshot: RGB(76,183,248) */
    --accent: #4ca8e2;
    --accent-glow: rgba(76, 168, 226, 0.3);
    --accent-deep: #0a3066;           /* Deep button blue RGB(10,48,102) */
    --accent-purple: #7c6ff0;
    /* Feedback colors */
    --correct: #22c55e;
    --correct-glow: rgba(34, 197, 94, 0.25);
    --wrong: #ef4444;
    --wrong-glow: rgba(239, 68, 68, 0.25);
    /* Nav — nearly black RGB(1,3,13) */
    --nav-bg: rgba(1, 3, 14, 0.95);
    /* Radii */
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 22px;
    --radius-xl: 28px;
    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 60px rgba(76, 168, 226, 0.12);
    --shadow-card-hover: 0 12px 40px rgba(0, 0, 0, 0.55), 0 0 60px rgba(76, 168, 226, 0.08);
    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    /* Layout */
    --max-width: 1320px;
    --nav-height: 56px;
    --stats-dock-height: 180px;
}

/* --- Reset --- */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Background: flag mosaic + radial glow — layered for depth */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        /* Flag mosaic texture — dark and subtle */
        url('/static/images/bg-mosaik.png') center / cover no-repeat,
        /* Radial glow overlays */
        radial-gradient(ellipse 70% 50% at 50% 30%, rgba(76, 168, 226, 0.04) 0%, transparent 60%),
        radial-gradient(ellipse 50% 40% at 70% 65%, rgba(124, 111, 240, 0.025) 0%, transparent 60%);
    background-blend-mode: normal, normal, normal;
    pointer-events: none;
    z-index: 0;
}

main { position: relative; z-index: 1; flex: 1; }

.has-stats-dock main { padding-bottom: var(--stats-dock-height); }

/* ============================================================
   Navigation — screenshot: ~55px, very dark RGB(0,3,13)
   ============================================================ */
.navbar {
    position: sticky;
    top: 0;
    z-index: 100;
    height: var(--nav-height);
    background: var(--nav-bg);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.nav-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 28px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--text-primary);
    font-weight: 700;
    font-size: 0.95rem;
}

.nav-icon {
    width: 22px;
    height: 22px;
    color: var(--accent);
}

.nav-logo-image {
    height: 100px;
    width: auto;
    display: block;
    filter: brightness(0) invert(1);
    opacity: 0.92;
}

.nav-logo-text { letter-spacing: -0.01em; }

.nav-links { display: flex; gap: 2px; }

.nav-link {
    text-decoration: none;
    color: var(--text-secondary);
    padding: 7px 16px;
    border-radius: 8px;
    font-weight: 500;
    font-size: 0.875rem;
    transition: all var(--transition-fast);
}

.nav-link:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.04);
}

.nav-link.active {
    color: var(--text-primary);
    background: rgba(76, 168, 226, 0.1);
}

/* ============================================================
   Hero Section — deep blue center glow, bright title text
   ============================================================ */
.hero {
    position: relative;
    padding: 80px 24px 60px;
    text-align: center;
    overflow: hidden;
    /* Simulates the natural brightness gradient seen in screenshots */
    background: radial-gradient(ellipse 60% 50% at 50% 40%, rgba(76, 168, 226, 0.06) 0%, transparent 70%);
}

.hero-glow {
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    pointer-events: none;
}

.hero-glow-1 {
    width: 600px; height: 600px;
    background: rgba(76, 168, 226, 0.05);
    top: -200px; left: 50%;
    transform: translateX(-50%);
}

.hero-glow-2 {
    width: 400px; height: 400px;
    background: rgba(124, 111, 240, 0.04);
    bottom: -120px; right: -80px;
}

.hero-content {
    position: relative; z-index: 2;
    max-width: 680px; margin: 0 auto;
}

.hero-title {
    font-size: clamp(2.2rem, 5.5vw, 3.4rem);
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.1;
    margin-bottom: 14px;
    /* Screenshot text: ~RGB(233,234,242) to bright white */
    background: linear-gradient(135deg, #e0e4f0 0%, #f4f5f9 50%, #d4dcf8 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero-subtitle {
    font-size: 1.05rem;
    color: var(--text-secondary);
    margin-bottom: 32px;
    line-height: 1.5;
    max-width: 460px;
    margin-left: auto;
    margin-right: auto;
}

.hero-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 11px 26px;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    text-decoration: none;
    border: none;
    cursor: pointer;
    transition: all var(--transition-normal);
    letter-spacing: -0.01em;
    font-family: inherit;
}

.btn-primary {
    /* Cyan-blue gradient matching screenshot accent */
    background: linear-gradient(135deg, #4ca8e2, #5b8df0);
    color: #fff;
    box-shadow: 0 4px 20px rgba(76, 168, 226, 0.3);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 28px rgba(76, 168, 226, 0.4);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-primary);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.15);
}

/* ============================================================
   Explore Section
   ============================================================ */
.explore-section {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 50px 28px 80px;
}

.section-header {
    text-align: center;
    margin-bottom: 32px;
}

.section-title {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 6px;
}

.section-subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* --- Search & Filter --- */
.controls {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-bottom: 32px;
    align-items: center;
}

.search-wrapper {
    position: relative;
    width: 100%;
    max-width: 440px;
}

.search-icon {
    position: absolute;
    left: 14px; top: 50%;
    transform: translateY(-50%);
    width: 16px; height: 16px;
    color: var(--text-muted);
    pointer-events: none;
    opacity: 0.6;
}

.search-input {
    width: 100%;
    padding: 11px 16px 11px 42px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
    transition: all var(--transition-normal);
}

.search-input::placeholder { color: var(--text-muted); }

.search-input:focus {
    border-color: rgba(76, 168, 226, 0.4);
    background: rgba(255, 255, 255, 0.05);
    box-shadow: 0 0 0 3px rgba(76, 168, 226, 0.06);
}

.filter-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
}

.filter-btn {
    padding: 7px 16px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(255, 255, 255, 0.02);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.filter-btn:hover {
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.1);
}

.filter-btn.active {
    background: rgba(10, 48, 102, 0.5);    /* Deep blue from screenshot RGB(10,48,102) */
    border-color: rgba(76, 168, 226, 0.3);
    color: var(--accent);
}

/* ============================================================
   Flag Grid — ~8 columns, cards ~140px, gap ~12px
   ============================================================ */
.flag-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(135px, 1fr));
    gap: 10px;
}

.flag-card {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-normal);
    overflow: visible;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.flag-card:hover {
    transform: translateY(-3px);
    background: var(--bg-card-hover);
    border-color: var(--border-card-hover);
    box-shadow: var(--shadow-card-hover);
    z-index: 10;
}

.flag-card-inner {
    padding: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.flag-image-wrapper {
    width: 100%;
    aspect-ratio: 4 / 3;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.flag-card-info {
    text-align: center;
    width: 100%;
    overflow: hidden;
    padding: 0 2px;
}

.flag-card-name {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.flag-card-continent {
    display: block;
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-top: 1px;
}

/* --- Tooltip — glassmorphism with blue border glow --- */
.flag-tooltip {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    background: rgba(14, 18, 38, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(76, 168, 226, 0.2);
    border-radius: 10px;
    padding: 8px 14px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: all var(--transition-normal);
    z-index: 20;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6), 0 0 30px rgba(76, 168, 226, 0.06);
}

.flag-tooltip::after {
    content: '';
    position: absolute;
    top: 100%; left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: rgba(76, 168, 226, 0.2);
}

.flag-card:hover .flag-tooltip {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.tooltip-name {
    font-weight: 700;
    font-size: 0.8rem;
    color: var(--text-primary);
}

.tooltip-detail {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-top: 1px;
}

/* --- No Results --- */
.no-results {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.no-results svg { margin-bottom: 12px; opacity: 0.4; }

.no-results h3 {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

/* ============================================================
   Quiz Section
   ============================================================ */
.quiz-section {
    max-width: 640px;
    margin: 0 auto;
    padding: 50px 24px 80px;
}

.quiz-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* --- Quiz Stats --- */
.quiz-header {
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    border-radius: var(--radius-md);
    padding: 14px 18px;
    backdrop-filter: blur(12px);
}

.quiz-stats {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
}

.stat-item {
    text-align: center;
    min-width: 65px;
    padding: 7px 12px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.02);
}

.stat-label {
    display: block;
    font-size: 0.65rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.stat-value {
    display: block;
    font-size: 1rem;
    font-weight: 700;
}

.correct-stat .stat-value { color: var(--correct); }
.wrong-stat .stat-value { color: var(--wrong); }
.streak-stat .stat-value { color: var(--accent); }

/* --- Quiz Card --- */
.quiz-card {
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    border-radius: var(--radius-lg);
    padding: 28px 22px;
    backdrop-filter: blur(12px);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.quiz-flag-wrapper {
    width: 100%;
    max-width: 380px;
    aspect-ratio: 4 / 3;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: 0 8px 40px rgba(76, 168, 226, 0.05);
}

.quiz-flag {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.quiz-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
    padding: 8px 18px;
    background: rgba(76, 168, 226, 0.04);
    border: 1px solid rgba(76, 168, 226, 0.08);
    border-radius: 8px;
    text-align: center;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    transition: all var(--transition-fast);
}

.quiz-hint:hover { border-color: rgba(76, 168, 226, 0.2); }

/* --- Choices --- */
.quiz-choices {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 100%;
}

.choice-btn {
    padding: 15px 18px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-card);
    background: rgba(255, 255, 255, 0.02);
    color: var(--text-primary);
    font-size: 0.95rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition-normal);
    text-align: center;
}

.choice-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(76, 168, 226, 0.3);
    box-shadow: 0 0 20px rgba(76, 168, 226, 0.05);
}

.choice-btn:disabled { cursor: not-allowed; opacity: 0.7; }

.choice-btn.correct {
    background: rgba(34, 197, 94, 0.1);
    border-color: var(--correct);
    color: var(--correct);
    box-shadow: 0 0 20px var(--correct-glow);
    animation: pulse-correct 0.5s ease;
}

.choice-btn.wrong {
    background: rgba(239, 68, 68, 0.1);
    border-color: var(--wrong);
    color: var(--wrong);
    box-shadow: 0 0 20px var(--wrong-glow);
    animation: shake 0.4s ease;
}

.choice-btn.reveal-correct {
    background: rgba(34, 197, 94, 0.06);
    border-color: rgba(34, 197, 94, 0.25);
    color: var(--correct);
}

@keyframes pulse-correct {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.015); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-3px); }
    40% { transform: translateX(3px); }
    60% { transform: translateX(-3px); }
    80% { transform: translateX(3px); }
}

.quiz-feedback {
    font-size: 1rem;
    font-weight: 700;
    text-align: center;
    min-height: 24px;
}

.quiz-feedback.correct-feedback { color: var(--correct); }
.quiz-feedback.wrong-feedback { color: var(--wrong); }

.quiz-next-btn { min-width: 160px; }

/* --- Finished --- */
.quiz-finished { padding: 16px 0; }

.finished-card {
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    border-radius: var(--radius-lg);
    padding: 36px 22px;
    text-align: center;
    backdrop-filter: blur(12px);
}

.finished-card h2 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 6px;
}

.finished-score {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.finished-details {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin-bottom: 28px;
    flex-wrap: wrap;
}

.finished-stat { text-align: center; min-width: 70px; }

.finished-stat-value {
    display: block;
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--accent);
}

.finished-stat:nth-child(2) .finished-stat-value { color: var(--wrong); }
.finished-stat:nth-child(3) .finished-stat-value { color: var(--accent-purple); }

.finished-stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.finished-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ============================================================
   Footer
   ============================================================ */
.footer {
    border-top: 1px solid rgba(255, 255, 255, 0.04);
    padding: 0;
    margin-top: auto;
}

/* ============================================================
   Stats Dock (Home only)
   ============================================================ */
.stats-dock {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(1, 3, 14, 0.12);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}

.has-stats-dock .footer { margin-bottom: var(--stats-dock-height); }

.footer-stats {
    display: flex;
    justify-content: center;
    gap: 32px;
    padding: 36px 24px;
    flex-wrap: wrap;
}

.footer-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-width: 90px;
}

.footer-stat-icon {
    width: 28px;
    height: 28px;
    color: var(--accent);
    opacity: 0.82;
    margin-bottom: 4px;
    transition: opacity var(--transition-fast);
}

.footer-stat:hover .footer-stat-icon {
    opacity: 0.9;
}

.footer-stat-icon svg {
    width: 100%;
    height: 100%;
}

.footer-stat-icon img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
}

.footer-stat-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.footer-stat-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 500;
}

/* --- Bottom Row --- */
.footer-bottom {
    border-top: 1px solid rgba(255, 255, 255, 0.03);
    padding: 18px 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    max-width: var(--max-width);
    margin: 0 auto;
}

.footer-links {
    display: flex;
    gap: 4px;
    align-items: center;
}

.footer-links a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.72rem;
    transition: color var(--transition-fast);
}

.footer-links a:hover {
    color: var(--text-secondary);
}

.footer-dot {
    color: var(--text-muted);
    opacity: 0.3;
    font-size: 0.7rem;
}

.footer-branding {
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.12);
    letter-spacing: 0.02em;
}

.footer-branding-centered {
    text-align: center;
    padding: 0 24px 18px;
}

.footer-branding span {
    color: rgba(255, 255, 255, 0.18);
    font-weight: 500;
}

/* --- Nav legal link (subtle) --- */
.nav-link-legal {
    font-size: 0.8rem;
    opacity: 0.6;
}

.nav-link-legal:hover,
.nav-link-legal.active {
    opacity: 1;
}

/* ============================================================
   Hamburger Menu (mobile)
   ============================================================ */
.hamburger {
    display: none;               /* hidden on desktop */
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    width: 44px;
    height: 44px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    cursor: pointer;
    z-index: 200;
}

.hamburger-line {
    display: block;
    width: 20px;
    height: 1.5px;
    background: var(--text-secondary);
    border-radius: 2px;
    transition: all 0.25s ease;
    transform-origin: center;
}

.hamburger.active .hamburger-line:nth-child(1) {
    transform: translateY(6.5px) rotate(45deg);
}

.hamburger.active .hamburger-line:nth-child(2) {
    opacity: 0;
}

.hamburger.active .hamburger-line:nth-child(3) {
    transform: translateY(-6.5px) rotate(-45deg);
}

/* --- Mobile slide-in nav --- */
.mobile-nav {
    position: fixed;
    top: var(--nav-height);
    right: 0;
    width: 260px;
    max-width: 80vw;
    height: calc(100dvh - var(--nav-height));
    background: var(--nav-bg);
    backdrop-filter: blur(28px);
    -webkit-backdrop-filter: blur(28px);
    border-left: 1px solid rgba(255, 255, 255, 0.06);
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    z-index: 150;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.5);
}

.mobile-nav.open {
    transform: translateX(0);
}

.mobile-nav-link {
    display: flex;
    align-items: center;
    text-decoration: none;
    color: var(--text-secondary);
    padding: 14px 16px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 1rem;
    transition: all var(--transition-fast);
    min-height: 48px;            /* touch target */
}

.mobile-nav-link:hover,
.mobile-nav-link:active {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.mobile-nav-link.active {
    color: var(--accent);
    background: rgba(76, 168, 226, 0.1);
}

/* --- Overlay behind mobile menu --- */
.mobile-menu-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 140;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.mobile-menu-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* ============================================================
   Legal Page
   ============================================================ */
.legal-section {
    max-width: 720px;
    margin: 0 auto;
    padding: 60px 28px 80px;
}

.legal-container {
    background: rgba(6, 9, 18, 0.78);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 18px;
    padding: 26px 26px;
    backdrop-filter: blur(22px);
    -webkit-backdrop-filter: blur(22px);
    box-shadow: var(--shadow-sm);
}

.legal-container h1 {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 4px;
    letter-spacing: -0.02em;
}

.legal-date {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-bottom: 32px;
}

.legal-container h2 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-top: 28px;
    margin-bottom: 8px;
}

.legal-container h3 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-top: 18px;
    margin-bottom: 8px;
}

.legal-container p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.7;
    margin-bottom: 12px;
}

.legal-container strong {
    color: var(--text-primary);
    font-weight: 600;
}

.legal-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 22px;
}

.legal-nav-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--text-secondary);
    padding: 7px 12px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(255, 255, 255, 0.02);
    font-weight: 600;
    font-size: 0.8rem;
    transition: all var(--transition-fast);
}

.legal-nav-link:hover {
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.04);
}

.legal-nav-link.active {
    color: var(--text-primary);
    border-color: rgba(76, 168, 226, 0.3);
    background: rgba(76, 168, 226, 0.12);
}

.legal-container ul {
    margin: 0 0 14px 18px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.7;
}

.legal-container li {
    margin-bottom: 6px;
}

.legal-container table {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0 18px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 12px;
    overflow: hidden;
}

.legal-container th,
.legal-container td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    vertical-align: top;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.legal-container th {
    color: var(--text-primary);
    font-weight: 600;
    background: rgba(255, 255, 255, 0.03);
}

.legal-container tr:last-child td {
    border-bottom: none;
}

.legal-cards {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-top: 18px;
}

.legal-card {
    text-decoration: none;
    padding: 14px 14px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(255, 255, 255, 0.02);
    transition: all var(--transition-normal);
}

.legal-card:hover {
    transform: translateY(-1px);
    border-color: rgba(76, 168, 226, 0.25);
    background: rgba(255, 255, 255, 0.03);
}

.legal-card-title {
    color: var(--text-primary);
    font-weight: 700;
    letter-spacing: -0.01em;
    margin-bottom: 4px;
}

.legal-card-subtitle {
    color: var(--text-secondary);
    font-size: 0.85rem;
    line-height: 1.6;
}

.legal-pre {
    white-space: pre-wrap;
    word-break: break-word;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 0.82rem;
    line-height: 1.6;
    color: var(--text-secondary);
    padding: 14px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

/* ============================================================
   Responsive — mobile-first improvements
   ============================================================ */
@media (max-width: 768px) {
    :root {
        --stats-dock-height: 200px;
    }

    /* --- Mobile navigation --- */
    .hamburger {
        display: flex;           /* show hamburger */
    }

    .nav-links {
        display: none;           /* hide desktop links */
    }

    .nav-brand {
        flex-shrink: 1;
        min-width: 0;
    }

    .nav-logo-image {
        height: 65px;
    }

    .nav-inner {
        padding: 0 12px;
        gap: 8px;
    }

    .nav-link {
        padding: 8px 14px;
        font-size: 0.85rem;
        min-height: 44px;
    }

    /* Hero */
    .hero {
        padding: 40px 16px 36px;
    }

    .hero-title {
        font-size: 1.8rem;
    }

    .hero-subtitle {
        font-size: 0.9rem;
    }

    .hero-buttons {
        flex-direction: column;
        align-items: center;
    }

    .btn {
        width: 100%;
        max-width: 260px;
        min-height: 48px;        /* touch target */
    }

    /* Legal */
    .legal-section {
        padding: 32px 14px 56px;
    }

    .legal-container {
        padding: 18px 14px;
        border-radius: 14px;
    }

    .legal-nav {
        gap: 6px;
    }

    .legal-nav-link {
        padding: 8px 12px;
        font-size: 0.78rem;
        min-height: 40px;
    }

    .legal-cards {
        grid-template-columns: 1fr;
    }

    /* Flag grid */
    .flag-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 6px;
    }

    .flag-card-inner {
        padding: 5px;
    }

    .flag-card-name {
        font-size: 0.65rem;
    }

    .flag-card-continent {
        font-size: 0.6rem;
    }

    .explore-section {
        padding: 20px 12px 56px;
    }

    .section-title {
        font-size: 1.35rem;
    }

    .controls {
        gap: 10px;
        margin-bottom: 24px;
    }

    .filter-btn {
        padding: 8px 14px;
        font-size: 0.78rem;
        min-height: 40px;
    }

    .search-input {
        font-size: 0.9rem;       /* prevent iOS zoom on focus */
        padding: 12px 16px 12px 42px;
    }

    /* Quiz */
    .quiz-section {
        padding: 28px 12px 56px;
    }

    .quiz-card {
        padding: 18px 10px;
        gap: 16px;
    }

    .quiz-choices {
        grid-template-columns: 1fr;
    }

    .choice-btn {
        padding: 14px 16px;
        font-size: 0.95rem;
        min-height: 48px;        /* touch target */
    }

    .quiz-stats { gap: 4px; }

    .stat-item {
        min-width: 55px;
        padding: 7px 10px;
    }

    .stat-value { font-size: 0.9rem; }

    .quiz-hint {
        font-size: 0.85rem;
        padding: 12px 14px;
        min-height: 44px;
    }

    /* Footer */
    .footer-bottom {
        flex-direction: column;
        text-align: center;
        padding: 14px 16px;
    }

    .footer-links a {
        font-size: 0.75rem;
        padding: 4px 2px;
    }

    .footer-stats {
        gap: 18px;
        padding: 24px 16px;
    }

    .footer-stat {
        min-width: 65px;
    }

    .footer-stat-value {
        font-size: 1.05rem;
    }
}

/* ============================================================
   Small phones
   ============================================================ */
@media (max-width: 480px) {
    :root {
        --stats-dock-height: 240px;
    }

    .nav-logo-image {
        height: 48px;
    }

    .flag-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 4px;
    }

    .flag-card-name {
        font-size: 0.58rem;
    }

    .hero-title {
        font-size: 1.45rem;
    }

    .filter-wrapper { gap: 4px; }

    .filter-btn {
        padding: 6px 10px;
        font-size: 0.72rem;
        min-height: 36px;
    }

    .controls { gap: 8px; }

    .btn {
        max-width: 100%;
    }

    .footer-stats { gap: 12px; }
    .footer-stat { min-width: 55px; }
    .footer-stat-value { font-size: 0.95rem; }

    .mobile-nav {
        width: 100%;
        max-width: 100%;
    }
}

/* ============================================================
   Safe-area insets (notched phones: iPhone X+, Pixel, etc.)
   ============================================================ */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .stats-dock {
        padding-bottom: env(safe-area-inset-bottom);
    }

    .footer {
        padding-bottom: env(safe-area-inset-bottom);
    }

    .mobile-nav {
        padding-bottom: env(safe-area-inset-bottom);
    }
}
