:root {
    --quest-ink: #101622;
    --quest-panel: rgba(13, 19, 31, 0.88);
    --quest-paper: #fff9e9;
    --quest-sky: #78c9ff;
    --quest-leaf: #8bd95e;
    --quest-gold: #ffd166;
    --quest-rose: #ff6b7a;
    --quest-violet: #7b61ff;
    --quest-line: rgba(255, 255, 255, 0.18);
}

.word-quest-page {
    min-height: 100vh;
    color: var(--quest-paper);
    background:
        linear-gradient(180deg, rgba(16, 22, 34, 0.76), rgba(16, 22, 34, 0.94)),
        url("../../gameress/craftpix-net-370528-free-medieval-ruins-cartoon-2d-tileset/PNG/Background/Background_01.png") center top / cover fixed no-repeat;
    overflow-x: hidden;
}

.quest-shell {
    width: min(100%, calc(var(--max) + 2.5rem));
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(18rem, 22rem);
    gap: 1rem;
    align-items: start;
    margin: 0 auto;
    padding: 7.7rem 1.25rem 3.5rem;
}

.quest-game-panel,
.quest-side-panel,
.design-grid article {
    border: 1px solid var(--quest-line);
    border-radius: 8px;
    background: var(--quest-panel);
    box-shadow: 0 26px 80px rgba(0, 0, 0, 0.34);
    backdrop-filter: blur(18px);
}

.quest-game-panel {
    overflow: hidden;
    min-width: 0;
}

.quest-game-head {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 1rem;
    align-items: start;
    padding: 1.1rem;
    border-bottom: 1px solid var(--quest-line);
    background:
        linear-gradient(135deg, rgba(120, 201, 255, 0.16), rgba(139, 217, 94, 0.11)),
        rgba(255, 255, 255, 0.035);
}

.quest-game-head h1 {
    margin: 0;
    font-size: clamp(2rem, 5.8vw, 4.4rem);
    line-height: 0.96;
    font-weight: 950;
}

.quest-game-head p:last-child {
    max-width: 47rem;
    margin: 0.75rem 0 0;
    color: rgba(255, 249, 233, 0.82);
}

.quest-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.65rem;
}

.phaser-wrap {
    position: relative;
    aspect-ratio: 16 / 9;
    min-height: 22rem;
    background: #0b1120;
    overflow: hidden;
}

#phaser-word-quest,
#phaser-word-quest canvas {
    width: 100%;
    height: 100%;
    display: block;
}

#phaser-word-quest canvas {
    image-rendering: pixelated;
}

.loading-cover {
    position: absolute;
    inset: 0;
    z-index: 7;
    display: grid;
    place-content: center;
    gap: 0.4rem;
    padding: 1rem;
    color: var(--quest-paper);
    text-align: center;
    background: rgba(9, 13, 23, 0.86);
}

.loading-cover span {
    color: rgba(255, 249, 233, 0.74);
    font-size: 0.92rem;
}

.loading-cover.is-hidden {
    display: none;
}

.quest-modal {
    position: absolute;
    inset: 0;
    z-index: 9;
    display: grid;
    place-items: center;
    padding: 1rem;
    background: rgba(8, 12, 20, 0.42);
}

.quest-modal[hidden] {
    display: none;
}

.quest-modal-card {
    width: min(36rem, 100%);
    max-height: 100%;
    overflow: auto;
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 8px;
    padding: 1rem;
    color: #141923;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(255, 249, 233, 0.96)),
        var(--quest-paper);
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
}

.quest-modal-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.quest-modal-top .section-kicker {
    color: #496500;
}

.quest-modal-top button {
    width: 2.35rem;
    height: 2.35rem;
    display: grid;
    place-items: center;
    color: #141923;
    border: 1px solid rgba(20, 25, 35, 0.16);
    border-radius: 6px;
    background: rgba(20, 25, 35, 0.05);
    cursor: pointer;
}

.quest-modal-top svg {
    width: 1.1rem;
    height: 1.1rem;
}

.quest-modal-card h2 {
    margin: 0.25rem 0 0.4rem;
    font-size: clamp(1.45rem, 4vw, 2.15rem);
    line-height: 1.05;
}

.quest-modal-card p {
    margin: 0;
    color: rgba(20, 25, 35, 0.78);
}

.quiz-answer-area {
    display: grid;
    gap: 0.65rem;
    margin-top: 1rem;
}

.answer-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.65rem;
}

.answer-button,
.chip-button,
.quiz-submit,
.spell-input {
    min-width: 0;
    border-radius: 6px;
    font-weight: 900;
}

.answer-button,
.chip-button,
.quiz-submit {
    min-height: 2.8rem;
    border: 1px solid rgba(20, 25, 35, 0.16);
    color: #141923;
    background: #ffffff;
    cursor: pointer;
}

.answer-button:hover,
.chip-button:hover,
.quiz-submit:hover {
    transform: translateY(-1px);
}

.answer-button.is-correct,
.quiz-submit {
    background: var(--quest-leaf);
}

.answer-button.is-wrong {
    color: #ffffff;
    background: var(--quest-rose);
}

.spell-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.65rem;
}

.spell-input {
    min-height: 2.85rem;
    padding: 0 0.85rem;
    border: 1px solid rgba(20, 25, 35, 0.18);
    color: #141923;
    background: #fff;
}

.word-chip-bank,
.word-chip-answer {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
    min-height: 3.25rem;
    padding: 0.65rem;
    border-radius: 6px;
    border: 1px dashed rgba(20, 25, 35, 0.22);
    background: rgba(20, 25, 35, 0.04);
}

.chip-button.is-selected {
    background: var(--quest-gold);
}

.quiz-feedback {
    display: none;
    margin-top: 1rem;
    padding: 0.85rem;
    border-radius: 6px;
    color: #141923;
    background: rgba(120, 201, 255, 0.24);
}

.quiz-feedback.is-visible {
    display: block;
}

.quest-side-panel {
    position: sticky;
    top: 6.2rem;
    display: grid;
    gap: 0.85rem;
    padding: 1rem;
}

.quest-objective h2 {
    margin: 0;
    font-size: 1.45rem;
    line-height: 1.15;
}

.quest-objective p:last-child {
    margin: 0.55rem 0 0;
    color: rgba(255, 249, 233, 0.78);
}

.quest-stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.55rem;
}

.quest-stats div,
.mastery-card,
.control-card,
.quest-log {
    border: 1px solid rgba(255, 255, 255, 0.13);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.055);
}

.quest-stats div {
    min-height: 4.3rem;
    display: grid;
    align-content: center;
    padding: 0.75rem;
}

.quest-stats span,
.mastery-card span {
    color: rgba(255, 249, 233, 0.68);
    font-size: 0.76rem;
    font-weight: 800;
    text-transform: uppercase;
}

.quest-stats strong {
    font-size: 1.55rem;
    line-height: 1;
}

.mastery-card,
.control-card,
.quest-log {
    padding: 0.85rem;
}

.mastery-card strong {
    display: block;
    margin-top: 0.15rem;
    font-size: 1.3rem;
}

.mastery-meter {
    height: 0.65rem;
    margin: 0.75rem 0 0.45rem;
    overflow: hidden;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
}

.mastery-meter span {
    display: block;
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, var(--quest-rose), var(--quest-gold), var(--quest-leaf));
}

.mastery-card p,
.quest-log {
    margin: 0;
    color: rgba(255, 249, 233, 0.76);
}

.control-card dl {
    display: grid;
    gap: 0.45rem;
    margin: 0;
}

.control-card div {
    display: grid;
    grid-template-columns: 5rem 1fr;
    gap: 0.5rem;
}

.control-card dt {
    color: var(--quest-gold);
    font-weight: 950;
}

.control-card dd {
    margin: 0;
    color: rgba(255, 249, 233, 0.78);
}

.touch-pad {
    display: none;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 0.55rem;
    padding: 0.75rem;
    border-top: 1px solid var(--quest-line);
    background: rgba(255, 255, 255, 0.045);
}

.touch-pad button {
    min-width: 0;
    min-height: 3rem;
    display: grid;
    place-items: center;
    color: var(--quest-paper);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.08);
}

.touch-pad svg {
    width: 1.18rem;
    height: 1.18rem;
}

.design-section {
    padding: 4.5rem 1.25rem 5rem;
    color: #101622;
    background: #f6fbff;
}

.design-section .section-heading h2 {
    max-width: 56rem;
    color: #101622;
}

.design-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1rem;
    margin-top: 1.5rem;
}

.design-grid article {
    min-height: 15rem;
    display: grid;
    align-content: start;
    gap: 0.55rem;
    padding: 1rem;
    color: #101622;
    background: #ffffff;
    box-shadow: 0 16px 48px rgba(18, 42, 70, 0.09);
}

.design-grid span {
    width: 2.3rem;
    height: 2.3rem;
    display: grid;
    place-items: center;
    border-radius: 6px;
    color: #101622;
    background: var(--quest-gold);
    font-weight: 950;
}

.design-grid h3 {
    margin: 0;
    font-size: 1.2rem;
    line-height: 1.2;
}

.design-grid p {
    margin: 0;
    color: rgba(16, 22, 34, 0.78);
}

.design-grid pre {
    max-width: 100%;
    overflow: auto;
    margin: 0;
    padding: 0.8rem;
    color: #f6fbff;
    border-radius: 6px;
    background: #151d2b;
    font-size: 0.8rem;
    line-height: 1.45;
}

@media (max-width: 1060px) {
    .quest-shell {
        grid-template-columns: 1fr;
    }

    .quest-side-panel {
        position: static;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .quest-objective,
    .quest-log {
        grid-column: 1 / -1;
    }

    .design-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 760px) {
    .quest-shell {
        padding: 6.4rem 0.75rem 2.5rem;
    }

    .quest-game-head,
    .quest-side-panel {
        grid-template-columns: 1fr;
    }

    .quest-actions {
        justify-content: flex-start;
    }

    .phaser-wrap {
        min-height: 15.5rem;
    }

    .answer-grid,
    .spell-row,
    .quest-stats,
    .design-grid {
        grid-template-columns: 1fr;
    }

    .touch-pad {
        display: grid;
    }

    .control-card {
        display: none;
    }

    .quest-modal {
        padding: 0.65rem;
    }

    .quest-modal-card {
        padding: 0.85rem;
    }
}
