/* ---- Base CSS Variables (Light Theme Defaults) ---- */
:root {
    --bg-primary: #fff;
    --bg-secondary: #f5f5f5;
    --bg-card: #fff;
    --text-primary: #333;
    --text-secondary: #666;
    --accent: #ff7043;
    --accent-secondary: #ffb74d;
    --border-color: rgba(0, 0, 0, 0.08);
    --shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    --font-scale: 1;
}

.game-sound-toggle {
    display: none;
    position: fixed;
    right: max(18px, env(safe-area-inset-right));
    bottom: max(18px, env(safe-area-inset-bottom));
    z-index: 2100;
    width: 52px;
    height: 52px;
    border: 0;
    border-radius: 50%;
    background: linear-gradient(135deg, #ffecb3, #ffb74d);
    color: #5d3b00;
    box-shadow: 0 10px 24px rgba(90, 60, 0, 0.26);
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.45rem;
    line-height: 1;
    transition: transform 0.18s ease, box-shadow 0.18s ease, filter 0.18s ease;
}

.game-sound-toggle:hover,
.game-sound-toggle:focus-visible {
    transform: translateY(-2px) scale(1.04);
    box-shadow: 0 14px 28px rgba(90, 60, 0, 0.32);
    outline: none;
}

.game-sound-toggle:active {
    transform: translateY(0) scale(0.98);
}

.game-sound-toggle.is-muted {
    background: linear-gradient(135deg, #eeeeee, #bdbdbd);
    color: #555;
    filter: grayscale(0.18);
}

.game-sound-toggle-icon {
    pointer-events: none;
}

.game-loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(circle at 30% 25%, rgba(255, 236, 179, 0.95), transparent 32%),
        linear-gradient(135deg, rgba(255, 167, 38, 0.96), rgba(255, 112, 67, 0.96));
    color: #5d3000;
    transition: opacity 0.24s ease, visibility 0.24s ease;
}

.game-loading-overlay.is-done {
    opacity: 0;
    visibility: hidden;
}

.game-loading-card {
    width: min(86vw, 360px);
    padding: 32px 26px 28px;
    border-radius: 28px;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 22px 50px rgba(93, 48, 0, 0.26);
    text-align: center;
    backdrop-filter: blur(10px);
}

.game-loading-spinner {
    width: 64px;
    height: 64px;
    margin: 0 auto 18px;
    border-radius: 50%;
    border: 7px solid rgba(255, 183, 77, 0.3);
    border-top-color: #ff8f00;
    border-right-color: #ffb300;
    animation: gameLoadingSpin 0.88s linear infinite;
}

.game-loading-title {
    font-size: 1.65rem;
    font-weight: 900;
    letter-spacing: 0.12em;
    margin-bottom: 8px;
}

.game-loading-text {
    font-size: 0.98rem;
    font-weight: 700;
    color: #8a5600;
    margin-bottom: 18px;
}

.game-loading-progress {
    width: 100%;
    height: 14px;
    overflow: hidden;
    border-radius: 999px;
    background: rgba(141, 82, 0, 0.13);
    box-shadow: inset 0 2px 5px rgba(93, 48, 0, 0.16);
}

.game-loading-progress-bar {
    width: 0%;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #ffb300, #ff7043, #ffca28);
    box-shadow: 0 4px 12px rgba(255, 112, 67, 0.36);
    transition: width 0.2s ease;
}

.game-loading-percent {
    margin-top: 10px;
    font-size: 0.95rem;
    font-weight: 900;
    color: #6d3d00;
}

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

@media (max-width: 520px) {
    .game-sound-toggle {
        width: 46px;
        height: 46px;
        right: max(12px, env(safe-area-inset-right));
        bottom: max(12px, env(safe-area-inset-bottom));
        font-size: 1.25rem;
    }

    .game-loading-card {
        width: min(90vw, 330px);
        padding: 28px 22px 24px;
    }

    .game-loading-spinner {
        width: 56px;
        height: 56px;
    }
}

/* ---- Page Transition Overlay ---- */

.page-transition-overlay {
    position: fixed;
    inset: 0;
    z-index: 5000;
    pointer-events: none;
    opacity: 0;
    background: radial-gradient(circle at 30% 25%, rgba(255, 236, 179, 0.96), transparent 32%),
                linear-gradient(135deg, rgba(255, 167, 38, 0.96), rgba(255, 112, 67, 0.96));
    transition: opacity 0.24s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.page-transition-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.page-transition-spinner {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 5px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    border-right-color: #fff;
    animation: gameLoadingSpin 0.78s linear infinite;
}

/* ---- Font Size Accessibility ---- */

body {
    font-size: calc(1rem * var(--font-scale));
}

.game-container .game-title {
    font-size: calc(1.55rem * var(--font-scale));
}

.grid-cell {
    font-size: calc(1.1rem * var(--font-scale));
}

@media (min-width: 521px) {
    .grid-cell {
        font-size: calc(1.35rem * var(--font-scale));
    }
}

/* ---- Game Settings Panel ---- */

.game-settings-panel {
    margin-top: 12px;
    padding: 10px 12px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.game-settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 4px;
}

.game-settings-row + .game-settings-row {
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.game-settings-label {
    font-size: 0.88rem;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.85);
    white-space: nowrap;
}

.game-settings-toggle {
    width: 44px;
    height: 26px;
    border: 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.22);
    position: relative;
    cursor: pointer;
    transition: background 0.2s ease;
    flex-shrink: 0;
}

.game-settings-toggle::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #fff;
    transition: transform 0.2s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}

.game-settings-toggle.active {
    background: #ffb74d;
}

.game-settings-toggle.active::after {
    transform: translateX(18px);
}

.game-settings-font-btns {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.game-settings-font-btn {
    width: 30px;
    height: 30px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.9);
    font-weight: 900;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.16s ease, border-color 0.16s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.game-settings-font-btn.active {
    background: rgba(255, 183, 77, 0.6);
    border-color: #ffb74d;
}

.game-settings-font-btn:hover {
    background: rgba(255, 255, 255, 0.18);
}

/* ---- Achievement Unlock Toast ---- */

.ach-unlock-toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-120px);
    z-index: 6000;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 22px;
    border-radius: 16px;
    background: linear-gradient(135deg, #ffb300, #ff7043);
    color: #fff;
    box-shadow: 0 12px 36px rgba(255, 112, 67, 0.45);
    opacity: 0;
    transition: transform 0.36s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.26s ease;
    pointer-events: none;
    max-width: min(92vw, 380px);
}

.ach-unlock-toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.ach-unlock-icon {
    font-size: 2rem;
    line-height: 1;
    flex-shrink: 0;
}

.ach-unlock-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.ach-unlock-title {
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    opacity: 0.85;
}

.ach-unlock-name {
    font-size: 1.1rem;
    font-weight: 900;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---- XP Level Bar (in menu) ---- */

.game-menu-xp-bar {
    margin-top: 10px;
    padding: 8px 12px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.1);
}

.game-menu-xp-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 5px;
}

.game-menu-xp-level {
    font-size: 0.85rem;
    font-weight: 900;
    color: #ffb74d;
}

.game-menu-xp-text {
    font-size: 0.72rem;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.7);
}

.game-menu-xp-track {
    width: 100%;
    height: 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.15);
    overflow: hidden;
}

.game-menu-xp-fill {
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #ffb300, #ff7043);
    transition: width 0.4s ease;
}

/* ---- Daily Tasks in Menu ---- */

.game-menu-task-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #ff5252;
    color: #fff;
    font-size: 0.68rem;
    font-weight: 900;
    margin-left: 6px;
    vertical-align: middle;
}

/* ---- Daily Tasks Panel in Menu ---- */

.game-menu-tasks-panel {
    margin-top: 8px;
    padding: 8px 10px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.game-menu-task-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 4px;
}

.game-menu-task-row + .game-menu-task-row {
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.game-menu-task-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.game-menu-task-name {
    font-size: 0.8rem;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.9);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.game-menu-task-desc {
    font-size: 0.68rem;
    font-weight: 600;
    color: rgba(255, 183, 77, 0.85);
}

.game-menu-task-progress {
    width: 48px;
    height: 5px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    overflow: hidden;
    flex-shrink: 0;
}

.game-menu-task-fill {
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #4caf50, #8bc34a);
    transition: width 0.3s ease;
}

.game-menu-task-status {
    font-size: 0.72rem;
    font-weight: 900;
    flex-shrink: 0;
    min-width: 28px;
    text-align: right;
    color: rgba(255, 255, 255, 0.7);
}

/* ---- Achievement List (idiom-library page) ---- */

.achievement-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
    padding: 12px 0;
}

.achievement-card {
    padding: 12px 10px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    text-align: center;
    transition: transform 0.15s ease, border-color 0.15s ease;
}

.achievement-card.unlocked {
    border-color: #ffb74d;
    background: rgba(255, 183, 77, 0.1);
}

.achievement-card .ach-icon {
    font-size: 1.6rem;
    margin-bottom: 4px;
}

.achievement-card .ach-name {
    font-size: 0.78rem;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.85);
    margin-bottom: 2px;
}

.achievement-card .ach-progress {
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.5);
}

.achievement-card.locked {
    opacity: 0.45;
    filter: grayscale(0.6);
}

.tasks-list-panel {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px 0;
}

.task-item-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.task-item-card.completed {
    border-color: #4caf50;
    background: rgba(76, 175, 80, 0.08);
}

.task-item-info {
    flex: 1;
    min-width: 0;
}

.task-item-title {
    font-weight: 700;
    font-size: 0.92rem;
    color: rgba(255, 255, 255, 0.9);
}

.task-item-desc {
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.55);
    margin-top: 2px;
}

.task-item-xp {
    font-weight: 900;
    font-size: 0.85rem;
    color: #ffb74d;
    white-space: nowrap;
}

.task-item-claim-btn {
    padding: 8px 14px;
    border: 0;
    border-radius: 10px;
    background: linear-gradient(135deg, #ffb300, #ff7043);
    color: #fff;
    font-weight: 800;
    font-size: 0.78rem;
    cursor: pointer;
    white-space: nowrap;
}

.task-item-claim-btn:disabled {
    opacity: 0.5;
    cursor: default;
}

/* ---- Achievement Progress Bar ---- */

.ach-progress-bar {
    width: 100%;
    height: 6px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.1);
    overflow: hidden;
    margin-top: 6px;
}

.ach-progress-fill {
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #ffb74d, #ff9800);
    transition: width 0.4s ease;
}

/* ---- Task Progress Bar ---- */

.task-progress-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 5px;
}

.task-progress-bar {
    flex: 1;
    height: 7px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.1);
    overflow: hidden;
}

.task-progress-fill {
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #4caf50, #8bc34a);
    transition: width 0.4s ease;
}

.task-progress-text {
    font-size: 0.7rem;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.55);
    white-space: nowrap;
    min-width: 32px;
    text-align: right;
}
