/* ==========================================================================
   TOUCH GRASS BINGO — LIGHT BOTANICAL NATURE DESIGN SYSTEM
   ========================================================================== */

:root {
    --font-main: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-sinhala: 'Noto Sans Sinhala', 'Outfit', sans-serif;

    --bg-base: #e8f5e9;
    --bg-gradient: linear-gradient(160deg, #d4edda 0%, #c8e6c9 40%, #dcedc8 100%);

    --surface-white: #ffffff;
    --surface-off: #f3faf4;
    --surface-border: rgba(76, 175, 80, 0.15);

    --accent-green: #2e7d32;
    --accent-mid: #388e3c;
    --accent-bright: #43a047;
    --accent-light: #a5d6a7;
    --accent-pill: #e8f5e9;
    --accent-gold: #f59e0b;
    --accent-gold-text: #7c4a00;

    --text-dark: #1b2e1c;
    --text-medium: #3d5c3e;
    --text-muted: #7a9b7c;
    --text-white: #ffffff;

    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 22px;
    --radius-full: 9999px;

    --shadow-card: 0 2px 12px rgba(46, 125, 50, 0.1), 0 1px 3px rgba(0,0,0,0.06);
    --shadow-btn: 0 4px 14px rgba(46, 125, 50, 0.35);
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);

    /* Safe Area Insets for notched phones & gesture bars */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-main);
    background: var(--bg-gradient);
    color: var(--text-dark);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 0;
    position: relative;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Decorative leaf background shapes */
.leaf-bg {
    position: fixed;
    pointer-events: none;
    z-index: 0;
    opacity: 0.55;
    filter: blur(0px);
}
.leaf-bg-tl {
    top: -30px;
    left: -40px;
    width: 340px;
    font-size: 240px;
    line-height: 1;
    transform: rotate(-20deg);
}
.leaf-bg-tr {
    top: -10px;
    right: -20px;
    width: 300px;
    font-size: 210px;
    line-height: 1;
    transform: rotate(15deg) scaleX(-1);
}
.leaf-bg-bl {
    bottom: 40px;
    left: -30px;
    font-size: 190px;
    transform: rotate(20deg);
}
.leaf-bg-br {
    bottom: 20px;
    right: -20px;
    font-size: 200px;
    transform: rotate(-15deg) scaleX(-1);
}
.leaf-bg-ml {
    top: 50%;
    left: -20px;
    font-size: 140px;
    transform: translateY(-50%) rotate(30deg);
    opacity: 0.35;
}
.leaf-bg-mr {
    top: 50%;
    right: -20px;
    font-size: 140px;
    transform: translateY(-50%) rotate(-30deg) scaleX(-1);
    opacity: 0.35;
}

/* Application Container */
.app-wrapper {
    width: 100%;
    max-width: 900px;
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: max(20px, var(--safe-top)) max(20px, var(--safe-right)) max(32px, var(--safe-bottom)) max(20px, var(--safe-left));
    min-height: 100vh;
    min-height: 100dvh;
}

/* ——— HEADER ——— */
.app-header {
    background: rgba(255, 255, 255, 0.88);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border-radius: var(--radius-lg);
    padding: 16px 20px 14px;
    box-shadow: var(--shadow-card);
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 14px;
    border: 1px solid rgba(255, 255, 255, 0.6);
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.brand-logo {
    width: 42px;
    height: 42px;
    background: linear-gradient(135deg, #2e7d32, #66bb6a);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    box-shadow: 0 3px 10px rgba(46, 125, 50, 0.3);
    flex-shrink: 0;
}

.brand-text-group {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}

.brand-name {
    font-size: 1.55rem;
    font-weight: 800;
    color: var(--text-dark);
    letter-spacing: -0.03em;
    line-height: 1.05;
    white-space: nowrap;
}

.brand-date {
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.header-stats-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(56, 142, 60, 0.12);
}

.header-pills-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.badge-location {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.70rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--accent-mid);
    background: var(--accent-pill);
    border: 1px solid rgba(56, 142, 60, 0.25);
    padding: 5px 11px;
    border-radius: var(--radius-full);
    white-space: nowrap;
    flex-shrink: 0;
}

.icon-btn {
    background: #f5f5f5;
    border: 1.5px solid #e0e0e0;
    color: var(--text-dark);
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
    touch-action: manipulation;
}

.icon-btn:hover {
    background: var(--accent-pill);
    border-color: var(--accent-bright);
    transform: translateY(-1px);
}

.streak-pill-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    background: #fff8e1;
    border: 1.5px solid rgba(255, 179, 0, 0.45);
    color: #e65100;
    font-family: var(--font-main);
    font-size: 0.82rem;
    font-weight: 800;
    padding: 7px 12px;
    min-height: 36px;
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(255, 152, 0, 0.15);
    touch-action: manipulation;
}

.streak-pill-btn:hover {
    background: #ffecb3;
    border-color: #ffb300;
    transform: translateY(-1px);
    box-shadow: 0 3px 12px rgba(255, 152, 0, 0.25);
}

.lang-pill-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    background: #e8f5e9;
    border: 1.5px solid rgba(46, 125, 50, 0.3);
    color: var(--accent-green);
    font-family: var(--font-main);
    font-size: 0.82rem;
    font-weight: 700;
    padding: 7px 11px;
    min-height: 40px;
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
    touch-action: manipulation;
}

.lang-pill-btn:hover {
    background: #c8e6c9;
    border-color: var(--accent-bright);
    transform: translateY(-1px);
}

.bingo-pill-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--accent-gold);
    border: none;
    color: var(--accent-gold-text);
    font-family: var(--font-main);
    font-size: 0.85rem;
    font-weight: 800;
    padding: 8px 16px;
    min-height: 36px;
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 3px 10px rgba(245, 158, 11, 0.35);
    white-space: nowrap;
    touch-action: manipulation;
}

.bingo-pill-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 5px 16px rgba(245, 158, 11, 0.5);
}

/* Progress Row */
.progress-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 0;
    background: #f8fdf8;
    border: 1.5px solid rgba(56, 142, 60, 0.15);
    border-radius: var(--radius-full);
    padding: 8px 16px;
}

.progress-bar-container {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.progress-leaf-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
}

.progress-bar-track {
    flex: 1;
    height: 8px;
    background: rgba(56, 142, 60, 0.12);
    border-radius: var(--radius-full);
    overflow: hidden;
    position: relative;
    min-width: 50px;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-mid), var(--accent-bright));
    border-radius: var(--radius-full);
    transition: width 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    min-width: 0%;
}

.progress-text {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}

.camera-tip {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}

/* ——— MAIN GRID ——— */
.main-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.grid-container {
    width: 100%;
}

.bingo-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    width: 100%;
}

/* Card Tile */
.card-tile {
    background: var(--surface-white);
    border: 1.5px solid rgba(56, 142, 60, 0.12);
    border-radius: var(--radius-md);
    padding: 14px 14px 12px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 8px;
    box-shadow: var(--shadow-card);
    transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
    position: relative;
    overflow: hidden;
    user-select: none;
    min-height: 130px;
    height: 100%;
    touch-action: manipulation;
}

.card-tile:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(46, 125, 50, 0.15);
    border-color: rgba(56, 142, 60, 0.3);
}

.card-tile:active {
    transform: scale(0.98);
}

/* Tile top row */
.tile-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.tile-num-tag {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--accent-bright);
    background: var(--accent-pill);
    padding: 3px 8px;
    border-radius: var(--radius-full);
    letter-spacing: 0.02em;
}

.tile-leaf-icon {
    font-size: 1.1rem;
    opacity: 0.75;
}

/* Tile text */
.tile-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* Tile text typography */
.card-primary {
    font-weight: 700;
    font-size: 1.02rem;
    color: var(--text-dark);
    line-height: 1.22;
    word-break: break-word;
}

.card-en.card-primary,
.card-en {
    font-family: var(--font-main);
    font-weight: 700;
    font-size: 1.02rem;
    color: var(--text-dark);
    line-height: 1.22;
    word-break: break-word;
    letter-spacing: -0.01em;
}

.card-si.card-primary {
    font-family: var(--font-sinhala);
    font-size: 1.02rem;
}

.card-sub {
    font-size: 0.74rem;
    font-weight: 500;
    color: var(--text-muted);
    line-height: 1.2;
}

.card-si.card-sub,
.card-si {
    font-family: var(--font-sinhala);
    font-size: 0.74rem;
    font-weight: 500;
    color: var(--text-muted);
    line-height: 1.2;
}

.card-en.card-sub {
    font-family: var(--font-main);
    font-size: 0.74rem;
}

/* English-only mode hides Sinhala subtext cleanly */
.lang-en-only .card-sub,
.lang-en-only .card-si {
    display: none !important;
}

/* Scan CTA Button inside tile */
.scan-label-short {
    display: none;
}
.scan-label-full {
    display: inline;
}

.tile-scan-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--accent-bright);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    font-family: var(--font-main);
    font-size: 0.78rem;
    font-weight: 700;
    width: 100%;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: var(--shadow-btn);
    pointer-events: none; /* clicks go through to the tile */
    margin-top: auto;
}

.card-tile:hover .tile-scan-btn {
    background: var(--accent-green);
}

.scan-btn-inner {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.scan-btn-icon {
    flex-shrink: 0;
}

.scan-btn-arrow {
    font-size: 0.8rem;
    font-weight: 900;
}

/* Completed tile state */
.card-tile.completed {
    background: linear-gradient(145deg, #f1fdf3, #e8f5e9);
    border-color: rgba(56, 142, 60, 0.35);
}

.card-tile.completed .tile-scan-btn {
    background: rgba(56, 142, 60, 0.15);
    color: var(--accent-green);
    box-shadow: none;
}

.card-tile.completed .tile-leaf-icon {
    opacity: 1;
}

/* Completed badge overlay */
.tile-thumbnail-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 60%;
    object-fit: cover;
    opacity: 0.18;
    pointer-events: none;
}

.completed-badge-icon {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 22px;
    height: 22px;
    background: var(--accent-green);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 900;
    box-shadow: 0 2px 6px rgba(46, 125, 50, 0.4);
    z-index: 2;
}

/* Verifying pulse */
.card-tile.verifying {
    animation: pulse-scan 1.2s ease-in-out infinite;
    border-color: var(--accent-gold);
}

@keyframes pulse-scan {
    0%, 100% { box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.3); }
    50% { box-shadow: 0 0 0 6px rgba(245, 158, 11, 0.1); }
}

/* Bingo line highlight */
.card-tile.in-bingo-line {
    border-color: var(--accent-gold);
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.4), var(--shadow-card);
}

/* ——— STATE CARDS ——— */
.state-card {
    background: rgba(255, 255, 255, 0.88);
    backdrop-filter: blur(14px);
    border: 1.5px solid var(--surface-border);
    border-radius: var(--radius-lg);
    padding: 48px 20px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow-card);
}

.state-card h3 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-dark);
}

.state-card p {
    font-size: 0.82rem;
    color: var(--text-muted);
}

.spinner {
    width: 44px;
    height: 44px;
    border: 3px solid rgba(56, 142, 60, 0.15);
    border-top-color: var(--accent-bright);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.error-icon { font-size: 2.4rem; }

/* ——— BINGO BANNER ——— */
.bingo-banner {
    background: linear-gradient(135deg, #2e7d32, #43a047);
    border-radius: var(--radius-md);
    padding: 14px 18px;
    color: white;
    box-shadow: 0 4px 16px rgba(46, 125, 50, 0.35);
    animation: slide-up 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.banner-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.banner-emoji { font-size: 1.8rem; }
.banner-text h4 { font-size: 0.95rem; font-weight: 800; }
.banner-text p { font-size: 0.75rem; opacity: 0.88; }

@keyframes slide-up {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ——— MODALS ——— */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(14, 40, 16, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: max(16px, var(--safe-top)) max(12px, var(--safe-right)) max(16px, var(--safe-bottom)) max(12px, var(--safe-left));
    animation: fade-in 0.2s ease;
    overflow-y: auto;
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
    background: white;
    border: 1.5px solid rgba(56, 142, 60, 0.2);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 400px;
    padding: 24px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    gap: 16px;
    animation: modal-pop 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    max-height: calc(100dvh - 32px);
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    margin: auto;
}

@keyframes modal-pop {
    from { opacity: 0; transform: scale(0.93); }
    to { opacity: 1; transform: scale(1); }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.result-badge {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    background: var(--accent-pill);
    color: var(--accent-green);
    border: 1px solid rgba(56, 142, 60, 0.25);
}

.badge-gold {
    background: #fffbeb;
    color: var(--accent-gold-text);
    border-color: rgba(245, 158, 11, 0.3);
}

.badge-success {
    background: #f0fdf4;
    color: #166534;
    border-color: rgba(34, 197, 94, 0.35);
}

.badge-error {
    background: #fff7ed;
    color: #9a3412;
    border-color: rgba(234, 88, 12, 0.3);
}

.modal-close-btn {
    background: #f5f5f5;
    border: none;
    color: #666;
    width: 34px;
    height: 34px;
    min-width: 34px;
    min-height: 34px;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
}

.modal-close-btn:hover {
    background: #eee;
    color: #333;
}

.modal-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 10px;
}

.result-big-icon {
    font-size: 3rem;
    margin-bottom: 2px;
}

.modal-body h3 {
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--text-dark);
}

.result-description {
    font-size: 0.86rem;
    color: var(--text-medium);
    line-height: 1.4;
}

/* Confidence Meter */
.confidence-box {
    width: 100%;
    background: #f8fdf8;
    border: 1.5px solid rgba(56, 142, 60, 0.15);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    text-align: left;
    margin-top: 4px;
}

.confidence-label-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.bold-stat {
    font-weight: 700;
    color: var(--accent-green);
}

.meter-track {
    width: 100%;
    height: 8px;
    background: rgba(56, 142, 60, 0.1);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.meter-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-mid), var(--accent-bright));
    border-radius: var(--radius-full);
    transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.ai-insight-text {
    font-size: 0.76rem;
    color: var(--text-muted);
    line-height: 1.35;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    padding-top: 6px;
    text-align: left;
}

/* Share preview */
.share-preview-box {
    width: 100%;
    background: #f8fdf8;
    border: 1.5px solid rgba(56, 142, 60, 0.15);
    border-radius: var(--radius-md);
    padding: 14px;
    text-align: center;
}

.share-preview-box pre {
    font-family: var(--font-main);
    font-size: 0.84rem;
    line-height: 1.55;
    color: var(--text-dark);
    white-space: pre-wrap;
}

/* Modal Buttons */
.modal-actions {
    display: flex;
    gap: 10px;
    width: 100%;
    margin-top: 4px;
}

.btn {
    flex: 1;
    padding: 12px 16px;
    min-height: 44px;
    border-radius: var(--radius-md);
    font-family: var(--font-main);
    font-size: 0.86rem;
    font-weight: 700;
    cursor: pointer;
    border: none;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    touch-action: manipulation;
}

.btn-primary {
    background: var(--accent-bright);
    color: white;
    box-shadow: var(--shadow-btn);
}

.btn-primary:hover {
    background: var(--accent-green);
    transform: translateY(-1px);
}

.btn-secondary {
    background: #f5f5f5;
    color: var(--text-dark);
    border: 1.5px solid #e0e0e0;
}

.btn-secondary:hover {
    background: #eeeeee;
}

.btn-gold {
    background: var(--accent-gold);
    color: var(--accent-gold-text);
    box-shadow: 0 4px 14px rgba(245, 158, 11, 0.35);
}

.btn-gold:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(245, 158, 11, 0.5);
}

/* Celebration Modal */
.modal-celebration {
    border-color: rgba(245, 158, 11, 0.4);
    box-shadow: 0 20px 50px rgba(245, 158, 11, 0.15);
}

.celebration-bounce {
    animation: trophy-bounce 1s ease-in-out infinite alternate;
}

@keyframes trophy-bounce {
    from { transform: translateY(0) scale(1); }
    to { transform: translateY(-8px) scale(1.08); }
}

.celebration-sub {
    font-size: 0.88rem;
    color: var(--text-medium);
}

.stats-pills {
    display: flex;
    gap: 12px;
    margin: 6px 0;
}

.stat-pill {
    background: #fffbeb;
    border: 1.5px solid rgba(245, 158, 11, 0.3);
    padding: 8px 18px;
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-num {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--accent-gold-text);
}

.stat-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 600;
}

/* ——— TOAST ——— */
.toast {
    position: fixed;
    bottom: max(20px, calc(var(--safe-bottom) + 16px));
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-dark);
    color: white;
    padding: 11px 22px;
    border-radius: var(--radius-full);
    font-size: 0.83rem;
    font-weight: 600;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    z-index: 200;
    white-space: normal;
    text-align: center;
    line-height: 1.35;
    max-width: min(92vw, 420px);
    width: max-content;
    animation: toast-slide 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes toast-slide {
    from { opacity: 0; transform: translate(-50%, 16px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

/* Confetti Canvas */
.confetti-canvas {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 999;
}

/* ——— FOOTER ——— */
.app-footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-top: 16px;
    text-align: center;
}

.privacy-pill {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.72rem;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(8px);
    padding: 7px 16px;
    border-radius: var(--radius-full);
    border: 1px solid rgba(56, 142, 60, 0.15);
}

.hacktober-credit {
    font-size: 0.68rem;
    color: var(--text-muted);
}

.hacktober-credit strong {
    color: var(--text-medium);
}

/* Utility */
.hidden { display: none !important; }

/* ==========================================================================
   MOBILE RESPONSIVE SYSTEM
   ========================================================================== */

/* Tablets and small laptops (<= 768px) */
@media (max-width: 768px) {
    .app-wrapper {
        padding: max(16px, var(--safe-top)) max(16px, var(--safe-right)) max(28px, var(--safe-bottom)) max(16px, var(--safe-left));
    }
    .bingo-grid {
        gap: 10px;
    }
    .card-tile {
        padding: 12px 10px 10px;
        min-height: 120px;
    }
    .card-primary, .card-en {
        font-size: 0.96rem;
    }
    .card-sub, .card-si {
        font-size: 0.72rem;
    }
}

/* Mobile Screens (<= 600px) */
@media (max-width: 600px) {
    .app-wrapper {
        padding: max(10px, var(--safe-top)) max(10px, var(--safe-right)) max(24px, var(--safe-bottom)) max(10px, var(--safe-left));
    }

    .app-header {
        padding: 12px 12px 10px;
        gap: 8px;
        border-radius: var(--radius-md);
        margin-bottom: 10px;
    }

    .header-top {
        gap: 8px;
    }

    .brand {
        gap: 8px;
    }

    .brand-logo {
        width: 36px;
        height: 36px;
        font-size: 1.2rem;
        border-radius: 10px;
    }

    .brand-name {
        font-size: 1.3rem;
    }

    .brand-date {
        font-size: 0.68rem;
    }

    .header-actions {
        gap: 6px;
    }

    .icon-btn {
        width: 36px;
        height: 36px;
        min-width: 36px;
        min-height: 36px;
        font-size: 0.92rem;
    }

    .lang-pill-btn {
        padding: 6px 11px;
        min-height: 36px;
        font-size: 0.78rem;
    }

    .header-stats-bar {
        padding-top: 8px;
        gap: 6px;
    }

    .header-pills-group {
        gap: 6px;
    }

    .badge-location {
        font-size: 0.64rem;
        padding: 4px 9px;
    }

    .streak-pill-btn {
        padding: 5px 10px;
        font-size: 0.76rem;
        min-height: 32px;
    }

    .bingo-pill-btn {
        padding: 6px 12px;
        font-size: 0.78rem;
        min-height: 32px;
    }

    /* Progress Row wraps on mobile */
    .progress-row {
        flex-direction: column;
        gap: 6px;
        padding: 8px 12px;
        border-radius: var(--radius-md);
        align-items: stretch;
    }

    .progress-bar-container {
        width: 100%;
        gap: 8px;
    }

    .progress-text {
        font-size: 0.70rem;
    }

    .camera-tip {
        display: flex;
        justify-content: center;
        width: 100%;
        font-size: 0.68rem;
        color: var(--text-muted);
        padding-top: 3px;
        border-top: 1px dashed rgba(56, 142, 60, 0.12);
    }

    /* Bingo Grid & Tiles */
    .bingo-grid {
        gap: 8px;
    }

    .card-tile {
        padding: 9px 8px 8px;
        min-height: 105px;
        border-radius: 12px;
        gap: 4px;
    }

    .tile-num-tag {
        font-size: 0.60rem;
        padding: 2px 5px;
    }

    .tile-leaf-icon {
        font-size: 0.95rem;
    }

    .card-primary,
    .card-en.card-primary,
    .card-en,
    .card-si.card-primary {
        font-size: clamp(0.76rem, 2.7vw, 0.88rem);
        line-height: 1.18;
    }

    .card-sub,
    .card-si.card-sub,
    .card-si,
    .card-en.card-sub {
        font-size: clamp(0.62rem, 2vw, 0.70rem);
        line-height: 1.15;
    }

    .tile-scan-btn {
        padding: 6px 6px;
        font-size: 0.72rem;
        border-radius: 8px;
        justify-content: center;
    }

    .scan-btn-inner {
        gap: 4px;
        justify-content: center;
        width: 100%;
    }

    .scan-btn-arrow {
        display: none;
    }

    /* Decorative leaves toned down on mobile */
    .leaf-bg {
        opacity: 0.22;
    }
    .leaf-bg-tl {
        top: -10px;
        left: -20px;
        font-size: 110px;
    }
    .leaf-bg-tr {
        top: -5px;
        right: -15px;
        font-size: 95px;
    }
    .leaf-bg-bl {
        bottom: 20px;
        left: -15px;
        font-size: 85px;
    }
    .leaf-bg-br {
        bottom: 10px;
        right: -15px;
        font-size: 90px;
    }
    .leaf-bg-ml,
    .leaf-bg-mr {
        display: none;
    }

    /* Modals on mobile */
    .modal-card {
        padding: 18px 16px;
        border-radius: var(--radius-md);
        gap: 12px;
        max-height: calc(100dvh - 24px);
    }

    .result-big-icon {
        font-size: 2.5rem;
    }

    .modal-body h3 {
        font-size: 1rem;
    }

    .result-description {
        font-size: 0.82rem;
    }

    .confidence-box {
        padding: 10px 12px;
        gap: 6px;
    }

    /* Bingo win banner */
    .bingo-banner {
        padding: 10px 14px;
        border-radius: var(--radius-sm);
    }
    .banner-content {
        gap: 10px;
    }
    .banner-emoji {
        font-size: 1.4rem;
    }
    .banner-text h4 {
        font-size: 0.86rem;
    }
    .banner-text p {
        font-size: 0.70rem;
    }

    /* Footer */
    .app-footer {
        margin-top: 12px;
        gap: 6px;
    }
    .privacy-pill {
        font-size: 0.68rem;
        padding: 6px 12px;
    }
    .hacktober-credit {
        font-size: 0.65rem;
    }
}

/* Compact Mobile (<= 440px, e.g., iPhone SE, Pixel 5, standard mobile) */
@media (max-width: 440px) {
    .scan-label-full {
        display: none;
    }
    .scan-label-short {
        display: inline;
    }

    .tile-scan-btn {
        padding: 5px 4px;
        font-size: 0.70rem;
    }

    .card-tile {
        padding: 8px 6px 6px;
        min-height: 98px;
    }

    .header-top {
        gap: 6px;
    }

    .brand-name {
        font-size: 1.2rem;
    }

    .header-actions {
        gap: 5px;
    }

    .icon-btn {
        width: 34px;
        height: 34px;
        min-width: 34px;
        min-height: 34px;
        font-size: 0.88rem;
    }

    .lang-pill-btn {
        padding: 5px 9px;
        min-height: 34px;
        font-size: 0.74rem;
    }

    .badge-location {
        font-size: 0.60rem;
        padding: 3px 7px;
    }

    .streak-pill-btn {
        padding: 5px 9px;
        font-size: 0.72rem;
        min-height: 30px;
    }

    .bingo-pill-btn {
        padding: 5px 10px;
        font-size: 0.74rem;
        min-height: 30px;
    }

    .stats-pills {
        gap: 8px;
        width: 100%;
    }

    .stat-pill {
        flex: 1;
        padding: 6px 12px;
    }

    .stat-num {
        font-size: 1.15rem;
    }

    .stat-label {
        font-size: 0.60rem;
    }
}

/* Narrow Mobile Screens (<= 360px, e.g., iPhone SE 1st Gen, narrow Android) */
@media (max-width: 360px) {
    .app-wrapper {
        padding: max(6px, var(--safe-top)) max(6px, var(--safe-right)) max(18px, var(--safe-bottom)) max(6px, var(--safe-left));
    }

    .bingo-grid {
        gap: 5px;
    }

    .card-tile {
        padding: 7px 5px 5px;
        min-height: 90px;
    }

    .card-primary,
    .card-en.card-primary,
    .card-en,
    .card-si.card-primary {
        font-size: 0.72rem;
    }

    .card-sub,
    .card-si.card-sub,
    .card-si,
    .card-en.card-sub {
        font-size: 0.60rem;
    }

    .tile-num-tag {
        font-size: 0.56rem;
        padding: 1px 4px;
    }

    .tile-leaf-icon {
        font-size: 0.85rem;
    }

    .tile-scan-btn {
        padding: 4px 2px;
        font-size: 0.66rem;
    }

    .header-stats-bar {
        gap: 4px;
    }

    .badge-location {
        font-size: 0.58rem;
        padding: 3px 5px;
    }

    .streak-pill-btn {
        padding: 4px 7px;
        font-size: 0.70rem;
    }

    .bingo-pill-btn {
        padding: 4px 8px;
        font-size: 0.70rem;
    }

    .modal-actions {
        flex-direction: column;
        gap: 8px;
    }

    .modal-actions .btn {
        width: 100%;
        padding: 10px 12px;
    }
}

/* Mobile Landscape Mode */
@media (max-height: 540px) and (orientation: landscape) {
    .app-wrapper {
        padding: max(6px, var(--safe-top)) max(14px, var(--safe-right)) max(12px, var(--safe-bottom)) max(14px, var(--safe-left));
    }

    .app-header {
        padding: 8px 12px;
        gap: 6px;
        margin-bottom: 8px;
    }

    .brand-logo {
        width: 30px;
        height: 30px;
        font-size: 1rem;
    }

    .brand-name {
        font-size: 1.15rem;
    }

    .header-stats-bar {
        padding-top: 6px;
        gap: 6px;
    }

    .bingo-grid {
        gap: 6px;
    }

    .card-tile {
        min-height: 85px;
        padding: 6px 8px;
    }

    .modal-card {
        max-height: calc(100vh - 20px);
        max-height: calc(100dvh - 20px);
        padding: 14px 16px;
    }

    .leaf-bg {
        display: none;
    }
}

/* Touch-specific ergonomic optimizations */
@media (hover: none) and (pointer: coarse) {
    .card-tile:active {
        transform: scale(0.97);
        transition: transform 0.1s ease;
    }
    .card-tile:hover {
        transform: none;
        box-shadow: var(--shadow-card);
    }
    .card-tile.completed:hover {
        transform: none;
    }
    .btn:active,
    .icon-btn:active,
    .lang-pill-btn:active,
    .streak-pill-btn:active,
    .bingo-pill-btn:active {
        transform: scale(0.95);
    }
}