/* 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 */

/* Equations: one screen, the grid under the header, the tray of numbers below. */
:root {
    --eq-bg: #f3f1ec;
    --eq-bg-glow: #fffdf8;
    --eq-panel: #ffffff;
    --eq-frame: #cdc5b6;
    --eq-cell-bg: #ffffff;
    --eq-cell-line: #cdc5b6;
    --eq-blank: #e9e5dc;
    --eq-blank-line: #c9c1b2;
    --eq-text: #2a2a33;
    --eq-muted: #8a8592;
    --eq-word-line: #c9c1b2;
    --eq-word-bg: rgba(255, 255, 255, .45);
    --eq-right: #e9f6eb;
    --eq-right-line: #6cc27e;
    --eq-wrong: #fbdcdc;
    --eq-wrong-line: #e8505b;
    --eq-wrong-text: #c8323d;
    --eq-select: #3fa7d6;
    --eq-tile-top: #8fd0ee;
    --eq-tile: #3fa7d6;
    --eq-tile-bottom: #2c8fbd;
}
:root[data-theme="dark"] {
    --eq-bg: #161a24;
    --eq-bg-glow: #232a3b;
    --eq-panel: #1f2533;
    --eq-frame: #0e1118;
    --eq-cell-bg: #2a3244;
    --eq-cell-line: #3a4457;
    --eq-blank: #222938;
    --eq-blank-line: #56617a;
    --eq-text: #eceef4;
    --eq-muted: #7f879b;
    --eq-word-line: #3a4357;
    --eq-word-bg: rgba(255, 255, 255, .03);
    --eq-right: #233529;
    --eq-right-line: #4fae67;
    --eq-wrong: #4a2329;
    --eq-wrong-line: #ff6f6a;
    --eq-wrong-text: #ff8a85;
    --eq-select: #6fc3ea;
}

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

.eq {
    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;
}

.eq-top {
    display: flex;
    align-items: center;
    gap: .5rem;
    width: 100%;
    padding: .75rem 0 .25rem;
}
.eq-back, .eq-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(--eq-panel);
    color: var(--eq-text);
    font-size: 1.2rem;
    text-decoration: none;
    cursor: pointer;
}
.eq-button:disabled { opacity: .4; cursor: default; }
.eq-scores { display: flex; justify-content: space-around; flex: 1 1 auto; min-width: 0; }
.eq-score { display: flex; flex-direction: column; align-items: center; min-width: 2.75rem; }
.eq-score > span:last-child { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.eq-score-best > span:last-child { font-size: 1rem; line-height: 1.4rem; color: var(--eq-muted); }
.eq-label { font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; color: var(--eq-muted); }

.eq-mascot {
    width: 3.2rem;
    height: 3.2rem;
    border-radius: 50%;
    overflow: hidden;
    background: var(--eq-panel);
    flex: 0 0 auto;
}

/* the grid: --eq-cell is set by equations.js to fit the board */
.eq-board {
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.eq-grid {
    display: grid;
    grid-template-columns: repeat(var(--eq-cols, 9), var(--eq-cell, 32px));
    grid-template-rows: repeat(var(--eq-rows, 9), var(--eq-cell, 32px));
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
/* the outline around an equation, behind its cells; where two cross they overlap */
.eq-word {
    margin: -2px;
    border: 2px solid var(--eq-word-line);
    border-radius: calc(var(--eq-cell, 32px) * .28);
    background: var(--eq-word-bg);
    pointer-events: none;
    transition: border-color .2s, background-color .2s;
}
.eq-word.eq-right { border-color: var(--eq-right-line); }
.eq-word.eq-wrong { border-color: var(--eq-wrong-line); background: color-mix(in srgb, var(--eq-wrong) 55%, transparent); }
.eq-cell {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    margin: 1px;
    border-radius: 18%;
    font-size: calc(var(--eq-cell, 32px) * .44);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    letter-spacing: -.03em;
    transition: background-color .2s, border-color .2s, color .2s;
}
.eq-num {
    background: var(--eq-cell-bg);
    border: 1px solid var(--eq-cell-line);
    box-shadow: 0 1px 2px rgba(0, 0, 0, .12);
}
.eq-op, .eq-eq {
    color: var(--eq-muted);
    font-weight: 600;
    font-size: calc(var(--eq-cell, 32px) * .5);
}
.eq-blank {
    background: var(--eq-blank);
    border: 1.5px dashed var(--eq-blank-line);
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, .12);
    cursor: pointer;
}
.eq-blank.eq-filled { border-style: solid; border-color: transparent; background: transparent; box-shadow: none; }
.eq-blank.eq-selected, .eq-blank.eq-target { border: 2px solid var(--eq-select); background: color-mix(in srgb, var(--eq-select) 18%, var(--eq-blank)); }
.eq-blank.eq-filled.eq-target { border-color: var(--eq-select); }

/* an equation that is complete: right (subtle) or wrong */
.eq-num.eq-right { background: var(--eq-right); border-color: var(--eq-right-line); }
.eq-op.eq-right, .eq-eq.eq-right { color: var(--eq-right-line); }
.eq-num.eq-wrong { background: var(--eq-wrong); border-color: var(--eq-wrong-line); }
.eq-op.eq-wrong, .eq-eq.eq-wrong { color: var(--eq-wrong-text); }
.eq-given.eq-wrong { color: var(--eq-wrong-text); }
.eq-blank.eq-filled.eq-wrong .eq-tile { box-shadow: 0 0 0 2px var(--eq-wrong-line), 0 2px 3px rgba(0, 0, 0, .25); }
.eq-blank.eq-filled.eq-right .eq-tile { box-shadow: 0 0 0 2px var(--eq-right-line), 0 2px 3px rgba(0, 0, 0, .2); }

/* the tiles: game pieces */
.eq-tile {
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    border-radius: 22%;
    background: linear-gradient(180deg, var(--eq-tile-top), var(--eq-tile) 55%, var(--eq-tile-bottom));
    border: 1px solid rgba(255, 255, 255, .45);
    box-shadow: 0 2px 3px rgba(0, 0, 0, .25), inset 0 -2px 0 rgba(0, 0, 0, .12);
    color: #fff;
    text-shadow: 0 1px 1px rgba(0, 0, 0, .35);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    letter-spacing: -.03em;
    cursor: grab;
    touch-action: none;
    transition: transform .12s, opacity .12s;
}
.eq-cell .eq-tile { font-size: calc(var(--eq-cell, 32px) * .44); }
.eq-tile.eq-dragging { opacity: .25; }
.eq-tile.eq-pop { animation: eq-pop .22s ease-out; }
@keyframes eq-pop { 0% { transform: scale(.7); } 70% { transform: scale(1.08); } 100% { transform: scale(1); } }

.eq-tray {
    --eq-tile-size: 2.9rem;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-content: flex-start;
    gap: .4rem;
    width: 100%;
    flex: 0 0 auto;
    padding: .5rem 0 .25rem;
    touch-action: none;
}
.eq-slot {
    width: var(--eq-tile-size);
    height: var(--eq-tile-size);
    border-radius: 22%;
    background: rgba(127, 127, 127, .1);
}
.eq-tray .eq-tile { font-size: calc(var(--eq-tile-size) * .42); }
.eq-tray .eq-tile[data-digits="3"] { font-size: calc(var(--eq-tile-size) * .36); }
.eq-tray .eq-tile.eq-selected { transform: translateY(-4px); box-shadow: 0 0 0 3px var(--eq-select), 0 6px 8px rgba(0, 0, 0, .3); }
.eq-cell .eq-tile[data-digits="3"] { font-size: calc(var(--eq-cell, 32px) * .38); }

.eq-floating {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 10;
    width: var(--eq-tile-size, 3rem);
    height: var(--eq-tile-size, 3rem);
    --eq-tile-size: 2.9rem;
    font-size: calc(var(--eq-tile-size) * .42);
    pointer-events: none;
    box-shadow: 0 8px 14px rgba(0, 0, 0, .35);
    transition: none;
}

.eq-hint { flex: 0 0 auto; margin: .25rem 0 .75rem; font-size: .8rem; text-align: center; color: var(--eq-muted); }

.eq-over {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, .45);
}
.eq-over[hidden] { display: none; }
.eq-over-box {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: .5rem 1rem;
    margin: 0 1rem;
    padding: 1.5rem 2rem;
    border-radius: 1rem;
    background: var(--eq-panel);
    color: var(--eq-text);
    text-align: left;
}
.eq-over-box h2 { margin-top: 0; }
.eq-over-best { color: #e0a100; font-weight: 700; }
.eq-over-mascot { width: 7.5rem; height: auto; }
.eq-over-buttons { grid-column: 1 / -1; display: flex; justify-content: center; gap: .75rem; }

@media (max-width: 22rem) {
    .eq-score-best { display: none; }
}
@media (prefers-reduced-motion: reduce) {
    .eq-cell, .eq-tile, .eq-word { transition: none; }
    .eq-tile.eq-pop { animation: none; }
}
