/* Synthwave: a night sky over a perspective grid running to a horizon, neon edges in magenta and cyan. The
   overlay is fixed over the page like the other games and carries game-dark-surface, so it is dark in both
   themes; its own colours are set here and every text colour is checked against the darkest backdrop. */
.spelling-overlay {
    --spelling-sky-top: #0b0221;
    --spelling-sky-bottom: #2a0845;
    --spelling-magenta: #f472d0;
    --spelling-cyan: #67e8f9;
    --spelling-text: #f5f3ff;
    --spelling-text-muted: #c4b5fd;
    --spelling-tile: rgba(20, 6, 40, 0.88);
    --spelling-danger: #fb7185;

    position: fixed;
    inset: 0;
    z-index: 1050;
    display: flex;
    flex-direction: column;
    overflow: hidden auto;
    background: linear-gradient(180deg, var(--spelling-sky-top) 0%, var(--spelling-sky-bottom) 62%, #12011f 100%);
    color: var(--spelling-text);
    padding-bottom: env(safe-area-inset-bottom);
}

html:has(.spelling-overlay) {
    overscroll-behavior: none;
}

/* The sun and the floor, behind everything and never in the way of a tap. The sun sits on the horizon and
   the floor is drawn over its lower half, so it sets behind the grid. The grid is a picture rather than a
   3D transform, so it looks the same on every browser that draws an SVG. */
.spelling-horizon {
    position: absolute;
    inset: auto 0 0;
    height: 34%;
    pointer-events: none;
}

.spelling-horizon::before {
    content: "";
    position: absolute;
    left: 50%;
    bottom: 100%;
    width: 10rem;
    height: 10rem;
    transform: translate(-50%, 50%);
    border-radius: 50%;
    background:
        repeating-linear-gradient(180deg, transparent 0 52%, rgba(11, 2, 33, 0.9) 52% 56%, transparent 56% 62%),
        linear-gradient(180deg, #fde68a 0%, #f472d0 55%, #a21caf 100%);
    opacity: 0.6;
}

.spelling-horizon::after {
    content: "";
    position: absolute;
    inset: 0;
    border-top: 2px solid rgba(244, 114, 208, 0.8);
    box-shadow: 0 -6px 18px rgba(244, 114, 208, 0.45);
    background:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 200' preserveAspectRatio='none'%3E%3Cg stroke='%23f472d0' stroke-opacity='0.55' stroke-width='1.2' vector-effect='non-scaling-stroke'%3E%3Cline x1='200' y1='0' x2='-600' y2='200'/%3E%3Cline x1='200' y1='0' x2='-500' y2='200'/%3E%3Cline x1='200' y1='0' x2='-400' y2='200'/%3E%3Cline x1='200' y1='0' x2='-300' y2='200'/%3E%3Cline x1='200' y1='0' x2='-200' y2='200'/%3E%3Cline x1='200' y1='0' x2='-100' y2='200'/%3E%3Cline x1='200' y1='0' x2='0' y2='200'/%3E%3Cline x1='200' y1='0' x2='100' y2='200'/%3E%3Cline x1='200' y1='0' x2='200' y2='200'/%3E%3Cline x1='200' y1='0' x2='300' y2='200'/%3E%3Cline x1='200' y1='0' x2='400' y2='200'/%3E%3Cline x1='200' y1='0' x2='500' y2='200'/%3E%3Cline x1='200' y1='0' x2='600' y2='200'/%3E%3Cline x1='200' y1='0' x2='700' y2='200'/%3E%3Cline x1='200' y1='0' x2='800' y2='200'/%3E%3Cline x1='200' y1='0' x2='900' y2='200'/%3E%3Cline x1='200' y1='0' x2='1000' y2='200'/%3E%3C/g%3E%3Cg stroke='%2367e8f9' stroke-opacity='0.45' stroke-width='1.2' vector-effect='non-scaling-stroke'%3E%3Cline x1='0' y1='3.1' x2='400' y2='3.1'/%3E%3Cline x1='0' y1='12.5' x2='400' y2='12.5'/%3E%3Cline x1='0' y1='28.1' x2='400' y2='28.1'/%3E%3Cline x1='0' y1='50.0' x2='400' y2='50.0'/%3E%3Cline x1='0' y1='78.1' x2='400' y2='78.1'/%3E%3Cline x1='0' y1='112.5' x2='400' y2='112.5'/%3E%3Cline x1='0' y1='153.1' x2='400' y2='153.1'/%3E%3Cline x1='0' y1='200.0' x2='400' y2='200.0'/%3E%3C/g%3E%3C/svg%3E") center / 100% 100% no-repeat,
        linear-gradient(180deg, #1a0533 0%, #0b0221 100%);
}

.spelling-header {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    padding-top: calc(0.75rem + env(safe-area-inset-top));
    font-variant-numeric: tabular-nums;
}

.spelling-score {
    display: inline-block;
    white-space: nowrap;
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--spelling-cyan);
    text-shadow: 0 0 10px rgba(103, 232, 249, 0.55);
    transform-origin: left center;
    animation: spelling-score-bump 420ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes spelling-score-bump {
    0%   { transform: scale(1); }
    35%  { transform: scale(1.2); }
    100% { transform: scale(1); }
}

.spelling-mastery {
    color: var(--spelling-text-muted);
    font-size: 0.9rem;
    min-width: 0;
}

/* Bootstrap 5.1 has no button variables, so each state is set outright, or its own dark text shows through. */
.spelling-difficulty-button,
.spelling-difficulty-button:hover,
.spelling-difficulty-button:focus,
.spelling-difficulty-button:active {
    margin-left: auto;
    min-height: 2.75rem;
    color: var(--spelling-text);
    border: 1px solid rgba(244, 114, 208, 0.6);
}

.spelling-difficulty-button:hover {
    background: rgba(244, 114, 208, 0.18);
}

.spelling-difficulty-button:disabled {
    color: var(--spelling-text-muted);
}

.spelling-close-button {
    background: none;
    border: none;
    color: inherit;
    min-width: 2.75rem;
    min-height: 2.75rem;
}

.spelling-stage {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    width: 100%;
    max-width: 34rem;
    margin: 0 auto;
    padding: 0.5rem 1rem 1.5rem;
}

.spelling-prompt-label {
    margin: 0;
    font-size: 0.8rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--spelling-text-muted);
}

.spelling-prompt {
    margin: 0;
    font-size: clamp(1.6rem, 6vw, 2.4rem);
    font-weight: 800;
    text-align: center;
    color: var(--spelling-text);
    text-shadow: 0 0 18px rgba(244, 114, 208, 0.6);
    overflow-wrap: anywhere;
}

.spelling-word {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.6rem 1.2rem;
    width: 100%;
    min-height: 3rem;
}

/* A word never breaks across lines; only the gaps between words do. A word too long for the screen
   shrinks its slots instead, which is what the longest word's length on .spelling-word is for. */
.spelling-word-group {
    display: inline-flex;
    flex-wrap: nowrap;
    gap: 0.3rem;
    --spelling-slot-width: min(2rem, calc((100vw - 2rem) / var(--spelling-longest-word) - 0.3rem));
}

.spelling-word.is-done {
    animation: spelling-word-pulse 600ms ease-out;
}

@keyframes spelling-word-pulse {
    0%   { transform: scale(1); filter: drop-shadow(0 0 0 transparent); }
    40%  { transform: scale(1.08); filter: drop-shadow(0 0 14px var(--spelling-cyan)); }
    100% { transform: scale(1); filter: drop-shadow(0 0 0 transparent); }
}

.spelling-slot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--spelling-slot-width, 2rem);
    height: 2.6rem;
    font-size: 1.4rem;
    font-weight: 700;
    border-bottom: 3px solid rgba(103, 232, 249, 0.7);
    color: var(--spelling-text);
}

.spelling-slot.is-given {
    width: calc(var(--spelling-slot-width, 2rem) / 2);
    border-bottom-color: transparent;
    color: var(--spelling-text-muted);
}

.spelling-slot.is-filled {
    border-bottom-color: var(--spelling-magenta);
    text-shadow: 0 0 10px rgba(244, 114, 208, 0.8);
    animation: spelling-letter-in 320ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes spelling-letter-in {
    0%   { transform: translateY(0.6rem) scale(0.4); opacity: 0; }
    100% { transform: none; opacity: 1; }
}

.spelling-line {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    border-bottom: 3px solid rgba(103, 232, 249, 0.7);
    min-width: 8rem;
    padding: 0 0.25rem;
    text-align: center;
}

.spelling-caret {
    display: inline-block;
    width: 2px;
    height: 1.4rem;
    margin-left: 2px;
    vertical-align: -0.15rem;
    background: var(--spelling-cyan);
    animation: spelling-caret-blink 1s steps(1) infinite;
}

@keyframes spelling-caret-blink {
    50% { opacity: 0; }
}

.spelling-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(3rem, 1fr));
    gap: 0.6rem;
    width: 100%;
}

.spelling-tile {
    position: relative;
    aspect-ratio: 1;
    min-height: 2.75rem;
    border-radius: 0.6rem;
    border: 2px solid var(--spelling-cyan);
    background: var(--spelling-tile);
    color: var(--spelling-text);
    font-size: 1.5rem;
    font-weight: 800;
    box-shadow: 0 0 10px rgba(103, 232, 249, 0.45), inset 0 0 10px rgba(103, 232, 249, 0.15);
    transition: transform 120ms ease-out;
}

.spelling-tile:hover:not(.is-used) {
    transform: translateY(-2px);
}

.spelling-tile:focus-visible {
    outline: 3px solid var(--spelling-magenta);
    outline-offset: 2px;
}

/* A used tile keeps its place, so the tray does not jump, and stays focusable, so a keyboard player keeps
   theirs; it bursts and then fades out of sight. */
.spelling-tile.is-used {
    pointer-events: none;
    animation: spelling-tile-gone 450ms ease-out forwards;
}

@keyframes spelling-tile-gone {
    0%   { transform: scale(1); opacity: 1; }
    30%  { transform: scale(1.2); opacity: 1; box-shadow: 0 0 22px var(--spelling-magenta); }
    100% { transform: scale(0.6); opacity: 0; }
}

.spelling-spark {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 0.45rem;
    height: 0.45rem;
    border-radius: 50%;
    background: var(--spelling-magenta);
    box-shadow: 0 0 8px var(--spelling-magenta);
    --angle: calc(var(--spark) * 45deg);
    animation: spelling-spark-fly 450ms ease-out forwards;
}

.spelling-spark:nth-child(odd) {
    background: var(--spelling-cyan);
    box-shadow: 0 0 8px var(--spelling-cyan);
}

@keyframes spelling-spark-fly {
    0%   { transform: translate(-50%, -50%) rotate(var(--angle)) translateY(0); opacity: 1; }
    100% { transform: translate(-50%, -50%) rotate(var(--angle)) translateY(-2.6rem); opacity: 0; }
}

.spelling-tile.is-hint {
    border-color: var(--spelling-magenta);
    animation: spelling-hint-pulse 900ms ease-in-out infinite;
}

@keyframes spelling-hint-pulse {
    50% { box-shadow: 0 0 24px var(--spelling-magenta), inset 0 0 14px rgba(244, 114, 208, 0.5); }
}

/* 0 to 100 to 0 percent over 500 ms, on the tile that was wrong. */
.spelling-wrong-mark {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--spelling-danger);
    font-size: 2rem;
    text-shadow: 0 0 10px var(--spelling-danger);
    transform: scale(0);
    animation: spelling-wrong 500ms ease-in-out forwards;
}

@keyframes spelling-wrong {
    0%   { transform: scale(0); }
    50%  { transform: scale(1); }
    100% { transform: scale(0); }
}

/* Two names for one shake, so a second miss restarts it: the class changes, and the animation with it. */
.spelling-stage.is-shaking-a { animation: spelling-shake-a 320ms ease-in-out; }
.spelling-stage.is-shaking-b { animation: spelling-shake-b 320ms ease-in-out; }

@keyframes spelling-shake-a {
    20%, 60% { transform: translateX(-6px); }
    40%, 80% { transform: translateX(6px); }
}

@keyframes spelling-shake-b {
    20%, 60% { transform: translateX(-6px); }
    40%, 80% { transform: translateX(6px); }
}

.spelling-verdict {
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    border: 1px solid rgba(244, 114, 208, 0.5);
    background: rgba(11, 2, 33, 0.85);
    animation: spelling-letter-in 300ms ease-out;
}

.spelling-verdict-title {
    margin: 0 0 0.25rem;
    font-weight: 700;
}

.spelling-bonus-row {
    display: flex;
    justify-content: space-between;
    margin: 0;
    color: var(--spelling-text-muted);
}

.spelling-difficulties,
.spelling-panel,
.spelling-result {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 1rem;
    background: rgba(11, 2, 33, 0.82);
}

.spelling-difficulties-title,
.spelling-result-title {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 800;
    text-shadow: 0 0 14px rgba(244, 114, 208, 0.7);
}

.spelling-difficulty-choice,
.spelling-difficulty-choice:hover,
.spelling-difficulty-choice:focus,
.spelling-difficulty-choice:active {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: min(100%, 22rem);
    min-height: 2.75rem;
    text-align: left;
    color: var(--spelling-text);
    background: var(--spelling-tile);
    border: 2px solid rgba(103, 232, 249, 0.6);
}

.spelling-difficulty-choice:hover {
    border-color: var(--spelling-cyan);
    background: rgba(40, 14, 72, 0.95);
}

.spelling-difficulty-choice.is-chosen {
    border-color: var(--spelling-magenta);
}

.spelling-difficulty-name {
    font-weight: 800;
}

.spelling-difficulty-description {
    font-size: 0.85rem;
    color: var(--spelling-text-muted);
}

.spelling-result-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 1.5rem;
    border-radius: 1rem;
    border: 2px solid var(--spelling-magenta);
    background: var(--spelling-tile);
    box-shadow: 0 0 30px rgba(244, 114, 208, 0.45);
}

.spelling-result-record {
    margin: 0;
    color: #fde68a;
    font-weight: 700;
}

.spelling-result-score {
    margin: 0;
    font-size: 3rem;
    font-weight: 800;
    color: var(--spelling-cyan);
}

.spelling-result-label {
    margin: 0;
    color: var(--spelling-text-muted);
}

.spelling-result-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.spelling-result-actions .btn,
.spelling-panel .btn {
    min-height: 2.75rem;
}

/* Without motion the colour still says what happened: no shake, no sparks, no growth. */
@media (prefers-reduced-motion: reduce) {
    .spelling-score,
    .spelling-word.is-done,
    .spelling-slot.is-filled,
    .spelling-caret,
    .spelling-spark,
    .spelling-tile.is-hint,
    .spelling-stage.is-shaking-a,
    .spelling-stage.is-shaking-b,
    .spelling-verdict {
        animation: none;
    }

    .spelling-spark {
        display: none;
    }

    .spelling-tile.is-used {
        animation: none;
        opacity: 0;
    }

    .spelling-wrong-mark {
        display: none;
    }

    /* The universal rule in app.css makes every animation instant, so the miss is held as a colour
       until the next tap instead of flashed. */
    .spelling-tile:has(.spelling-wrong-mark) {
        border-color: var(--spelling-danger);
        background: rgba(251, 113, 133, 0.25);
    }
}
