/* ================================
   Shared shell for the games under /games/<name>/
   Same brand tokens and type as the catalog pages (css/catalog.css).
   Every game page wraps its content in <div class="gm">.
   ================================ */

.gm,
.gm-dialog {
    --gm-bg: #f3f7fe;
    --gm-ink: #0d1f3c;
    --gm-muted: #4f6283;
    --gm-card: #ffffff;
    --gm-line: #dbe5f4;
    --gm-blue: #1d5fc4;
    --gm-blue-ink: #ffffff;
    --gm-tint: #e8f0fd;
    --gm-orange: #e07a0c;
    --gm-green: #1f9d55;
    --gm-red: #d64545;
    --gm-shadow: rgba(23, 56, 120, 0.12);
    --gm-head: 'Montserrat', 'Nunito', system-ui, sans-serif;
    --gm-body: 'Mulish', 'Nunito', system-ui, sans-serif;
}

.gm {
    background: var(--gm-bg);
    color: var(--gm-ink);
    font-family: var(--gm-body);
    border: 1px solid var(--gm-line);
    border-radius: 1.25rem;
    padding: clamp(1rem, 3.5vw, 2.25rem);
    display: grid;
    gap: clamp(1rem, 2.5vw, 1.5rem);
}

html.dark .gm,
html.dark .gm-dialog {
    --gm-bg: #111a2c;
    --gm-ink: #e8eefa;
    --gm-muted: #a3b3cd;
    --gm-card: #172440;
    --gm-line: #263a60;
    --gm-blue: #79a9ff;
    --gm-blue-ink: #0b1528;
    --gm-tint: #1a2b4b;
    --gm-orange: #ffad4d;
    --gm-green: #4cd38a;
    --gm-red: #ff7a7a;
    --gm-shadow: rgba(0, 0, 0, 0.35);
}

.gm h1, .gm h2, .gm h3, .gm p { margin: 0; }
.gm [hidden] { display: none !important; }

.gm svg.gm-i {
    width: 18px;
    height: 18px;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.gm a:focus-visible,
.gm button:focus-visible,
.gm select:focus-visible,
.gm summary:focus-visible {
    outline: 2px solid var(--gm-blue);
    outline-offset: 3px;
    border-radius: 10px;
}

/* ---------- page top ---------- */
.gm-top {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 0.75rem 1.5rem;
}

.gm-back {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-family: var(--gm-head);
    font-weight: 700;
    font-size: 0.78rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--gm-blue);
    text-decoration: none;
}
.gm-back:hover { text-decoration: underline; }

.gm .gm-title {
    font-family: var(--gm-head);
    font-weight: 800;
    font-size: clamp(1.5rem, 3.4vw, 2.1rem);
    line-height: 1.15;
    letter-spacing: -0.02em;
    color: var(--gm-ink);
    margin-top: 0.4rem;
}

.gm-sub {
    margin-top: 0.35rem !important;
    color: var(--gm-muted);
    font-size: 0.98rem;
    line-height: 1.5;
}

/* ---------- bar: stats + actions ---------- */
.gm-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
}

.gm-stats, .gm-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.gm-stat {
    display: grid;
    gap: 0.1rem;
    min-width: 5.5rem;
    padding: 0.45rem 0.85rem;
    background: var(--gm-card);
    border: 1px solid var(--gm-line);
    border-radius: 0.8rem;
}
.gm-stat-label {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--gm-muted);
}
.gm-stat-value {
    font-family: var(--gm-head);
    font-weight: 800;
    font-size: 1.15rem;
    font-variant-numeric: tabular-nums;
    color: var(--gm-ink);
}

/* ---------- buttons ---------- */
.gm-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    min-height: 2.5rem;
    padding: 0.5rem 1rem;
    border-radius: 0.75rem;
    border: 1px solid var(--gm-line);
    background: var(--gm-card);
    color: var(--gm-ink);
    font-family: var(--gm-body);
    font-weight: 700;
    font-size: 0.92rem;
    line-height: 1.2;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: transform 0.12s ease, background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.gm-btn:hover { border-color: var(--gm-blue); }
.gm-btn:active { transform: translateY(1px) scale(0.98); }
.gm-btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.gm-btn--primary {
    background: var(--gm-blue);
    border-color: var(--gm-blue);
    color: var(--gm-blue-ink);
    box-shadow: 0 6px 16px -8px var(--gm-blue);
}
.gm-btn--primary:hover { filter: brightness(1.08); }

.gm-btn--accent {
    background: var(--gm-orange);
    border-color: var(--gm-orange);
    color: #fff;
    box-shadow: 0 6px 16px -8px var(--gm-orange);
}
html.dark .gm-btn--accent { color: #1d1203; }
.gm-btn--accent:hover { filter: brightness(1.06); }

.gm-btn--icon { padding: 0.5rem; min-width: 2.5rem; }
.gm-btn--lg { min-height: 3rem; padding: 0.7rem 1.4rem; font-size: 1rem; border-radius: 0.9rem; }

/* segmented control (mode / difficulty pickers) */
.gm-seg {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    padding: 0.25rem;
    background: var(--gm-tint);
    border: 1px solid var(--gm-line);
    border-radius: 0.85rem;
}
.gm-seg button {
    border: 0;
    background: transparent;
    color: var(--gm-muted);
    font: inherit;
    font-weight: 700;
    font-size: 0.88rem;
    padding: 0.45rem 0.85rem;
    border-radius: 0.6rem;
    cursor: pointer;
}
.gm-seg button[aria-pressed="true"] {
    background: var(--gm-card);
    color: var(--gm-ink);
    box-shadow: 0 2px 8px -3px var(--gm-shadow);
}

.gm-select {
    min-height: 2.5rem;
    padding: 0.4rem 2rem 0.4rem 0.75rem;
    border-radius: 0.75rem;
    border: 1px solid var(--gm-line);
    background: var(--gm-card);
    color: var(--gm-ink);
    font: inherit;
    font-weight: 600;
    font-size: 0.92rem;
    max-width: 100%;
    width: 100%;
}

/* ---------- stage: where the game lives ---------- */
.gm-stage {
    position: relative;
    display: grid;
    place-items: center;
    min-width: 0;
}

/* status line under / above the board */
.gm-status {
    min-height: 1.6em;
    text-align: center;
    font-weight: 700;
    color: var(--gm-ink);
}

/* ---------- how to play ---------- */
.gm-help {
    background: var(--gm-card);
    border: 1px solid var(--gm-line);
    border-radius: 1rem;
    padding: 0.2rem 1.1rem;
}
.gm-help summary {
    cursor: pointer;
    padding: 0.75rem 0;
    font-family: var(--gm-head);
    font-weight: 700;
    font-size: 0.95rem;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.gm-help summary::-webkit-details-marker { display: none; }
.gm-help summary::after {
    content: '';
    width: 0.5rem;
    height: 0.5rem;
    margin-left: auto;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
    transition: transform 0.2s ease;
}
.gm-help[open] summary::after { transform: rotate(-135deg); }
.gm-help ul {
    margin: 0 0 1rem;
    padding-left: 1.2rem;
    color: var(--gm-muted);
    line-height: 1.65;
}
.gm-help li + li { margin-top: 0.2rem; }
.gm-help kbd {
    font-family: inherit;
    font-size: 0.82em;
    font-weight: 700;
    padding: 0.05rem 0.4rem;
    border: 1px solid var(--gm-line);
    border-bottom-width: 2px;
    border-radius: 0.35rem;
    background: var(--gm-tint);
    color: var(--gm-ink);
}

/* ---------- dialog ---------- */
.gm-dialog {
    border: 0;
    padding: 0;
    border-radius: 1.25rem;
    max-width: min(26rem, calc(100vw - 2rem));
    width: 100%;
    background: transparent;
    color: inherit;
}
.gm-dialog::backdrop {
    background: rgba(8, 16, 34, 0.55);
    backdrop-filter: blur(3px);
}
.gm-dialog[open] { animation: gm-pop 0.22s ease-out; }
.gm-dialog-card {
    background: var(--gm-card);
    color: var(--gm-ink);
    border: 1px solid var(--gm-line);
    border-radius: 1.25rem;
    padding: 1.6rem 1.5rem 1.3rem;
    text-align: center;
    font-family: var(--gm-body);
    box-shadow: 0 24px 60px -20px rgba(0, 0, 0, 0.45);
}
.gm-dialog-icon { font-size: 2.6rem; line-height: 1; margin-bottom: 0.6rem; }
.gm-dialog-title {
    font-family: var(--gm-head);
    font-weight: 800;
    font-size: 1.35rem;
    margin: 0 0 0.4rem;
}
.gm-dialog-body { color: var(--gm-muted); line-height: 1.55; margin: 0 0 1.2rem; }
.gm-dialog-body strong { color: var(--gm-ink); }
.gm-dialog-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.5rem; }

@keyframes gm-pop {
    from { opacity: 0; transform: translateY(8px) scale(0.97); }
    to { opacity: 1; transform: none; }
}

/* ---------- toast ---------- */
.gm-toast {
    position: fixed;
    left: 50%;
    bottom: 1.5rem;
    z-index: 60;
    transform: translate(-50%, 1rem);
    opacity: 0;
    pointer-events: none;
    padding: 0.6rem 1.1rem;
    border-radius: 999px;
    background: #0d1f3c;
    color: #fff;
    font-family: 'Mulish', system-ui, sans-serif;
    font-weight: 700;
    font-size: 0.9rem;
    box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
    transition: opacity 0.2s ease, transform 0.2s ease;
}
.gm-toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* page wrapper */
.gm-page {
    max-width: 64rem;
    margin: 0 auto;
    padding: clamp(1rem, 3vw, 2rem) clamp(0.75rem, 3vw, 1.5rem);
}

@media (max-width: 640px) {
    .gm { border-radius: 1rem; }
    .gm-bar { justify-content: center; }
    .gm-stat { min-width: 4.6rem; padding: 0.4rem 0.7rem; }
}

@media (prefers-reduced-motion: reduce) {
    .gm *, .gm-dialog { animation: none !important; transition: none !important; }
}

/* ---------- topic cards (vocabulary games) ---------- */
.gm-topics {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
    gap: 0.6rem;
}
.gm-topic {
    display: grid;
    justify-items: start;
    gap: 0.3rem;
    padding: 0.8rem 0.9rem;
    border: 1px solid var(--gm-line);
    border-radius: 1rem;
    background: var(--gm-card);
    color: var(--gm-ink);
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.gm-topic:hover { transform: translateY(-2px); border-color: var(--gm-blue); box-shadow: 0 10px 20px -14px var(--gm-shadow); }
.gm-topic-emoji { font-size: 1.7rem; line-height: 1; }
.gm-topic-name { font-weight: 800; line-height: 1.25; }
.gm-topic-meta { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.gm-topic-level, .gm-topic-best {
    padding: 0.05rem 0.45rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 800;
    background: var(--gm-tint);
    color: var(--gm-blue);
}
.gm-topic-best { background: rgba(31, 157, 85, 0.14); color: var(--gm-green); }
.gm-credit { font-size: 0.82rem; }
.gm-credit a { color: var(--gm-blue); }

/* ---------- full screen ---------- */
.gm { position: relative; }
.gm-fs {
    position: absolute;
    z-index: 5;
    top: clamp(0.6rem, 2vw, 1rem);
    right: clamp(0.6rem, 2vw, 1rem);
    min-width: 2.25rem;
    min-height: 2.25rem;
    padding: 0.35rem;
}
html.gm-no-scroll, html.gm-no-scroll body { overflow: hidden; }

.gm.is-full {
    /* height left for the board once the slim title row and padding are taken off */
    --gm-h: calc(100vh - 5.5rem);
    --gm-h: calc(100dvh - 5.5rem);
    position: fixed;
    inset: 0;
    z-index: 1000;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    box-sizing: border-box;
    overflow-y: auto;
    align-content: start;
    gap: 0.75rem;
    padding: 0.75rem clamp(0.75rem, 2vw, 1.5rem);
    border: 0;
    border-radius: 0;
}
.gm.is-full .gm-sub,
.gm.is-full .gm-back,
.gm.is-full .gm-help { display: none; }
.gm.is-full .gm-title { margin-top: 0; font-size: 1.25rem; }
.gm.is-full .gm-top { align-items: center; padding-right: 3rem; }
