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

/* Sudoku: one screen, the grid under the header and the pad under the grid. */
:root {
    --sd-bg: #f3f1ec;
    --sd-bg-glow: #fffdf8;
    --sd-panel: #ffffff;
    --sd-line: #2f3444;
    --sd-thin: #d6d0c4;
    --sd-cell: #fffdf8;
    --sd-near: #ece6da;
    --sd-same: #d7e3f7;
    --sd-selected: #b9cff2;
    --sd-text: #2a2a33;
    --sd-muted: #77737f;
    --sd-entry: #2465d6;
    --sd-note: #6b6875;
    --sd-accent: #e8505b;
    --sd-conflict-bg: #fbdcdc;
    --sd-pad: #ffffff;
    --sd-pad-done: #e5e1d8;
    --sd-solved: #ffe08a;
}
:root[data-theme="dark"] {
    --sd-bg: #161a24;
    --sd-bg-glow: #232a3b;
    --sd-panel: #1f2533;
    --sd-line: #8d96ad;
    --sd-thin: #343c4f;
    --sd-cell: #1c2230;
    --sd-near: #252d3e;
    --sd-same: #2c3e60;
    --sd-selected: #34507f;
    --sd-text: #eceef4;
    --sd-muted: #8d93a5;
    --sd-entry: #79acff;
    --sd-note: #a4aabb;
    --sd-conflict-bg: #4a2630;
    --sd-pad: #252c3b;
    --sd-pad-done: #1a1f2b;
    --sd-solved: #8a6a12;
}

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

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

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

/* the grid: 3 × 3 boxes of 3 × 3 cells; the gaps are the lines */
.sd-board {
    position: relative;
    flex: 0 1 auto;
    margin-top: auto; /* with the setting's margin-bottom: the grid and pad in the middle */
    width: min(100%, calc(100dvh - 16.5rem));
    min-width: 15rem;
}
.sd-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 2px;
    aspect-ratio: 1;
    padding: 2px;
    border-radius: .6rem;
    background: var(--sd-line);
    box-shadow: 0 .3rem 1rem rgba(0, 0, 0, .12);
    overflow: hidden;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: opacity .2s;
}
.sd-box {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 1px;
    background: var(--sd-thin);
    min-width: 0;
    min-height: 0;
}
.sd-cell {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    min-height: 0;
    background: var(--sd-cell);
    container-type: size;
    cursor: pointer;
    transition: background-color .12s;
}
.sd-cell.sd-near { background: var(--sd-near); }
.sd-cell.sd-same { background: var(--sd-same); }
.sd-cell.sd-selected { background: var(--sd-selected); }
.sd-cell.sd-conflict { background: var(--sd-conflict-bg); }
.sd-cell.sd-conflict.sd-selected { background: var(--sd-selected); }

.sd-value {
    font-size: 62cqh;
    line-height: 1;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-variant-numeric: tabular-nums;
}
.sd-given .sd-value { font-weight: 800; color: var(--sd-text); }
.sd-entry .sd-value { font-weight: 500; color: var(--sd-entry); }
.sd-cell.sd-conflict .sd-value, .sd-cell.sd-wrong .sd-value { color: var(--sd-accent); }
.sd-cell.sd-wrong .sd-value { text-decoration: underline wavy; text-decoration-thickness: 1px; text-underline-offset: 2px; }

.sd-notes {
    position: absolute;
    inset: 1px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    pointer-events: none;
}
.sd-notes > span {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 25cqh;
    line-height: 1;
    font-weight: 600;
    color: var(--sd-note);
    border-radius: 30%;
}
.sd-notes > span.sd-note-same { background: var(--sd-entry); color: #fff; }

.sd-making-text {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    margin: 0;
    font-weight: 600;
    color: var(--sd-muted);
}
.sd.sd-making .sd-grid { opacity: .25; }
.sd.sd-making .sd-making-text { display: flex; }

/* the pad */
.sd-pad {
    width: min(100%, 30rem);
    margin-top: .75rem;
    touch-action: manipulation;
}
.sd-digits { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: .3rem; }
.sd-digit, .sd-tool {
    border: 0;
    border-radius: .6rem;
    background: var(--sd-pad);
    color: var(--sd-text);
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .12);
    transition: background-color .12s, color .12s, transform .08s;
}
.sd-digit:active, .sd-tool:active { transform: scale(.94); }
.sd-digit {
    position: relative;
    height: 3.4rem;
    padding: 0;
    font-size: 1.6rem;
    font-weight: 600;
    color: var(--sd-entry);
}
.sd-left {
    position: absolute;
    right: .3rem;
    bottom: .15rem;
    font-size: .6rem;
    font-weight: 600;
    color: var(--sd-muted);
}
.sd-digit.sd-done { background: var(--sd-pad-done); color: var(--sd-muted); opacity: .45; box-shadow: none; }
/* minmax(0, 1fr): the three always fit, also with longer words (Dutch) on a small
   phone; the icon goes above the word when the word needs the room */
.sd-tools { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .5rem; margin-top: .5rem; }
.sd-tool {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    min-width: 0;
    height: 2.8rem;
    padding: 0 .3rem;
    font-size: .95rem;
}
.sd-tool span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 380px) {
    .sd-tool { flex-direction: column; gap: 0; height: 3.1rem; font-size: .78rem; }
    .sd-tool i { font-size: 1.05rem; }
}
.sd-tool i { font-size: 1.2rem; }
.sd-tool:disabled { opacity: .4; cursor: default; }
.sd-tool.sd-on { background: var(--sd-entry); color: #fff; }
.sd-setting {
    display: flex;
    align-items: center;
    gap: .4rem;
    margin: .6rem 0 auto;
    padding-bottom: .5rem;
    font-size: .85rem;
    color: var(--sd-muted);
}
.sd-setting input { width: 1.1rem; height: 1.1rem; accent-color: var(--sd-entry); }

.sd.sd-solved .sd-pad, .sd.sd-making .sd-pad { opacity: .5; pointer-events: none; }

/* solved: a wave of colour from the middle out */
.sd.sd-solved .sd-cell {
    animation: sd-wave .6s ease-out both;
    animation-delay: var(--sd-delay, 0ms);
}
@keyframes sd-wave {
    0% { background: var(--sd-cell); transform: scale(1); }
    40% { background: var(--sd-solved); transform: scale(1.12); }
    100% { background: var(--sd-cell); transform: scale(1); }
}

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

/* the mascot's portrait in the header */
.sd-mascot {
    width: 3.2rem;
    height: 3.2rem;
    border-radius: 50%;
    overflow: hidden;
    background: var(--sd-panel);
    flex: 0 0 auto;
}
@media (max-width: 22rem) {
    .sd-score-level { display: none; }
}
@media (prefers-reduced-motion: reduce) {
    .sd.sd-solved .sd-cell { animation: none; background: var(--sd-solved); }
    .sd-cell, .sd-digit, .sd-tool { transition: none; }
    .sd-digit:active, .sd-tool:active { transform: none; }
}
