* {
    box-sizing: border-box;
}

body {
    /* A nice font that uses a user's built in font */
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    color: #333;
    margin: 0;
    padding: 0;
    overflow-x: hidden;
}

.navbar {
    border-bottom: 2px solid #333;
    padding: 15px;
    text-align: center;
    margin-bottom: 0;
}

.brand {
    font-size: 40px;
}

.scoreboard {
    max-width: 295px;
    width: 100%;
    margin: 10px auto;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
    row-gap: 10px;
    column-gap: 5px;
}

.scoreboard-letter {
    height: 50px;
    width: 50px;
    border-radius: 5px;
    font-size: 30px;
    text-transform: uppercase;
    border: 3px solid #ccc;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
}

.correct {
    background-color: darkgreen;
    color: white;
} 

.close {
  background-color: goldenrod;
  color: white;
}

.wrong {
    background-color: #888;
    color: white;
}

.invalid {
    animation: flash 1s;
}

/* Flashes red border and then fades back to grey */

@keyframes flash {
    5% {
        border-color: crimson;
    }

    100% {
        border-color: #ccc;
    }
}

.spiral {
    font-size: 50px;
    animation: spin 1.5s linear infinite;
}

/* Rotates clockwise indefinitely*/
@keyframes spin {
    to {
        transform: rotate(350deg);
    }
}

/* Visibility hidden means the items is still there and taking  up space but just not shown. display: none doesn't take up space */
.info-bar {
    visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.show {
    visibility: visible;
}

/* winner animation */

@keyframes rainbow {
  100%,
  0% {
    color: rgb(255, 0, 0);
  }
  8% {
    color: rgb(255, 127, 0);
  }
  16% {
    color: rgb(255, 255, 0);
  }
  25% {
    color: rgb(127, 255, 0);
  }
  33% {
    color: rgb(0, 255, 0);
  }
  41% {
    color: rgb(0, 255, 127);
  }
  50% {
    color: rgb(0, 255, 255);
  }
  58% {
    color: rgb(0, 127, 255);
  }
  66% {
    color: rgb(0, 0, 255);
  }
  75% {
    color: rgb(127, 0, 255);
  }
  83% {
    color: rgb(255, 0, 255);
  }
  91% {
    color: rgb(255, 0, 127);
  }
}

.winner {
  animation: rainbow 4s infinite linear;
}

.keyboard {
    margin: 20px auto;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Hide keyboard by default */
.keyboard {
    display: none;
}

/* Show keyboard only on mobile screens */
@media (max-width: 600px) {
  .scoreboard {
    max-width: 300px;
    width: 100%;
    margin: 15px 15;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
    row-gap: 10px;
    column-gap: 5px;
}

    .scoreboard-letter {
        height: 44px;    /* increased from 32px */
        width: 44px;     /* increased from 32px */
        font-size: 28px; /* increased from 18px */
        border-radius: 6px;
    }
    
    .keyboard {
        display: flex;
        flex-direction: column;
        width: 100vw;
        max-width: 100vw;
        padding: 0 2vw 2vw 2vw; /* reduced side and bottom padding */
        box-sizing: border-box;
        gap: 4px; /* reduced gap between rows */
        align-items: center;
        background: transparent;
        position: fixed;
        left: 0;
        bottom: 0;
        z-index: 100;
    }
    .keyboard-row {
        display: flex;
        justify-content: center;
        width: 100%;
        gap: 2px; /* reduced gap between keys */
    }
    .key, .key-action {
        flex: 1 1 0;
        min-width: 0;
        padding: 10px 0; /* slightly reduced vertical padding */
        font-size: 1rem;
        border-radius: 6px;
        margin: 0;
        box-sizing: border-box;
    }
    .key-action {
        flex: 1.2 1 0;
    }
}

.key {
    padding: 10px 0;
    width: 32px;
    font-size: 1.1rem;
    border: 1px solid #bbb;
    border-radius: 6px;
    background: #f8f8f8;
    font-weight: bold;
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
}

.key:active {
    background: #ddd;
}

.key-action {
    width: 50px;
    font-size: 1rem;
}

@media (max-width: 600px) {
    .navbar {
        padding: 10px;
    }
    .brand {
        font-size: 28px;
    }
    .scoreboard {
        max-width: 98vw;
        width: 100vw;
        margin: 16px auto 120px auto; /* extra bottom margin for keyboard */
        display: grid;
        grid-template-columns: repeat(5, 1fr);
        row-gap: 12px;
        column-gap: 8px;
        justify-items: center;
        align-items: center;
    }
    .scoreboard-letter {
        height: 54px;      /* medium size */
        width: 54px;
        font-size: 32px;
        border-radius: 8px;
        background: #222;
        color: #eee;
        border: 3px solid #444;
        display: flex;
        align-items: center;
        justify-content: center;
        margin: 0;
    }
    .spiral {
        font-size: 32px;
    }
    .info-bar {
        font-size: 1rem;
        padding: 6px;
    }
    .keyboard {
        display: flex;
        flex-direction: column;
        width: 100vw;
        max-width: 100vw;
        padding: 0 2vw 2vw 2vw;
        box-sizing: border-box;
        gap: 4px;
        align-items: center;
        background: transparent;
        position: fixed;
        left: 0;
        bottom: 0;
        z-index: 100;
    }
    .keyboard-row {
        display: flex;
        justify-content: center;
        width: 100%;
        gap: 2px;
    }
    .key, .key-action {
        flex: 1 1 0;
        min-width: 0;
        padding: 12px 0;
        font-size: 1.1rem;
        border-radius: 6px;
        margin: 0;
        box-sizing: border-box;
    }
    .key-action {
        flex: 1.2 1 0;
    }
}

.key {
    padding: 10px 0;
    width: 32px;
    font-size: 1.1rem;
    border: 1px solid #bbb;
    border-radius: 6px;
    background: #f8f8f8;
    font-weight: bold;
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
}

.key:active {
    background: #ddd;
}

.key-action {
    width: 50px;
    font-size: 1rem;
}

@media (max-width: 600px) {
    .navbar {
        padding: 10px;
    }
    .brand {
        font-size: 28px;
    }
    .scoreboard {
        max-width: 98vw;
        width: 100vw;
        margin: 16px auto 120px auto; /* extra bottom margin for keyboard */
        display: grid;
        grid-template-columns: repeat(5, 1fr);
        row-gap: 12px;
        column-gap: 8px;
        justify-items: center;
        align-items: center;
    }
    .scoreboard-letter {
        height: 54px;      /* medium size */
        width: 54px;
        font-size: 32px;
        border-radius: 8px;
        background: #222;
        color: #eee;
        border: 3px solid #444;
        display: flex;
        align-items: center;
        justify-content: center;
        margin: 0;
    }
    .spiral {
        font-size: 32px;
    }
    .info-bar {
        font-size: 1rem;
        padding: 6px;
    }
    .keyboard {
        display: flex;
        flex-direction: column;
        width: 100vw;
        max-width: 100vw;
        padding: 0 2vw 2vw 2vw;
        box-sizing: border-box;
        gap: 4px;
        align-items: center;
        background: transparent;
        position: fixed;
        left: 0;
        bottom: 0;
        z-index: 100;
    }
    .keyboard-row {
        display: flex;
        justify-content: center;
        width: 100%;
        gap: 2px;
    }
    .key, .key-action {
        flex: 1 1 0;
        min-width: 0;
        padding: 12px 0;
        font-size: 1.1rem;
        border-radius: 6px;
        margin: 0;
        box-sizing: border-box;
    }
    .key-action {
        flex: 1.2 1 0;
    }
}

/* Dark mode styles */
body.dark-mode {
    background: #181818;
    color: #eee;
}

body.dark-mode .navbar {
    border-bottom: 2px solid #eee;
}

body.dark-mode .scoreboard-letter {
    background: #222;
    border-color: #444;
    color: #eee;
}

body.dark-mode .keyboard {
    background: #222;
}

body.dark-mode .key {
    background: #333;
    color: #eee;
    border-color: #555;
}

body.dark-mode .key:active {
    background: #444;
}

body.dark-mode .correct {
    background-color: #228B22;
    color: #fff;
}

body.dark-mode .close {
    background-color: #b8860b;
    color: #fff;
}

body.dark-mode .wrong {
    background-color: #555;
    color: #fff;
}