* {
    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: 5vh;
    --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;
    /* max-width: 65vw; */
}

.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;
}

/* When the game section is shown we'll use a three-row grid: top / canvas / bottom */
.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: 98dvh;
    width: 100%;
    display: grid;
    grid-template-rows: 7vh 3.5vh 0.9fr 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;
}

.game-info {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0;
    font-size: var(--fs-md);
    font-weight: bold;
    flex-wrap: wrap;
    gap: 1.1vw;
    width: 65vw;
    align-items: center;
    justify-self: center;
}

.score, .timer {
    background: rgba(255, 255, 255, 0.2);
    padding: 0.5vh 1vw;
    border-radius: 0.7vw;
    border: 0.2vh solid #FFD700;
    flex: 1;
    min-width: 8vw;
    font-size: var(--fs-xs);
}

.score span, .timer span {
    font-weight: 800;
}

.canvas-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 65vw;
    height: 100%;
    min-height: 0;
    max-width: 100%;
    max-height: 100%;
    overflow: hidden;
    box-sizing: border-box;
    justify-self: center;
    padding: 0;
}

#gameCanvas {
    border: 0.3vw solid #FFD700;
    border-radius: 1.1vw;
    background: #2C3E50;
    display: block;
    box-shadow: 0 0.4vh 0.7vh rgba(0, 0, 0, 0.3);
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    cursor: pointer;
    box-sizing: border-box;
}

.controls {
    font-size: var(--fs-sm);
}

.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, #667eea, #764ba2);
    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;
}

.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 {
    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 {
    transform: translateY(0);
}

/* Touch Controls */
.touch-controls {
    position: fixed;
    bottom: 8vh;
    right: 2vw;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5vh;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.game-section.show .touch-controls {
    opacity: 1;
    pointer-events: auto;
}

.touch-middle {
    display: flex;
    gap: 0.5vh;
    align-items: center;
}

.touch-btn {
    width: 7vh;
    height: 7vh;
    border: 0.3vh solid rgba(255, 215, 0, 0.8);
    border-radius: 1.5vh;
    background: linear-gradient(135deg, rgba(78, 205, 196, 0.9), rgba(68, 160, 141, 0.9));
    color: white;
    font-size: 4vh;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 0.4vh 1.1vh rgba(0, 0, 0, 0.3);
    transition: all 0.1s ease;
    touch-action: manipulation;
}

.touch-btn:active {
    transform: scale(0.95);
    background: linear-gradient(135deg, rgba(68, 160, 141, 0.9), rgba(78, 205, 196, 0.9));
    box-shadow: 0 0.2vh 0.5vh rgba(0, 0, 0, 0.3);
}

/* Hide touch controls on non-touch devices (optional) */
@media (hover: hover) and (pointer: fine) {
    .touch-controls {
        display: none;
    }
}