/* ================================================================
   Adventure Quest Game — Base Styles
   ================================================================ */

.aqg-game-wrapper {
    --aqg-bg: #0b1220;
    --aqg-card: #0f172a;
    --aqg-text: #e2e8f0;
    --aqg-muted: #94a3b8;
    --aqg-accent: #38bdf8;
    --aqg-good: #22c55e;
    --aqg-bad: #ef4444;
    --aqg-warn: #fbbf24;
    --aqg-radius: 16px;
    --aqg-shadow: 0 12px 40px rgba(0,0,0,.35);

    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Ubuntu, 'Helvetica Neue', Arial, sans-serif;
    color: var(--aqg-text);
    position: relative;
    width: 100%;
    min-height: 600px;
    overflow: hidden;
    line-height: 1.5;
    font-size: 14px;
    box-sizing: border-box;
}
.aqg-game-wrapper *, .aqg-game-wrapper *::before, .aqg-game-wrapper *::after {
    box-sizing: border-box;
}

/* ================================================================
   INTRO SCREEN
   ================================================================ */
.aqg-intro {
    position: relative;
    min-height: 600px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--aqg-bg);
    overflow: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.aqg-intro-bg {
    position: absolute;
    inset: 0;
    opacity: .08;
    background-image:
        linear-gradient(to right, var(--aqg-accent) 1px, transparent 1px),
        linear-gradient(to bottom, var(--aqg-accent) 1px, transparent 1px);
    background-size: 40px 40px;
}

.aqg-intro-bg::before,
.aqg-intro-bg::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: .25;
    animation: aqg-pulse 4s ease-in-out infinite;
}
.aqg-intro-bg::before {
    top: 60px; left: 30px;
    width: 280px; height: 280px;
    background: var(--aqg-accent);
}
.aqg-intro-bg::after {
    bottom: 60px; right: 30px;
    width: 360px; height: 360px;
    background: var(--aqg-accent2, var(--aqg-accent));
    animation-delay: 1.5s;
}

@keyframes aqg-pulse {
    0%, 100% { opacity: .2; transform: scale(1); }
    50% { opacity: .3; transform: scale(1.08); }
}

.aqg-intro-content {
    position: relative;
    z-index: 2;
    text-align: center;
    padding: 40px 24px;
    max-width: 480px;
    width: 100%;
    animation: aqg-fadeUp .8s ease forwards;
}

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

.aqg-intro-icon {
    width: 100px;
    height: 100px;
    margin: 0 auto 24px;
    color: var(--aqg-accent);
    position: relative;
}
.aqg-intro-icon svg {
    width: 100%;
    height: 100%;
}
.aqg-intro-emoji {
    font-size: 72px;
    line-height: 100px;
    text-align: center;
}
.aqg-intro-icon::before {
    content: '';
    position: absolute;
    inset: -20px;
    border-radius: 50%;
    background: var(--aqg-accent);
    filter: blur(50px);
    opacity: .3;
    animation: aqg-pulse 3s ease-in-out infinite;
}

.aqg-title {
    font-size: clamp(2rem, 7vw, 3.2rem);
    font-weight: 900;
    line-height: 1.1;
    margin: 0 0 8px;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--aqg-accent), var(--aqg-accent2, #fff));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.aqg-tagline {
    color: var(--aqg-muted);
    font-size: clamp(1rem, 3vw, 1.15rem);
    font-weight: 500;
    margin: 0 0 24px;
}

.aqg-story-box {
    background: rgba(255,255,255,.04);
    border: 1px solid rgba(255,255,255,.08);
    border-radius: var(--aqg-radius);
    padding: 16px 20px;
    margin-bottom: 24px;
    text-align: left;
    font-size: .9rem;
    line-height: 1.6;
    color: var(--aqg-text);
    max-height: 200px;
    overflow-y: auto;
}

.aqg-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 32px;
    animation: aqg-fadeScale .7s ease forwards .5s;
    opacity: 0;
}
@keyframes aqg-fadeScale {
    to { opacity: 1; transform: scale(1); }
    from { opacity: 0; transform: scale(.95); }
}

.aqg-stat {
    background: rgba(255,255,255,.04);
    border: 1px solid rgba(255,255,255,.08);
    border-radius: var(--aqg-radius);
    padding: 14px 10px;
    text-align: center;
    transition: transform .2s, border-color .2s;
}
.aqg-stat:hover {
    border-color: rgba(255,255,255,.15);
    transform: scale(1.04);
}
.aqg-stat-val {
    display: block;
    font-size: 1.6rem;
    font-weight: 900;
    color: #fff;
}
.aqg-stat-lbl {
    font-size: .7rem;
    color: var(--aqg-muted);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
}

.aqg-btn-start {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: linear-gradient(135deg, var(--aqg-accent), var(--aqg-accent2, var(--aqg-accent)));
    color: #fff;
    font-weight: 900;
    font-size: 1.1rem;
    padding: 18px 44px;
    border: none;
    border-radius: var(--aqg-radius);
    cursor: pointer;
    box-shadow: 0 16px 48px rgba(0,0,0,.4);
    transition: transform .15s, box-shadow .15s;
    position: relative;
    overflow: hidden;
}
.aqg-btn-start:hover {
    transform: scale(1.05);
    box-shadow: 0 20px 56px rgba(0,0,0,.5);
}
.aqg-btn-start:active { transform: scale(1); }
.aqg-btn-start::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,.2), transparent);
    transform: translateX(-100%);
    animation: aqg-shimmer 2.5s ease-in-out infinite;
}
@keyframes aqg-shimmer {
    0%   { transform: translateX(-100%); }
    50%  { transform: translateX(100%); }
    100% { transform: translateX(100%); }
}

.aqg-gps-hint {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
    margin-top: 24px;
    color: var(--aqg-muted);
    font-size: .8rem;
}
.aqg-gps-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--aqg-good);
    box-shadow: 0 0 10px rgba(34,197,94,.5);
    animation: aqg-pulse 2s ease-in-out infinite;
}

/* ================================================================
   GAME SCREEN
   ================================================================ */
.aqg-app {
    position: relative;
    width: 100%;
    height: 600px;
    display: flex;
    flex-direction: column;
    background: var(--aqg-bg);
    overflow: hidden;
}

.aqg-header {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
    background: linear-gradient(180deg, rgba(15,23,42,.95), rgba(15,23,42,.8));
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255,255,255,.08);
    z-index: 30;
}
.aqg-header-title {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
    flex: 1 1 160px;
    min-width: 140px;
}
.aqg-header-title strong { font-size: .95rem; }
.aqg-header-title small { font-size: .7rem; color: var(--aqg-muted); font-weight: 600; }

.aqg-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(0,0,0,.35);
    border: 1px solid rgba(255,255,255,.1);
    font-size: .8rem;
    white-space: nowrap;
    user-select: none;
}
.aqg-pill b { font-variant-numeric: tabular-nums; }
.aqg-pill-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--aqg-accent);
    box-shadow: 0 0 0 3px rgba(255,255,255,.06);
}
.aqg-pill.aqg-active .aqg-pill-dot { background: var(--aqg-good); }

.aqg-header-btns {
    display: inline-flex;
    gap: 4px;
    padding: 3px;
    border-radius: 16px;
    background: rgba(0,0,0,.25);
    border: none;
}
.aqg-icon-btn {
    appearance: none;
    width: 36px; height: 36px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    background: rgba(255,255,255,.08);
    border: none;
    color: var(--aqg-text);
    font-size: 1.05rem;
    transition: transform .12s, background .15s, box-shadow .15s;
    box-shadow: none;
}
.aqg-icon-btn:hover { background: rgba(255,255,255,.15); }
.aqg-icon-btn:active { transform: scale(.93); }
.aqg-icon-btn.aqg-danger { background: rgba(239,68,68,.15); color: #ef4444; }

.aqg-main {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.aqg-map {
    width: 100%;
    height: 100%;
}

/* Status bar */
.aqg-status {
    position: absolute;
    left: 10px; right: 10px; bottom: 10px;
    background: rgba(15,23,42,.92);
    border: 1px solid rgba(255,255,255,.1);
    border-radius: 14px;
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: var(--aqg-shadow);
    z-index: 25;
    backdrop-filter: blur(10px);
    transition: border-color .3s;
}
.aqg-status-msg { flex: 1; font-size: .82rem; }
.aqg-status-acc { font-size: .75rem; color: var(--aqg-muted); white-space: nowrap; }
.aqg-status.aqg-error {
    border-color: var(--aqg-bad);
    box-shadow: 0 0 0 2px rgba(239,68,68,.2);
}

/* Question panel */
.aqg-panel {
    position: absolute;
    left: 0; right: 0; bottom: -100%;
    background: rgba(15,23,42,.97);
    border-top: 1px solid rgba(255,255,255,.1);
    border-radius: 18px 18px 0 0;
    padding: 14px 14px 18px;
    box-shadow: var(--aqg-shadow);
    transition: bottom .25s ease;
    z-index: 100;
    max-height: 78%;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}
.aqg-panel.aqg-open { bottom: 0; }

.aqg-panel-top {
    display: flex;
    align-items: center;
    gap: 8px;
}

.aqg-badge {
    display: inline-flex;
    align-items: center;
    padding: 5px 10px;
    border-radius: 999px;
    background: rgba(0,0,0,.4);
    border: 1px solid rgba(255,255,255,.1);
    font-size: .75rem;
    font-weight: 700;
    white-space: nowrap;
}

.aqg-timer {
    margin-left: auto;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    padding: 5px 10px;
    border-radius: 999px;
    border: 1px solid rgba(255,255,255,.12);
    background: rgba(0,0,0,.3);
    font-size: .9rem;
}
.aqg-timer.aqg-urgent {
    border-color: rgba(239,68,68,.5);
    color: #fecaca;
    animation: aqg-pulse 1s ease-in-out infinite;
}

.aqg-hint-box {
    margin: 10px 0;
    padding: 10px 12px;
    border-radius: 12px;
    background: rgba(251,191,36,.08);
    border: 1px solid rgba(251,191,36,.25);
    font-size: .82rem;
    color: var(--aqg-warn);
}

.aqg-q-title {
    font-size: 1.1rem;
    margin: 10px 0 4px;
    font-weight: 700;
}
.aqg-q-text {
    font-size: .9rem;
    margin: 0 0 12px;
    line-height: 1.4;
}

.aqg-opts { display: grid; gap: 8px; }

.aqg-opt {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 10px 12px;
    border-radius: 14px;
    border: 1px solid rgba(255,255,255,.1);
    background: rgba(0,0,0,.2);
    cursor: pointer;
    transition: background .15s, border-color .15s, transform .08s;
    user-select: none;
    font-size: .9rem;
}
.aqg-opt:hover { background: rgba(0,0,0,.3); }
.aqg-opt:active { transform: scale(.99); }
.aqg-opt input { margin-top: 3px; }
.aqg-opt.aqg-selected {
    border-color: var(--aqg-accent);
    background: rgba(56,189,248,.06);
}

.aqg-result {
    margin-top: 10px;
    padding: 10px 12px;
    border-radius: 14px;
    border: 1px solid rgba(255,255,255,.1);
    background: rgba(0,0,0,.2);
    font-size: .82rem;
    line-height: 1.4;
    display: none;
}
.aqg-result.aqg-show { display: block; }
.aqg-result.aqg-good { border-color: rgba(34,197,94,.4); background: rgba(34,197,94,.06); }
.aqg-result.aqg-bad  { border-color: rgba(239,68,68,.4); background: rgba(239,68,68,.06); }
.aqg-fact { border-color: rgba(255,255,255,.15); background: rgba(255,255,255,.03); }

.aqg-panel-actions {
    display: flex;
    gap: 10px;
    margin-top: 12px;
}

.aqg-btn {
    flex: 1;
    appearance: none;
    border: none;
    padding: 10px 14px;
    border-radius: 12px;
    background: var(--aqg-accent);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
    font-size: .9rem;
    transition: transform .08s, opacity .15s;
}
.aqg-btn:hover { opacity: .9; }
.aqg-btn:active { transform: scale(.98); }
.aqg-btn:disabled { opacity: .4; cursor: not-allowed; }
.aqg-btn-sec {
    background: rgba(255,255,255,.08);
    border: 1px solid rgba(255,255,255,.12);
    color: var(--aqg-text);
}

/* Leaderboard */
.aqg-lb {
    position: absolute;
    top: 10px; right: 10px;
    width: min(380px, calc(100% - 20px));
    max-height: calc(100% - 20px);
    overflow-y: auto;
    background: rgba(15,23,42,.94);
    border: 1px solid rgba(255,255,255,.1);
    border-radius: var(--aqg-radius);
    box-shadow: var(--aqg-shadow);
    z-index: 25;
    backdrop-filter: blur(10px);
}
.aqg-lb-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    border-bottom: 1px solid rgba(255,255,255,.06);
}
.aqg-lb-header strong { font-size: .95rem; }
.aqg-lb-header small { display: block; font-size: .7rem; color: var(--aqg-muted); }
.aqg-lb-header .aqg-btn-sec { flex: 0; white-space: nowrap; }
.aqg-lb-content { padding: 12px; }

.aqg-lb-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .78rem;
}
.aqg-lb-table th, .aqg-lb-table td {
    padding: 7px 5px;
    border-bottom: 1px solid rgba(255,255,255,.06);
    text-align: left;
}
.aqg-lb-table th { color: var(--aqg-muted); font-weight: 700; }
.aqg-lb-table tr:last-child td { border-bottom: none; }

.aqg-lb-save {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}
.aqg-lb-save input {
    flex: 1;
    padding: 9px 12px;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,.12);
    background: rgba(0,0,0,.25);
    color: var(--aqg-text);
    outline: none;
    font-size: .85rem;
}
.aqg-lb-save .aqg-btn { flex: 0; white-space: nowrap; }

/* Leaflet label */
.aqg-label {
    background: rgba(15,23,42,.85);
    border: 1px solid rgba(255,255,255,.15);
    color: var(--aqg-text);
    padding: 5px 8px;
    border-radius: 8px;
    font-weight: 700;
    font-size: .7rem;
    line-height: 1.2;
    white-space: nowrap;
    pointer-events: none;
    box-shadow: 0 6px 20px rgba(0,0,0,.3);
}
.aqg-label .aqg-label-pts {
    color: var(--aqg-muted);
    font-weight: 600;
    font-size: .65rem;
}

/* === Task Type UIs === */
.aqg-text-input-wrap { margin: 12px 0; }
.aqg-text-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid rgba(148,163,184,.3);
    border-radius: 10px;
    background: rgba(15,23,42,.6);
    color: #e2e8f0;
    font-size: 1rem;
    outline: none;
    transition: border-color .2s;
}
.aqg-text-input:focus { border-color: #a855f7; }

/* QR Scanner */
.aqg-qr-area { position: relative; text-align: center; }
.aqg-qr-video { width: 100%; max-width: 300px; border-radius: 12px; background: #000; }
.aqg-qr-overlay { position: relative; display: flex; align-items: center; justify-content: center; margin: 12px 0; }
.aqg-qr-frame { width: 200px; height: 200px; border: 3px solid #a855f7; border-radius: 12px; }

/* Photo */
.aqg-photo-area { text-align: center; }
.aqg-photo-file-input { display: none; }
.aqg-photo-btn { display: inline-block; cursor: pointer; margin: 12px 0; }
.aqg-photo-preview { margin: 12px auto; max-width: 280px; }
.aqg-photo-img { width: 100%; border-radius: 12px; border: 2px solid rgba(148,163,184,.2); }
.aqg-photo-desc { font-size: .85rem; color: #94a3b8; margin-bottom: 8px; font-style: italic; }

/* Riddle hints */
.aqg-riddle-hints { margin: 12px 0; }
.aqg-riddle-hint {
    padding: 10px 14px;
    background: rgba(99,102,241,.1);
    border-left: 3px solid #6366f1;
    border-radius: 0 8px 8px 0;
    margin-bottom: 8px;
    font-size: .9rem;
    animation: aqg-hint-reveal .3s ease-out;
}
@keyframes aqg-hint-reveal {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}
.aqg-btn-hint { margin-bottom: 12px; font-size: .85rem; }

/* Lock overlay */
.aqg-lock-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15,23,42,.92);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10;
    border-radius: inherit;
    backdrop-filter: blur(4px);
}
.aqg-lock-icon { font-size: 3rem; margin-bottom: 12px; }
.aqg-lock-text { font-size: 1.1rem; font-weight: 600; color: #e2e8f0; margin-bottom: 8px; }
.aqg-lock-prereqs { font-size: .85rem; color: #94a3b8; text-align: center; line-height: 1.5; }

/* Kids theme overrides for new elements */
.aqg-theme-kids .aqg-text-input {
    background: rgba(255,251,235,.6);
    color: #1c1917;
    border-color: rgba(249,115,22,.2);
}
.aqg-theme-kids .aqg-text-input:focus { border-color: #f97316; }
.aqg-theme-kids .aqg-riddle-hint {
    background: rgba(249,115,22,.1);
    border-left-color: #f97316;
}
.aqg-theme-kids .aqg-lock-overlay {
    background: rgba(255,251,235,.95);
}
.aqg-theme-kids .aqg-lock-text { color: #1c1917; }

/* Story blocks */
.aqg-story-content { padding: 8px 0; }
.aqg-story-text-content {
    font-size: 1rem;
    line-height: 1.7;
    color: #e2e8f0;
    padding: 16px;
    background: rgba(99,102,241,.08);
    border-left: 3px solid #6366f1;
    border-radius: 0 10px 10px 0;
    margin: 12px 0;
    white-space: pre-line;
}
.aqg-theme-kids .aqg-story-text-content {
    color: #1c1917;
    background: rgba(249,115,22,.08);
    border-left-color: #f97316;
}

/* Responsive */
@media (max-width: 480px) {
    .aqg-header { gap: 6px; }
    .aqg-pill { padding: 5px 8px; font-size: .72rem; }
    .aqg-icon-btn { width: 34px; height: 34px; font-size: 1rem; }
}

/* === Fullscreen mode === */
.aqg-game-wrapper[data-fullscreen="true"],
.aqg-game-wrapper:fullscreen,
.aqg-game-wrapper:-webkit-full-screen {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 999999 !important;
    margin: 0 !important;
    padding: 0 !important;
    border-radius: 0 !important;
    max-width: none !important;
    max-height: none !important;
}

.aqg-game-wrapper[data-fullscreen="true"] .aqg-app,
.aqg-game-wrapper:fullscreen .aqg-app,
.aqg-game-wrapper:-webkit-full-screen .aqg-app {
    height: 100vh !important;
    max-height: 100vh !important;
}

.aqg-game-wrapper[data-fullscreen="true"] .aqg-map,
.aqg-game-wrapper:fullscreen .aqg-map,
.aqg-game-wrapper:-webkit-full-screen .aqg-map {
    height: 100% !important;
    flex: 1 !important;
}

/* Mobile-specific: auto-enter fullscreen feel */
@media (max-width: 768px) {
    .aqg-game-wrapper {
        min-height: auto;
    }

    .aqg-game-wrapper .aqg-intro {
        min-height: 100vh;
        min-height: 100dvh;
        padding-bottom: 20px;
    }

    .aqg-game-wrapper .aqg-app {
        height: 100vh;
        height: 100dvh;
        min-height: 0;
    }

    .aqg-game-wrapper .aqg-map {
        min-height: 0;
        flex: 1;
    }

    /* Larger touch targets on mobile */
    .aqg-icon-btn {
        min-width: 44px;
        min-height: 44px;
        font-size: 1.2rem;
    }

    .aqg-btn, .aqg-btn-start {
        min-height: 48px;
        font-size: 1rem;
    }

    .aqg-header {
        flex-wrap: wrap;
        gap: 4px;
        flex-shrink: 0;
    }

    .aqg-header-title {
        flex: 1 1 100%;
    }

    /* Hide pills on very small screens to save space */
    .aqg-pill {
        padding: 4px 8px;
        font-size: .7rem;
    }

    .aqg-panel {
        max-height: 65vh;
        max-height: 65dvh;
        overflow-y: auto;
    }

    .aqg-story-box {
        max-height: 35vh;
    }

    .aqg-story-text-content {
        max-height: 40vh;
        overflow-y: auto;
    }
}

/* PWA standalone mode detection */
@media (display-mode: standalone), (display-mode: fullscreen) {
    .aqg-game-wrapper .aqg-app {
        height: 100vh;
        height: 100dvh;
    }
}
