* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Responsive type scale using clamp() so UI scales across viewports and DPRs.
   Tweak these variables to tune type across all games. */
:root {
    --fs-xxs: 2.0vh;
    --fs-xs: 1.7vh;
    --fs-sm: 2.0vh;
    --fs-md: 2.2vh;
    --fs-lg: 4vw;
    --fs-xl: 4vh;
    --fs-2xl: clamp(3vw, 6vw, 4.5vw);
}

html { 
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    -webkit-text-size-adjust: none;
    -moz-text-size-adjust: none;
    text-size-adjust: none;
}

body {
    font-family: 'Arial', sans-serif;
    font-size: 1.5vw;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    margin: 0;
    padding: 0;
    position: fixed;
    top: 0;
    left: 0;
    -webkit-text-size-adjust: none;
    -moz-text-size-adjust: none;
    text-size-adjust: none;
}

.game-container {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    max-width: 100vw;
    max-height: 100vh;
    overflow: hidden;
    position: relative;
    flex-direction: column;
    text-align: center;
}

h1 {
    margin-bottom: 0.5vh;
    font-size: var(--fs-xl);
    text-shadow: 0.3vw 0.3vw 0.6vw rgba(0, 0, 0, 0.5);
    justify-self: center;
    align-self: center;
}

/* Section styles */
.instructions-section, .game-section {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.instructions-container {
    position: relative;
    width: 100%;
    max-width: 100%;
    max-height: 95vh;
    padding: clamp(0.7vh, 2vh, 2.2vh);
    align-items: center;
    justify-content: center;
    overflow-y: auto;
    overflow-x: hidden;
    box-sizing: border-box;
    gap: clamp(0.5vh, 1vh, 1.2vh);
    text-align: center;
}

.menu-logo {
  position: absolute;
  left: 1.1vw;
  top: 0.7vh;
  width: clamp(3.5vw, 9vw, 7vw);
  height: auto;
  object-fit: contain;
  display: block;
  z-index: 20;
  pointer-events: auto;
}

.game-section {
    display: none;
    flex-direction: column;
}

/* When the game section is shown */
.game-section.show {
    display: flex !important;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

.game-grid {
    height: 98vh;
    height: 100dvh;
    width: 100%;
    display: grid;
    grid-template-rows: 8vh 1fr 5vh;
    gap: 0.2vh;
    align-items: stretch;
    overflow: hidden;
    margin: 0;
    padding: 0.3vh;
    box-sizing: border-box;
    flex-direction: column;
}

.objective {
    text-align: left;
    padding: clamp(0.7vh, 1.5vh, 1.4vh);
    background: rgba(255, 255, 255, 0.2);
    border-radius: 1.4vw;
    font-size: var(--fs-md);
    line-height: 1.4;
    border: 0.2vw solid rgba(255, 215, 0, 0.3);
    max-width: 85vw;
    margin: 0 auto clamp(0.7vh, 2vh, 1.8vh) auto;
}

.learning-block {
    background: rgba(255, 255, 255, 0.15);
    padding: 1.5vh;
    border-radius: 1.1vw;
    margin-top: 1vh;
    font-size: var(--fs-md);
}

.bubble-legend {
    margin-bottom: clamp(0.7vh, 2vh, 1.8vh);
    align-items: center;
    width: 100%;
    gap: clamp(0.3vh, 0.8vh, 0.7vh);
}

.bubble-legend h3 {
    font-size: var(--fs-md);
    color: #FFD700;
    text-shadow: 0.15vw 0.15vw 0.3vw rgba(0, 0, 0, 0.5);
    text-align: center;
    width: 100%;
    margin-bottom: 1vh;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.9vw;
    font-size: var(--fs-xs);
    text-align: left;
    justify-content: flex-start;
    margin-bottom: clamp(0.3vh, 0.5vh, 0.5vh);
    width: 100%;
    max-width: 88vw;
}

.legend-number {
    width: 1.7vw;
    height: 1.7vw;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2vw;
    font-weight: bold;
    color: white;
    text-shadow: 0.15vw 0.15vw 0.3vw rgba(0, 0, 0, 0.5);
    flex-shrink: 0;
    background: linear-gradient(135deg, #4ECDC4, #44A08D);
}

.game-header {
    display: flex;
    width: 100%;
    justify-content: space-between;
    align-items: center;
    background: rgba(255,255,255,0.15);
    padding: clamp(0.7vh, 1.5vh, 1.1vh) clamp(0.7vw, 2vw, 1.5vw);
    border-radius: 1.1vw;
    backdrop-filter: blur(0.9vw);
    margin: 0;
    position: relative;
    min-height: 6vh;
    gap: 1vw;
}

.budget-display {
    font-size: var(--fs-sm);
    font-weight: bold;
    color: #FFD700;
    white-space: nowrap;
    flex: 0 1 auto;
}

.timer {
    font-size: var(--fs-md);
    font-weight: bold;
    color: #FF6B6B;
    text-align: center;
    flex: 1 1 auto;
}

.timer.warning {
    animation: timer-warning 1s infinite;
}

@keyframes timer-warning {
    0%, 100% {
        color: #FF6B6B;
    }
    50% {
        color: #FF0000;
        transform: scale(1.1);
    }
}

.game-controls {
    display: flex;
    gap: 0.7vw;
    flex: 0 1 auto;
}

.game-content {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    width: 100%;
    height: 100%;
    min-height: 0;
    max-width: 100%;
    max-height: 100%;
    overflow: hidden;
    box-sizing: border-box;
    padding: 0.5vh;
    align-items: center;
}

.items-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-auto-rows: minmax(12vh, 1fr);
    gap: 0.7vw;
    width: 100%;
    max-width: 90vw;
    align-content: start;
    padding: 1vh;
    box-sizing: border-box;
    overflow-y: auto;
    max-height: 100%;
    -webkit-overflow-scrolling: touch;
}

.item-card {
    background: rgba(255, 255, 255, 0.9);
    color: #333;
    border-radius: 1.1vw;
    text-align: center;
    cursor: pointer;
    box-shadow: 0 0.4vh 0.7vh rgba(0, 0, 0, 0.2);
    position: relative;
    overflow: hidden;
    border: 0.3vw solid #CCC;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0.5vh;
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    min-height: 12vh;
    transition: transform 0.2s, box-shadow 0.2s;
}

.item-card:hover {
    transform: translateY(-0.5vh);
    box-shadow: 0 0.7vh 1.5vh rgba(0, 0, 0, 0.3);
}

.item-card.purchased {
    opacity: 0.6;
    transform: scale(0.95);
    cursor: not-allowed;
    pointer-events: none;
}

.item-card.purchased:hover {
    transform: scale(0.95);
}

.item-icon {
    font-size: 4vh;
    margin-bottom: 0.5vh;
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 0 0 auto;
    filter: drop-shadow(0.2vw 0.2vw 0.4vw rgba(0, 0, 0, 0.1));
}

.item-name {
    font-size: var(--fs-xxs);
    font-weight: bold;
    margin: 0.3vh 0;
    line-height: 1.2;
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.item-price {
    font-size: var(--fs-xxs);
    font-weight: 700;
    color: #2E8B57;
    margin: 0.3vh 0;
    flex: 0 0 auto;
}

.purchased-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(34, 139, 34, 0.9);
    color: white;
    padding: 0.7vh 1.5vw;
    border-radius: 1.8vw;
    font-weight: bold;
    font-size: var(--fs-md);
}

/* Common button styles */
.start-btn {
    background: linear-gradient(45deg, #4ECDC4, #44A08D);
    border: none;
    color: white;
    padding: clamp(0.9vh, 2vh, 1.4vh) clamp(1.5vw, 3vw, 2.8vw);
    font-size: var(--fs-md);
    border-radius: 2.3vw;
    cursor: pointer;
    box-shadow: 0 0.4vh 1.4vh rgba(0, 0, 0, 0.2);
    transition: transform 0.2s;
    margin: clamp(0.7vh, 2vh, 1.8vh) 0.5vw;
}

.replay-btn {
    background: linear-gradient(45deg, #FF6B6B, #4ECDC4);
    border: none;
    color: white;
    padding: clamp(0.7vh, 1.5vh, 1.1vh) clamp(1.2vw, 3vw, 2.2vw);
    font-size: var(--fs-xs);
    border-radius: 2.3vw;
    cursor: pointer;
    margin: 0.35vh;
    box-shadow: 0 0.4vh 1.1vh rgba(0, 0, 0, 0.2);
    transition: transform 0.2s;
    justify-self: center;
    width: max-content;
    place-self: center;
    white-space: nowrap;
    flex-shrink: 1;
}

.back-btn {
    background: linear-gradient(45deg, #6c757d, #495057);
    border: none;
    color: white;
    padding: clamp(0.7vh, 1.5vh, 1.1vh) clamp(1.2vw, 3vw, 2.2vw);
    font-size: var(--fs-xs);
    border-radius: 1.8vw;
    cursor: pointer;
    box-shadow: 0 0.4vh 1.1vh rgba(0, 0, 0, 0.2);
    transition: transform 0.2s;
    white-space: nowrap;
    flex-shrink: 1;
}

.done-btn {
    background: linear-gradient(45deg, #32CD32, #228B22);
    border: none;
    color: white;
    padding: 0.7vh 1.8vw;
    font-size: var(--fs-xs);
    border-radius: 3vw;
    cursor: pointer;
    box-shadow: 0 0.4vh 1.1vh rgba(0, 0, 0, 0.2);
    transition: transform 0.2s;
    white-space: nowrap;
}

.pause-btn {
    background: linear-gradient(45deg, #4ECDC4, #44A08D);
    border: none;
    color: white;
    padding: 0;
    width: 3.8vh;
    height: 3.8vh;
    min-width: 3.8vh;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0.4vh 1.1vh rgba(0, 0, 0, 0.2);
    transition: transform 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: var(--fs-sm);
}

.game-buttons {
    display: flex;
    gap: clamp(0.5vw, 1.5vw, 1.1vw);
    justify-content: center;
    align-items: center;
    flex-wrap: nowrap;
    padding: 0.2vh 0.5vw;
    width: 100%;
    min-height: 5vh;
}

.game-buttons .replay-btn,
.game-buttons .back-btn {
    padding: clamp(0.7vh, 1.5vh, 1.1vh) clamp(1.2vw, 3vw, 2.2vw);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0.35vh;
}

.start-btn:hover, .replay-btn:hover, .back-btn:hover, .done-btn:hover, .pause-btn:hover {
    transform: translateY(-0.3vh);
    box-shadow: 0 0.9vh 2.6vh rgba(0, 0, 0, 0.3);
}

.start-btn:active, .replay-btn:active, .back-btn:active, .done-btn:active, .pause-btn:active {
    transform: translateY(0);
}

/* Game Over Screen */
.game-over-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(0.7vw);
    -webkit-backdrop-filter: blur(0.7vw);
}

.game-over-screen {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 1.8vw;
    padding: 3vh 2vw;
    box-shadow: 0 1.8vh 3.5vh rgba(0, 0, 0, 0.3);
    border: 0.3vw solid rgba(255, 255, 255, 0.2);
    max-width: 80vw;
    text-align: center;
    color: white;
}

.game-over-screen h2 {
    font-size: var(--fs-2xl);
    margin-bottom: 2vh;
    text-shadow: 0.2vw 0.2vw 0.4vw rgba(0, 0, 0, 0.3);
}

.game-over-screen.win h2 {
    color: #32CD32;
}

.game-over-screen.lose h2 {
    color: #FF6B6B;
}

.game-message {
    font-size: var(--fs-md);
    font-weight: bold;
    margin-bottom: 2.8vh;
    padding: 1.8vh;
    border-radius: 0.9vw;
    background: rgba(255, 255, 255, 0.1);
    line-height: 1.5;
}

.final-stats p {
    font-size: var(--fs-md);
    margin-bottom: 0.9vh;
}

.game-over-buttons {
    display: flex;
    gap: clamp(0.5vw, 1.5vw, 1.1vw);
    justify-content: center;
    margin-top: 2.8vh;
    flex-wrap: wrap;
}

.game-over-buttons .start-btn,
.game-over-buttons .back-btn {
    margin: 0.35vh;
}

/* Pause Popup Styles */
.pause-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(0.5vw);
}

.pause-popup {
    background: linear-gradient(135deg, #2E8B57 0%, #3CB371 100%);
    border-radius: 1.8vw;
    padding: 0;
    box-shadow: 0 1.8vh 3.5vh rgba(0, 0, 0, 0.3);
    border: 0.3vw solid rgba(255, 255, 255, 0.2);
    max-width: 46vw;
    width: 90%;
    max-height: 90vh;
    overflow: hidden;
    animation: popup-appear 0.3s ease-out;
}

@keyframes popup-appear {
    from {
        opacity: 0;
        transform: scale(0.8) translateY(-4.5vh);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.pause-popup-header {
    background: rgba(255, 255, 255, 0.1);
    padding: 1.8vh 2.3vw;
    border-bottom: 0.2vh solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.pause-popup-header .stat-value {
    font-size: var(--fs-md);
    color: white;
    font-weight: bold;
}

.close-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 3.2vh;
    height: 3.2vh;
    border-radius: 50%;
    cursor: pointer;
    font-size: var(--fs-md);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.pause-popup-content {
    padding: 2.3vh;
    color: white;
    overflow: auto;
}

.pause-stats {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 1.4vw;
    padding: 1.8vh;
    margin-bottom: 2.3vh;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.7vh 0;
    border-bottom: 0.1vh solid rgba(255, 255, 255, 0.1);
}

.stat-item:last-child {
    border-bottom: none;
}

.stat-value {
    font-weight: bold;
    color: #FFD700;
    font-size: var(--fs-sm);
}

.pause-popup-actions {
    display: flex;
    gap: 1.4vw;
    justify-content: center;
    flex-wrap: wrap;
}

.resume-btn-popup {
    background: linear-gradient(45deg, #00CED1, #008B8B);
    color: white;
    border: none;
    padding: 1.4vh 2.3vw;
    border-radius: 4.5vw;
    font-size: var(--fs-md);
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 0.4vh 1.1vh rgba(0, 206, 209, 0.3);
    display: flex;
    align-items: center;
    gap: 0.7vw;
    min-width: 13vw;
    justify-content: center;
    transition: transform 0.2s;
}

.resume-btn-popup:hover {
    background: linear-gradient(45deg, #008B8B, #006666);
    transform: translateY(-0.2vh) scale(1.05);
    box-shadow: 0 0.5vh 1.5vh rgba(0, 206, 209, 0.4);
}
