/* Chain Sum
   Porcelain number tiles on a deep indigo board; chains are colored strands.
   One typeface (Bricolage Grotesque, variable weight and width). */

@font-face {
    font-family: 'Bricolage';
    src: url('../fonts/bricolage.woff2') format('woff2');
    font-weight: 200 800;
    font-stretch: 75% 100%;
    font-display: swap;
}

:root {
    --bg-0: #0E0F2C;        /* board well, deepest */
    --bg-1: #14163A;        /* app background */
    --bg-2: #1D2050;        /* raised surfaces */
    --bg-3: #282C66;        /* pressed / borders */
    --line: rgba(190, 194, 240, 0.12);
    --text: #F2F0FA;
    --text-2: #A9ACD8;
    --text-3: #7074AC;
    --paper: #ECE6D8;
    --paper-hi: #FAF7F0;
    --paper-shade: #C4B99F;
    --tile-ink: #1C1F4D;
    --danger: #FF6B5E;
    --font: 'Bricolage', ui-rounded, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
    --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --safe-t: env(safe-area-inset-top, 0px);
    --safe-b: env(safe-area-inset-bottom, 0px);
    --safe-l: env(safe-area-inset-left, 0px);
    --safe-r: env(safe-area-inset-right, 0px);
    --ad-height: 0px;
    color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg-1);
    color: var(--text);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    user-select: none;
    overscroll-behavior: none;
    overflow: hidden;
}

body {
    background:
        radial-gradient(120% 60% at 50% -10%, #23276A 0%, transparent 60%),
        var(--bg-1);
}

h1, h2, p, ol, ul, dl, dd { margin: 0; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; }
svg { display: block; }
[hidden] { display: none !important; }

.sr-only {
    position: absolute; width: 1px; height: 1px; overflow: hidden;
    clip: rect(0 0 0 0); white-space: nowrap;
}

:focus { outline: none; }
:focus-visible { outline: 3px solid var(--paper); outline-offset: 3px; border-radius: 12px; }

/* ------------------------------------------------------------ screens */

.screen {
    position: fixed;
    inset: 0;
    display: none;
    flex-direction: column;
    padding: var(--safe-t) var(--safe-r) 0 var(--safe-l);
}

.screen.is-active {
    display: flex;
    animation: screen-in 0.28s var(--ease-out);
}

@keyframes screen-in {
    from { opacity: 0; transform: translateY(10px); }
}

.screen-scroll {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding-bottom: calc(24px + var(--safe-b));
    scrollbar-width: none;
}
.screen-scroll::-webkit-scrollbar { display: none; }

/* Top bar used by every screen except home */
.bar {
    display: grid;
    grid-template-columns: 48px 1fr 48px;
    align-items: center;
    gap: 8px;
    padding: 10px 12px 6px;
    max-width: 560px;
    width: 100%;
    margin: 0 auto;
}

.bar-title { text-align: center; min-width: 0; }
.bar-title h1 {
    font-size: 20px;
    font-weight: 750;
    font-stretch: 85%;
    letter-spacing: -0.01em;
    line-height: 1.15;
}
.bar-title p { font-size: 13px; color: var(--text-2); }

.icon-btn {
    width: 48px;
    height: 48px;
    border-radius: 16px;
    display: grid;
    place-items: center;
    color: var(--text);
    transition: background 0.15s, transform 0.15s;
}
.icon-btn:active { background: var(--bg-2); transform: scale(0.94); }
.icon-btn svg {
    width: 26px; height: 26px;
    fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.icon-btn-spacer { width: 48px; }

/* ------------------------------------------------------------ buttons */

.btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    width: 100%;
    min-height: 56px;
    padding: 12px 20px;
    border-radius: 18px;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.005em;
    transition: transform 0.12s, box-shadow 0.12s, background 0.15s;
}

/* Primary buttons are porcelain tiles, like the board */
.btn-primary {
    background: linear-gradient(180deg, var(--paper-hi), var(--paper));
    color: var(--tile-ink);
    box-shadow: inset 0 -4px 0 var(--paper-shade), 0 8px 24px -10px rgba(0, 0, 0, 0.6);
}
.btn-primary:active {
    transform: translateY(2px);
    box-shadow: inset 0 -2px 0 var(--paper-shade), 0 4px 12px -8px rgba(0, 0, 0, 0.6);
}
.btn-primary.btn-danger {
    background: linear-gradient(180deg, #FF8A7F, var(--danger));
    color: #2A0B07;
    box-shadow: inset 0 -4px 0 #C2463B;
}

.btn-quiet { color: var(--text-2); min-height: 48px; font-weight: 600; }
.btn-quiet:active { background: var(--bg-3); }

.btn-label { font-size: 20px; font-weight: 800; font-stretch: 85%; }
.btn-detail { font-size: 14px; font-weight: 550; opacity: 0.7; }

.link-btn {
    display: block;
    margin: 28px auto 0;
    padding: 12px 16px;
    color: var(--text-2);
    font-weight: 600;
    text-decoration: underline;
    text-decoration-color: var(--text-3);
    text-underline-offset: 4px;
}

/* ------------------------------------------------------------ home */

/* The home screen fills exactly one screen: brand in the middle, actions at the
   bottom within thumb reach. It only scrolls on very short screens. */
.screen-scroll:has(> .home) { padding-bottom: 0; }
.home {
    display: flex;
    flex-direction: column;
    min-height: 100%;
    max-width: 440px;
    margin: 0 auto;
    padding: 8px 20px calc(16px + var(--safe-b));
}

.home-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 56px;
}
.home-top .icon-btn { margin-left: auto; }

.streak-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 34px;
    padding: 0 12px 0 8px;
    border-radius: 999px;
    background: var(--bg-2);
    font-weight: 750;
    font-variant-numeric: tabular-nums;
}
.streak-chip svg { width: 20px; height: 20px; fill: #FF923F; }

.hero {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 8px 0 28px;
}

.logo-mark { width: 120px; height: 120px; margin-bottom: 22px; overflow: visible; }
.logo-tiles rect { fill: var(--paper); }
.logo-strand {
    fill: none;
    stroke: #FF6B5E;
    stroke-width: 14;
    stroke-linecap: round;
    stroke-linejoin: round;
}
/* The strand draws itself once, on launch */
.is-launching .logo-strand {
    stroke-dasharray: 1;
    stroke-dashoffset: 1;
    animation: strand-draw 1.1s 0.25s var(--ease-out) forwards;
}
.logo-knot { fill: #FF6B5E; transform-origin: 100px 20px; }
.is-launching .logo-knot { animation: knot-in 0.35s var(--spring) both; }

@keyframes strand-draw { to { stroke-dashoffset: 0; } }
@keyframes knot-in { from { transform: scale(0); } }

.wordmark {
    font-size: 58px;
    font-weight: 800;
    font-stretch: 75%;
    letter-spacing: -0.035em;
    line-height: 0.95;
}

.tagline {
    margin-top: 12px;
    max-width: 30ch;
    color: var(--text-2);
    font-size: 16px;
    text-wrap: balance;
}

.home-actions { display: flex; flex-direction: column; gap: 12px; }

.btn-play { min-height: 72px; }
.btn-play .btn-label { font-size: 26px; }
.btn-continue { min-height: 76px; }

.home-links { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.pill-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 52px;
    border-radius: 18px;
    background: var(--bg-2);
    box-shadow: inset 0 0 0 1px var(--line);
    font-size: 16px;
    font-weight: 650;
    transition: transform 0.12s, background 0.15s;
}
.pill-btn:active { transform: scale(0.97); background: var(--bg-3); }
.pill-btn svg {
    width: 22px; height: 22px;
    fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

.daily-card {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 14px;
    width: 100%;
    padding: 14px 16px 14px 14px;
    border-radius: 22px;
    background: var(--bg-2);
    box-shadow: inset 0 0 0 1px var(--line);
    text-align: left;
    transition: transform 0.12s, background 0.15s;
}
.daily-card:active { transform: scale(0.985); background: var(--bg-3); }

.daily-tile {
    position: relative;
    width: 52px;
    height: 52px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    background: linear-gradient(180deg, var(--paper-hi), var(--paper));
    box-shadow: inset 0 -4px 0 var(--paper-shade);
    color: var(--tile-ink);
    font-size: 24px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}
.daily-card.is-done .daily-tile {
    background: #27C08A;
    color: #032419;
    box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.18);
}

.daily-text { display: flex; flex-direction: column; min-width: 0; }
.daily-title { font-size: 18px; font-weight: 750; }
.daily-meta { font-size: 14px; color: var(--text-2); }

.daily-action {
    padding: 8px 14px;
    border-radius: 999px;
    background: var(--paper);
    color: var(--tile-ink);
    font-weight: 750;
    font-size: 15px;
    white-space: nowrap;
}
.daily-card.is-done .daily-action { background: transparent; color: var(--text-2); box-shadow: inset 0 0 0 1.5px var(--bg-3); }

.section-title {
    margin: 32px 0 10px;
    font-size: 15px;
    font-weight: 650;
    color: var(--text-2);
}

.track-list {
    display: flex;
    flex-direction: column;
    border-radius: 22px;
    background: var(--bg-2);
    box-shadow: inset 0 0 0 1px var(--line);
    overflow: hidden;
}

.track-row {
    display: grid;
    grid-template-columns: 36px 1fr auto 16px;
    align-items: center;
    gap: 14px;
    min-height: 64px;
    padding: 0 18px 0 16px;
    text-align: left;
    transition: background 0.15s;
}
.track-row + .track-row { border-top: 1px solid var(--line); }
.track-row:active { background: var(--bg-3); }
.track-row::after {
    content: '';
    width: 9px; height: 9px;
    border-right: 2px solid var(--text-3);
    border-top: 2px solid var(--text-3);
    transform: rotate(45deg);
}

/* Miniature board: n x n porcelain cells with a staircase chain in the track color */
.track-glyph {
    display: grid;
    grid-template-columns: repeat(var(--n), 1fr);
    gap: 1.5px;
    width: 36px;
    height: 36px;
    padding: 3px;
    border-radius: 9px;
    background: var(--bg-0);
}
.track-glyph i { border-radius: 1.5px; background: var(--paper); opacity: 0.22; }
.track-glyph i.on { background: var(--track); opacity: 1; }
.track-text { display: flex; flex-direction: column; min-width: 0; }
.track-name { font-size: 18px; font-weight: 700; line-height: 1.2; }
.track-size { font-size: 14px; color: var(--text-3); }
.track-progress { font-size: 14px; color: var(--text-3); font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------ play (difficulty) */

.tracks {
    max-width: 520px;
    margin: 0 auto;
    padding: 10px 20px 0;
}
.tracks .section-title { margin-top: 28px; }

/* ------------------------------------------------------------ shop */

.shop {
    max-width: 520px;
    margin: 0 auto;
    padding: 10px 20px 0;
}

.hint-balance {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 18px;
    margin-bottom: 14px;
    border-radius: 22px;
    background: var(--bg-2);
    box-shadow: inset 0 0 0 1px var(--line);
}
.hint-balance-icon {
    flex: none;
    width: 56px;
    height: 56px;
    border-radius: 16px;
    display: grid;
    place-items: center;
    background: #FFC23D;
    box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.16);
}
.hint-balance-icon svg {
    width: 30px; height: 30px;
    fill: none; stroke: #2E2000; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.hint-balance-text { display: flex; flex-direction: column; min-width: 0; }
.hint-balance-text b { font-size: 26px; font-weight: 800; font-stretch: 85%; line-height: 1.1; }
.hint-balance-text small { font-size: 14px; color: var(--text-2); }

.offer-list { display: flex; flex-direction: column; gap: 10px; }
#hints .offer-list { margin-top: 20px; }

.offer {
    display: grid;
    grid-template-columns: 52px 1fr auto;
    align-items: center;
    gap: 14px;
    width: 100%;
    min-height: 72px;
    padding: 10px 14px 10px 10px;
    border-radius: 20px;
    background: var(--bg-2);
    box-shadow: inset 0 0 0 1px var(--line);
    text-align: left;
    transition: transform 0.12s, background 0.15s, opacity 0.15s;
}
#hints .offer { background: var(--bg-1); }
button.offer:active:not(:disabled) { transform: scale(0.985); background: var(--bg-3); }
.offer:disabled { opacity: 0.5; }

/* Offer icons are porcelain tiles, like the board */
.offer-icon {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    background: linear-gradient(180deg, var(--paper-hi), var(--paper));
    box-shadow: inset 0 -4px 0 var(--paper-shade);
    color: var(--tile-ink);
}
.offer-icon b { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.offer-icon svg {
    width: 26px; height: 26px;
    fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round;
}
.offer-icon svg path[d^="M8 5.5"] { fill: currentColor; stroke: none; }
/* The bundle: coral frame and a flag, the one loud element in the Shop */
#shop-featured:not(:empty) { margin-bottom: 10px; }
.offer.is-featured {
    position: relative;
    min-height: 84px;
    margin-top: 10px;
    box-shadow: inset 0 0 0 2px #FF6B5E, 0 16px 34px -18px rgba(255, 107, 94, 0.55);
}
.offer.is-featured .offer-icon { background: #FF6B5E; box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.18); color: #2A0B07; }
.offer.is-featured .offer-icon svg { fill: currentColor; stroke: none; }
.offer.is-featured .offer-text small { color: var(--text-2); font-weight: 600; }
.offer-flag {
    position: absolute;
    top: -11px;
    left: 18px;
    padding: 3px 10px;
    border-radius: 999px;
    background: #FF6B5E;
    color: #2A0B07;
    font-size: 12px;
    font-weight: 800;
}
.offer.is-owned .offer-icon { background: #27C08A; color: #032419; box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.18); }

.offer-text { display: flex; flex-direction: column; min-width: 0; }
.offer-text b { font-size: 17px; font-weight: 700; }
.offer-text small { font-size: 13px; color: #FFC23D; font-weight: 650; }
.offer.is-owned .offer-text small { color: var(--text-2); font-weight: 500; }

.offer-price {
    padding: 8px 14px;
    border-radius: 999px;
    background: var(--paper);
    color: var(--tile-ink);
    font-weight: 750;
    font-size: 15px;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.shop-note {
    margin-top: 6px;
    padding: 14px 16px;
    border-radius: 16px;
    background: var(--bg-2);
    color: var(--text-2);
    font-size: 15px;
    text-align: center;
    text-wrap: balance;
}

/* ------------------------------------------------------------ level select */

.levels {
    max-width: 520px;
    margin: 0 auto;
    padding: 10px 20px 0;
}

.levels-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    margin-top: 22px;
}

.level-tile {
    position: relative;
    aspect-ratio: 1;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: linear-gradient(180deg, var(--paper-hi), var(--paper));
    box-shadow: inset 0 -4px 0 var(--paper-shade);
    color: var(--tile-ink);
    transition: transform 0.12s;
}
.level-tile:active:not(:disabled) { transform: translateY(2px); }
.level-num { font-size: 20px; font-weight: 750; font-variant-numeric: tabular-nums; line-height: 1; }

.level-tile.is-solved {
    background: var(--bg-2);
    color: var(--text);
    box-shadow: inset 0 0 0 1px var(--line);
}
.level-tile.is-next { box-shadow: inset 0 -4px 0 var(--paper-shade), 0 0 0 3px var(--bg-1), 0 0 0 5px var(--paper); }
.level-tile:disabled {
    background: transparent;
    color: var(--text-3);
    box-shadow: inset 0 0 0 1.5px var(--bg-3);
}

.level-stars { display: flex; gap: 1px; }
.level-stars .star { width: 11px; height: 11px; }

.star path { fill: var(--bg-3); }
.star.is-on path { fill: #FFC23D; }

/* ------------------------------------------------------------ game */

#screen-game { padding-bottom: calc(var(--safe-b) + var(--ad-height)); }

.game-timer {
    justify-self: end;
    padding-right: 6px;
    font-size: 16px;
    font-weight: 650;
    color: var(--text-2);
    font-variant-numeric: tabular-nums;
}

.game-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 560px;
    margin: 0 auto;
    padding: 4px 16px 0;
}
/* Sit the board a little above center on tall screens; tools stay at the bottom */
.game-body::before { content: ''; flex: 1; }
.game-body::after { content: ''; flex: 1.8; }

.hud {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: end;
    gap: 8px 12px;
    width: var(--board-size);
    padding: 4px 2px 0;
}

.readout { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.readout-value {
    font-size: 44px;
    font-weight: 800;
    font-stretch: 75%;
    letter-spacing: -0.03em;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    transition: color 0.2s;
}
.readout-target { font-size: 16px; color: var(--text-2); font-weight: 550; white-space: nowrap; }
.readout[data-mode="chain"] .readout-value { color: var(--chain); }
.readout.is-over .readout-value { color: var(--danger); }

.chain-dots {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
    max-width: 150px;
    padding-bottom: 6px;
}
.chain-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    box-shadow: inset 0 0 0 2px var(--chain);
    transition: transform 0.2s var(--spring), background 0.2s;
}
.chain-dot.is-done { background: var(--chain); }
.chain-dot.is-active { transform: scale(1.35); }

.readout-bar {
    grid-column: 1 / -1;
    height: 6px;
    border-radius: 3px;
    background: var(--bg-2);
    overflow: hidden;
}
.readout-bar::after {
    content: '';
    display: block;
    height: 100%;
    width: calc(var(--p, 0) * 100%);
    border-radius: inherit;
    background: var(--paper);
    transition: width 0.2s var(--ease-out), background 0.2s;
}
.readout[data-mode="chain"] ~ .readout-bar::after { background: var(--chain); }
.readout.is-over ~ .readout-bar::after { background: var(--danger); }

/* Board: as large as fits between the HUD and the toolbar */
.board-wrap {
    width: 100%;
    display: grid;
    place-items: center;
    padding: 20px 0 16px;
}

#screen-game {
    --board-size: min(calc(100vw - 36px - var(--safe-l) - var(--safe-r)), 520px,
                      calc(100dvh - 290px - var(--safe-t) - var(--safe-b) - var(--ad-height)));
}

.board {
    --cell: 60px;
    position: relative;
    width: var(--board-size);
    height: var(--board-size);
    border-radius: calc(var(--cell) * 0.24);
    background: var(--bg-0);
    box-shadow: 0 0 0 calc(var(--cell) * 0.12) var(--bg-0), 0 24px 50px -20px rgba(0, 0, 0, 0.8);
    touch-action: none;
    cursor: pointer;
}

.board-strands {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
}
.board-strands path {
    fill: none;
    stroke-width: 0.34;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.tile {
    --g: 0.06;
    position: absolute;
    left: calc((var(--c) + var(--g)) / var(--n) * 100%);
    top: calc((var(--r) + var(--g)) / var(--n) * 100%);
    width: calc((1 - 2 * var(--g)) / var(--n) * 100%);
    height: calc((1 - 2 * var(--g)) / var(--n) * 100%);
    display: grid;
    place-items: center;
    border-radius: calc(var(--cell) * var(--tile-round, 0.2));
    background: var(--tile-texture, none), linear-gradient(180deg, var(--paper-hi), var(--paper));
    box-shadow: inset 0 calc(var(--cell) * -0.06) 0 var(--paper-shade), var(--tile-edge, 0 0 transparent);
    color: var(--tile-ink);
    transition: background-color 0.18s, color 0.18s, box-shadow 0.18s, transform 0.18s var(--spring), opacity 0.3s, filter 0.3s;
}

.tile:not(.in-chain) .tile-value { text-shadow: var(--tile-glow, none); }
.tile-value {
    font-size: calc(var(--cell) * 0.44);
    font-weight: 750;
    font-stretch: 90%;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    margin-top: calc(var(--cell) * -0.04);
}

.tile.in-chain {
    background: var(--chain);
    color: var(--chain-ink);
    box-shadow: inset 0 calc(var(--cell) * -0.06) 0 rgba(0, 0, 0, 0.2),
                inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

/* Start tiles: always colored, marked with a porcelain ring, carry the target tag */
.tile.is-start { z-index: 2; }
.tile.is-start::before {
    content: '';
    position: absolute;
    inset: calc(var(--cell) * 0.07);
    border-radius: calc(var(--cell) * 0.15);
    box-shadow: inset 0 0 0 calc(var(--cell) * 0.035) rgba(255, 255, 255, 0.75);
    pointer-events: none;
}

.tile.is-satisfied::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: linear-gradient(160deg, rgba(255, 255, 255, 0.32) 0%, transparent 45%);
    pointer-events: none;
}

.tile.is-head {
    z-index: 3;
    transform: scale(1.08);
    box-shadow: inset 0 calc(var(--cell) * -0.06) 0 rgba(0, 0, 0, 0.2),
                0 0 0 calc(var(--cell) * 0.05) var(--bg-0),
                0 0 0 calc(var(--cell) * 0.1) var(--chain);
}

.tile-tag {
    position: absolute;
    top: calc(var(--cell) * -0.17);
    right: calc(var(--cell) * -0.17);
    min-width: calc(var(--cell) * 0.46);
    height: calc(var(--cell) * 0.34);
    padding: 0 calc(var(--cell) * 0.07);
    border-radius: 999px;
    display: grid;
    place-items: center;
    background: var(--bg-0);
    color: var(--text);
    box-shadow: inset 0 0 0 calc(var(--cell) * 0.035) var(--chain);
    font-size: calc(var(--cell) * 0.21);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    line-height: 1;
    transition: background 0.2s, color 0.2s;
}
.tile-tag.is-satisfied {
    background: var(--paper-hi);
    color: var(--tile-ink);
    box-shadow: inset 0 0 0 calc(var(--cell) * 0.035) var(--paper-hi);
}
.tile-tag.is-over {
    background: var(--danger);
    color: #2A0B07;
    box-shadow: none;
}

/* Live sum next to the finger while drawing */
.sum-bubble {
    position: absolute;
    left: calc((var(--c) + 0.5) / var(--n) * 100%);
    top: calc(var(--r) / var(--n) * 100%);
    z-index: 5;
    display: flex;
    align-items: baseline;
    gap: 1px;
    padding: 6px 12px 7px;
    border-radius: 999px;
    background: var(--bg-0);
    box-shadow: inset 0 0 0 2.5px var(--chain), 0 10px 24px -8px rgba(0, 0, 0, 0.8);
    color: var(--text);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transform: translate(-50%, -100%) scale(0.8);
    transition: opacity 0.12s, transform 0.12s var(--spring);
}
.sum-bubble b { font-size: 22px; font-weight: 800; line-height: 1; }
.sum-bubble span { font-size: 14px; color: var(--text-2); font-weight: 600; }
.sum-bubble.is-visible { opacity: 1; transform: translate(-50%, calc(-100% - 8px)); }
.sum-bubble.is-below { top: calc((var(--r) + 1) / var(--n) * 100%); }
.sum-bubble.is-below.is-visible { transform: translate(-50%, 8px); }
.sum-bubble.is-match { background: var(--chain); color: #0E0F2C; box-shadow: 0 10px 24px -8px rgba(0, 0, 0, 0.8); }
.sum-bubble.is-match span { color: rgba(14, 15, 44, 0.7); }
.sum-bubble.is-over { box-shadow: inset 0 0 0 2.5px var(--danger), 0 10px 24px -8px rgba(0, 0, 0, 0.8); }
.sum-bubble.is-over b { color: var(--danger); }

/* Tile feedback */
.tile.pop { animation: tile-pop 0.22s var(--spring); }
@keyframes tile-pop { from { transform: scale(0.82); } }

.tile.shake { animation: tile-shake 0.3s; }
@keyframes tile-shake {
    25% { transform: translateX(-6%); }
    50% { transform: translateX(5%); }
    75% { transform: translateX(-3%); }
}

.tile.ripple { animation: tile-ripple 0.42s var(--ease-out) calc(var(--i) * 45ms); }
@keyframes tile-ripple {
    40% { transform: scale(1.12); filter: brightness(1.15); }
}

.tile.wave { animation: tile-wave 0.6s var(--ease-out) calc(var(--i) * 50ms); }
@keyframes tile-wave {
    35% { transform: translateY(-12%) scale(1.06); filter: brightness(1.2); }
}

.coach {
    width: var(--board-size);
    margin-bottom: 6px;
    padding: 10px 14px;
    border-radius: 14px;
    background: var(--bg-2);
    color: var(--text-2);
    font-size: 15px;
    text-align: center;
    text-wrap: balance;
}

.toolbar {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    width: 100%;
    max-width: 440px;
    margin: 0 auto;
    padding: 6px 16px 14px;
}

.tool {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 10px 0 9px;
    border-radius: 18px;
    background: var(--bg-2);
    box-shadow: inset 0 0 0 1px var(--line);
    font-size: 13px;
    font-weight: 650;
    color: var(--text);
    transition: transform 0.12s, background 0.15s, opacity 0.15s;
}
.tool:active:not(:disabled) { transform: scale(0.96); background: var(--bg-3); }
.tool:disabled { opacity: 0.35; }
.tool svg {
    width: 24px; height: 24px;
    fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.tool-badge {
    position: absolute;
    top: 6px;
    right: calc(50% - 26px);
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 999px;
    display: grid;
    place-items: center;
    background: #FFC23D;
    color: #2E2000;
    font-size: 12px;
    font-weight: 800;
}

/* ------------------------------------------------------------ settings */

.settings {
    max-width: 520px;
    margin: 0 auto;
    padding: 12px 20px 0;
}

.group {
    border-radius: 20px;
    background: var(--bg-2);
    box-shadow: inset 0 0 0 1px var(--line);
    overflow: hidden;
}
.group + .group { margin-top: 16px; }
.group:not(:has(.row:not([hidden]))) { display: none; }

.row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    min-height: 58px;
    padding: 0 18px;
    font-size: 17px;
    font-weight: 600;
    text-align: left;
}
button.row:active { background: var(--bg-3); }
.row:not([hidden]) ~ .row:not([hidden]) { border-top: 1px solid var(--line); }
.row-value { color: var(--text-2); font-weight: 600; }
.row-danger { color: var(--danger); }

.switch {
    position: relative;
    flex: none;
    width: 52px;
    height: 32px;
    border-radius: 999px;
    background: var(--bg-3);
    transition: background 0.2s;
}
.switch::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--text-2);
    transition: transform 0.22s var(--spring), background 0.2s;
}
[aria-checked="true"] .switch { background: #27C08A; }
[aria-checked="true"] .switch::after { transform: translateX(20px); background: var(--paper-hi); }

.app-version { margin-top: 24px; text-align: center; font-size: 13px; color: var(--text-3); }

/* ------------------------------------------------------------ sheets */

.backdrop {
    position: fixed;
    inset: 0;
    z-index: 20;
    background: rgba(6, 7, 24, 0.6);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
}
.backdrop.is-visible { opacity: 1; pointer-events: auto; }

/* Sheets sit above the banner ad (a native view drawn over the page), so their
   buttons are never hidden behind it. --ad-height is 0 when no banner shows. */
.sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: var(--ad-height);
    z-index: 30;
    max-width: 520px;
    max-height: calc(100dvh - var(--safe-t) - var(--ad-height) - 24px);
    margin: 0 auto;
    overflow-y: auto;
    padding: 28px 24px calc(20px + var(--safe-b));
    border-radius: 30px 30px 0 0;
    background: var(--bg-2);
    box-shadow: 0 -1px 0 var(--line), 0 -30px 60px -20px rgba(0, 0, 0, 0.6);
    transform: translateY(105%);
    transition: transform 0.32s var(--ease-out);
}
.sheet.is-open { transform: translateY(0); }

.sheet-dialog {
    left: 20px;
    right: 20px;
    bottom: auto;
    top: 50%;
    max-width: 400px;
    border-radius: 26px;
    padding-bottom: 20px;
    transform: translateY(-40%) scale(0.96);
    opacity: 0;
    transition: transform 0.25s var(--ease-out), opacity 0.2s;
}
.sheet-dialog.is-open { transform: translateY(-50%); opacity: 1; }

.sheet-title {
    font-size: 30px;
    font-weight: 800;
    font-stretch: 80%;
    letter-spacing: -0.025em;
    line-height: 1.05;
    text-align: center;
}

.sheet-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 24px; }

.dialog-body { margin-top: 10px; color: var(--text-2); text-align: center; text-wrap: pretty; }

.win-stars { display: flex; justify-content: center; gap: 10px; margin-top: 18px; }
.win-stars .star { width: 46px; height: 46px; }
.sheet.is-open .win-stars .star { animation: star-in 0.45s var(--spring) both; animation-delay: calc(0.15s + var(--i) * 0.12s); }
@keyframes star-in { from { transform: scale(0) rotate(-30deg); } }

.win-stats {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin-top: 20px;
    text-align: center;
}
.win-stats dt { font-size: 14px; color: var(--text-2); }
.win-stats dd { font-size: 30px; font-weight: 800; font-stretch: 80%; font-variant-numeric: tabular-nums; }
.win-note { margin-top: 14px; text-align: center; color: var(--text-2); }
.win-earned { color: #FFC23D; font-weight: 650; }

/* Optional reward on the win sheet: clearly a choice, never in the way of "Next" */
.win-bonus {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    min-height: 52px;
    margin-top: 16px;
    border-radius: 16px;
    background: rgba(255, 194, 61, 0.12);
    box-shadow: inset 0 0 0 1.5px rgba(255, 194, 61, 0.5);
    color: #FFC23D;
    font-weight: 700;
    font-size: 16px;
    transition: transform 0.12s, background 0.15s;
}
.win-bonus:active { transform: scale(0.98); background: rgba(255, 194, 61, 0.2); }
.win-bonus svg { width: 20px; height: 20px; fill: currentColor; }
.win-bonus:disabled { opacity: 0.5; }

/* Daily card while a broken streak can be saved */
.daily-card.is-save .daily-tile { background: #FF923F; color: #2E1300; box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.18); }
.daily-card.is-save .daily-action { background: #FF923F; color: #2E1300; }

.howto-steps {
    list-style: none;
    padding: 0;
    margin-top: 20px;
    display: grid;
    gap: 14px;
    counter-reset: step;
}
.howto-steps li {
    display: grid;
    grid-template-columns: 104px 1fr;
    align-items: center;
    gap: 16px;
    counter-increment: step;
}
.howto-steps p { font-size: 16px; text-wrap: pretty; }
.howto-steps p::before {
    content: counter(step);
    display: inline-grid;
    place-items: center;
    width: 22px;
    height: 22px;
    margin-right: 8px;
    border-radius: 50%;
    background: var(--bg-3);
    font-size: 13px;
    font-weight: 800;
}
.howto-art {
    width: 104px;
    height: 104px;
    border-radius: 18px;
    background: var(--bg-0);
    padding: 6px;
}

.mini-board { width: 100%; height: 100%; overflow: visible; }
.mini-strands path { fill: none; stroke-width: 0.34; stroke-linecap: round; stroke-linejoin: round; }
.mini-tiles text { font-family: var(--font); font-size: 0.42px; font-weight: 750; text-anchor: middle; }
.mini-tag rect { fill: var(--bg-0); stroke: var(--chain); stroke-width: 0.04; }
.mini-tag text { fill: var(--text); font-family: var(--font); font-size: 0.28px; font-weight: 800; text-anchor: middle; }
.mini-tag.is-done rect { fill: var(--paper-hi); stroke: var(--paper-hi); }
.mini-tag.is-done text { fill: var(--tile-ink); }

.howto-tips {
    margin-top: 20px;
    padding: 14px 16px 14px 34px;
    border-radius: 16px;
    background: var(--bg-1);
    color: var(--text-2);
    font-size: 15px;
    display: grid;
    gap: 6px;
}

/* ------------------------------------------------------------ toast */

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(108px + var(--safe-b) + var(--ad-height));
    z-index: 40;
    width: max-content;
    max-width: min(420px, calc(100vw - 40px));
    padding: 12px 18px;
    border-radius: 16px;
    background: var(--paper-hi);
    color: var(--tile-ink);
    font-weight: 600;
    font-size: 15px;
    text-align: center;
    box-shadow: 0 16px 40px -12px rgba(0, 0, 0, 0.7);
    opacity: 0;
    transform: translate(-50%, 12px);
    transition: opacity 0.2s, transform 0.25s var(--ease-out);
    pointer-events: none;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast.is-top { bottom: auto; top: calc(16px + var(--safe-t)); transform: translate(-50%, -12px); }
.toast.is-top.is-visible { transform: translate(-50%, 0); }

/* ------------------------------------------------------------ chapters, tiers and rewards */

:root {
    --hard: #FF6B5E;
    --nightmare: #A06CFF;
    --nightmare-deep: #2A1D5C;
}

.home-top .icon-btn + .icon-btn { margin-left: 0; }
.pill-btn svg .is-empty { stroke-dasharray: 2.5 2.5; }

.streak-freezes {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    margin-left: 6px;
    padding-left: 8px;
    border-left: 1px solid var(--line);
    color: #9FD8FF;
}
.streak-freezes svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Mosaic: art in the placed tiles, numbered covers on the rest */
.mosaic { width: 100%; height: auto; overflow: visible; }
.mosaic-cover rect { fill: var(--bg-2); stroke: var(--line); stroke-width: 2; }
.mosaic-cover text { display: none; }
.mosaic-large .mosaic-cover text {
    display: inline;
    fill: var(--text-3);
    font-family: var(--font);
    font-size: 34px;
    font-weight: 750;
    text-anchor: middle;
}
.mosaic-cover.is-next rect { stroke: var(--paper); stroke-width: 5; }
.mosaic-cover.is-boss rect { fill: var(--nightmare-deep); }
.mosaic-cover.is-boss text { fill: var(--nightmare); }
.mosaic-fresh { fill: #fff; transform-box: fill-box; transform-origin: center; animation: piece-in 1s var(--ease-out) 0.35s both; pointer-events: none; }
@keyframes piece-in {
    0% { opacity: 1; transform: scale(1.12); }
    100% { opacity: 0; transform: scale(1); }
}
.mosaic-shine { animation: shine 2.4s 0.4s var(--ease-out) both; }
@keyframes shine { from { transform: translateX(0); } to { transform: translateX(640px); } }

/* Level select: one section per chapter */
.chapter + .chapter { margin-top: 30px; }
.levels .chapter:first-child { margin-top: 22px; }
.chapter-head {
    display: grid;
    grid-template-columns: 44px 1fr auto;
    align-items: center;
    gap: 14px;
    width: 100%;
    padding: 8px 4px 8px 0;
    text-align: left;
}
.chapter-head:active { opacity: 0.8; }
.chapter-art { display: block; width: 44px; }
.chapter-text { display: flex; flex-direction: column; min-width: 0; }
.chapter-text b { font-size: 18px; font-weight: 750; line-height: 1.2; }
.chapter-text span { font-size: 14px; color: var(--text-2); }
.chapter-count { font-size: 14px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.chapter .levels-grid { margin-top: 12px; }

.level-tier {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 14px;
    height: 14px;
}
.level-tile.is-hard .level-tier { fill: var(--hard); }
.level-tile.is-nightmare .level-tier { fill: var(--nightmare); }
.level-tile.is-hard:not(:disabled):not(.is-solved) { box-shadow: inset 0 -4px 0 var(--paper-shade), inset 0 0 0 2.5px var(--hard); }
.level-tile.is-hard.is-next { box-shadow: inset 0 -4px 0 var(--paper-shade), inset 0 0 0 2.5px var(--hard), 0 0 0 3px var(--bg-1), 0 0 0 5px var(--paper); }
.level-tile.is-nightmare:not(.is-solved) {
    background: linear-gradient(180deg, #4A3590, var(--nightmare-deep));
    color: #F0E8FF;
    box-shadow: inset 0 -4px 0 #170F38, 0 0 18px -4px rgba(160, 108, 255, 0.6);
}
.level-tile.is-nightmare:not(.is-solved) .level-tier { fill: #E4D4FF; }
.level-tile.is-nightmare:disabled { opacity: 0.75; }
.level-tile.is-nightmare.is-next { box-shadow: inset 0 -4px 0 #170F38, 0 0 0 3px var(--bg-1), 0 0 0 5px var(--nightmare), 0 0 24px rgba(160, 108, 255, 0.6); }
.level-tile.is-solved .level-tier { opacity: 0.8; }

/* Game: tier badge and a glow around the board on special levels */
.tier-badge {
    display: inline-block;
    margin-left: 8px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 750;
    font-stretch: 100%;
    letter-spacing: 0.02em;
    vertical-align: 3px;
}
#screen-game[data-tier="hard"] .tier-badge { background: rgba(255, 107, 94, 0.16); color: var(--hard); }
#screen-game[data-tier="nightmare"] .tier-badge { background: rgba(160, 108, 255, 0.2); color: #C7A8FF; }
#screen-game[data-tier="hard"] .board {
    box-shadow: 0 0 0 calc(var(--cell) * 0.12) var(--bg-0), 0 0 0 calc(var(--cell) * 0.12 + 2px) rgba(255, 107, 94, 0.55), 0 24px 50px -20px rgba(0, 0, 0, 0.8);
}
#screen-game[data-tier="nightmare"] .board {
    box-shadow: 0 0 0 calc(var(--cell) * 0.12) var(--bg-0), 0 0 0 calc(var(--cell) * 0.12 + 2px) rgba(160, 108, 255, 0.8),
                0 0 60px -6px rgba(160, 108, 255, 0.45), 0 24px 50px -20px rgba(0, 0, 0, 0.8);
}

/* Win sheet: mosaic progress */
.win-mosaic {
    display: grid;
    grid-template-columns: 64px 1fr;
    align-items: center;
    gap: 16px;
    margin-top: 20px;
    padding: 12px 16px 12px 12px;
    border-radius: 18px;
    background: var(--bg-1);
    text-align: left;
}
.win-mosaic-art { display: block; width: 64px; }
.win-mosaic-text { display: flex; flex-direction: column; min-width: 0; }
.win-mosaic-text small { font-size: 13px; color: var(--text-3); font-weight: 600; }
.win-mosaic-text b { font-size: 18px; font-weight: 750; line-height: 1.2; }
.win-mosaic-text span { font-size: 14px; color: var(--text-2); font-variant-numeric: tabular-nums; }

/* Win sheet: the boss chest */
.win-chest {
    display: grid;
    grid-template-columns: 56px 1fr;
    grid-template-rows: auto auto;
    align-items: center;
    column-gap: 16px;
    width: 100%;
    margin-top: 12px;
    padding: 12px 16px 12px 12px;
    border-radius: 18px;
    background: linear-gradient(135deg, rgba(160, 108, 255, 0.22), rgba(255, 194, 61, 0.14));
    box-shadow: inset 0 0 0 1.5px rgba(160, 108, 255, 0.5);
    text-align: left;
}
.win-chest .chest { grid-row: span 2; width: 56px; height: 50px; }
.win-chest:not(.is-open) .chest { animation: chest-wiggle 2.2s 0.8s infinite; }
.chest svg { width: 100%; height: 100%; overflow: visible; }
.chest-body { fill: #C79766; }
.chest-band { stroke: #8A6236; stroke-width: 4; }
.chest-lid { fill: #DDAF7C; transform-origin: 6px 26px; transition: transform 0.45s var(--spring); }
.chest-lock { fill: #FFC23D; }
.win-chest.is-open .chest-lid { transform: rotate(-24deg) translate(-2px, -6px); }
.win-chest-text { font-size: 18px; font-weight: 750; }
.win-chest:not(.is-open) .win-chest-text { grid-row: span 2; }
.chest-loot { display: none; flex-wrap: wrap; gap: 6px; }
.chest-loot span {
    padding: 3px 10px;
    border-radius: 999px;
    background: rgba(255, 194, 61, 0.16);
    color: #FFC23D;
    font-weight: 750;
    font-size: 15px;
}
.win-chest.is-open .chest-loot { display: flex; animation: loot-in 0.4s var(--spring) both; }
.win-chest.is-open .win-chest-text { font-size: 14px; color: var(--text-2); font-weight: 600; }
@keyframes chest-wiggle {
    0%, 80%, 100% { transform: rotate(0); }
    84% { transform: rotate(-7deg); }
    88% { transform: rotate(6deg); }
    92% { transform: rotate(-4deg); }
    96% { transform: rotate(2deg); }
}
@keyframes loot-in { from { opacity: 0; transform: translateY(6px) scale(0.9); } }
.win-rank { color: #C7A8FF; font-weight: 650; }

/* Before a Nightmare */
.nightmare-mark {
    width: 72px;
    height: 72px;
    margin: 0 auto 14px;
    display: grid;
    place-items: center;
    border-radius: 22px;
    background: linear-gradient(180deg, #4A3590, var(--nightmare-deep));
    box-shadow: 0 0 40px -6px rgba(160, 108, 255, 0.7), inset 0 -4px 0 #170F38;
}
.nightmare-mark svg { width: 38px; height: 38px; fill: #E4D4FF; }
.nightmare-mark .spark { fill: #FFC23D; }
.btn-primary.btn-nightmare {
    background: linear-gradient(180deg, #B48BFF, var(--nightmare));
    color: #14072E;
    box-shadow: inset 0 -4px 0 #6B3FC4, 0 8px 24px -10px rgba(160, 108, 255, 0.7);
}

.mosaic-large { width: min(100%, 300px); margin: 20px auto 0; }

/* ------------------------------------------------------------ gallery */

.gallery {
    max-width: 520px;
    margin: 0 auto;
    padding: 10px 20px 0;
}

.rank-card {
    display: grid;
    grid-template-columns: 64px 1fr;
    gap: 6px 16px;
    align-items: center;
    padding: 18px;
    border-radius: 22px;
    background: linear-gradient(135deg, #2C2470, var(--bg-2));
    box-shadow: inset 0 0 0 1px var(--line);
}
.rank-badge {
    width: 64px;
    height: 64px;
    display: grid;
    place-items: center;
    border-radius: 20px;
    background: linear-gradient(180deg, #FFD36B, #E8A82A);
    box-shadow: inset 0 -4px 0 #B07A12, 0 8px 22px -8px rgba(255, 194, 61, 0.6);
    color: #3A2600;
    font-size: 30px;
    font-weight: 800;
    font-stretch: 80%;
}
.rank-text { display: flex; flex-direction: column; min-width: 0; }
.rank-text small { font-size: 13px; color: var(--text-3); font-weight: 600; }
.rank-text b { font-size: 26px; font-weight: 800; font-stretch: 85%; line-height: 1.1; }
.rank-text span { font-size: 14px; color: var(--text-2); }
.rank-bar {
    grid-column: 1 / -1;
    height: 8px;
    margin-top: 10px;
    border-radius: 999px;
    background: var(--bg-0);
    overflow: hidden;
}
.rank-bar i {
    display: block;
    height: 100%;
    width: calc(var(--p, 0) * 100%);
    min-width: 8px;
    border-radius: inherit;
    background: #FFC23D;
}

.theme-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}
.theme-card {
    container-type: inline-size;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px 10px 12px;
    border-radius: 20px;
    background: var(--bg-2);
    box-shadow: inset 0 0 0 1px var(--line);
    text-align: left;
    transition: transform 0.12s;
}
.theme-card:active:not(:disabled) { transform: scale(0.97); }
.theme-card[aria-pressed="true"] { box-shadow: inset 0 0 0 2.5px var(--paper); }
.theme-card b { margin-top: 10px; font-size: 16px; font-weight: 700; line-height: 1.2; }
.theme-card small { font-size: 13px; color: var(--text-3); line-height: 1.25; }
.theme-card[aria-pressed="true"] small { color: var(--text); font-weight: 650; }
.theme-card:disabled .theme-preview { opacity: 0.88; }
.theme-card small { display: flex; align-items: center; gap: 5px; }
.theme-lock { flex: none; width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

/* A real 4 x 4 board, sized from the card's width */
.theme-preview {
    --n: 4;
    --cell: calc((100cqi - 20px) * 0.22);
    position: relative;
    display: block;
    aspect-ratio: 1;
    border-radius: 14px;
    background: var(--bg-0);
}
.tp-board { position: absolute; inset: 6%; }
.theme-preview .tile { transition: none; }

.gallery-note { margin: -2px 0 6px; font-size: 14px; color: var(--text-3); text-wrap: pretty; }
.gallery-empty { margin-top: 12px; color: var(--text-2); }
.mosaic-track { margin: 18px 0 10px; font-size: 18px; font-weight: 750; }
.mosaic-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px 12px;
}
.mosaic-card { display: flex; flex-direction: column; gap: 2px; text-align: left; min-width: 0; }
.mosaic-card:active { opacity: 0.8; }
.mosaic-card .mosaic { margin-bottom: 6px; }
.mosaic-card b { font-size: 14px; font-weight: 700; line-height: 1.2; }
.mosaic-card small { font-size: 12px; color: var(--text-3); }

/* ------------------------------------------------------------ board themes
   Scoped to the board and the theme previews; buttons stay porcelain.
   Each theme sets the tile colors and the board well; some add a texture
   (--tile-texture), squarer or rounder tiles (--tile-round), an edge
   (--tile-edge) or glowing numerals (--tile-glow). Empty tiles must stay
   clearly different from the 12 chain colors in ui/palette.js. */

body[data-board-theme="sand"] .board, .theme-preview[data-theme="sand"] {
    --paper: #E2D3B6; --paper-hi: #F1E7D2; --paper-shade: #B09A72; --tile-ink: #3A2C16; --bg-0: #18142E;
}
body[data-board-theme="mint"] .board, .theme-preview[data-theme="mint"] {
    --paper: #CDE9DB; --paper-hi: #E6F6EE; --paper-shade: #8DBDA6; --tile-ink: #0E3325; --bg-0: #0B1A26;
}
body[data-board-theme="lavender"] .board, .theme-preview[data-theme="lavender"] {
    --paper: #DCD3F0; --paper-hi: #EEE9FA; --paper-shade: #A79BCB; --tile-ink: #2A1B52; --bg-0: #120C2A;
}
body[data-board-theme="blush"] .board, .theme-preview[data-theme="blush"] {
    --paper: #F0D6D8; --paper-hi: #FBEBEC; --paper-shade: #C79CA1; --tile-ink: #44151F; --bg-0: #1A0F26;
}
body[data-board-theme="ocean"] .board, .theme-preview[data-theme="ocean"] {
    --paper: #D2E4F5; --paper-hi: #EAF3FC; --paper-shade: #8FAFCF; --tile-ink: #0A2A4A; --bg-0: #041A33;
    --tile-round: 0.3;
}
body[data-board-theme="slate"] .board, .theme-preview[data-theme="slate"] {
    --paper: #CDD1D8; --paper-hi: #E4E7EC; --paper-shade: #8E949F; --tile-ink: #1B1F27; --bg-0: #121419;
    --tile-round: 0.12;
}
body[data-board-theme="wood"] .board, .theme-preview[data-theme="wood"] {
    --paper: #EEDCBC; --paper-hi: #F7EAD2; --paper-shade: #B48D5A; --tile-ink: #3D230C; --bg-0: #1E130B;
    --tile-texture: repeating-linear-gradient(100deg, rgba(150, 95, 35, 0.12) 0 1.5px, transparent 1.5px 6px),
                    repeating-linear-gradient(96deg, rgba(150, 95, 35, 0.08) 0 1px, transparent 1px 13px);
    --tile-round: 0.14;
}
body[data-board-theme="ink"] .board, .theme-preview[data-theme="ink"] {
    --paper: #F7F7F4; --paper-hi: #FFFFFF; --paper-shade: #A3A3A0; --tile-ink: #111111; --bg-0: #0A0A0A;
    --tile-round: 0.06;
}
body[data-board-theme="matcha"] .board, .theme-preview[data-theme="matcha"] {
    --paper: #D9E4BE; --paper-hi: #EAF1D6; --paper-shade: #9DAE73; --tile-ink: #1E2E0C; --bg-0: #0F1E12;
}
body[data-board-theme="sunset"] .board, .theme-preview[data-theme="sunset"] {
    --paper: #F8D2C2; --paper-hi: #FFEBDD; --paper-shade: #CF9682; --tile-ink: #4A1530; --bg-0: #22102E;
    --tile-round: 0.3;
}
body[data-board-theme="chalkboard"] .board, .theme-preview[data-theme="chalkboard"] {
    --paper: #2F4A3E; --paper-hi: #3A5A4B; --paper-shade: #1B2F26; --tile-ink: #F1F5EC; --bg-0: #121D17;
    --tile-texture: radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.07), transparent 55%);
    --tile-round: 0.1;
}
body[data-board-theme="cocoa"] .board, .theme-preview[data-theme="cocoa"] {
    --paper: #4A3226; --paper-hi: #5E4133; --paper-shade: #2C1D15; --tile-ink: #F6E7D3; --bg-0: #140B07;
}
body[data-board-theme="obsidian"] .board, .theme-preview[data-theme="obsidian"] {
    --paper: #2D3068; --paper-hi: #3A3E80; --paper-shade: #191B45; --tile-ink: #E9E7FB; --bg-0: #06071A;
}
body[data-board-theme="marble"] .board, .theme-preview[data-theme="marble"] {
    --paper: #EDEDEE; --paper-hi: #FAFAFB; --paper-shade: #A9A9B1; --tile-ink: #2B2B33; --bg-0: #18181F;
    --tile-texture: linear-gradient(118deg, transparent 36%, rgba(110, 112, 128, 0.22) 38.5%, transparent 41%),
                    linear-gradient(32deg, transparent 58%, rgba(110, 112, 128, 0.16) 60%, transparent 63%),
                    linear-gradient(160deg, transparent 70%, rgba(110, 112, 128, 0.12) 71.5%, transparent 73%);
}
body[data-board-theme="neon"] .board, .theme-preview[data-theme="neon"] {
    --paper: #14142E; --paper-hi: #1C1C3E; --paper-shade: #0A0A1C; --tile-ink: #7DF9FF; --bg-0: #000008;
    --tile-edge: inset 0 0 0 1.5px rgba(125, 249, 255, 0.35);
    --tile-glow: 0 0 8px rgba(125, 249, 255, 0.85);
    --tile-round: 0.26;
}
body[data-board-theme="gold"] .board, .theme-preview[data-theme="gold"] {
    --paper: #F4E8C6; --paper-hi: #FFF8E4; --paper-shade: #B8862A; --tile-ink: #6B4C0B; --bg-0: #110E24;
    --tile-edge: inset 0 0 0 2px rgba(214, 168, 58, 0.85);
    --tile-texture: linear-gradient(135deg, rgba(255, 255, 255, 0.65) 0 18%, transparent 38%, transparent 62%, rgba(214, 168, 58, 0.22) 100%);
}

/* ------------------------------------------------------------ tutorial */

.bar-skip {
    display: none;
    justify-self: end;
    min-height: 40px;
    padding: 0 12px;
    border-radius: 14px;
    color: var(--text-2);
    font-size: 15px;
    font-weight: 650;
}
.bar-skip:active { background: var(--bg-2); }
#screen-game[data-mode="tutorial"] .bar-skip { display: block; }
#screen-game[data-mode="tutorial"] .game-timer,
#screen-game[data-mode="tutorial"] .toolbar { display: none; }

/* The card under the board: step dots, a title, and what to do next */
.tutor {
    width: var(--board-size);
    margin-top: 4px;
    padding: 14px 16px 15px;
    border-radius: 20px;
    background: var(--bg-2);
    box-shadow: inset 0 0 0 1px var(--line);
    transition: box-shadow 0.2s;
}
.tutor[data-tone="good"] { box-shadow: inset 0 0 0 2px #27C08A; }
.tutor[data-tone="warn"] { box-shadow: inset 0 0 0 2px var(--danger); }
.tutor.is-fresh { animation: tutor-in 0.4s var(--ease-out); }
.tutor.is-warn { animation: tutor-nudge 0.32s; }
@keyframes tutor-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes tutor-nudge {
    30% { transform: translateX(-4px); }
    65% { transform: translateX(3px); }
}

.tutor-head { display: flex; align-items: center; gap: 10px; }
.tutor-steps { display: flex; gap: 5px; }
.tutor-steps i {
    width: 18px;
    height: 6px;
    border-radius: 3px;
    background: var(--bg-3);
    transition: background 0.25s, width 0.25s var(--ease-out);
}
.tutor-steps i.is-current { width: 26px; background: var(--paper); }
.tutor-steps i.is-done { background: #27C08A; }
.tutor-title { font-size: 18px; font-weight: 800; font-stretch: 85%; letter-spacing: -0.01em; }
.tutor-text { margin-top: 6px; color: var(--text-2); font-size: 15px; line-height: 1.45; text-wrap: pretty; }
.tutor-text b { color: var(--text); font-weight: 800; font-variant-numeric: tabular-nums; }

/* Spotlight: tiles outside the current step step back */
.board.has-focus .tile:not(.is-focus) { opacity: 0.38; filter: saturate(0.6); }

/* Route arrows in the gaps between tiles */
.board-guide {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 4;
    overflow: visible;
    pointer-events: none;
}
.board-guide path {
    fill: none;
    stroke: var(--chain);
    stroke-width: 0.075;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.board-guide path.guide-back { stroke: var(--bg-0); stroke-width: 0.17; }
.board-guide g { animation: guide-flow 1.6s ease-in-out infinite; animation-delay: calc(var(--i) * 0.12s); }
@keyframes guide-flow { 50% { opacity: 0.35; } }

/* The demo hand. The wrapper is a point on the board; the fingertip sits on it. */
.board.is-guiding .tile { outline: calc(var(--cell) * 0.06) solid transparent; outline-offset: calc(var(--cell) * 0.02); }
.ghost-hand {
    position: absolute;
    z-index: 6;
    width: 0;
    height: 0;
    pointer-events: none;
}
.ghost-hand svg {
    position: absolute;
    left: 0;
    top: 0;
    width: max(46px, calc(var(--cell) * 0.85));
    height: max(46px, calc(var(--cell) * 0.85));
    transform: translate(-33.3%, -8.3%);
    filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.5));
    overflow: visible;
}
.hand-fill { fill: var(--paper-hi); stroke: var(--tile-ink); stroke-width: 1.3; stroke-linejoin: round; }
.hand-crease { fill: none; stroke: var(--tile-ink); stroke-width: 1.1; stroke-linecap: round; opacity: 0.55; }
.ghost-touch {
    position: absolute;
    width: max(30px, calc(var(--cell) * 0.5));
    height: max(30px, calc(var(--cell) * 0.5));
    margin: calc(max(30px, calc(var(--cell) * 0.5)) / -2) 0 0 calc(max(30px, calc(var(--cell) * 0.5)) / -2);
    border-radius: 50%;
    background: rgba(250, 247, 240, 0.28);
    box-shadow: 0 0 0 3px rgba(250, 247, 240, 0.7);
    opacity: 0;
}

.tutorial-badge {
    width: 64px;
    height: 64px;
    margin: 0 auto 14px;
    border-radius: 18px;
    display: grid;
    place-items: center;
    background: #27C08A;
    box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.18);
    color: #032419;
}
.tutorial-badge svg { width: 34px; height: 34px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.sheet.is-open .tutorial-badge { animation: star-in 0.5s var(--spring) 0.1s both; }
#tutorial-done .howto-tips { margin-top: 18px; }

/* ------------------------------------------------------------ praise */

/* A word that pops up over a chain that just matched, bigger as the combo grows */
.praise-pop {
    --size: calc(var(--cell) * 0.36);
    position: absolute;
    z-index: 7;
    padding: 0.18em 0.6em 0.24em;
    border-radius: 999px;
    background: var(--chain);
    color: var(--chain-ink);
    box-shadow: 0 0 0 calc(var(--cell) * 0.05) var(--bg-0), 0 14px 30px -10px rgba(0, 0, 0, 0.85);
    font-size: clamp(18px, var(--size), 40px);
    font-weight: 800;
    font-stretch: 75%;
    letter-spacing: -0.01em;
    line-height: 1;
    white-space: nowrap;
    pointer-events: none;
    transform: translate(-50%, -50%);
    animation: praise-pop 1.25s var(--ease-out) both;
}
.praise-pop.is-l2 { --size: calc(var(--cell) * 0.42); }
.praise-pop.is-l3 { --size: calc(var(--cell) * 0.48); }
.praise-pop.is-l4 { --size: calc(var(--cell) * 0.54); }
.praise-pop.is-l5 { --size: calc(var(--cell) * 0.6); }
/* Two small sparkles at the ends */
.praise-pop::before, .praise-pop::after {
    content: '';
    position: absolute;
    width: 0.5em;
    height: 0.5em;
    background: var(--paper-hi);
    clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
    animation: praise-spark 1.25s var(--ease-out) both;
}
.praise-pop::before { left: -0.2em; top: -0.25em; }
.praise-pop::after { right: -0.15em; bottom: -0.2em; width: 0.38em; height: 0.38em; animation-delay: 0.08s; }
@keyframes praise-pop {
    0% { opacity: 0; transform: translate(-50%, -30%) scale(0.4) rotate(-8deg); }
    18% { opacity: 1; transform: translate(-50%, -50%) scale(1.12) rotate(-3deg); }
    30% { transform: translate(-50%, -50%) scale(1) rotate(-3deg); }
    75% { opacity: 1; transform: translate(-50%, -78%) scale(1) rotate(-3deg); }
    100% { opacity: 0; transform: translate(-50%, -105%) scale(0.92) rotate(-3deg); }
}
@keyframes praise-spark {
    0%, 12% { opacity: 0; transform: scale(0) rotate(0); }
    30% { opacity: 1; transform: scale(1.2) rotate(45deg); }
    70% { opacity: 1; transform: scale(0.9) rotate(90deg); }
    100% { opacity: 0; transform: scale(0.4) rotate(120deg); }
}

/* Win sheet: the title is the compliment, the line below says why */
.sheet.is-open .win-title { animation: win-title-in 0.5s var(--spring) both; }
@keyframes win-title-in { from { opacity: 0; transform: scale(0.7); } }
.win-praise {
    margin-top: 6px;
    text-align: center;
    color: var(--text-2);
    font-size: 15px;
    font-weight: 600;
    text-wrap: balance;
}
.win-praise:empty { display: none; }

/* ------------------------------------------------------------ small screens */

@media (max-height: 700px) {
    .hero { padding-bottom: 16px; }
    .logo-mark { width: 84px; height: 84px; margin-bottom: 14px; }
    .wordmark { font-size: 46px; }
    .tagline { margin-top: 8px; font-size: 15px; }
    .btn-play { min-height: 64px; }
    .home-actions { gap: 10px; }
    .readout-value { font-size: 36px; }
    .sheet { padding-top: 22px; }
    .win-stars { margin-top: 12px; }
    .win-stars .star { width: 38px; height: 38px; }
    .win-stats { margin-top: 12px; }
    .win-mosaic { margin-top: 14px; }
    .win-chest .chest { width: 48px; height: 44px; }
    .win-chest { padding-block: 8px; }
    #screen-game {
        --board-size: min(calc(100vw - 36px), 520px, calc(100dvh - 260px - var(--safe-t) - var(--safe-b) - var(--ad-height)));
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-delay: 0ms !important;
        transition-duration: 0.01ms !important;
    }
    .is-launching .logo-strand { stroke-dashoffset: 0; }
    /* Praise still shows, as a plain fade */
    .praise-pop { animation: praise-fade 1.4s both !important; }
    .praise-pop::before, .praise-pop::after { display: none; }
    .ghost-hand svg { opacity: 1; }
}
@keyframes praise-fade { 0%, 75% { opacity: 1; } 100% { opacity: 0; } }
