/* ============================================================
   Definition Auction — TOEFL Vocabulary Game
   game.css
   All selectors are prefixed .vg- to avoid collisions.
   Mount element: #vocab-game-root (inside .vocab-game)
   ============================================================ */

/* ── CSS custom properties (scoped to the component) ─────── */
/*
   Forest theme palette
   ┌─────────────────────────────────────────────────────┐
   │ bg         #f2ede4   warm parchment                 │
   │ surface    #faf7f1   cream card                     │
   │ surface2   #ece6d8   slightly deeper parchment      │
   │ text       #2a3b28   dark forest green              │
   │ muted      #6b7c60   sage green                     │
   │ accent     #7a5c1e   golden bark (sunlight)         │
   │ accent2    #a07828   lighter warm gold              │
   │ green      #2d7a4a   forest green (correct)         │
   │ red        #a83c30   earthy red (wrong)             │
   │ amber      #a06818   harvest amber (missed)         │
   │ blue       #3d7068   deep teal (drop target)        │
   └─────────────────────────────────────────────────────┘
*/
.vocab-game {
    --vg-bg: #f2ede4;
    --vg-surface: #faf7f1;
    --vg-surface2: #ece6d8;
    --vg-border: rgba(42, 59, 40, 0.1);
    --vg-border2: rgba(42, 59, 40, 0.22);
    --vg-text: #2a3b28;
    --vg-muted: #6b7c60;
    --vg-accent: #7a5c1e;
    --vg-accent2: #a07828;
    --vg-green: #2d7a4a;
    --vg-green-bg: rgba(45, 122, 74, 0.1);
    --vg-red: #a83c30;
    --vg-red-bg: rgba(168, 60, 48, 0.1);
    --vg-amber: #a06818;
    --vg-amber-bg: rgba(160, 104, 24, 0.1);
    --vg-blue: #3d7068;
    --vg-blue-bg: rgba(61, 112, 104, 0.12);
    --vg-r: 10px;
    --vg-rlg: 16px;
    --vg-fd: "Playfair Display", Georgia, serif;
    --vg-fb: "DM Sans", system-ui, sans-serif;
    --vg-fm: "DM Mono", monospace;
    --vg-touch: 44px;
    --vg-slot-h: 50px;

    font-family: var(--vg-fb);
    color: var(--vg-text);
    -webkit-font-smoothing: antialiased;
}

.vg-giveup-btn {
    display: none;
}

@media (max-width: 600px) {
    .vg-giveup-btn {
        display: inline;
    }
}

/* ── Game chrome (top bar) ───────────────────────────────── */
.vg-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.1rem;
    flex-wrap: wrap;
}

.vg-topic {
    font-family: var(--vg-fm);
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--vg-muted);
    border: 1px solid var(--vg-border);
    border-radius: 4px;
    padding: 4px 8px;
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.vg-topic strong {
    color: var(--vg-accent);
    font-weight: 500;
}

.vg-stat {
    background: var(--vg-surface);
    border: 1px solid var(--vg-border);
    border-radius: var(--vg-r);
    padding: 5px 14px;
    text-align: center;
    min-width: 56px;
    flex-shrink: 0;
}

.vg-stat-num {
    font-size: 1.15rem;
    font-weight: 500;
    color: var(--vg-text);
    line-height: 1;
}

.vg-stat-lbl {
    font-size: 0.6rem;
    color: var(--vg-muted);
    margin-top: 2px;
    font-family: var(--vg-fm);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* ── Timer ───────────────────────────────────────────────── */
.vg-timer {
    position: relative;
    width: 52px;
    height: 52px;
    flex-shrink: 0;
}

.vg-timer svg {
    transform: rotate(-90deg);
}

.vg-timer-track {
    fill: none;
    stroke: var(--vg-border2);
    stroke-width: 3.5;
}

.vg-timer-arc {
    fill: none;
    stroke: var(--vg-accent);
    stroke-width: 3.5;
    stroke-linecap: round;
    transition:
        stroke-dashoffset 1s linear,
        stroke 0.4s;
}

.vg-timer-num {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--vg-fm);
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--vg-text);
    transition: color 0.4s;
}

/* ── Arena — desktop 2-column ────────────────────────────── */
.vg-arena {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}

.vg-col-head {
    font-family: var(--vg-fm);
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--vg-muted);
    margin-bottom: 0.5rem;
    padding-left: 2px;
}

.vg-word-slots,
.vg-def-pool {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

/* ── Word slot ───────────────────────────────────────────── */
.vg-word-slot {
    background: var(--vg-surface);
    border: 1px solid var(--vg-border);
    border-radius: var(--vg-r);
    padding: 10px 12px;
    min-height: var(--vg-touch);
    cursor: pointer;
    transition:
        border-color 0.15s,
        background 0.15s;
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
}

/* Left accent bar */
.vg-word-slot::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--vg-accent);
    opacity: 0;
    transition: opacity 0.2s;
    border-radius: 3px 0 0 3px;
}

.vg-word-slot:active:not(.locked) {
    background: var(--vg-surface2);
}

@media (hover: hover) {
    .vg-word-slot:hover:not(.locked) {
        border-color: var(--vg-border2);
        background: var(--vg-surface2);
    }
    .vg-word-slot:hover:not(.locked)::before {
        opacity: 0.5;
    }
}

/* States */
.vg-word-slot.drop-target {
    border-color: var(--vg-blue);
    background: var(--vg-blue-bg);
}
.vg-word-slot.drop-target::before {
    opacity: 1;
    background: var(--vg-blue);
}

.vg-word-slot.correct {
    border-color: var(--vg-green);
    background: var(--vg-green-bg);
    cursor: default;
    animation: vg-pop 0.22s ease;
}
.vg-word-slot.correct::before {
    opacity: 1;
    background: var(--vg-green);
}

.vg-word-slot.wrong {
    animation: vg-shake 0.35s ease;
    border-color: var(--vg-red);
    background: var(--vg-red-bg);
}

.vg-word-slot.missed {
    border-color: var(--vg-amber);
    background: var(--vg-amber-bg);
    cursor: default;
}
.vg-word-slot.missed::before {
    opacity: 1;
    background: var(--vg-amber);
}

.vg-word-slot.locked {
    cursor: default;
}

/* ── Audio button ────────────────────────────────────────── */
.vg-audio-btn {
    width: var(--vg-touch);
    height: var(--vg-touch);
    flex-shrink: 0;
    background: none;
    border: 1px solid var(--vg-border2);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--vg-muted);
    transition:
        border-color 0.15s,
        color 0.15s,
        background 0.15s,
        transform 0.1s;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.vg-audio-btn:active {
    transform: scale(0.86);
}

@media (hover: hover) {
    .vg-audio-btn:hover {
        border-color: var(--vg-accent);
        color: var(--vg-accent);
        background: rgba(201, 168, 76, 0.08);
    }
}

.vg-audio-btn svg {
    width: 20px;
    height: 20px;
    min-width: 20px;
    flex-shrink: 0;
    pointer-events: none;
}

.vg-audio-btn.no-audio {
    opacity: 0.22;
    cursor: default;
    pointer-events: none;
}
.vg-audio-btn.playing {
    border-color: var(--vg-accent);
    color: var(--vg-accent);
    background: rgba(201, 168, 76, 0.1);
}

/* ── Word text inside slot ───────────────────────────────── */
.vg-word-text {
    flex: 1;
    min-width: 0;
}

.vg-slot-word {
    font-family: var(--vg-fd);
    font-size: clamp(0.88rem, 2.5vw, 1rem);
    font-weight: 500;
    color: var(--vg-text);
    letter-spacing: -0.01em;
}

.vg-word-slot.correct .vg-slot-word {
    color: var(--vg-green);
}
.vg-word-slot.missed .vg-slot-word {
    color: var(--vg-amber);
}

.vg-slot-def {
    font-size: 0.7rem;
    color: var(--vg-muted);
    margin-top: 3px;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.vg-word-slot.correct .vg-slot-def {
    color: rgba(76, 175, 130, 0.65);
}
.vg-word-slot.missed .vg-slot-def {
    color: rgba(232, 160, 48, 0.65);
}

.vg-slot-icon {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 11px;
    opacity: 0;
    transition: opacity 0.2s;
}

.vg-word-slot.correct .vg-slot-icon {
    opacity: 1;
    background: var(--vg-green);
    color: #fff;
}
.vg-word-slot.missed .vg-slot-icon {
    opacity: 1;
    background: var(--vg-amber);
    color: #fff;
}

/* ── Definition chip ─────────────────────────────────────── */
.vg-def-chip {
    background: var(--vg-surface);
    border: 1px solid var(--vg-border);
    border-radius: var(--vg-r);
    padding: 11px 14px;
    font-size: 0.8rem;
    line-height: 1.55;
    color: var(--vg-muted);
    cursor: grab;
    transition:
        border-color 0.15s,
        background 0.15s,
        opacity 0.25s;
    min-height: var(--vg-touch);
    display: flex;
    align-items: center;
    position: relative;
    /* Required for custom touch drag — disables browser native scroll on chip */
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

@media (hover: hover) {
    .vg-def-chip:hover:not(.used) {
        border-color: var(--vg-border2);
        background: var(--vg-surface2);
        color: var(--vg-text);
        transform: translateX(-2px);
    }
}

.vg-def-chip.selected {
    border-color: var(--vg-accent);
    background: rgba(201, 168, 76, 0.08);
    color: var(--vg-accent2);
}

/* Arrow indicator when a chip is tap-selected */
.vg-def-chip.selected::after {
    content: "→";
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--vg-accent);
    font-size: 0.9rem;
}

.vg-def-chip.is-dragging {
    opacity: 0.3;
}

/* Collapse used chips with a smooth transition */
.vg-def-chip.used {
    opacity: 0;
    pointer-events: none;
    min-height: 0;
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    border-top-width: 0;
    border-bottom-width: 0;
    overflow: hidden;
    transition: all 0.3s;
}

/* ── Touch drag ghost ────────────────────────────────────── */
#touch-ghost {
    position: fixed;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.9;
    border: 1.5px solid var(--vg-accent);
    border-radius: var(--vg-r);
    background: var(--vg-surface2);
    color: var(--vg-accent2);
    padding: 11px 14px;
    font-size: 0.8rem;
    line-height: 1.55;
    font-family: var(--vg-fb);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.55);
    transform: scale(1.04) rotate(-1deg);
    max-width: 260px;
    transition: none;
}

/* ── Bottom bar ──────────────────────────────────────────── */
.vg-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-top: 0.75rem;
    flex-wrap: wrap;
}

.vg-hint {
    font-size: 0.72rem;
    color: var(--vg-muted);
    font-family: var(--vg-fm);
    flex: 1;
    min-width: 100px;
}

.vg-hint strong {
    color: var(--vg-accent);
    font-weight: 500;
}

.vg-btn-row {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

/* ── Buttons ─────────────────────────────────────────────── */
.vocab-game button {
    font-family: var(--vg-fb);
    font-size: 0.8rem;
    font-weight: 500;
    border-radius: var(--vg-r);
    cursor: pointer;
    border: 1px solid var(--vg-border2);
    background: var(--vg-surface);
    color: var(--vg-muted);
    padding: 8px 16px;
    transition: all 0.15s;
    min-height: var(--vg-touch);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.vocab-game button:active {
    transform: scale(0.96);
}

@media (hover: hover) {
    .vocab-game button:hover {
        background: var(--vg-surface2);
        color: var(--vg-text);
    }
}

.vocab-game button.primary {
    background: var(--vg-accent);
    color: #faf7f1;
    border-color: var(--vg-accent);
}

@media (hover: hover) {
    .vocab-game button.primary:hover {
        background: var(--vg-accent2);
        border-color: var(--vg-accent2);
    }
}

/* ── Results overlay ─────────────────────────────────────── */
.vg-results {
    background: var(--vg-surface);
    border: 1px solid var(--vg-border);
    border-radius: var(--vg-rlg);
    padding: 1.75rem 1.5rem;
    margin-bottom: 1.25rem;
    text-align: center;
}

.vg-results-score {
    font-family: var(--vg-fd);
    font-size: clamp(1.5rem, 10vw, 2rem);
    font-weight: 500;
    color: var(--vg-text);
    line-height: 1;
    letter-spacing: -0.03em;
}

.vg-results-label {
    font-size: 1rem;
    color: var(--vg-muted);
    margin: 0.5rem 0 1.2rem;
    font-family: var(--vg-fm);
}

.vg-results-label strong {
    color: var(--vg-accent);
    font-weight: 500;
}

.vg-total-score {
    font-size: 1.8rem;
    color: var(--vg-muted);
    color: red;
    font-family: var(--vg-fm);
    margin-bottom: 0.9rem;
}
.vg-total-score strong {
    color: var(--vg-text);
    font-weight: 500;
}

.vg-streak-dots {
    display: flex;
    gap: 6px;
    justify-content: center;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.vg-streak-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--vg-border2);
}

.vg-streak-dot.correct {
    background: var(--vg-green);
}
.vg-streak-dot.missed {
    background: var(--vg-amber);
}

.vg-results-btns {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
}

/* Review round CTA — shown after last regular round if there are misses.
   Slightly larger than the standard primary button to signal importance. */
/* Debug/test button — dashed border signals it is not part of normal gameplay */
.vg-autosolve-btn {
    border-style: dashed !important;
    opacity: 0.75;
    font-size: 0.72rem !important;
    letter-spacing: 0.03em;
}
.vg-autosolve-btn:hover {
    opacity: 1;
}

.vg-review-cta {
    font-size: 0.9rem !important;
    padding: 10px 22px !important;
    letter-spacing: 0.01em;
}

/* Pulse animation — applied to the primary forward-action button in results.
   Draws the eye without being distracting. Stops on hover/focus. */
.vg-pulse {
    animation: vg-pulse 2s ease-in-out 0.6s infinite;
}

.vg-pulse:hover,
.vg-pulse:focus {
    animation: none;
}

/* ── Review list (post-round) ────────────────────────────── */
.vg-review-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 1rem;
}

.vg-review-item {
    background: var(--vg-surface);
    border: 1px solid var(--vg-border);
    border-radius: var(--vg-r);
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.vg-review-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.vg-review-dot.correct {
    background: var(--vg-green);
}
.vg-review-dot.missed {
    background: var(--vg-amber);
}

.vg-review-word {
    font-family: var(--vg-fd);
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--vg-text);
    min-width: 90px;
    flex-shrink: 0;
}

.vg-review-def {
    font-size: 0.74rem;
    color: var(--vg-muted);
    flex: 1;
    line-height: 1.45;
    min-width: 100px;
}

/* ── Error screen ────────────────────────────────────────── */
.vocab-game .error-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 50vh;
    gap: 1rem;
    text-align: center;
}

/* ══════════════════════════════════════════════════════════
   MOBILE  (≤ 600px)
   Page locks to 100dvh. Only the def pool scrolls.
   Drag events no longer compete with page scroll.
══════════════════════════════════════════════════════════ */
@media (max-width: 600px) {
    /* Full-screen overlay — applied by JS (initVocabGame) on mobile.
     Lifts the game above the page instantly via position:fixed.
     No html/body scroll locking = no reflow, no position jump. */
    .vocab-game.vg-fullscreen {
        position: fixed;
        inset: 0; /* top:0 left:0 right:0 bottom:0 */
        z-index: 1000; /* above site header/nav/footer */
        background: var(--vg-bg, #f2ede4);
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    /* Mount root fills remaining height */
    #vocab-game-root {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    /* Chrome becomes a compact top bar */
    .vg-header {
        flex-shrink: 0;
        margin: 0;
        padding: 0.6rem 0.9rem 0.5rem;
        border-bottom: 1px solid var(--vg-border);
        gap: 0.5rem;
        flex-wrap: nowrap;
    }

    .vg-topic {
        font-size: 0.6rem;
        padding: 3px 6px;
    }
    .vg-stat {
        padding: 3px 10px;
        min-width: 48px;
    }
    .vg-stat-num {
        font-size: 1rem;
    }
    .vg-stat-lbl {
        font-size: 0.55rem;
    }
    .vg-timer {
        width: 44px;
        height: 44px;
    }
    .vg-timer svg {
        width: 44px;
        height: 44px;
    }

    /* Game body wrapper (injected by JS on mobile) */
    .vg-game-body {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        padding: 0.6rem 0.9rem 0;
    }

    /* Arena: flex column, fixed words / scrollable defs */
    .vg-arena {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
        gap: 0.6rem;
        overflow: hidden;
        grid-template-columns: unset;
        margin-bottom: 0;
    }

    /* Words column: fixed, never scrolls */
    .vg-col-words {
        flex-shrink: 0;
        order: 1;
    }
    .vg-col-head {
        font-size: 0.6rem;
        margin-bottom: 0.4rem;
    }
    .vg-word-slots {
        gap: 5px;
    }

    /* Fixed-height slots so layout never shifts */
    .vg-word-slot {
        height: var(--vg-slot-h);
        min-height: var(--vg-slot-h);
        max-height: var(--vg-slot-h);
        padding: 0 10px;
        overflow: hidden;
    }

    /* Audio btn: visually 36px, touch target still 44px via negative margin */
    .vg-audio-btn {
        width: 36px;
        height: 36px;
        margin: -4px;
        padding: 4px;
        flex-shrink: 0;
    }

    .vg-slot-word {
        font-size: 0.88rem;
    }
    .vg-slot-def {
        font-size: 0.65rem;
        margin-top: 1px;
    }

    /* Defs column: fills remaining height, scrolls independently */
    .vg-col-defs {
        flex: 1;
        min-height: 0;
        order: 2;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        position: relative;
    }

    /* Fade at bottom signals scrollability */
    .vg-col-defs::after {
        content: "";
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        height: 32px;
        background: linear-gradient(transparent, var(--vg-bg, #f2ede4));
        pointer-events: none;
        z-index: 1;
    }

    .vg-def-pool {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        gap: 5px;
        padding-bottom: 36px; /* clears fade + safe area */
        scrollbar-width: none;
    }

    .vg-def-pool::-webkit-scrollbar {
        display: none;
    }

    .vg-def-chip {
        font-size: 0.78rem;
        padding: 10px 12px;
        min-height: 44px;
    }

    /* Bottom bar: pinned, respects iPhone home indicator */
    .vg-bar {
        flex-shrink: 0;
        margin: 0;
        padding: 0.5rem 0.9rem;
        padding-bottom: calc(0.5rem + env(safe-area-inset-bottom, 0px));
        border-top: 1px solid var(--vg-border);
    }

    .vg-hint {
        font-size: 0.66rem;
    }
    .vocab-game button {
        padding: 7px 12px;
        font-size: 0.75rem;
    }

    /* Results: scrollable since no drag needed there */
    .vg-results-wrap {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 0.75rem 0.9rem;
        padding-bottom: env(safe-area-inset-bottom, 1rem);
    }
}

/* Very small phones (≤ 375px) */
@media (max-width: 375px) {
    .vocab-game {
        --vg-slot-h: 46px;
    }
    .vg-slot-word {
        font-size: 0.82rem;
    }
    .vg-def-chip {
        font-size: 0.74rem;
        padding: 9px 11px;
    }
}

/* ── Animations ──────────────────────────────────────────── */
@keyframes vg-pulse {
    0%,
    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(122, 92, 30, 0);
    }
    50% {
        transform: scale(1.035);
        box-shadow: 0 0 0 6px rgba(122, 92, 30, 0);
    }
    40% {
        box-shadow: 0 0 0 6px rgba(122, 92, 30, 0.25);
    }
}

@keyframes vg-shake {
    0%,
    100% {
        transform: translateX(0);
    }
    25% {
        transform: translateX(-6px);
    }
    75% {
        transform: translateX(6px);
    }
}

@keyframes vg-pop {
    0%,
    100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.02);
    }
}
