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

/* Swap: one screen, the header and the hexagon board below it. */
:root {
    --sw-bg: #f3f1ec;
    --sw-bg-glow: #fffdf8;
    --sw-panel: #ffffff;
    --sw-frame: #cdc5b6;
    --sw-cell-top: #e9e5dc;
    --sw-cell: #ddd7cb;
    --sw-text: #2a2a33;
    --sw-muted: #77737f;
    --sw-low: #d6453d;
}
:root[data-theme="dark"] {
    --sw-bg: #161a24;
    --sw-bg-glow: #232a3b;
    --sw-panel: #1f2533;
    --sw-frame: #0e1118;
    --sw-cell-top: #2a3244;
    --sw-cell: #232a3a;
    --sw-text: #eceef4;
    --sw-muted: #8d93a5;
    --sw-low: #ff7a70;
}

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

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

.sw-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    width: 100%;
    padding: .75rem 0 .25rem;
}
.sw-back, .sw-new {
    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(--sw-panel);
    color: var(--sw-text);
    font-size: 1.2rem;
    text-decoration: none;
    cursor: pointer;
}
.sw-scores { display: flex; gap: .75rem; }
.sw-score { display: flex; flex-direction: column; align-items: center; min-width: 3.4rem; }
.sw-score > span:last-child { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.sw-label { font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; color: var(--sw-muted); }
.sw-moves.sw-low > span:last-child { color: var(--sw-low); }

.sw-board {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.sw-board-svg {
    display: block;
    width: min(100%, calc((100dvh - 8.5rem) * var(--sw-aspect, .75)));
    height: auto;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
}
.sw-help {
    margin: .25rem 0 .75rem;
    font-size: .8rem;
    color: var(--sw-muted);
    text-align: center;
}

.sw-panel polygon, .sw-panel-shadow polygon {
    fill: var(--sw-frame);
    stroke: var(--sw-frame);
    stroke-width: 6;
    stroke-linejoin: round;
}
.sw-panel-shadow { transform: translateY(1.2px); opacity: .18; }
.sw-panel-shadow polygon { fill: #000; stroke: #000; stroke-width: 7; }
.sw-cell { fill: url(#sw-empty); }

/* a tile: its place in transform (moves with a transition), the look inside */
.sw-tile { transition: transform .28s cubic-bezier(.5, 0, .75, 1.2); cursor: pointer; }
.sw-tile.sw-still { transition: none; }
.sw-tile-in { transform-box: fill-box; transform-origin: center; transition: transform .12s, filter .12s; }
.sw-hex { stroke: rgba(255, 255, 255, .45); stroke-width: .6; stroke-linejoin: round; }
.sw-ring { fill: rgba(255, 255, 255, .14); stroke: none; }
.sw-symbol { fill: rgba(255, 255, 255, .92); stroke-width: .13; stroke-linejoin: round; }
.sw-tile.sw-selected .sw-tile-in { transform: scale(1.1); filter: brightness(1.15) drop-shadow(0 0 1.5px rgba(255, 255, 255, .9)); }

/* a star: a white rim and a glow; it bursts its neighbours when it clears */
.sw-rays { display: none; fill: rgba(255, 255, 255, .7); }
.sw-tile.sw-star .sw-rays { display: inline; }
.sw-tile.sw-star .sw-hex { stroke: #ffd23f; stroke-width: 1.3; }
.sw-tile.sw-star .sw-ring { display: none; }
.sw-tile.sw-star .sw-tile-in { animation: sw-glow 1.4s ease-in-out infinite alternate; }
@keyframes sw-glow {
    from { filter: drop-shadow(0 0 0 rgba(255, 240, 180, 0)); }
    to { filter: drop-shadow(0 0 2.5px rgba(255, 240, 180, 1)) brightness(1.12); }
}

.sw-tile.sw-clearing .sw-tile-in { animation: sw-clear .26s ease-in forwards; }
@keyframes sw-clear {
    40% { transform: scale(1.18); filter: brightness(1.6); }
    100% { transform: scale(0); opacity: 0; }
}
.sw-tile.sw-making .sw-tile-in { animation: sw-make .26s ease-out; }
@keyframes sw-make {
    50% { transform: scale(1.25) rotate(30deg); filter: brightness(1.6); }
}
.sw-tile.sw-hint .sw-tile-in { animation: sw-hint 1s ease-in-out infinite; }
@keyframes sw-hint {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); filter: brightness(1.2); }
}
.sw-burst {
    fill: none;
    stroke: #fff;
    stroke-width: 2;
    transform-box: fill-box;
    transform-origin: center;
    animation: sw-burst .5s ease-out forwards;
}
@keyframes sw-burst {
    from { transform: scale(.6); opacity: 1; }
    to { transform: scale(2.6); opacity: 0; }
}

.sw-pop {
    position: absolute;
    left: 50%;
    top: 40%;
    transform: translate(-50%, -50%);
    font-size: 1.8rem;
    font-weight: 800;
    white-space: nowrap;
    color: var(--sw-text);
    text-shadow: 0 2px 6px var(--sw-bg);
    pointer-events: none;
    animation: sw-pop 1s ease-out forwards;
}
.sw-pop-big { font-size: 2.4rem; color: #e0a100; }
@keyframes sw-pop {
    0% { opacity: 0; transform: translate(-50%, -20%) scale(.8); }
    20% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
    100% { opacity: 0; transform: translate(-50%, -120%) scale(1); }
}

.sw-over {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, .45);
}
.sw-over[hidden] { display: none; }
.sw-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(--sw-panel);
    color: var(--sw-text);
    text-align: left;
}
.sw-over-box h2 { margin-top: 0; }
.sw-over-best { color: #e0a100; font-weight: 700; }
.sw-over-mascot { width: 7.5rem; height: auto; }
.sw-over-buttons { grid-column: 1 / -1; display: flex; justify-content: center; gap: .75rem; }

/* the mascot's portrait in the header */
.sw-mascot {
    width: 3.4rem;
    height: 3.4rem;
    border-radius: 50%;
    overflow: hidden;
    background: var(--sw-panel);
    flex: 0 0 auto;
}

@media (max-width: 22rem) {
    .sw-scores { gap: .4rem; }
    .sw-score { min-width: 2.8rem; }
    .sw-mascot { width: 2.8rem; height: 2.8rem; }
}

@media (prefers-reduced-motion: reduce) {
    .sw-tile, .sw-tile-in { transition: none; }
    .sw-tile.sw-star .sw-tile-in, .sw-tile.sw-hint .sw-tile-in, .sw-burst, .sw-pop { animation: none; }
    .sw-tile.sw-hint .sw-tile-in { transform: scale(1.1); }
}
