/* ════════════════════════════════════════════════════
   THEME MODE
   Styles for the settings cog and the display-theme sheet
   (Colours / White pieces / Mono), shared across Classic/Pro/Extreme.
   Doesn't touch stylesheetcomplete.css.
   ════════════════════════════════════════════════════ */

/* ── Cog button — plain icon, no box, sits just left of the account tab ──
   The account tab expands leftward on hover/focus and has no fixed width
   (it sizes to "Sign in" or the signed-in username), so we can't reliably
   slide the cog along with it in CSS. Instead #accountBtn is raised above
   the cog in the stacking order, so when the tab expands it simply slides
   over the top of the cog — the cog goes underneath rather than colliding
   with the tab's text or intercepting its click. */
#themeCogBtn {
    position: fixed;
    top: 14px;
    right: 46px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    z-index: 499;
    opacity: 0.9;
    transition: opacity 0.15s, transform 0.15s;
}

#themeCogBtn:hover,
#themeCogBtn:focus-visible {
    opacity: 1;
    transform: rotate(25deg);
}

#themeCogBtn svg {
    flex-shrink: 0;
    color: #fff;
    /* No pill background behind the icon any more, so give it its own
       shadow for legibility over both the light canvas and the orange
       gradient edge. */
    filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.55));
}

#accountBtn {
    /* Sit above the cog so the tab slides over it on hover, instead of the
       cog appearing to float on top of the tab's label. */
    z-index: 501;
}

/* On mobile there's no hover state to reveal the account tab, so it just
   sits as a small icon at the top right — putting the cog beside it made
   the pair feel cramped. Stack the cog underneath instead. Account tab is
   roughly top:8px + ~34px tall on mobile (see #accountBtn's mobile rule in
   stylesheetcomplete.css), so 50px clears it with a bit of breathing room. */
@media (max-width: 480px) {
    #themeCogBtn {
        top: 50px;
        right: 8px;
        width: 28px;
        height: 28px;
    }

    /* On mobile the canvas fills almost the whole viewport even in
       Colours mode (no padding/white-box breakpoint below 700px), so the
       cog sits directly over the light canvas background there — a white
       icon all but disappears against it. Switch to dark grey (matching
       the account button's own icon colour) and drop the shadow, which
       doesn't help against a light background. The dark-mode themes
       (orange/blue/pink/mono backdrop) keep the white icon + shadow,
       since that's still what's behind the cog there. */
    body:not(.jigsy-dark-mode) #themeCogBtn svg {
        color: #4a4a4a;
        filter: none;
    }
}

/* ════════════════════════════════════════════════════
   THEME SHEET (bottom sheet, mirrors #accountSheet)
   ════════════════════════════════════════════════════ */

#themeSheet {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 10001;
    display: none;
    align-items: flex-end;
    justify-content: center;
    backdrop-filter: blur(2px);
}

#themeSheet.open {
    display: flex;
}

#themeSheetPanel {
    background: #fff;
    border-radius: 20px 20px 0 0;
    width: 100%;
    max-width: 420px;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    padding: 0 0 env(safe-area-inset-bottom, 12px);
    animation: tmSlideUp 0.26s cubic-bezier(0.22, 1, 0.36, 1);
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
    font-family: 'Momo Trust Display', Arial, sans-serif;
}

@keyframes tmSlideUp {
    from { transform: translateY(60px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}

@media (min-width: 560px) {
    #themeSheet {
        align-items: center;
    }
    #themeSheetPanel {
        border-radius: 18px;
        max-height: 80vh;
    }
}

#themeSheetHandle {
    display: flex;
    justify-content: center;
    padding: 12px 0 4px;
    cursor: grab;
    touch-action: none;
}

#themeSheetHandle > div {
    width: 36px;
    height: 4px;
    background: #ddd;
    border-radius: 2px;
}

#themeSheetClose {
    position: absolute;
    top: 10px;
    right: 12px;
    background: none;
    border: none;
    color: #bbb;
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s, background 0.15s;
    z-index: 1;
    min-width: 30px;
    min-height: 30px;
}

#themeSheetClose:hover {
    color: #555;
    background: #f0f0f0;
}

.tm-view {
    padding: 8px 24px 26px;
}

.tm-title {
    font-size: 22px;
    font-weight: normal;
    color: #222;
    margin: 12px 0 6px;
}

.tm-sub {
    font-size: 13px;
    color: #888;
    margin-bottom: 16px;
    line-height: 1.4;
}

/* ── Preview swatches — selectable buttons, one per board style ─ */
.tm-preview-group {
    display: flex;
    gap: 10px;
    margin-bottom: 8px;
}

.tm-preview-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 7px;
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    cursor: pointer;
    font-family: inherit;
}

.tm-preview-swatch {
    width: 100%;
    height: 62px;
    border-radius: 10px;
    position: relative;
    overflow: hidden;
    border: 1.5px solid #eee;
    box-sizing: border-box;
    transition: border-color 0.15s, box-shadow 0.15s;
}

/* Selected state — ring around the swatch plus a tick badge, top right */
.tm-preview-btn--active .tm-preview-swatch {
    border-color: #333;
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.12);
}

.tm-preview-check {
    display: none;
    position: absolute;
    top: 6px;
    right: 6px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.78);
    align-items: center;
    justify-content: center;
}

.tm-preview-btn--active .tm-preview-check {
    display: flex;
}

.tm-preview-caption {
    font-size: 13px;
    color: #444;
    letter-spacing: 0.01em;
}

.tm-preview-btn--active .tm-preview-caption {
    color: #222;
    font-weight: 600;
}

.tm-preview-swatch--classic {
    background: #f1f2eb;
}

.tm-preview-swatch--classic .tm-dot {
    position: absolute;
    width: 26px;
    height: 26px;
    border-radius: 6px;
}

.tm-preview-swatch--classic .tm-dot--1 { background: #de9236; top: 10px; left: 14px; }
.tm-preview-swatch--classic .tm-dot--2 { background: #6aaac6; top: 18px; left: 32px; }
.tm-preview-swatch--classic .tm-dot--3 { background: #de3681; top: 8px;  left: 50px; }

.tm-preview-swatch--minimal {
    /* Set to the actual per-variant dark-mode gradient by theme-mode.js;
       falls back to a generic dark tone if that hasn't run yet. */
    background: var(--tm-preview-dark-bg, #8a5220);
}

/* "Mono" swatch — same white-piece/black-overlap rendering as "White
   pieces", but a flat neutral grey backdrop (hardcoded — unlike the
   Colours/White-pieces swatches it doesn't vary per game variant, so there's
   no need to set it via a JS custom property). */
.tm-preview-swatch--mono {
    background: linear-gradient(131deg, #585858 0%, #626262 25%, #727272 50%, #626262 75%, #585858 100%);
}

.tm-preview-swatch--minimal .tm-blob,
.tm-preview-swatch--mono .tm-blob {
    position: absolute;
    width: 30px;
    height: 30px;
    border-radius: 7px;
    background: radial-gradient(circle at center, rgba(255,255,255,0.5) 0%, rgba(255,255,255,1) 100%);
}

.tm-preview-swatch--minimal .tm-blob--1,
.tm-preview-swatch--mono .tm-blob--1 { top: 12px; left: 16px; }
.tm-preview-swatch--minimal .tm-blob--2,
.tm-preview-swatch--mono .tm-blob--2 { top: 20px; left: 34px; }
.tm-preview-swatch--minimal .tm-overlap,
.tm-preview-swatch--mono .tm-overlap {
    position: absolute;
    width: 12px;
    height: 14px;
    top: 20px;
    left: 34px;
    background: #000;
    border-radius: 3px;
}

/* ── Section label (groups the HUD toggles) ─ */
.tm-section-label {
    font-size: 11px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #bbb;
    margin: 18px 0 2px;
}

/* ── Option row + switch ─ */
.tm-option-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 0;
}

/* Divider only between two consecutive option rows — not before the first
   one, regardless of what other elements precede it. */
.tm-option-row + .tm-option-row {
    border-top: 1px solid #f0f0f0;
}

.tm-option-text {
    flex: 1;
}

.tm-option-label {
    font-size: 15px;
    color: #222;
}

.tm-option-desc {
    font-size: 12px;
    color: #999;
    margin-top: 2px;
    line-height: 1.35;
}

.tm-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 26px;
    flex-shrink: 0;
}

.tm-switch input {
    opacity: 0;
    width: 44px;
    height: 26px;
    margin: 0;
    position: absolute;
    cursor: pointer;
    z-index: 1;
}

.tm-switch-track {
    position: absolute;
    inset: 0;
    background: #ddd;
    border-radius: 26px;
    transition: background 0.18s;
}

.tm-switch-track::before {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    left: 3px;
    top: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.18s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

.tm-switch input:checked + .tm-switch-track {
    background: #de9236;
}

.tm-switch input:checked + .tm-switch-track::before {
    transform: translateX(18px);
}

.tm-footnote {
    font-size: 11px;
    color: #bbb;
    margin-top: 14px;
    line-height: 1.5;
}

/* ════════════════════════════════════════════════════
   DARK MODE — edge-to-edge play area
   Applied to <body class="jigsy-dark-mode"> by theme-mode.js.
   Canvas sizing/position is handled in JS (setupCanvasMinimal /
   positionUIElementsMinimal); this just strips the frame that would
   otherwise sit around the play area, and flushes the bottom controls.
   ════════════════════════════════════════════════════ */

/* Body itself is sized with CSS 100vh (stylesheetcomplete.css) while the
   canvas is sized from JS window.innerHeight (setupCanvasMinimal) — on
   mobile Safari those two don't always agree, and body's flex centring
   then leaves a thin sliver of the body element showing above/below the
   canvas. --tm-canvas-bg is set in theme-mode.js to whatever the canvas'
   own background currently is, so that sliver is invisible instead of
   showing the wrong (always orange/blue/pink) body gradient underneath. */
body.jigsy-dark-mode {
    background: var(--tm-canvas-bg, #4a4a4a);
}

body.jigsy-dark-mode #canvasContainer {
    padding: 0;
    background: none;
    border-radius: 0;
    box-shadow: none;
}

body.jigsy-dark-mode canvas#gameCanvas {
    border-radius: 0;
}

/* Keep this "14px" in sync with EDGE_PAD in theme-mode.js and the iOS fix
   in index-theme-test.htm — dark mode pulls the HUD in from the true edge
   a little rather than sitting flush against it. */
body.jigsy-dark-mode #controls {
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
}

/* #hintBtn's position is set directly by positionUIElementsMinimal() in
   theme-mode.js (it needs the canvas rect, same as the timer/logo), so
   there's no CSS rule for it here — an inline style always wins anyway. */

/* ── HUD lozenges — timer / move counter / date, dark mode only ─ */
body.jigsy-dark-mode #timer,
body.jigsy-dark-mode #moveCounter,
body.jigsy-dark-mode #levelIndicator {
    background: rgba(0, 0, 0, 0.6);
    border: none;
    border-radius: 8px;
    color: #fff;
}

body.jigsy-dark-mode #levelIndicator:hover {
    background: rgba(0, 0, 0, 0.72);
}

/* Timer's pause/play icons are inline SVGs with a hardcoded dark fill —
   override it so they read on the black lozenge. */
body.jigsy-dark-mode #timer svg path {
    fill: #fff;
}

/* ── Timer / move-counter show-hide toggles (theme sheet) ───────────────
   The game itself sets these elements' inline style.display at several
   call sites, so a body-class + !important override is the reliable way
   to force them hidden regardless of what the game code just did. */
body.jigsy-hide-timer #timer {
    display: none !important;
}

body.jigsy-hide-movecounter #moveCounter {
    display: none !important;
}

/* ── Doubled win animation — dark mode only ──────────────────────────────
   Same technique as triangles/jigsy-adp.html's "v2 win animation": two
   stacked Lottie instances layered on top of each other instead of one.
     - #lottieAnimation (wave 1): black circles, scaled 1.25x, rendered with
       mix-blend-mode: difference — the AdP "ink" effect, inverts whatever's
       underneath it.
     - #lottieAnimationDark2 (wave 2): white circles, scaled 1.55x, rotated,
       fired ~220ms later by theme-mode.js — lands as a second wave.
   Classic theme leaves both elements with their original (unscoped) styling
   — #lottieAnimation stays centred via #lottieContainer's flex layout, and
   #lottieAnimationDark2 is simply never used. */
body.jigsy-dark-mode #lottieAnimation {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(1.25);
    mix-blend-mode: difference;
}

body.jigsy-dark-mode #lottieAnimationDark2 {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 80vw;
    max-width: 980px;
    height: 80vw;
    max-height: 980px;
    transform: translate(-50%, -50%) scale(1.55) rotate(22deg);
}
