html {
    height: 100%;
}

:root {
    --peg-size: 5vmin;
    --feedback-peg-size: 1vmin;
    --font-size: 1.5rem;
}

/* ... other styles ... */

.feedback-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.2vh;
    background-color: #6B4226;
    padding: 0.5vh;
    border-radius: 5px;
    width: calc(var(--peg-size) * 0.8);
    height: calc(var(--peg-size) * 0.8);
    place-items: center;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #2c2c2c 0%, #1a1a1a 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    margin: 0;
}

#game-container {
    background-color: #8B4513; /* SaddleBrown */
    border: 10px solid #A0522D; /* Sienna */
    border-radius: 20px;
    padding: 1rem;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.5), inset 0 0 10px rgba(0,0,0,0.5);
    text-align: center;
    width: 90%;
    max-width: 500px;
    height: 95vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    margin: auto;
}

.hidden {
    display: none;
}

#difficulty-selection {
    margin: auto;
}

#difficulty-selection h2 {
    color: #FFD700;
    font-size: 2.5rem;
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.8), 0 0 20px rgba(255, 215, 0, 0.3);
    margin-bottom: 1rem;
    font-weight: bold;
    letter-spacing: 2px;
}

#difficulty-selection p {
    color: #F0E68C;
    font-size: 1.3rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.6);
    margin-bottom: 1.5rem;
    font-weight: 500;
}

#difficulty-selection button {
    padding: 15px 30px;
    font-size: var(--font-size);
    margin: 10px;
    cursor: pointer;
    border: 3px solid #FFD700;
    border-radius: 12px;
    background: linear-gradient(145deg, #E6994A, #CD853F);
    color: white;
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
    box-shadow: 0 4px 8px rgba(0,0,0,0.4), inset 0 1px 2px rgba(255,255,255,0.3);
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: rgba(255, 215, 0, 0.3);
}

@media (hover: hover) {
    #difficulty-selection button:hover {
        background: linear-gradient(145deg, #F4A460, #E6994A);
        transform: translateY(-2px);
        box-shadow: 0 6px 12px rgba(0,0,0,0.5), inset 0 1px 2px rgba(255,255,255,0.4);
    }
}

#difficulty-selection button:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0,0,0,0.4);
}

#game-board {
    display: flex;
    flex-direction: column;
    gap: 1.5vh;
    flex-grow: 1;
    min-height: 0;
}

#secret-code-area {
    background-color: #6B2E00;
    padding: 1vh;
    border-radius: 10px;
}

#secret-code-area h3 {
    color: #FFD700;
    margin: 0 0 1vh 0;
    font-size: calc(var(--font-size) * 0.9);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8), 0 0 10px rgba(255, 215, 0, 0.2);
    font-weight: bold;
    letter-spacing: 1px;
}

#secret-code {
    display: flex;
    justify-content: center;
    gap: 1.5vh;
    background-color: #4A2500;
    padding: 1vh;
    border-radius: 5px;
}

#guesses-container {
    display: flex;
    flex-direction: column-reverse;
    gap: 1vh;
    overflow-y: auto;
    flex-grow: 1;
    align-items: center;
    -webkit-overflow-scrolling: touch; /* iOS momentum scrolling */
}

.guess-row {
    display: flex;
    gap: 1.5vh;
    align-items: center;
    background-color: #A0522D;
    padding: 1vh;
    border-radius: 10px;
    flex-shrink: 0;
}

.guess-pegs {
    display: flex;
    gap: 1.5vh;
}

.peg {
    width: var(--peg-size);
    height: var(--peg-size);
    border-radius: 50%;
    background-color: #6B4226; /* Darker wood color for empty hole */
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.6);
    cursor: pointer;
}

#color-palette {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.5vh;
    padding: 1.5vh;
    margin-top: 1.5vh;
    background-color: #6B2E00;
    border-radius: 10px;
}

.color-pegs-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5vh;
    justify-content: center;
}

.buttons-wrapper {
    display: flex;
    flex-direction: column;
    gap: 1vh;
}

.buttons-wrapper button {
    padding: 12px 20px;
    min-height: 44px; /* Mobile tap target minimum */
    font-size: calc(var(--font-size) * 0.7);
    border: 2px solid #FFD700;
    border-radius: 8px;
    background: linear-gradient(145deg, #E6994A, #CD853F);
    color: white;
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
    box-shadow: 0 2px 4px rgba(0,0,0,0.3), inset 0 1px 2px rgba(255,255,255,0.2);
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: rgba(255, 215, 0, 0.3);
}

@media (hover: hover) {
    .buttons-wrapper button:hover {
        background: linear-gradient(145deg, #F4A460, #E6994A);
        transform: translateY(-1px);
        box-shadow: 0 3px 6px rgba(0,0,0,0.4);
    }
}

.buttons-wrapper button:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.color-peg {
    width: var(--peg-size);
    height: var(--peg-size);
    min-width: 44px; /* Mobile tap target minimum */
    min-height: 44px; /* Mobile tap target minimum */
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3), inset 0 -2px 3px rgba(0,0,0,0.4);
    transition: transform 0.1s;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: rgba(255, 215, 0, 0.3);
}

@media (hover: hover) {
    .color-peg:hover {
        transform: scale(1.1);
    }
}

.feedback-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5vh;
    background-color: #6B4226;
    padding: 0.5vh;
    border-radius: 5px;
    width: calc(var(--peg-size) * 0.8);
    height: calc(var(--peg-size) * 0.8);
}

.feedback-peg {
    width: var(--feedback-peg-size);
    height: var(--feedback-peg-size);
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.2);
    box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.3), 0 1px 1px rgba(0, 0, 0, 0.2);
}

.black-peg {
    background-color: black;
}

.white-peg {
    background-color: white;
}

#win-message, #lose-message {
    margin: auto;
    color: white;
}

#win-message h2 {
    color: #FFD700;
    font-size: 3rem;
    text-shadow: 3px 3px 8px rgba(0, 0, 0, 0.8), 0 0 30px rgba(255, 215, 0, 0.5);
    margin-bottom: 1.5rem;
    font-weight: bold;
    letter-spacing: 3px;
    animation: pulse 1.5s ease-in-out infinite;
}

#lose-message h2 {
    color: #FF6347;
    font-size: 2.5rem;
    text-shadow: 3px 3px 8px rgba(0, 0, 0, 0.8), 0 0 20px rgba(255, 99, 71, 0.3);
    margin-bottom: 1rem;
    font-weight: bold;
    letter-spacing: 2px;
}

#lose-message p {
    color: #F0E68C;
    font-size: 1.2rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.6);
    margin: 1rem 0;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

#play-again-btn, #play-again-btn-lose {
    padding: 15px 30px;
    font-size: var(--font-size);
    cursor: pointer;
    border: 3px solid #FFD700;
    border-radius: 12px;
    background: linear-gradient(145deg, #E6994A, #CD853F);
    color: white;
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
    box-shadow: 0 4px 8px rgba(0,0,0,0.4), inset 0 1px 2px rgba(255,255,255,0.3);
    margin-top: 20px;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: rgba(255, 215, 0, 0.3);
}

@media (hover: hover) {
    #play-again-btn:hover, #play-again-btn-lose:hover {
        background: linear-gradient(145deg, #F4A460, #E6994A);
        transform: translateY(-2px);
        box-shadow: 0 6px 12px rgba(0,0,0,0.5), inset 0 1px 2px rgba(255,255,255,0.4);
    }
}

#play-again-btn:active, #play-again-btn-lose:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0,0,0,0.4);
}

#reveal-code {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 10px;
}

#nav-buttons {
    display: flex;
    justify-content: flex-start;
    margin-bottom: 1rem;
}

.back-button {
    display: inline-block;
    padding: 14px 24px;
    min-height: 44px; /* Mobile tap target minimum */
    background: linear-gradient(145deg, #E6994A, #CD853F);
    color: white;
    text-decoration: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: bold;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    border: 2px solid #FFD700;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
    box-shadow: 0 3px 6px rgba(0,0,0,0.3), inset 0 1px 2px rgba(255,255,255,0.2);
    transition: all 0.2s ease;
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(255, 215, 0, 0.3);
}

@media (hover: hover) {
    .back-button:hover {
        background: linear-gradient(145deg, #F4A460, #E6994A);
        transform: translateY(-2px);
        box-shadow: 0 5px 10px rgba(0,0,0,0.4);
    }
}

.back-button:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

/* For smaller screens - ensure minimum tap target size */
@media (max-height: 700px) {
    :root {
        --peg-size: 44px; /* Fixed size to meet mobile tap target minimum */
        --feedback-peg-size: 1.2vh;
        --font-size: 1.2rem;
    }
}

/* For very small screens */
@media (max-height: 600px) {
    :root {
        --peg-size: 40px;
        --feedback-peg-size: 1vh;
        --font-size: 1rem;
    }

    #game-container {
        height: 98vh;
        padding: 0.5rem;
    }
}

/* Landscape orientation - optimize for horizontal space */
@media (max-height: 700px) and (orientation: landscape) {
    #game-container {
        max-width: 90vw;
        height: 95vh;
    }

    #difficulty-selection h2 {
        font-size: 2rem;
        margin-bottom: 0.5rem;
    }

    #difficulty-selection p {
        font-size: 1rem;
        margin-bottom: 1rem;
    }

    #difficulty-selection button {
        padding: 10px 20px;
        margin: 5px;
        font-size: 1rem;
    }

    #secret-code-area {
        padding: 0.5vh;
    }

    #guesses-container {
        gap: 0.8vh;
    }

    .guess-row {
        padding: 0.5vh;
    }
}

/* Tablet landscape */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
    #game-container {
        max-width: 600px;
    }
}