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

/* Triangles: one screen, board on top, the three pieces below. */
:root {
    --tri-bg: #f3f1ec;
    --tri-bg-glow: #fffdf8;
    --tri-panel: #ffffff;
    --tri-frame: #cdc5b6;
    --tri-cell-top: #e9e5dc;
    --tri-cell: #ddd7cb;
    --tri-text: #2a2a33;
    --tri-muted: #77737f;
}
:root[data-theme="dark"] {
    --tri-bg: #161a24;
    --tri-bg-glow: #232a3b;
    --tri-panel: #1f2533;
    --tri-frame: #0e1118;
    --tri-cell-top: #2a3244;
    --tri-cell: #232a3a;
    --tri-text: #eceef4;
    --tri-muted: #8d93a5;
}

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

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

.tri-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: .75rem 0 .25rem;
}
.tri-back, .tri-new {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    border: 0;
    border-radius: 50%;
    background: var(--tri-panel);
    color: var(--tri-text);
    font-size: 1.2rem;
    text-decoration: none;
    cursor: pointer;
}
.tri-scores { display: flex; gap: 2rem; }
.tri-score { display: flex; flex-direction: column; align-items: center; min-width: 4rem; }
.tri-score > span:last-child { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tri-label { font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; color: var(--tri-muted); }

.tri-board {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.tri-board-svg {
    display: block;
    width: min(100%, calc((100dvh - 15rem) * var(--tri-aspect, 1.15)));
    height: auto;
    touch-action: none;
}
.tri-panel polygon, .tri-panel-shadow polygon {
    fill: var(--tri-frame);
    stroke: var(--tri-frame);
    stroke-width: .6;
    stroke-linejoin: round;
}
.tri-panel-shadow { transform: translateY(.12px); opacity: .18; }
.tri-panel-shadow polygon { fill: #000; stroke: #000; stroke-width: .7; }
.tri-cell { fill: url(#tri-empty); transition: fill .12s; }
.tri-cell.tri-filled, .tri-block { stroke: rgba(255, 255, 255, .35); stroke-width: .025; stroke-linejoin: round; }
.tri-cell.tri-preview { fill: var(--tri-preview); opacity: .45; }
.tri-cell.tri-filled.tri-will-clear, .tri-cell.tri-preview.tri-will-clear { opacity: 1; filter: brightness(1.25); }
.tri-cell.tri-clearing {
    transform-box: fill-box;
    transform-origin: center;
    animation: tri-clear .35s ease-in forwards;
}
@keyframes tri-clear {
    40% { transform: scale(1.15); filter: brightness(1.6); }
    100% { transform: scale(0); opacity: 0; }
}

.tri-tray {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    width: 100%;
    height: 10rem;
    flex: 0 0 auto;
    padding-bottom: .5rem;
    touch-action: none;
}
.tri-slot {
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    touch-action: none;
}
.tri-slot.tri-dragging .tri-piece { opacity: .15; }
.tri-slot.tri-nofit .tri-piece { opacity: .3; filter: grayscale(1); }
.tri-piece { pointer-events: none; overflow: visible; }

.tri-floating {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 10;
    pointer-events: none;
    filter: drop-shadow(0 6px 8px rgba(0, 0, 0, .3));
}

.tri-pop {
    position: absolute;
    left: 50%;
    top: 40%;
    transform: translate(-50%, -50%);
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--tri-text);
    text-shadow: 0 2px 6px var(--tri-bg);
    pointer-events: none;
    animation: tri-pop 1s ease-out forwards;
}
@keyframes tri-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); }
}

.tri-over {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, .45);
}
.tri-over[hidden] { display: none; }
.tri-over-box {
    padding: 1.5rem 2rem;
    border-radius: 1rem;
    background: var(--tri-panel);
    color: var(--tri-text);
    text-align: center;
}
.tri-over-box h2 { margin-top: 0; }
.tri-over-best { color: #e0a100; font-weight: 700; }
.tri-day { margin: -.5rem 0 .5rem; color: var(--tri-muted); font-size: .85rem; }

/* the mascot: her portrait in the header, all of her when the game is over */
.tri-mascot {
    width: 3.4rem;
    height: 3.4rem;
    border-radius: 50%;
    overflow: hidden;
    background: var(--tri-panel);
    flex: 0 0 auto;
}
.tri-over-box { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: .5rem 1rem; text-align: left; margin: 0 1rem; }
.tri-over-mascot { width: 7.5rem; height: auto; }
.tri-over-buttons { grid-column: 1 / -1; display: flex; justify-content: center; gap: .75rem; }
