/* ==========================================================================
   Gravity Word Match Game — Styles (v1.1)
   All classes namespaced with .gwg- to avoid WordPress theme conflicts.
   ========================================================================== */ 

#gwg-container {
    position: relative;
    width: 100%;
    max-width: 1400px;
    /* Screen-based sizing: fills most of the viewport, with sane caps */
    height: 88vh;
    min-height: 500px;
    max-height: 950px;
    margin: 0 auto;
    overflow: hidden;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    contain: layout style;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
    background: linear-gradient(180deg, #1e3a8a 0%, #3b82f6 100%);
    transition: background 1.2s ease;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

#gwg-container * {
    box-sizing: border-box;
}

#gwg-container.gwg-level-1 {
    background: linear-gradient(180deg, #0f2847 0%, #2563eb 50%, #60a5fa 100%);
}
#gwg-container.gwg-level-2 {
    background: linear-gradient(180deg, #4a1a1a 0%, #dc2626 50%, #fb923c 100%);
}
#gwg-container.gwg-level-3 {
    background: linear-gradient(180deg, #1a0033 0%, #7c3aed 50%, #ec4899 100%);
}
#gwg-container.gwg-level-4 {
    background: linear-gradient(180deg, #042f2e 0%, #0d9488 50%, #5eead4 100%);
}
#gwg-container.gwg-level-5 {
    background: linear-gradient(180deg, #422006 0%, #ca8a04 50%, #fde047 100%);
}

/* Canvas layer */
#gwg-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    /* Yellow reticle cursor (matches the warning-glow accent), with the
       built-in crosshair as fallback if the browser refuses the data URL. */
    cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32"><circle cx="16" cy="16" r="11" fill="none" stroke="%23fde047" stroke-width="2.5"/><circle cx="16" cy="16" r="2" fill="%23fde047"/><line x1="16" y1="2" x2="16" y2="9" stroke="%23fde047" stroke-width="2.5"/><line x1="16" y1="23" x2="16" y2="30" stroke="%23fde047" stroke-width="2.5"/><line x1="2" y1="16" x2="9" y2="16" stroke="%23fde047" stroke-width="2.5"/><line x1="23" y1="16" x2="30" y2="16" stroke="%23fde047" stroke-width="2.5"/></svg>') 16 16, crosshair;
}

/* ============ HUD ============ */

#gwg-hud {
    position: absolute;
    inset: 0;
    z-index: 2;
    pointer-events: none;
}

.gwg-hud-top {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    pointer-events: none;
}

.gwg-hud-stat {
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 10px;
    padding: 8px 14px;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.4px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    pointer-events: auto;
}

.gwg-hud-stat-label {
    font-size: 10px;
    opacity: 0.75;
    text-transform: uppercase;
    margin-bottom: 2px;
    letter-spacing: 0.8px;
}

.gwg-hud-stat-value {
    font-size: 16px;
    font-weight: 700;
}

.gwg-hud-stat-correct { color: #4ade80; }
.gwg-hud-stat-wrong { color: #f87171; }

/* Prompt word display — top-center; shows English or Chinese based on variation */
.gwg-prompt-word,
.gwg-english-word {
    position: absolute;
    top: 78px;
    left: 50%;
    transform: translateX(-50%);
    color: #fff;
    font-size: clamp(22px, 3.2vw, 40px);
    font-weight: 800;
    letter-spacing: 0.8px;
    text-shadow: 0 0 24px rgba(255, 255, 255, 0.5), 0 3px 14px rgba(0, 0, 0, 0.5);
    padding: 8px 28px;
    background: rgba(0, 0, 0, 0.28);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border-radius: 14px;
    border: 1.5px solid rgba(255, 255, 255, 0.2);
    pointer-events: none;
    white-space: nowrap;
    animation: gwg-glow 2.5s ease-in-out infinite;
}

@keyframes gwg-glow {
    0%, 100% { box-shadow: 0 0 24px rgba(255, 255, 255, 0.2), 0 6px 24px rgba(0, 0, 0, 0.35); }
    50% { box-shadow: 0 0 40px rgba(255, 255, 255, 0.45), 0 6px 24px rgba(0, 0, 0, 0.35); }
}

/* Combo counter */
.gwg-combo {
    position: absolute;
    top: 50%;
    right: 30px;
    transform: translateY(-50%) scale(0);
    color: #fbbf24;
    font-size: clamp(24px, 3vw, 40px);
    font-weight: 900;
    text-shadow: 0 0 20px rgba(251, 191, 36, 0.8), 0 0 40px rgba(251, 191, 36, 0.4);
    pointer-events: none;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    letter-spacing: 2px;
}

.gwg-combo.gwg-active {
    transform: translateY(-50%) scale(1);
}

.gwg-combo-x {
    font-size: 0.7em;
    opacity: 0.8;
}

/* Progress bar */
.gwg-progress {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    width: 70%;
    max-width: 400px;
    height: 8px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    /* Allow the marker to extend above/below the bar without being clipped. */
    overflow: visible;
    pointer-events: none;
}

.gwg-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #4ade80 0%, #22d3ee 100%);
    border-radius: 4px;
    width: 0%;
    transition: width 0.4s ease;
    box-shadow: 0 0 10px rgba(74, 222, 128, 0.5);
}

/* Square marker rides the leading edge of the progress fill, showing the
   number of completed words in this level. */
.gwg-progress-marker {
    position: absolute;
    top: 50%;
    left: 0%;
    transform: translate(-50%, -50%);
    width: 28px;
    height: 28px;
    transition: left 0.4s ease;
    pointer-events: none;
    z-index: 5;
}

.gwg-marker-svg {
    width: 100%;
    height: 100%;
    display: block;
    filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.5));
}

/* Pause button */
.gwg-pause-btn {
    position: absolute;
    bottom: 16px;
    right: 16px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.2s;
}
.gwg-pause-btn:hover { background: rgba(0, 0, 0, 0.55); transform: scale(1.08); }
.gwg-pause-btn:active { transform: scale(0.94); }

/* ============ Flash overlays ============ */

.gwg-flash {
    position: absolute;
    inset: 0;
    z-index: 3;
    pointer-events: none;
    opacity: 0;
    mix-blend-mode: overlay;
}
.gwg-flash-correct { background: radial-gradient(ellipse at center, rgba(74, 222, 128, 0.6) 0%, transparent 70%); }
.gwg-flash-wrong   { background: radial-gradient(ellipse at center, rgba(239, 68, 68, 0.6) 0%, transparent 70%); }

/* ============ Screens (Start, Level Complete, Game Over, Pause) ============ */

.gwg-screen {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px 32px 48px;
    text-align: center;
    color: #fff;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.gwg-screen.gwg-active {
    display: flex;
}

.gwg-screen-title {
    font-size: clamp(32px, 5vw, 56px);
    font-weight: 900;
    margin: 0 0 8px;
    background: linear-gradient(135deg, #fde047 0%, #fb923c 50%, #f472b6 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 1px;
    text-shadow: 0 4px 30px rgba(251, 191, 36, 0.3);
}

/* WordPress converts emoji entities (e.g. &#127942;) into <img class="emoji">.
   Cap the image so it doesn't dwarf the heading. */
.gwg-screen-title img,
.gwg-screen-title img.emoji,
.gwg-screen-title img.wp-smiley {
    max-width: 12%;
    height: auto;
    width: auto;
    vertical-align: middle;
    display: inline-block;
    margin: 0 4px;
}

.gwg-screen-subtitle {
    font-size: clamp(15px, 1.8vw, 19px);
    opacity: 0.9;
    margin: 0 0 24px;
    max-width: 600px;
    line-height: 1.6;
}

.gwg-btn {
    display: inline-block;
    padding: 14px 40px;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    border: none;
    border-radius: 50px;
    background: linear-gradient(135deg, #fb923c 0%, #f472b6 100%);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(244, 114, 182, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.3);
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s;
    margin: 8px;
    font-family: inherit;
}

.gwg-btn:hover {
    transform: translateY(-3px) scale(1.03);
    box-shadow: 0 12px 32px rgba(244, 114, 182, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.gwg-btn:active {
    transform: translateY(-1px) scale(0.98);
}

/* Disabled state for the start-screen Next button.
   Override every interaction state (hover/active/focus) AND block pointer
   events outright so no hover lift or active shrink can fire. */
.gwg-btn:disabled,
.gwg-btn[disabled],
.gwg-btn:disabled:hover,
.gwg-btn[disabled]:hover,
.gwg-btn:disabled:active,
.gwg-btn[disabled]:active,
.gwg-btn:disabled:focus,
.gwg-btn[disabled]:focus {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
    transform: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.gwg-btn-secondary {
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.25);
    box-shadow: none;
    font-size: 16px;
    padding: 12px 32px;
}
.gwg-btn-secondary:hover {
    background: rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

/* Stats grid on summary screens */
.gwg-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin: 20px 0 28px;
    width: 100%;
    max-width: 520px;
}

.gwg-stat-card {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 16px;
    padding: 18px 10px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.gwg-stat-card-label {
    font-size: 11px;
    opacity: 0.7;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 6px;
}

.gwg-stat-card-value {
    font-size: clamp(22px, 3.5vw, 36px);
    font-weight: 800;
}

.gwg-stat-card.gwg-correct .gwg-stat-card-value { color: #4ade80; }
.gwg-stat-card.gwg-wrong   .gwg-stat-card-value { color: #f87171; }
.gwg-stat-card.gwg-accuracy .gwg-stat-card-value { color: #fbbf24; }
.gwg-stat-card.gwg-score   .gwg-stat-card-value { color: #fde047; }

/* 4-card layout used on level/game complete screens when a Score card is present. */
.gwg-stats.gwg-stats-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    max-width: 680px;
}

.gwg-score-total {
    margin: -8px 0 18px;
    font-size: 13px;
    letter-spacing: 0.6px;
    color: #fde047;
    opacity: 0.85;
}

/* Stars */
.gwg-stars {
    font-size: 44px;
    margin: 0 0 14px;
    letter-spacing: 8px;
    color: #fbbf24;
    text-shadow: 0 0 20px rgba(251, 191, 36, 0.6);
}

.gwg-star-dim { opacity: 0.2; }

/* Instructions modal content */
.gwg-instructions {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    padding: 18px 22px;
    max-width: 520px;
    margin-bottom: 22px;
    font-size: 14px;
    line-height: 1.7;
    text-align: left;
}

.gwg-instructions strong {
    color: #fde047;
}

/* Sound toggle */
.gwg-sound-toggle {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 11;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.2s;
    pointer-events: auto;
}
.gwg-sound-toggle:hover { background: rgba(0, 0, 0, 0.65); transform: scale(1.08); }

/* ============ Responsive (mobile/tablet) ============ */

@media (max-width: 900px) {
    #gwg-container {
        height: 90vh;
        min-height: 480px;
        max-height: none;
    }
    .gwg-english-word {
        top: 70px;
        padding: 7px 22px;
    }
}

@media (max-width: 640px) {
    #gwg-container {
        height: 92vh;
        min-height: 450px;
        border-radius: 0;
        max-width: 100%;
    }
    .gwg-english-word {
        top: 64px;
        padding: 6px 18px;
        font-size: clamp(20px, 5vw, 30px);
    }
    .gwg-hud-top {
        padding: 10px 12px;
        gap: 6px;
    }
    .gwg-hud-stat {
        padding: 6px 10px;
        font-size: 11px;
        border-radius: 8px;
    }
    .gwg-hud-stat-label {
        font-size: 9px;
    }
    .gwg-hud-stat-value {
        font-size: 13px;
    }
    .gwg-stats {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }
    .gwg-stats.gwg-stats-4 {
        grid-template-columns: repeat(2, 1fr);
    }
    .gwg-stat-card {
        padding: 12px 6px;
    }
    .gwg-btn {
        padding: 12px 28px;
        font-size: 15px;
    }
    .gwg-combo {
        right: 12px;
    }
    .gwg-progress-marker {
        width: 22px;
        height: 22px;
    }
    .gwg-sound-toggle {
        width: 36px;
        height: 36px;
        top: 12px;
        right: 12px;
    }
}

/* Very short viewport (landscape mobile) */
@media (max-height: 500px) {
    #gwg-container {
        height: 98vh;
        min-height: 380px;
    }
    .gwg-english-word {
        top: 56px;
    }
}

/* Accessibility: respect reduced motion */
@media (prefers-reduced-motion: reduce) {
    .gwg-prompt-word,
    .gwg-english-word { animation: none; }
    #gwg-container { transition: none; }
}

/* ============ Variation cards (start screen) ============ */

.gwg-variation-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    width: 100%;
    max-width: 920px;
    margin: 12px 0 22px;
}

/* Tablet / mid-width: drop to 2 columns so 4 cards still read comfortably. */
@media (max-width: 900px) {
    .gwg-variation-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        max-width: 560px;
    }
}

.gwg-variation-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    padding: 22px 18px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 18px;
    color: #fff;
    text-decoration: none;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1),
                background 0.2s, border-color 0.2s, box-shadow 0.2s;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    cursor: pointer;
    /* Reset native button styles so the <button> variant looks identical to the old <a> version. */
    -webkit-appearance: none;
    appearance: none;
    font: inherit;
    text-align: inherit;
    width: 100%;
}

.gwg-variation-card:hover {
    transform: translateY(-4px) scale(1.02);
    background: rgba(255, 255, 255, 0.14);
    border-color: rgba(253, 224, 71, 0.6);
    box-shadow: 0 12px 32px rgba(244, 114, 182, 0.25);
}

/* Persistent "selected" state — same layout, just a stronger yellow accent. */
.gwg-variation-card.selected,
.gwg-variation-card.selected:hover {
    border-color: #fde047;
    background: rgba(253, 224, 71, 0.12);
    box-shadow: 0 0 0 2px rgba(253, 224, 71, 0.6),
                0 12px 32px rgba(244, 114, 182, 0.25);
}

.gwg-variation-card-icon {
    font-size: clamp(20px, 2.4vw, 28px);
    font-weight: 800;
    letter-spacing: 1px;
    color: #fde047;
    text-shadow: 0 0 16px rgba(253, 224, 71, 0.45);
    font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
}

.gwg-variation-card-title {
    font-size: clamp(15px, 1.7vw, 18px);
    font-weight: 800;
    letter-spacing: 0.4px;
}

.gwg-variation-card-desc {
    font-size: 13px;
    opacity: 0.85;
    line-height: 1.5;
    text-align: center;
}

.gwg-variation-card-desc strong { color: #fde047; }

.gwg-level-indicator {
    margin-top: 8px;
    font-size: 13px;
    opacity: 0.75;
    letter-spacing: 1px;
}

.gwg-level-indicator strong {
    color: #fde047;
    margin: 0 4px;
}

/* Topic picker row (start screen) */
.gwg-topic-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 4px 0 10px;
    width: 100%;
    max-width: 360px;
}

.gwg-topic-label {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.6px;
    text-transform: uppercase;
    opacity: 0.85;
}

.gwg-topic-select {
    flex: 1;
    padding: 10px 14px;
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 10px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, #fde047 50%),
                      linear-gradient(135deg, #fde047 50%, transparent 50%);
    background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    padding-right: 32px;
    font-family: inherit;
}

.gwg-topic-select:focus {
    outline: none;
    border-color: rgba(253, 224, 71, 0.7);
    background-color: rgba(255, 255, 255, 0.14);
}

.gwg-topic-select option {
    color: #1e293b;
    background: #fff;
}

.gwg-levels-available {
    margin: 6px 0 14px;
    font-size: 13px;
    letter-spacing: 0.6px;
    opacity: 0.85;
}

.gwg-levels-available [data-gwg="topic-levels"] {
    color: #fde047;
    font-weight: 800;
    margin: 0 2px;
}

/* Page 2 — variation + topic line under the title */
.gwg-topic-line {
    margin: -6px 0 16px;
    font-size: 14px;
    letter-spacing: 0.6px;
    opacity: 0.9;
}

.gwg-topic-line strong { color: #fde047; }

@media (max-width: 640px) {
    .gwg-variation-grid {
        grid-template-columns: 1fr;
        gap: 10px;
        max-width: 360px;
    }
    .gwg-variation-card {
        flex-direction: row;
        text-align: left;
        padding: 14px 16px;
        gap: 14px;
    }
    .gwg-variation-card-icon { flex: 0 0 auto; }
    .gwg-variation-card-title,
    .gwg-variation-card-desc { text-align: left; }
}

/* ============ Per-variation typography for the prompt word ============ */

#gwg-container[data-variation="charreco"] .gwg-prompt-word,
#gwg-container[data-variation="chareng"] .gwg-prompt-word {
    font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
    letter-spacing: 2px;
    font-size: clamp(28px, 4vw, 52px);
}

#gwg-container[data-variation="pinyin"] .gwg-prompt-word,
#gwg-container[data-variation="charwrite"] .gwg-prompt-word {
    letter-spacing: 0.8px;
}
