@import url('https://fonts.googleapis.com/css2?family=Londrina+Solid:wght@400;900&display=swap');

:root {
    --bg: #444444;
    --gold: #f5c978;
    --cream: #fbebcd;
    --cream-dark: #f3d9a8;
    --ink: #444444;
    --orange: #ff6a00;
    --green: #6aaa64;
    --present: #ff9a3c;
    --absent: #8a8a8a;
    --track: #5a5a5a;
    --display: 'Londrina Solid', Impact, 'Arial Narrow Bold', sans-serif;

    /* sizes that shrink on short screens so everything fits without scrolling */
    --btn: clamp(46px, 8vh, 72px);
    --key: clamp(38px, 7.5vh, 64px);
    --gap: 10px;
    --pad: 20px;
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;

    /* page = exactly one screen tall; scroll only if the screen is tiny */
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow-y: auto;

    font-family: var(--display);
    background: var(--bg);
    color: var(--cream);
}


/* HEADER */

header {
    flex: none;
    height: clamp(66px, 12vh, 130px);

    display: flex;
    align-items: center;
    justify-content: center;

    border-bottom: 1px solid #555;
}

.logo {
    display: flex;
    align-items: center;
    gap: 24px;

    color: var(--gold);
    font-size: clamp(34px, 7vh, 64px);
    font-weight: 900;
    line-height: 1;
}

.logo-icon {
    width: clamp(40px, 8vh, 72px);
    height: clamp(40px, 8vh, 72px);
    object-fit: contain;
}


/* MAIN GAME: fills the rest of the screen */

main {
    flex: 1;
    min-height: 0;

    display: flex;
    flex-direction: column;

    width: 100%;
    padding: clamp(10px, 2vh, 24px) 24px clamp(8px, 1.5vh, 20px);
}


/* TOP BAR
   left  = import + subject (always far left)
   middle = question (always centered)
   right = hint + how to play (always far right) */

.top-bar {
    flex: none;

    display: grid;
    grid-template-columns: 1fr min(900px, calc(100vw - 48px - 660px)) 1fr;
    align-items: center;

    margin-bottom: clamp(10px, 2vh, 28px);
}

.top-left,
.top-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.top-left {
    justify-self: start;
}

.top-right {
    justify-self: end;
}

.round-button {
    width: var(--btn);
    height: var(--btn);

    border: none;
    border-radius: 50%;

    background: var(--gold);
    color: var(--ink);

    font-family: var(--display);
    font-size: calc(var(--btn) * 0.55);
    font-weight: 900;

    cursor: pointer;

    display: flex;
    align-items: center;
    justify-content: center;
}

.round-button svg {
    width: 52%;
    height: 52%;
}

.pill-button {
    height: var(--btn);
    padding: 0 calc(var(--btn) * 0.55);

    border: none;
    border-radius: 999px;

    background: var(--gold);
    color: var(--ink);

    font-family: var(--display);
    font-size: calc(var(--btn) * 0.55);
    font-weight: 900;

    cursor: pointer;
}

.round-button:hover,
.pill-button:hover {
    filter: brightness(1.08);
}

.question-bar {
    min-height: var(--btn);

    padding: 8px 32px;

    background: var(--cream);
    color: var(--ink);

    border-radius: calc(var(--btn) / 2);

    display: flex;
    align-items: center;
    justify-content: center;

    text-align: center;

    font-size: clamp(18px, 3.6vh, 30px);
    line-height: 1.15;
}


/* BOARD
   The area between the top bar and the keyboard is the "board-area".
   The tiles are sized from that area, so the board always fits. */

.board-area {
    flex: 1 1 0;
    min-height: 150px;

    container-type: size;

    display: flex;
    align-items: center;
    justify-content: center;
}

#board {
    --cols: 5;

    /* tile size = smallest of: 64px, what fits the width, what fits the height */
    --tile: max(
        22px,
        min(
            64px,
            calc((100cqw - 2 * var(--pad) - (var(--cols) - 1) * var(--gap)) / var(--cols)),
            calc((100cqh - 2 * var(--pad) - 4 * var(--gap)) / 5)
        )
    );

    width: calc(var(--cols) * var(--tile) + (var(--cols) - 1) * var(--gap) + 2 * var(--pad));
    flex: none;

    padding: var(--pad);

    background: var(--gold);
    border-radius: 14px;

    display: flex;
    flex-direction: column;
    gap: var(--gap);
}

.row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: var(--gap);
}

.tile {
    aspect-ratio: 1;

    border: none;
    border-radius: 8px;

    display: flex;
    align-items: center;
    justify-content: center;

    font-size: calc(var(--tile) * 0.6);
    font-weight: 900;

    text-transform: uppercase;

    color: var(--ink);
    background: var(--cream);
}

.tile.filled {
    background: var(--cream-dark);
}

.tile.correct {
    background: var(--green);
    color: white;
}

.tile.present {
    background: var(--present);
    color: white;
}

.tile.absent {
    background: var(--absent);
    color: white;
}


/* KEYBOARD */

#keyboard {
    flex: none;

    width: 100%;
    max-width: 760px;

    margin: clamp(8px, 2vh, 24px) auto 0;

    display: flex;
    flex-direction: column;
    gap: clamp(5px, 1vh, 10px);
}

.key-row {
    display: flex;
    justify-content: center;
    gap: clamp(5px, 1vh, 10px);
}

.key {
    height: var(--key);

    flex: 1;
    max-width: 64px;

    border: none;
    border-radius: 8px;

    background: var(--cream);
    color: var(--ink);

    font-family: var(--display);
    font-size: calc(var(--key) * 0.47);
    font-weight: 900;

    cursor: pointer;

    text-transform: uppercase;
}

.key:hover {
    filter: brightness(0.95);
}

.key.wide {
    max-width: 96px;
    flex: 1.5;
}

.key.correct {
    background: var(--green);
    color: white;
}

.key.present {
    background: var(--present);
    color: white;
}

.key.absent {
    background: var(--absent);
    color: white;
}


/* MESSAGE */

#message {
    flex: none;

    text-align: center;

    margin-top: 6px;

    font-size: 22px;
    font-weight: 900;

    min-height: 26px;
}


/* PROGRESS BAR (bottom, centered) */

.progress-wrap {
    flex: none;

    position: relative;

    width: 100%;
    max-width: 760px;
    height: 60px;

    margin: 0 auto;
}

.progress-track {
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;

    height: 20px;
    transform: translateY(-50%);

    background: var(--track);
    border-radius: 999px;

    overflow: hidden;
}

#progressBar {
    height: 100%;
    width: 30px;

    background: var(--gold);
    border-radius: 999px;

    transition: width 0.6s ease;
}

#train {
    position: absolute;
    left: 0;
    top: 50%;

    width: 60px;
    height: 60px;

    transform: translateY(-50%);
    transition: left 0.6s ease;

    display: flex;
    align-items: center;
    justify-content: center;
}

#train img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* shown only if images/train.png is missing */
#train.emoji::after {
    content: "🚂";
    font-size: 44px;
}


/* POPUPS */

.popup-page {
    display: none;

    position: fixed;
    top: 0;
    left: 0;

    width: 100%;
    height: 100%;

    background: rgba(0, 0, 0, 0.7);

    align-items: center;
    justify-content: center;

    z-index: 100;
}

.popup {
    width: 90%;
    max-width: 450px;
    max-height: 90vh;
    overflow-y: auto;

    background: var(--cream);
    color: var(--ink);

    padding: 30px;

    border-radius: 14px;

    text-align: center;

    position: relative;

    font-size: 22px;

    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

.popup h2 {
    margin-top: 0;

    font-size: 44px;
    font-weight: 900;
    color: var(--orange);
}

.popup .small {
    font-size: 20px;
}

.close-button {
    position: absolute;

    right: 15px;
    top: 15px;

    border: none;

    background: transparent;
    color: var(--ink);

    font-family: var(--display);
    font-size: 26px;
    font-weight: 900;

    cursor: pointer;
}


/* IMPORT FORM */

#importText {
    width: 100%;

    padding: 10px;

    border: 2px solid var(--gold);
    border-radius: 10px;

    background: white;
    color: var(--ink);

    font-family: inherit;
    font-size: 18px;

    resize: vertical;
}

.file-label {
    display: block;
    margin: 14px 0 6px;
    font-size: 20px;
}

#importFile {
    max-width: 100%;
    font-family: inherit;
    font-size: 16px;
}

.error {
    min-height: 24px;
    margin: 10px 0 0;
    color: #b32020;
    font-size: 18px;
}


/* EXAMPLES */

.example {
    margin: 20px 0;
}

.example-row {
    display: flex;
    justify-content: center;
    gap: 8px;
}

.example-tile {
    width: 48px;
    height: 48px;

    border-radius: 8px;

    background: white;

    display: flex;
    align-items: center;
    justify-content: center;

    font-weight: 900;
    font-size: 26px;
}

.example-tile.correct {
    background: var(--green);
    color: white;
}

.example-tile.present {
    background: var(--present);
    color: white;
}


/* BUTTONS */

.main-button,
.secondary-button,
.difficulty-button {
    width: 100%;

    padding: 12px;
    margin-top: 10px;

    border: none;
    border-radius: 10px;

    font-family: var(--display);
    font-size: 26px;
    font-weight: 900;

    cursor: pointer;
}

.main-button {
    background: var(--ink);
    color: var(--cream);
}

.main-button:hover {
    background: #5a5a5a;
}

.secondary-button {
    background: var(--gold);
    color: var(--ink);
}

.difficulty-button {
    background: var(--ink);
    color: var(--cream);
}

.difficulty-button:hover {
    background: var(--orange);
    color: white;
}


/* SHORT SCREENS (laptops at 100% zoom) */

@media (max-height: 800px) {

    :root {
        --pad: 14px;
        --gap: 8px;
    }

    .progress-wrap {
        height: 50px;
    }

    #message {
        min-height: 20px;
        margin-top: 2px;
        font-size: 18px;
    }
}


/* NARROW SCREENS: question goes on its own row, still centered */

@media (max-width: 1050px) {

    .top-bar {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        gap: 12px;
    }

    .top-left,
    .top-right {
        gap: 12px;
    }

    .question-bar {
        order: 3;
        flex: 1 1 100%;
        padding: 8px 20px;
    }

    main {
        padding-left: 14px;
        padding-right: 14px;
    }

    .logo {
        gap: 12px;
    }
}

@media (max-width: 700px) {

    :root {
        --pad: 12px;
        --gap: 6px;
        --btn: 48px;
        --key: 46px;
    }

    .key-row {
        gap: 5px;
    }
}
