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

:root {
    --bg: #0f172a;
    --bg-card: #1e293b;
    --bg-card-hover: #334155;
    --surface: #1e293b;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --accent: #6366f1;
    --accent-glow: rgba(99, 102, 241, 0.3);
    --success: #22c55e;
    --success-bg: rgba(34, 197, 94, 0.15);
    --fail: #f97316;
    --fail-bg: rgba(249, 115, 22, 0.15);
    --radius: 16px;
    --radius-sm: 10px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    overscroll-behavior: none;
}

body {
    display: flex;
    flex-direction: column;
    max-width: 480px;
    margin: 0 auto;
    position: relative;
    min-height: 100dvh;
}

/* Screens */
.screen {
    display: none;
    flex-direction: column;
    flex: 1;
    min-height: 100dvh;
}
.screen.active {
    display: flex;
}

/* HOME */
.home-hero {
    padding: calc(60px + var(--safe-top)) 24px 32px;
    text-align: center;
}
.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 8px;
}
.logo-icon {
    font-size: 42px;
    filter: drop-shadow(0 0 20px var(--accent-glow));
}
.logo h1 {
    font-size: 36px;
    font-weight: 800;
    background: linear-gradient(135deg, #818cf8, #6366f1, #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.5px;
}
.tagline {
    color: var(--text-muted);
    font-size: 16px;
    font-weight: 500;
}

.category-section {
    padding: 0 20px 40px;
    flex: 1;
}
.category-section h2 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 16px;
}
.category-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.category-card {
    background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: var(--radius);
    padding: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 16px;
    -webkit-tap-highlight-color: transparent;
}
.category-card:active {
    transform: scale(0.98);
    background: var(--bg-card-hover);
}
.category-card .cat-emoji {
    font-size: 36px;
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.05);
    border-radius: 14px;
    flex-shrink: 0;
}
.category-card .cat-info h3 {
    font-size: 17px;
    font-weight: 700;
    margin-bottom: 4px;
}
.category-card .cat-info p {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.4;
}

/* GAME SCREEN */
.game-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: calc(16px + var(--safe-top)) 16px 12px;
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 10;
}
.btn-icon {
    background: var(--surface);
    border: none;
    color: var(--text);
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
}
.btn-icon:active {
    opacity: 0.7;
}
.game-title {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 17px;
    min-width: 0;
}
.game-title span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.progress-badge {
    background: var(--accent);
    color: white;
    font-weight: 700;
    font-size: 14px;
    padding: 6px 14px;
    border-radius: 20px;
    flex-shrink: 0;
}

.progress-bar-container {
    height: 4px;
    background: rgba(255,255,255,0.06);
    margin: 0 16px;
    border-radius: 2px;
    overflow: hidden;
}
.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #6366f1, #a78bfa);
    border-radius: 2px;
    width: 0%;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.items-list {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
    padding-bottom: 200px;
    overflow-y: auto;
}
.item-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px;
    background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: var(--radius-sm);
    transition: all 0.3s ease;
}
.item-row.found {
    background: var(--success-bg);
    border-color: rgba(34, 197, 94, 0.2);
}
.item-check {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2.5px solid var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.3s ease;
}
.item-row.found .item-check {
    background: var(--success);
    border-color: var(--success);
}
.item-check svg {
    opacity: 0;
    transition: opacity 0.3s ease;
}
.item-row.found .item-check svg {
    opacity: 1;
}
.item-label {
    font-size: 15px;
    font-weight: 500;
    flex: 1;
}
.item-row.found .item-label {
    color: var(--success);
}

/* Camera dock */
.camera-dock {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 480px;
    padding: 16px 20px calc(16px + var(--safe-bottom));
    background: linear-gradient(to top, var(--bg) 60%, transparent);
    z-index: 20;
}
.camera-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 16px;
    background: linear-gradient(135deg, #6366f1, #7c3aed);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 16px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 4px 24px var(--accent-glow);
    transition: all 0.2s ease;
}
.btn-restart {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 10px;
    margin-top: 8px;
    background: transparent;
    color: var(--text-muted);
    border: 1.5px solid var(--bg-card-hover);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: all 0.2s ease;
}
.btn-restart:active {
    background: var(--bg-card);
    color: var(--text);
}
.camera-btn:active {
    transform: scale(0.97);
}

/* Overlays */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 24px;
}
.overlay.active {
    display: flex;
}
#overlay-permission.active {
    z-index: 110;
}

.result-card, .complete-card, .loading-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 32px 24px;
    text-align: center;
    width: 100%;
    max-width: 380px;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}

.result-icon {
    font-size: 56px;
    margin-bottom: 12px;
}
.result-card h2 {
    font-size: 22px;
    font-weight: 800;
    margin-bottom: 8px;
}
.result-card p {
    color: var(--text-muted);
    font-size: 15px;
    line-height: 1.5;
    margin-bottom: 16px;
}
.result-photo {
    width: 100%;
    max-height: 200px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
}

.btn-primary {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, #6366f1, #7c3aed);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.btn-primary:active {
    opacity: 0.85;
}

/* Complete */
.confetti-emoji {
    font-size: 64px;
    margin-bottom: 12px;
    animation: bounce 0.6s ease;
}
@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-20px); }
}
.complete-card h2 {
    font-size: 26px;
    font-weight: 800;
    margin-bottom: 8px;
}
.complete-card p {
    color: var(--text-muted);
    font-size: 15px;
    margin-bottom: 12px;
}
.complete-time {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 20px;
}

/* Loading */
.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255,255,255,0.1);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
.loading-card p {
    color: var(--text-muted);
    font-size: 15px;
}

/* Item found animation */
.item-row.just-found {
    animation: popIn 0.5s ease;
}
@keyframes popIn {
    0% { transform: scale(1); }
    30% { transform: scale(1.04); }
    100% { transform: scale(1); }
}

/* Custom game form */
.custom-form {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    flex: 1;
}
.custom-hint {
    color: var(--text-muted);
    font-size: 14px;
    line-height: 1.5;
}
.custom-textarea {
    width: 100%;
    min-height: 200px;
    background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: inherit;
    font-size: 15px;
    padding: 16px;
    resize: vertical;
    outline: none;
    transition: border-color 0.2s;
}
.custom-textarea:focus {
    border-color: var(--accent);
}
.custom-textarea::placeholder {
    color: rgba(148, 163, 184, 0.5);
}

/* Custom card accent border */
.custom-card {
    border: 1px dashed rgba(99, 102, 241, 0.4) !important;
}

/* Mode Tabs */
.mode-tabs {
    display: flex;
    margin: 0 20px 20px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 4px;
    gap: 4px;
}
.mode-tab {
    flex: 1;
    padding: 10px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}
.mode-tab.active {
    background: var(--accent);
    color: white;
}

.tab-content {
    display: none;
    flex-direction: column;
    flex: 1;
}
.tab-content.active {
    display: flex;
}

/* Multiplayer menu */
.multi-menu {
    padding: 0 20px 40px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.multi-option {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px;
    background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: var(--radius);
    cursor: pointer;
    text-align: left;
    color: var(--text);
    font-family: inherit;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}
.multi-option:active {
    transform: scale(0.98);
    background: var(--bg-card-hover);
}
.multi-option-icon {
    font-size: 32px;
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.05);
    border-radius: 14px;
    flex-shrink: 0;
}
.multi-option h3 {
    font-size: 17px;
    font-weight: 700;
    margin-bottom: 4px;
}
.multi-option p {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.4;
}

/* Multi forms */
.multi-form {
    padding: 20px;
    display: flex;
    flex-direction: column;
}
.form-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}
.form-input {
    width: 100%;
    padding: 14px 16px;
    background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: inherit;
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s;
}
.form-input:focus {
    border-color: var(--accent);
}
.form-input::placeholder {
    color: rgba(148, 163, 184, 0.5);
}
.code-input {
    text-transform: uppercase;
    font-size: 24px;
    font-weight: 800;
    text-align: center;
    letter-spacing: 6px;
}

/* Lobby */
.lobby-content {
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.room-code-display {
    background: var(--bg-card);
    border: 2px dashed rgba(99, 102, 241, 0.4);
    border-radius: var(--radius);
    padding: 20px 32px;
    text-align: center;
    margin-bottom: 24px;
    width: 100%;
}
.room-code-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
}
.room-code-value {
    font-size: 36px;
    font-weight: 800;
    letter-spacing: 8px;
    color: var(--accent);
}
.lobby-heading {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
    align-self: flex-start;
}
.lobby-players {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.lobby-player {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255,255,255,0.06);
}
.lobby-player-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}
.lobby-player-name {
    flex: 1;
    font-weight: 600;
    font-size: 15px;
}
.lobby-player-badge {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 4px 8px;
    border-radius: 6px;
    background: rgba(99, 102, 241, 0.2);
    color: var(--accent);
}
.lobby-wait {
    color: var(--text-muted);
    font-size: 14px;
    margin-top: 24px;
    animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* Leaderboard */
.leaderboard {
    display: flex;
    gap: 6px;
    padding: 8px 16px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.leaderboard:empty {
    display: none;
}
.lb-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--bg-card);
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
    border: 1px solid rgba(255,255,255,0.06);
}
.lb-chip.me {
    border-color: var(--accent);
    background: rgba(99, 102, 241, 0.15);
}
.lb-rank {
    font-weight: 800;
    color: var(--text-muted);
    font-size: 12px;
}
.lb-score {
    color: var(--accent);
    font-weight: 700;
}

/* Timer badge */
.timer-badge {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 700;
    flex-shrink: 0;
    color: var(--text);
    background: var(--surface);
    border: 1px solid rgba(255,255,255,0.1);
}
.timer-badge.warning {
    color: #f97316;
    border-color: rgba(249, 115, 22, 0.4);
    background: rgba(249, 115, 22, 0.1);
}
.timer-badge.danger {
    color: #ef4444;
    border-color: rgba(239, 68, 68, 0.4);
    background: rgba(239, 68, 68, 0.1);
    animation: pulse 1s ease-in-out infinite;
}

/* Timer pills */
.timer-pills {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
    width: 100%;
}
.timer-pill {
    padding: 8px 16px;
    border-radius: 20px;
    border: 1px solid rgba(255,255,255,0.15);
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}
.timer-pill.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}
.timer-section {
    width: 100%;
}

/* GPS card */
.gps-card {
    border: 1px dashed rgba(34, 197, 94, 0.4) !important;
}

/* Settings card */
.settings-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.btn-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(255,255,255,0.08);
    border-radius: 50%;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: all 0.2s;
}
.btn-close:active {
    background: rgba(255,255,255,0.15);
}

/* Custom timer row */
.custom-timer-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    justify-content: center;
}

/* Toggle switch */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 12px 0;
    gap: 12px;
}
.toggle-label {
    font-size: 14px;
    color: var(--text-muted);
    flex: 1;
}
.toggle-btn {
    position: relative;
    width: 48px;
    height: 28px;
    border: none;
    border-radius: 14px;
    background: rgba(255,255,255,0.15);
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.2s;
    -webkit-tap-highlight-color: transparent;
}
.toggle-btn[data-on="true"] {
    background: var(--success);
}
.toggle-knob {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: white;
    transition: transform 0.2s;
}
.toggle-btn[data-on="true"] .toggle-knob {
    transform: translateX(20px);
}

/* Confetti */
.confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
    overflow: hidden;
}
.confetti-piece {
    position: absolute;
    top: -10px;
    width: 8px;
    height: 14px;
    border-radius: 2px;
    animation: confetti-fall 2s ease-out forwards;
}
@keyframes confetti-fall {
    0% { transform: translateY(0) rotate(0deg); opacity: 1; }
    100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

/* Shake animation */
.shake {
    animation: shake 0.4s ease-in-out;
}
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-8px); }
    40% { transform: translateX(8px); }
    60% { transform: translateX(-5px); }
    80% { transform: translateX(5px); }
}

/* Photo gallery */
.photo-gallery {
    width: 100%;
    max-height: 300px;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin: 16px 0;
}
.photo-gallery .gallery-title {
    grid-column: 1 / -1;
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin: 0;
    text-align: center;
}
.gallery-item {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    aspect-ratio: 1;
}
.gallery-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.gallery-label {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0,0,0,0.7));
    color: #fff;
    font-size: 0.75rem;
    padding: 14px 6px 6px;
    text-align: center;
}

/* App footer */
.app-footer {
    padding: 24px 16px calc(16px + var(--safe-bottom));
    text-align: center;
}
.footer-links {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}
.footer-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.8rem;
    transition: color 0.2s;
}
.footer-link:hover { color: var(--accent); }
.footer-sep { color: var(--text-muted); font-size: 0.7rem; }
.footer-version {
    color: var(--text-muted);
    font-size: 0.7rem;
    opacity: 0.6;
}

/* Text button (secondary) */
.btn-text {
    background: none;
    border: none;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    padding: 8px 16px;
}
.btn-text:hover { color: var(--text); }

/* Game screens: pinned to viewport so items-list scrolls */
#screen-game,
#screen-multi-game {
    position: fixed;
    inset: 0;
    max-width: 480px;
    margin: 0 auto;
    min-height: 0;
    background: var(--bg);
    z-index: 5;
}
#screen-game.active,
#screen-multi-game.active {
    display: flex;
    flex-direction: column;
}
#screen-game .items-list,
#screen-multi-game .items-list {
    flex: 1 1 0px;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    touch-action: pan-y;
}

/* Lock body scroll during gameplay */
body.game-active {
    overflow: hidden;
    position: fixed;
    width: 100%;
}

/* Scrollbar */
::-webkit-scrollbar { width: 0; }
