/* begin license *
 *
 * Small browser games on swl and swindl
 *
 * All rights reserved.
 *
 * Copyright (C) 2026 moatley moatley@lost-monkeys.net
 *
 * This file is part of "Games"
 *
 * end license */

/* Guess the word: one screen, the tiles under the header and the keyboard at the
   bottom. The marks are blue (right place) and amber (elsewhere), safe for most
   colour blindness, and each has its own shape too: a dot for right place, stripes
   and a ring for elsewhere; not in the word is plain grey. */
:root {
    --gs-bg: #f3f1ec;
    --gs-bg-glow: #fffdf8;
    --gs-panel: #ffffff;
    --gs-text: #2a2a33;
    --gs-muted: #6f6b78;
    --gs-frame: #d6d0c4;
    --gs-frame-filled: #8e8799;
    --gs-key: #ffffff;
    --gs-hit: #1f63c9;
    --gs-hit-text: #ffffff;
    --gs-near: #f2a31b;
    --gs-near-stripe: #ffc254;
    --gs-near-text: #2a2a33;
    --gs-miss: #6e6a78;
    --gs-miss-text: #ffffff;
    --gs-key-miss: #d9d4cb;
    --gs-key-miss-text: #8a8592;
    --gs-toast: #2a2a33;
    --gs-enter: #e14b57;
    --gs-toast-text: #ffffff;
}
:root[data-theme="dark"] {
    --gs-bg: #161a24;
    --gs-bg-glow: #232a3b;
    --gs-panel: #1f2533;
    --gs-text: #eceef4;
    --gs-muted: #9aa0b2;
    --gs-frame: #343c4f;
    --gs-frame-filled: #8d96ad;
    --gs-key: #2b3344;
    --gs-hit: #3a7be0;
    --gs-hit-text: #ffffff;
    --gs-near: #f5b03a;
    --gs-near-stripe: #ffcf72;
    --gs-near-text: #1d2030;
    --gs-miss: #454c5e;
    --gs-miss-text: #e3e6ee;
    --gs-key-miss: #171b24;
    --gs-key-miss-text: #7f879c;
    --gs-toast: #eceef4;
    --gs-toast-text: #1d2030;
}

body.guess-page {
    margin: 0;
    background: radial-gradient(ellipse at 50% 40%, var(--gs-bg-glow), var(--gs-bg) 70%) var(--gs-bg);
    min-height: 100vh;
    color: var(--gs-text);
    overscroll-behavior: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    touch-action: manipulation;
}

.gs {
    --gs-gap: .35rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100vh;
    height: 100dvh;
    max-width: 34rem;
    margin: 0 auto;
    padding: env(safe-area-inset-top) .5rem env(safe-area-inset-bottom);
    box-sizing: border-box;
}

.gs-top {
    display: flex;
    align-items: center;
    gap: .5rem;
    width: 100%;
    padding: .6rem .25rem .25rem;
    box-sizing: border-box;
}
.gs-back, .gs-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    flex: 0 0 auto;
    border: 0;
    border-radius: 50%;
    background: var(--gs-panel);
    color: var(--gs-text);
    font-size: 1.2rem;
    text-decoration: none;
    cursor: pointer;
}
.gs-scores { display: flex; justify-content: space-around; flex: 1 1 auto; min-width: 0; }
.gs-score { display: flex; flex-direction: column; align-items: center; min-width: 2.75rem; }
.gs-score > span:last-child { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.gs-score-best > span:last-child { color: var(--gs-muted); }
.gs-label { font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; color: var(--gs-muted); }
.gs-mascot {
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    overflow: hidden;
    background: var(--gs-panel);
    flex: 0 0 auto;
}

/* the tiles: as big as fits, in width and in height */
.gs-board {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow-x: clip; /* a shaking row of six makes no sideways scroll */
}
.gs-grid {
    --gs-tile: min(
        calc((100vw - 1rem - (var(--gs-length) - 1) * var(--gs-gap)) / var(--gs-length)),
        calc((100dvh - 19.5rem - 5 * var(--gs-gap)) / 6),
        4.2rem
    );
    display: grid;
    gap: var(--gs-gap);
}
.gs-row {
    display: grid;
    grid-template-columns: repeat(var(--gs-length), var(--gs-tile));
    gap: var(--gs-gap);
}
.gs-tile {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--gs-tile);
    height: var(--gs-tile);
    box-sizing: border-box;
    border: 2px solid var(--gs-frame);
    border-radius: 22%;
    background: var(--gs-panel);
    color: var(--gs-text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: calc(var(--gs-tile) * .52);
    font-weight: 800;
    text-transform: uppercase;
    line-height: 1;
}
.gs-tile.gs-filled { border-color: var(--gs-frame-filled); }
.gs-tile.gs-pop { animation: gs-pop .12s ease-out; }
.gs-tile.gs-turn { animation: gs-turn .26s ease-in-out; }

/* the marks: colour and a shape, on tiles, keys and the legend */
.gs-hit, .gs-near, .gs-miss { border-color: transparent !important; }
.gs-hit { background: var(--gs-hit) !important; color: var(--gs-hit-text) !important; }
.gs-near {
    background: repeating-linear-gradient(135deg, var(--gs-near) 0 .3rem, var(--gs-near-stripe) .3rem .6rem) !important;
    color: var(--gs-near-text) !important;
}
.gs-miss { background: var(--gs-miss) !important; color: var(--gs-miss-text) !important; }
.gs-tile.gs-hit::after, .gs-key.gs-hit::after, .gs-mini.gs-hit::after,
.gs-tile.gs-near::after, .gs-key.gs-near::after, .gs-mini.gs-near::after {
    content: "";
    position: absolute;
    right: 9%;
    bottom: 9%;
    width: 18%;
    aspect-ratio: 1;
    border-radius: 50%;
    box-sizing: border-box;
}
.gs-hit::after { background: var(--gs-hit-text); }
.gs-near::after { border: 2px solid var(--gs-near-text); }
.gs-key.gs-hit::after, .gs-key.gs-near::after { width: .45rem; right: .2rem; bottom: .2rem; }
.gs-key.gs-near::after { border-width: 1.5px; }
.gs-key.gs-miss { background: var(--gs-key-miss) !important; color: var(--gs-key-miss-text) !important; box-shadow: none; }

.gs-row.gs-shake { animation: gs-shake .4s ease-in-out; }
.gs-row.gs-win .gs-tile { animation: gs-jump .5s ease-out both; }
.gs-row.gs-win .gs-tile:nth-child(2) { animation-delay: .08s; }
.gs-row.gs-win .gs-tile:nth-child(3) { animation-delay: .16s; }
.gs-row.gs-win .gs-tile:nth-child(4) { animation-delay: .24s; }
.gs-row.gs-win .gs-tile:nth-child(5) { animation-delay: .32s; }
.gs-row.gs-win .gs-tile:nth-child(6) { animation-delay: .4s; }
@keyframes gs-pop { 50% { transform: scale(1.1); } }
@keyframes gs-turn { 50% { transform: scaleY(.05); } }
@keyframes gs-shake {
    20%, 60% { transform: translateX(-.5rem); }
    40%, 80% { transform: translateX(.5rem); }
}
@keyframes gs-jump { 40% { transform: translateY(-.6rem) rotate(-4deg); } 70% { transform: translateY(0) rotate(2deg); } }
@media (prefers-reduced-motion: reduce) {
    .gs-tile, .gs-row { animation: none !important; }
}

.gs-toast {
    position: absolute;
    top: .25rem;
    left: 50%;
    z-index: 5;
    transform: translateX(-50%);
    margin: 0;
    padding: .45rem .9rem;
    border-radius: 2rem;
    background: var(--gs-toast);
    color: var(--gs-toast-text);
    font-weight: 600;
    font-size: .9rem;
    white-space: nowrap;
    box-shadow: 0 4px 14px rgba(0, 0, 0, .2);
}
.gs-toast[hidden] { display: none; }
.gs-loading-text {
    display: none;
    position: absolute;
    inset: 0;
    margin: 0;
    align-items: center;
    justify-content: center;
    color: var(--gs-muted);
}
.gs.gs-loading .gs-loading-text { display: flex; }
.gs.gs-loading .gs-grid, .gs.gs-loading .gs-keys { opacity: .3; pointer-events: none; }

.gs-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: .2rem 1rem;
    margin: .4rem 0 0;
    padding: 0;
    list-style: none;
    font-size: .75rem;
    color: var(--gs-muted);
}
.gs-legend li { display: flex; align-items: center; gap: .35rem; }
.gs-mini {
    position: relative;
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border-radius: 25%;
}
.gs-mini.gs-near { background: repeating-linear-gradient(135deg, var(--gs-near) 0 .15rem, var(--gs-near-stripe) .15rem .3rem) !important; }
.gs-mini::after { border-width: 1.5px !important; width: 40% !important; right: 12% !important; bottom: 12% !important; }

/* the keyboard */
.gs-keys {
    width: min(100%, 32rem);
    margin: .5rem 0 .6rem;
    display: grid;
    gap: .4rem;
    touch-action: manipulation;
}
.gs-key-row { display: flex; justify-content: center; gap: .3rem; }
.gs-key {
    position: relative;
    flex: 1 1 0;
    min-width: 0;
    max-width: 3rem;
    height: 3.2rem;
    padding: 0;
    border: 0;
    border-radius: .55rem;
    background: var(--gs-key);
    color: var(--gs-text);
    font-size: 1.15rem;
    font-weight: 700;
    text-transform: uppercase;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .14);
    transition: background-color .15s, color .15s, transform .08s;
}
.gs-key:active { transform: scale(.93); }
.gs-key.gs-wide { flex: 1.5 1 0; max-width: 4.5rem; font-size: 1.3rem; }
.gs-key[data-key="enter"] { background: var(--gs-enter); color: #fff; }
.gs.gs-done .gs-keys { opacity: .6; pointer-events: none; }

@media (max-height: 600px) {
    .gs-legend { display: none; }
    .gs-key { height: 2.8rem; }
    .gs-grid { --gs-tile: min(calc((100vw - 1rem - (var(--gs-length) - 1) * var(--gs-gap)) / var(--gs-length)), calc((100dvh - 16rem - 5 * var(--gs-gap)) / 6), 4.2rem); }
}

.gs-over {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, .45);
}
.gs-over[hidden] { display: none; }
.gs-over-box {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: .5rem 1rem;
    margin: 0 1rem;
    padding: 1.5rem 1.5rem;
    border-radius: 1rem;
    background: var(--gs-panel);
    color: var(--gs-text);
    text-align: left;
}
.gs-over-box h2 { margin-top: 0; }
.gs-over-box p { margin: .25rem 0; }
.gs-over-word { letter-spacing: .12em; color: var(--gs-hit); }
:root[data-theme="dark"] .gs-over-word { color: #8db8ff; }
.gs-over-mascot { width: 6.5rem; height: auto; }
.gs-stats {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: .5rem;
    margin: .25rem 0;
    text-align: center;
}
.gs-stat { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.gs-stat-label { line-height: 1.2; font-size: .68rem; letter-spacing: .06em; text-transform: uppercase; color: var(--gs-muted); }
.gs-stats > div { display: flex; flex-direction: column; }
.gs-over-buttons { grid-column: 1 / -1; display: flex; justify-content: center; gap: .75rem; }
