@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;600;800&display=swap');

:root {
    --primary: #10b981;
    --primary-light: #34d399;
    --secondary: #3b82f6;
    --accent: #f59e0b;
    --danger: #ef4444;
    --bg-dark: #0f172a;
    --panel-bg: #1e293b;
    --panel-light: #334155;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: rgba(255, 255, 255, 0.1);
    --radius-lg: 1.5rem;
    --radius-md: 1rem;
    --shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.5);
    --font-main: 'Outfit', 'FreeSans', 'Noto Sans', sans-serif;
    --bg-soft: #2d3a4f;

    /* Safe Area Variables for modern phones */
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

select option {
    background: #1e293b;
    color: white;
}

html {
    -webkit-text-size-adjust: 100%;
}

html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    background: #0b1120 !important;
    overflow: hidden !important;
}

body {
    font-family: var(--font-main);
    color: var(--text-main);
    display: flex;
    justify-content: center;
    align-items: center;
}

#app {
    width: var(--app-width, 1200px);
    min-width: 1200px;
    height: 800px;
    flex-shrink: 0;
    background: var(--panel-bg);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
    transform-origin: center center;
}




/* --- HEADER --- */
.header {
    padding: 1.25rem calc(2rem + var(--safe-right)) 1.25rem calc(2rem + var(--safe-left));
    background: rgba(0, 0, 0, 0.3);
    border-bottom: 2px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo h1 {
    font-size: 1.8rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.2rem;
    color: var(--text-muted);
}

.learning-tag {
    display: block;
    font-size: 0.9rem;
    font-weight: 800;
    color: var(--secondary);
    text-transform: uppercase;
    margin-top: 0.2rem;
    letter-spacing: 1px;
}

.stats-bar {
    display: flex;
    gap: 1.25rem;
}

.stat {
    background: var(--panel-light);
    padding: 0.6rem 1.2rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 130px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

.stat-emoji {
    font-size: 1.8rem;
    filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.1));
}

.stat .value {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--accent);
    letter-spacing: -0.5px;
}

.pulse-soft {
    animation: pulse-soft 3s infinite ease-in-out;
}

@keyframes pulse-soft {

    0%,
    100% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.1);
        opacity: 0.9;
    }
}

/* --- MAIN LAYOUT --- */
.main-content {
    flex: 1;
    overflow: hidden;
    position: relative;
}

#shop-view {
    height: 100%;
    display: grid;
    grid-template-columns: 1fr 280px;
    /* Expansive shop floor + sidebar */
    gap: 1.5rem;
    padding: 1.5rem calc(1.5rem + var(--safe-right)) 1.5rem calc(1.5rem + var(--safe-left));
}

#shelves-container {
    height: 100%;
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    padding: 2rem;

    /* THE FIX: Use grid directly on the container where JS adds items */
    display: grid;
    grid-template-columns: repeat(5, 100px);
    grid-auto-rows: 100px;
    gap: 30px;

    justify-content: center;
    /* Center horizontally */
    align-content: center;
    /* Center vertically */

    overflow: hidden;
    /* No scrollbars allowed */
    width: 100%;
    min-width: 700px;
    /* Force minimum width to prevent sidebar shift */
}

.empty-shelf-msg {
    grid-column: 1 / span 5;
    text-align: center;
    color: var(--text-muted);
    font-style: italic;
}

.shelf-item {
    background: var(--panel-light);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    width: 100px;
    height: 100px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.shelf-item:hover {
    transform: translateY(-5px);
    background: #3c4a5e;
    border-color: var(--primary);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.4);
}

.shelf-item .icon {
    font-size: 2.2rem;
    margin-bottom: 0.1rem;
}

.shelf-item strong {
    font-size: 0.8rem;
    color: var(--text-main);
    font-weight: 800;
}

.shelf-item .count {
    position: absolute;
    top: -8px;
    right: -8px;
    background: var(--primary);
    color: white;
    font-weight: 800;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 0.7rem;
    box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.4);
    z-index: 10;
}

/* Management Sidebar */
.management-sidebar {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    background: rgba(0, 0, 0, 0.15);
    padding: 1.25rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    height: 100%;
    /* Fill the grid height */
}

.perks-box {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.perks-box.hidden {
    display: none;
}

.perks-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 800;
    letter-spacing: 0.05rem;
}

.perks-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.perk-icon {
    font-size: 1.5rem;
    background: var(--panel-light);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border: 1px solid var(--border);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.management-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.management-sidebar .secondary-btn {
    height: 75px;
    flex-shrink: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
}

.btn-emoji {
    font-size: 2rem;
    line-height: 1;
}

/* Main Action Button (Pinned to Bottom) */
#open-store-btn {
    margin-top: auto;
    height: 85px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: white;
    /* Changed from var(--bg-dark) */
    font-size: 1.2rem;
    font-weight: 800;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    /* Added for visibility */
    box-shadow: 0 10px 25px -5px rgba(16, 185, 129, 0.4);
}

#open-store-btn:hover {
    filter: brightness(1.1);
    transform: translateY(-3px);
}

#open-store-btn:active {
    transform: translateY(1px);
}

/* Buttons General */
button {
    font-family: inherit;
    font-weight: 800;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: none;
    border-radius: var(--radius-md);
}

.secondary-btn {
    background: var(--panel-light);
    color: white;
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

/* Mobile-friendly Button Hover Logic */
@media (hover: hover) {
    .secondary-btn:hover {
        background: var(--secondary);
        border-color: var(--secondary);
        transform: translateX(-5px);
    }
}

/* Snappy active state that releases on touch lift */
.secondary-btn:active {
    background: var(--secondary) !important;
    filter: brightness(1.2);
    transform: scale(0.95);
}

/* Prevent permanent blue state from focus */
.secondary-btn:focus {
    outline: none !important;
    background: var(--panel-light);
}

/* If the button is explicitly focused via keyboard, show a subtle border instead of full blue */
.secondary-btn:focus-visible {
    border-color: var(--secondary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3);
}

.shop-link-btn {
    background: #a855f7 !important;
    border-color: #c084fc !important;
}

.shopping-bag-pulse {
    animation: shop-flash 4s infinite ease-in-out;
}

@keyframes shop-flash {

    0%,
    100% {
        box-shadow: 0 0 0px rgba(168, 85, 247, 0);
        filter: brightness(1);
    }

    50% {
        box-shadow: 0 0 15px rgba(168, 85, 247, 0.6);
        filter: brightness(1.15);
    }
}

/* --- STABLE & PRACTICAL QUIZ OVERLAY --- */
.overlay {
    position: absolute;
    inset: 0;
    z-index: 500;
    background: #0f172a;
    /* Solid dark background for focus */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-evenly;
    /* Evenly distributes all elements vertically */
    padding: 1rem;
    overflow: hidden;
    /* Prevent any scrolling */
}

.overlay.hidden {
    display: none;
}

.day-timer {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    background: var(--accent);
    color: var(--bg-dark);
    padding: 0.6rem 1.2rem;
    border-radius: 50px;
    font-weight: 800;
    font-size: 1.1rem;
    z-index: 600;
}

/* Stable Center Container */
.game-container {
    width: 100%;
    max-width: 800px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.8rem;
    position: relative;
}

.customer-wrapper {
    position: relative;
    width: 100px;
    height: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.customer-avatar {
    font-size: 4.5rem;
    line-height: 1;
    z-index: 5;
}

/* Thought Bubble to the left of head */
.thought-bubble {
    position: absolute;
    top: -10px;
    left: -70px;
    background: white;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.3);
    z-index: 10;
}

/* Thought bubble tail - little bubbles */
.thought-bubble::before {
    content: '';
    position: absolute;
    bottom: 5px;
    right: -10px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
}

.thought-bubble::after {
    content: '';
    position: absolute;
    bottom: -8px;
    right: -18px;
    width: 10px;
    height: 10px;
    background: white;
    border-radius: 50%;
}

.thought-icon {
    font-size: 2.2rem;
}

/* Speech Bubble (Game Word) */
.speech-bubble {
    background: white;
    color: var(--bg-dark);
    width: 90%;
    max-width: 500px;
    height: 90px;
    /* Tighter height for the English word */
    border-radius: 1.5rem;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.4);
    padding: 0 1.5rem;
}

.speech-bubble::after {
    content: '';
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 12px solid transparent;
    border-right: 12px solid transparent;
    border-bottom: 12px solid white;
}

.game-word {
    font-size: 2.2rem;
    font-weight: 800;
    color: var(--secondary);
    text-align: center;
    line-height: 1.1;
}

/* Meter Bar */
.timer-bar {
    width: 100%;
    max-width: 500px;
    height: 14px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50px;
    overflow: hidden;
    flex-shrink: 0;
}

.timer-fill {
    height: 100%;
    background: var(--primary);
    box-shadow: 0 0 15px var(--primary);
}

/* Practical Choices */
.options-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    width: 95%;
    max-width: 850px;
}

.option-btn {
    height: 110px;
    /* Balanced height for translations */
    padding: 0.8rem;
    font-size: 1.3rem;
    background: var(--panel-light);
    color: white;
    border: 3px solid var(--border);
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    line-height: 1.2;
    overflow: hidden;
    word-break: break-word;
    border-radius: var(--radius-md);
    font-family: 'FreeSans', 'Noto Sans', sans-serif;
}

.option-btn.long-text {
    font-size: 1.1rem;
}

.option-btn.very-long-text {
    font-size: 0.9rem;
}

/* Feedback Animations */
.correct-anim {
    background: var(--success) !important;
    border-color: var(--primary-light) !important;
    transform: scale(1.02);
}

.wrong-anim {
    background: var(--danger) !important;
    border-color: #ff8a8a !important;
}

.shake {
    animation: shake 0.4s;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-8px);
    }

    75% {
        transform: translateX(8px);
    }
}

/* --- MODALS --- */
.modal {
    position: absolute;
    inset: 0;
    z-index: 10000;
    /* Increased to stay on top of everything */
    background: rgba(2, 6, 23, 0.9);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--panel-bg);
    width: 100%;
    max-width: 900px;
    max-height: 700px;
    /* Instead of 85vh */
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    padding: 1.5rem 2.5rem;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    display: flex;
    flex-direction: column;
}

.modal-header h2 {
    font-size: 1.6rem;
    color: var(--accent);
}

#mistakes-modal .modal-header h2 {
    color: var(--secondary);
}

.modal-money-label {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 600;
}

.modal-money-label .money-text {
    color: var(--accent);
    font-weight: 800;
}

.close-btn {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
    border: 1px solid var(--border);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}

.close-btn:hover {
    background: var(--danger);
    color: white;
}

.items-grid {
    padding: 2.5rem;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 2rem;
    overflow-y: auto;
    flex: 1;
}

.shop-item-card {
    background: var(--panel-light);
    padding: 1.5rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.75rem;
    transition: background 0.2s;
}

.shop-item-card:hover {
    background: #3c4a5e;
}

/* Mistakes Modal Custom Size */
#mistakes-modal .modal-content {
    max-width: 500px;
    height: 600px;
    /* Instead of 70vh */
    /* Fixed height ratio to force scrolling */
}

#mistakes-list {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

/* Custom Dialogue */
#dialog-modal {
    z-index: 20000;
}

/* Fix for visibility in true fullscreen mode */
:fullscreen .modal,
:-webkit-full-screen .modal {
    z-index: 2147483647;
    /* Highest possible z-index */
}

.dialog-content {
    max-width: 480px;
    border: 3px solid var(--accent) !important;
}

.dialog-body {
    padding: 3rem 2.5rem;
    text-align: center;
    font-size: 1.2rem;
    line-height: 1.6;
    font-weight: 600;
}

.mistake-item-card {
    padding: 1.2rem;
    border-bottom: 2px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.mistake-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 800;
    letter-spacing: 0.5px;
}

.mistake-source {
    font-size: 1.1rem;
    color: var(--text-main);
    margin-bottom: 0.4rem;
}

.mistake-result {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--secondary);
    word-break: break-word;
    /* Important for long translations */
    line-height: 1.2;
    font-family: 'FreeSans', 'Noto Sans', sans-serif;
}

.modal-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: center;
}

.modal-footer button {
    min-width: 160px;
    height: 50px;
    font-size: 1.1rem;
}

/* Leaderboard Styles */
.leaderboard-table {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 1rem;
}

#leaderboard-list {
    max-height: 50vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding-right: 5px;
}

.leaderboard-header-row,
.leaderboard-entry {
    display: grid;
    grid-template-columns: 60px 1fr 120px 100px 180px;
    padding: 1rem;
    border-radius: 8px;
    align-items: center;
}

.leaderboard-header-row {
    background: rgba(255, 255, 255, 0.05);
    font-weight: 600;
    color: var(--primary);
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 1px;
}

.leaderboard-entry {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    transition: background 0.2s, border-color 0.2s;
    cursor: default;
    /* Not clickable */
}

.leaderboard-entry:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--primary-soft);
}

.leaderboard-entry.player-row {
    background: linear-gradient(90deg, rgba(82, 113, 255, 0.1), rgba(0, 255, 136, 0.05));
    border: 1px solid var(--primary-soft);
}

.leaderboard-entry .rank {
    font-weight: 800;
    font-size: 1.2rem;
    opacity: 0.5;
}

.leaderboard-entry .store-name {
    font-weight: 600;
}

.leaderboard-entry .language {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.leaderboard-entry .rep {
    color: var(--secondary);
}

.leaderboard-entry .money {
    color: var(--primary);
    font-weight: 600;
}

/* Modal Enhancements */
.modal-body p {
    color: rgba(255, 255, 255, 0.7);
    line-height: 1.6;
}

#store-name-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 10px rgba(82, 113, 255, 0.3);
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4);
    }

    70% {
        box-shadow: 0 0 0 15px rgba(16, 185, 129, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    }
}

.pulse {
    animation: pulse 2s infinite;
}

::-webkit-scrollbar {
    width: 10px;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Fullscreen and Zent Mode Fallback */
#app.pseudo-fullscreen {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    z-index: 999999 !important;
    background: var(--panel-bg) !important;
    margin: 0 !important;
    border-radius: var(--radius-lg) !important;
    width: var(--app-width, 1200px) !important;
    min-width: 1200px !important;
    height: 800px !important;
}

:fullscreen body,
:-webkit-full-screen body {
    background: #0b1120 !important;
    overflow: hidden !important;
}