/* Bijuterii — match-3 (js/bijuterii.js). Tokens on :root, redefined under body.dark-theme.
   The board itself is a canvas and stays dark in both themes, so the gems shine. */
:root {
    --bj-accent: #7c3aed;
    --bj-accent-2: #6d28d9;
    --bj-accent-soft: #efe7ff;
    --bj-page-bg: #f5f2fc;
    --bj-card-bg: #ffffff;
    --bj-card-border: #e2daf3;
    --bj-muted: #625a78;
    --bj-shadow: 0 10px 30px rgba(60, 30, 120, .12);
    --bj-board-1: #2b2150;
    --bj-board-2: #1a1336;
    --bj-gold: #f5b70a;
    --bj-good: #15803d;
    --bj-bad: #dc2626;
    --bj-lock: #b9b2cc;
}

body.dark-theme {
    --bj-accent: #b48cff;
    --bj-accent-2: #c4a3ff;
    --bj-accent-soft: #241a3d;
    --bj-page-bg: #0e0a1a;
    --bj-card-bg: #181229;
    --bj-card-border: #2e2448;
    --bj-muted: #aaa1c2;
    --bj-shadow: 0 10px 30px rgba(0, 0, 0, .5);
    --bj-board-1: #221a42;
    --bj-board-2: #110c22;
    --bj-good: #4ade80;
    --bj-bad: #f87171;
    --bj-lock: #4a4163;
}

/* clip, not hidden: the site-wide `body { overflow-x: hidden }` would kill position: sticky. */
.bj-body, body.bj-body#page-top {
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--bj-page-bg);
    color: var(--text-color);
    min-height: 100vh;
    overflow-x: clip;
}
body.bj-max { overflow: hidden; }
.bj-main { padding-top: 92px; padding-bottom: 40px; }
.bj-game .container, .bj-hero .container { max-width: 980px; }

/* ---- hero ---- */
.bj-hero { text-align: center; padding: 4px 0 8px; }
.bj-hero h1 { font-weight: 800; font-size: clamp(1.6rem, 5vw, 2.2rem); margin-bottom: 4px; }
.bj-hero-icon { color: var(--bj-accent); }
.bj-lead { margin: 0 auto; max-width: 580px; color: var(--bj-muted); font-size: .98rem; line-height: 1.45; }

/* ---- menu ---- */
.bj-menu { max-width: 560px; margin: 10px auto 0; display: grid; gap: 10px; }
.bj-menu[hidden], .bj-map[hidden], .bj-play[hidden] { display: none; }
.bj-modes { display: grid; gap: 10px; }
.bj-mode { display: grid; grid-template-columns: 56px 1fr auto; align-items: center; gap: 12px; width: 100%; min-height: 78px; padding: 12px 14px; border-radius: 18px; border: 1px solid var(--bj-card-border); background: var(--bj-card-bg); color: inherit; text-align: left; box-shadow: var(--bj-shadow); cursor: pointer; touch-action: manipulation; transition: transform .15s, border-color .15s; }
.bj-mode:hover { border-color: var(--bj-accent); }
.bj-mode:active { transform: scale(.985); }
.bj-mode-icon { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; font-size: 1.5rem; color: #fff; background: linear-gradient(135deg, #8b5cf6, #db2777); }
.bj-mode[data-mode="zen"] .bj-mode-icon { background: linear-gradient(135deg, #10b981, #0ea5e9); }
.bj-mode[data-mode="rush"] .bj-mode-icon { background: linear-gradient(135deg, #f59e0b, #ef4444); }
.bj-mode-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.bj-mode-text strong { font-size: 1.12rem; font-weight: 800; }
.bj-mode-text small { color: var(--bj-muted); font-size: .86rem; line-height: 1.3; }
.bj-mode-rec { font-size: .8rem; font-weight: 800; color: var(--bj-accent); white-space: nowrap; text-align: right; }
.bj-resume { display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 56px; border-radius: 16px; border: 0; background: linear-gradient(135deg, var(--bj-accent), #db2777); color: #fff; font-weight: 700; font-size: 1rem; box-shadow: var(--bj-shadow); cursor: pointer; touch-action: manipulation; padding: 8px 14px; }
.bj-resume[hidden] { display: none; }

/* ---- level map ---- */
.bj-map { max-width: 620px; margin: 10px auto 0; }
.bj-map-head { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; margin-bottom: 10px; }
.bj-map-head h2 { margin: 0; font-size: 1.3rem; font-weight: 800; }
.bj-map-stars { font-weight: 800; color: var(--bj-gold); white-space: nowrap; }
.bj-map-stars svg { width: 18px; height: 18px; vertical-align: -3px; fill: currentColor; }
.bj-levels { display: grid; grid-template-columns: repeat(8, 1fr); gap: 7px; padding: 10px; border-radius: 18px; background: var(--bj-card-bg); border: 1px solid var(--bj-card-border); box-shadow: var(--bj-shadow); }
.bj-lv { position: relative; aspect-ratio: 1; min-height: 40px; border-radius: 12px; border: 0; background: linear-gradient(160deg, #8b5cf6, #6d28d9); color: #fff; font-weight: 900; font-size: 1rem; cursor: pointer; touch-action: manipulation; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; padding: 2px; box-shadow: inset 0 2px 0 rgba(255, 255, 255, .3), inset 0 -3px 0 rgba(0, 0, 0, .2); }
.bj-lv:nth-child(16n+9), .bj-lv:nth-child(16n+10), .bj-lv:nth-child(16n+11), .bj-lv:nth-child(16n+12), .bj-lv:nth-child(16n+13), .bj-lv:nth-child(16n+14), .bj-lv:nth-child(16n+15), .bj-lv:nth-child(16n+16) { background: linear-gradient(160deg, #ec4899, #be185d); }
.bj-lv .bj-lv-stars { display: flex; gap: 1px; line-height: 0; }
.bj-lv .bj-lv-stars svg { width: 9px; height: 9px; fill: rgba(255, 255, 255, .35); }
.bj-lv .bj-lv-stars svg.on { fill: #fde047; }
.bj-lv.is-locked { background: var(--bj-lock); color: rgba(255, 255, 255, .85); cursor: not-allowed; box-shadow: none; }
.bj-lv.is-next { outline: 3px solid var(--bj-gold); outline-offset: 1px; animation: bj-next 1.6s ease-in-out infinite; }
@keyframes bj-next { 50% { transform: scale(1.07); } }

/* ---- HUD ---- */
/* the board fits the screen height on wide screens (header + HUD + tools take about 350px) */
.bj-play { --bj-size: max(320px, min(560px, calc(100vh - 350px))); max-width: var(--bj-size); margin: 6px auto 0; }
@supports (height: 100dvh) { .bj-play { --bj-size: max(320px, min(560px, calc(100dvh - 350px))); } }
body.bj-playing .bj-lead { display: none; }
body.bj-playing .bj-hero h1 { font-size: clamp(1.3rem, 4vw, 1.7rem); margin-bottom: 2px; }
.bj-hud { display: grid; grid-template-columns: 76px 1fr 104px; gap: 8px; align-items: stretch; margin-bottom: 8px; }
.bj-box { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 6px 6px; border-radius: 14px; background: var(--bj-card-bg); border: 1px solid var(--bj-card-border); min-height: 64px; font-variant-numeric: tabular-nums; }
.bj-box small { font-size: .7rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; color: var(--bj-muted); }
.bj-box b { font-size: 1.5rem; font-weight: 900; line-height: 1.1; }
.bj-left-box.is-low b { color: var(--bj-bad); animation: bj-pulse .8s ease-in-out infinite; }
@keyframes bj-pulse { 50% { transform: scale(1.12); } }
.bj-score-box b { font-size: 1.25rem; }
.bj-starbar { position: relative; display: block; width: 88%; height: 7px; margin-top: 4px; border-radius: 4px; background: var(--bj-accent-soft); overflow: visible; }
.bj-starbar[hidden] { display: none; }
.bj-starbar > span { position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: 4px; background: linear-gradient(90deg, #f59e0b, #fde047); transition: width .4s; }
.bj-starbar i { position: absolute; top: 50%; width: 9px; height: 9px; margin: -4.5px 0 0 -4.5px; border-radius: 50%; background: var(--bj-card-border); border: 2px solid var(--bj-card-bg); }
.bj-starbar i.on { background: var(--bj-gold); }
.bj-goals { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px; padding: 6px; border-radius: 14px; background: var(--bj-card-bg); border: 1px solid var(--bj-card-border); min-height: 64px; }
.bj-goal { display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px 3px 4px; border-radius: 12px; background: var(--bj-accent-soft); font-weight: 900; font-variant-numeric: tabular-nums; font-size: 1.02rem; min-height: 36px; transition: transform .2s; }
.bj-goal canvas, .bj-goal svg { width: 28px; height: 28px; display: block; flex: none; }
.bj-goal.is-done { color: var(--bj-good); }
.bj-goal.is-bump { transform: scale(1.15); }
.bj-goal-note { font-size: .82rem; color: var(--bj-muted); font-weight: 700; text-align: center; line-height: 1.25; }

/* ---- board ---- */
.bj-stage { position: relative; width: 100%; max-width: var(--bj-size, 560px); margin: 0 auto; aspect-ratio: 1; border-radius: 18px; background: radial-gradient(120% 120% at 30% 10%, var(--bj-board-1), var(--bj-board-2)); box-shadow: var(--bj-shadow), inset 0 0 0 1px rgba(255, 255, 255, .06); overflow: hidden; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.bj-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.bj-canvas:focus-visible { box-shadow: inset 0 0 0 3px var(--bj-gold); border-radius: 18px; }
.bj-banner { position: absolute; left: 0; right: 0; top: 42%; margin: 0; text-align: center; font-weight: 900; font-size: clamp(1.8rem, 9vw, 3rem); color: #fff; text-shadow: 0 3px 0 #7c3aed, 0 6px 18px rgba(0, 0, 0, .6); pointer-events: none; opacity: 0; transform: scale(.6); }
.bj-banner.is-on { animation: bj-banner 1s cubic-bezier(.2, 1.4, .4, 1) forwards; }
@keyframes bj-banner { 0% { opacity: 0; transform: scale(.5) rotate(-6deg); } 25% { opacity: 1; transform: scale(1.1) rotate(2deg); } 70% { opacity: 1; transform: scale(1); } 100% { opacity: 0; transform: scale(1.05) translateY(-20px); } }
.bj-pause { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; background: rgba(14, 8, 30, .78); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.bj-pause[hidden] { display: none; }
.bj-pause-title { margin: 0; color: #fff; font-size: 2rem; font-weight: 900; }

/* ---- tools ---- */
.bj-tools { display: flex; justify-content: center; gap: 6px; margin: 10px auto 0; flex-wrap: wrap; }
.bj-round { width: 50px; height: 50px; border-radius: 14px; border: 1px solid var(--bj-card-border); background: var(--bj-card-bg); color: inherit; font-size: 1.15rem; display: grid; place-items: center; cursor: pointer; touch-action: manipulation; flex: none; }
.bj-round[hidden] { display: none; }
.bj-round:hover:not(:disabled) { border-color: var(--bj-accent); }
.bj-round:disabled { opacity: .4; cursor: not-allowed; }
.bj-round span[hidden] { display: none; }
#bj-hint { color: var(--bj-gold); }
.bj-status { margin: 8px 2px 0; min-height: 1.5em; font-weight: 700; text-align: center; color: var(--bj-muted); line-height: 1.4; }

/* ---- full screen ---- */
.bj-play:fullscreen { max-width: none; margin: 0; padding: 10px; background: var(--bj-page-bg); display: flex; flex-direction: column; justify-content: center; align-items: center; }
.bj-play:-webkit-full-screen { max-width: none; margin: 0; padding: 10px; background: var(--bj-page-bg); display: flex; flex-direction: column; justify-content: center; align-items: center; }
.bj-play.is-max { position: fixed; inset: 0; z-index: 1052; max-width: none; margin: 0; padding: 10px; background: var(--bj-page-bg); display: flex; flex-direction: column; justify-content: center; align-items: center; overflow: auto; }
.bj-play:fullscreen .bj-hud, .bj-play:fullscreen .bj-stage { width: min(100%, calc(100vh - 210px), 640px); max-width: none; }
.bj-play:-webkit-full-screen .bj-hud, .bj-play:-webkit-full-screen .bj-stage { width: min(100%, calc(100vh - 210px), 640px); max-width: none; }
.bj-play.is-max .bj-hud, .bj-play.is-max .bj-stage { width: min(100%, calc(100vh - 210px), 640px); max-width: none; }
@supports (height: 100dvh) {
    .bj-play.is-max .bj-hud, .bj-play.is-max .bj-stage { width: min(100%, calc(100dvh - 210px), 640px); }
}

/* ---- buttons / records / help ---- */
.bj-btn { min-height: 48px; padding: 8px 14px; border: 1px solid var(--bj-card-border); border-radius: 14px; background: var(--bj-card-bg); color: inherit; font-weight: 700; font-size: .95rem; cursor: pointer; touch-action: manipulation; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.bj-btn:hover:not(:disabled) { border-color: var(--bj-accent); }
.bj-btn-primary { background: var(--bj-accent); border-color: var(--bj-accent); color: #fff; }
body.dark-theme .bj-btn-primary { color: #170c33; }
.bj-mode:focus-visible, .bj-btn:focus-visible, .bj-round:focus-visible, .bj-lv:focus-visible, .bj-link:focus-visible, .bj-resume:focus-visible { outline: 3px solid var(--bj-gold); outline-offset: 2px; }
.bj-record { text-align: center; color: var(--bj-muted); font-size: .88rem; margin: 12px 0 0; min-height: 1.3em; }
.bj-record b { color: var(--text-color); }
.bj-reset-wrap { text-align: center; margin: 2px 0 0; }
.bj-link { border: 0; background: none; padding: 6px 0; color: var(--bj-muted); font-size: .82rem; font-weight: 600; text-decoration: underline; cursor: pointer; }
.bj-help { max-width: 760px; margin: 14px auto 0; padding: 12px 16px; border-radius: 14px; background: var(--bj-card-bg); border: 1px solid var(--bj-card-border); }
.bj-help summary { cursor: pointer; font-weight: 700; }
.bj-help ul { margin: 10px 0 0; padding-left: 20px; color: var(--bj-muted); line-height: 1.55; }
.bj-help li { margin-bottom: 4px; }
.bj-help strong { color: var(--text-color); }
.bj-help p.bj-credit { color: var(--bj-muted); margin: 10px 0 0; line-height: 1.5; font-size: .8rem; }
.bj-help a { color: var(--bj-accent); }
.bj-powered { text-align: center; color: var(--bj-muted); font-size: .85rem; margin: 26px 0 0; }
.bj-powered a { color: var(--bj-accent); }

/* ---- dialogs ---- */
.bj-overlay { position: fixed; inset: 0; z-index: 2000; display: grid; place-items: center; padding: 16px; background: rgba(10, 5, 25, .55); animation: bj-fade .2s ease-out; }
.bj-overlay[hidden] { display: none; }
@keyframes bj-fade { from { opacity: 0; } }
.bj-dialog { width: 100%; max-width: 400px; max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow: auto; padding: 20px 16px 16px; border-radius: 22px; background: var(--bj-card-bg); color: var(--text-color); text-align: center; box-shadow: 0 20px 50px rgba(0, 0, 0, .35); animation: bj-rise .25s ease-out; }
@keyframes bj-rise { from { transform: translateY(16px) scale(.97); opacity: 0; } }
.bj-dialog h2 { font-weight: 800; font-size: 1.45rem; margin: 2px 0 8px; }
.bj-dialog-sub { color: var(--bj-muted); margin: 0 0 6px; line-height: 1.45; }
.bj-dialog-sub b { color: var(--text-color); }
.bj-tip { margin: 10px 0 0; padding: 10px 12px; border-radius: 12px; background: var(--bj-accent-soft); font-size: .92rem; line-height: 1.4; text-align: left; }
.bj-tip[hidden] { display: none; }
.bj-intro-goals { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 6px 0 10px; }
.bj-intro-goals .bj-goal { font-size: 1.15rem; padding: 6px 12px 6px 6px; }
.bj-intro-goals .bj-goal canvas, .bj-intro-goals .bj-goal svg { width: 34px; height: 34px; }
.bj-dialog-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 8px; margin-top: 14px; }
.bj-over-stars { display: flex; justify-content: center; gap: 6px; height: 56px; align-items: flex-end; }
.bj-over-stars[hidden] { display: none; }
.bj-over-stars span { width: 46px; height: 46px; background: var(--bj-card-border); -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 1.8l3.1 6.6 7.2.9-5.3 5 1.4 7.1L12 17.9l-6.4 3.5L7 14.3l-5.3-5 7.2-.9z'/%3E%3C/svg%3E") center / contain no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 1.8l3.1 6.6 7.2.9-5.3 5 1.4 7.1L12 17.9l-6.4 3.5L7 14.3l-5.3-5 7.2-.9z'/%3E%3C/svg%3E") center / contain no-repeat; }
.bj-over-stars span:nth-child(2) { width: 56px; height: 56px; }
.bj-over-stars span.on { background: linear-gradient(160deg, #fde047, #f59e0b); animation: bj-star .5s cubic-bezier(.2, 1.6, .4, 1) both; }
.bj-over-stars span.on:nth-child(2) { animation-delay: .25s; }
.bj-over-stars span.on:nth-child(3) { animation-delay: .5s; }
@keyframes bj-star { from { transform: scale(0) rotate(-90deg); } }

@media (max-width: 420px) {
    .bj-hud { grid-template-columns: 1fr 1fr; }
    .bj-goals { grid-column: 1 / -1; grid-row: 2; min-height: 48px; }
    .bj-box { min-height: 56px; flex-direction: row; gap: 10px; }
    .bj-score-box { flex-wrap: wrap; row-gap: 2px; }
    .bj-score-box .bj-starbar { width: 92%; margin-top: 0; }
    .bj-box b { font-size: 1.35rem; }
    .bj-levels { grid-template-columns: repeat(6, 1fr); gap: 6px; padding: 8px; }
    .bj-tools { gap: 5px; }
    .bj-round { width: 46px; height: 46px; }
    .bj-mode { grid-template-columns: 48px 1fr; }
    .bj-mode-icon { width: 48px; height: 48px; font-size: 1.3rem; }
    .bj-mode-rec { grid-column: 2; text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
    .bj-banner, .bj-dialog, .bj-overlay, .bj-lv.is-next, .bj-over-stars span, .bj-left-box.is-low b { animation: none !important; transition: none !important; }
    .bj-banner.is-on { opacity: 1; transform: none; }
}
