/* Blocuri — falling blocks (js/blocuri.js). Theme-aware like the other game pages: tokens on :root,
   redefined under body.dark-theme. The canvas reads the --bl-* board colours, so a theme switch
   repaints the field too. */
:root {
    --bl-accent: #7c3aed;
    --bl-accent-2: #f59e0b;
    --bl-page-bg: #f6f4ff;
    --bl-card-bg: #ffffff;
    --bl-card-border: #e4e0f5;
    --bl-muted: #64748b;
    --bl-shadow: 0 10px 30px rgba(46, 16, 101, .13);
    --bl-stage-bg: #ece9fb;
    --bl-board: #fbfaff;
    --bl-grid: rgba(76, 29, 149, .07);
    --bl-frame: #c4b5fd;
    --bl-panel: #ffffff;
    --bl-panel-text: #4c1d95;
    --bl-ink: #1e1b4b;
    --bl-danger: #e11d48;
    --bl-overlay: rgba(236, 233, 251, .74);
    --bl-key-bg: #ffffff;
}

body.dark-theme {
    --bl-accent: #a78bfa;
    --bl-accent-2: #fbbf24;
    --bl-page-bg: #0c0a1d;
    --bl-card-bg: #1a1733;
    --bl-card-border: #312c59;
    --bl-muted: #a5a3c4;
    --bl-shadow: 0 10px 30px rgba(0, 0, 0, .5);
    --bl-stage-bg: #07061a;
    --bl-board: #110f26;
    --bl-grid: rgba(196, 181, 253, .06);
    --bl-frame: #4c3d8f;
    --bl-panel: #18153a;
    --bl-panel-text: #ddd6fe;
    --bl-ink: #ede9fe;
    --bl-danger: #fb7185;
    --bl-overlay: rgba(7, 6, 26, .72);
    --bl-key-bg: #1d1a40;
}

/* clip, not hidden: the site-wide `body { overflow-x: hidden }` makes <body> a scroll
   container that never scrolls, which silently kills any position: sticky inside. */
.bl-body, body.bl-body#page-top {
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--bl-page-bg);
    color: var(--text-color);
    min-height: 100vh;
    overflow-x: clip;
}
body.bl-playing { overscroll-behavior: none; }
body.bl-max { overflow: hidden; }
.bl-main { padding-top: 96px; padding-bottom: 40px; }
.bl-game .container, .bl-hero .container { max-width: 760px; }

/* ---- hero ---- */
.bl-hero { text-align: center; padding: 4px 0 12px; }
.bl-hero h1 { font-weight: 800; font-size: clamp(1.6rem, 5vw, 2.3rem); margin: 0 0 6px; display: inline-flex; align-items: center; gap: 12px; }
.bl-hero-icon { width: 46px; height: 46px; border-radius: 14px; display: inline-grid; place-items: center; font-size: 22px; color: #fff; background: linear-gradient(135deg, #7c3aed, #f59e0b); box-shadow: var(--bl-shadow); }
.bl-lead { max-width: 600px; margin: 0 auto; color: var(--bl-muted); font-size: 1rem; line-height: 1.55; }

/* ---- the stage: stats bar, the field (canvas) and the optional key pad ---- */
.bl-stage {
    position: relative;
    display: flex;
    flex-direction: column;
    height: clamp(460px, calc(100vh - 96px), 900px);
    width: min(100%, 680px);
    margin: 0 auto;
    background: var(--bl-stage-bg);
    border-radius: 18px;
    overflow: hidden;
    box-shadow: var(--bl-shadow);
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    outline: none;
}
.bl-stage:focus-visible { box-shadow: 0 0 0 3px var(--bl-accent), var(--bl-shadow); }
@media (max-width: 575.98px) {
    .bl-stage { width: calc(100% + 24px); margin: 0 -12px; border-radius: 0; }
}
.bl-stage:fullscreen { width: 100%; height: 100% !important; border-radius: 0; margin: 0; }
.bl-stage:-webkit-full-screen { width: 100%; height: 100% !important; border-radius: 0; margin: 0; }
.bl-stage.is-max { position: fixed; inset: 0; z-index: 1052; width: 100vw; height: 100vh !important; margin: 0; border-radius: 0; }
@supports (height: 100dvh) { .bl-stage.is-max { height: 100dvh !important; } }

/* two rows: mode name + buttons on top, the four numbers under them (a phone is narrow, not short) */
.bl-bar { flex: none; display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "name tools" "stats stats"; align-items: center; gap: 6px 6px; padding: 8px 8px 4px; }
.bl-modename { grid-area: name; margin: 0; min-width: 0; padding-left: 4px; font-weight: 800; font-size: 1rem; color: var(--bl-panel-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bl-modename small { font-weight: 600; font-size: .8rem; color: var(--bl-muted); }
.bl-stats { grid-area: stats; min-width: 0; display: grid; grid-template-columns: 1.3fr 1fr 1fr 1fr; gap: 5px; }
.bl-tools { grid-area: tools; }
.bl-stat { min-width: 0; padding: 4px 6px; border-radius: 10px; background: var(--bl-panel); border: 1px solid var(--bl-card-border); line-height: 1.1; text-align: center; }
.bl-stat small { display: block; font-size: .66rem; font-weight: 700; letter-spacing: .02em; text-transform: uppercase; color: var(--bl-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bl-stat strong { display: block; font-size: 1.02rem; font-weight: 800; color: var(--bl-panel-text); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bl-stat.is-warn strong { color: var(--bl-danger); }
.bl-tools { flex: none; display: flex; gap: 4px; }
.bl-round { width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--bl-card-border); display: grid; place-items: center; background: var(--bl-panel); color: var(--bl-panel-text); font-size: 15px; cursor: pointer; touch-action: manipulation; padding: 0; }
.bl-round:hover, .bl-round:focus-visible { border-color: var(--bl-accent); }
.bl-round:focus-visible { outline: 2px solid var(--bl-accent); outline-offset: 1px; }
.bl-round[aria-pressed="true"]#bl-padbtn { background: var(--bl-accent); border-color: var(--bl-accent); color: #fff; }
.bl-round[hidden], .bl-round span[hidden] { display: none; }
.bl-stage[data-phase="setup"] #bl-pause, .bl-stage[data-phase="over"] #bl-pause { visibility: hidden; }

.bl-play { position: relative; flex: 1; min-height: 0; }
.bl-canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; touch-action: none; cursor: pointer; }

/* big messages: lines, T-spins, combos */
.bl-banner { position: absolute; left: 50%; top: 32%; z-index: 2; transform: translate(-50%, -50%) scale(.85); margin: 0; padding: 8px 18px; border-radius: 16px; max-width: 76%; text-align: center; color: #fff; font-weight: 900; font-size: clamp(1.15rem, 5.4vw, 1.9rem); line-height: 1.12; letter-spacing: .02em; text-shadow: 0 2px 10px rgba(0, 0, 0, .45); background: linear-gradient(135deg, rgba(124, 58, 237, .92), rgba(219, 39, 119, .9)); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; }
.bl-banner.is-on { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.bl-banner small { display: block; font-size: .52em; font-weight: 700; letter-spacing: .03em; opacity: .95; }
.bl-banner.is-gold { background: linear-gradient(135deg, rgba(245, 158, 11, .95), rgba(234, 88, 12, .92)); }
.bl-banner.is-bad { background: linear-gradient(135deg, rgba(225, 29, 72, .92), rgba(124, 45, 18, .9)); }

/* ---- on-screen keys (optional) ---- */
.bl-pad { flex: none; display: grid; grid-template-columns: repeat(4, 1fr); grid-template-areas: "hold ccw cw hard" "left down down right"; gap: 6px; padding: 6px 8px 10px; }
.bl-pad[hidden] { display: none; }
.bl-key { min-height: 50px; border-radius: 14px; border: 1px solid var(--bl-card-border); background: var(--bl-key-bg); color: var(--bl-panel-text); font-size: 1.35rem; font-weight: 800; display: grid; place-items: center; cursor: pointer; touch-action: none; box-shadow: 0 2px 0 var(--bl-card-border); padding: 0; }
.bl-key span { font-size: .9rem; letter-spacing: .02em; }
.bl-key.is-down, .bl-key:active { transform: translateY(1px); box-shadow: none; background: var(--bl-accent); color: #fff; border-color: var(--bl-accent); }
.bl-key-accent { background: var(--bl-accent); border-color: var(--bl-accent); color: #fff; }
.bl-key[data-act="hold"] { grid-area: hold; }
.bl-key[data-act="ccw"] { grid-area: ccw; }
.bl-key[data-act="cw"] { grid-area: cw; }
.bl-key[data-act="hard"] { grid-area: hard; }
.bl-key[data-act="left"] { grid-area: left; }
.bl-key[data-act="down"] { grid-area: down; }
.bl-key[data-act="right"] { grid-area: right; }
.bl-key:focus-visible { outline: 2px solid var(--bl-accent); outline-offset: 2px; }

/* ---- overlays (setup, pause, game over) ---- */
.bl-overlay { position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center; padding: 12px; background: var(--bl-overlay); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); overflow-y: auto; touch-action: manipulation; }
.bl-overlay[hidden] { display: none; }
.bl-card { width: 100%; max-width: 380px; margin: auto; display: flex; flex-direction: column; gap: 10px; padding: 18px 16px; border-radius: 18px; background: var(--bl-card-bg); border: 1px solid var(--bl-card-border); box-shadow: var(--bl-shadow); color: var(--text-color); text-align: center; }
.bl-card h2 { font-weight: 800; font-size: 1.4rem; margin: 0; }
.bl-modes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.bl-mode { min-height: 64px; padding: 8px 8px; border: 1px solid var(--bl-card-border); border-radius: 14px; background: var(--bl-page-bg); color: inherit; font-weight: 800; font-size: .98rem; line-height: 1.15; display: flex; align-items: center; gap: 8px; cursor: pointer; touch-action: manipulation; text-align: left; }
.bl-mode svg, .bl-mode i { flex: none; width: 18px; color: var(--bl-accent); }
.bl-mode small { display: block; font-weight: 500; font-size: .74rem; color: var(--bl-muted); margin-top: 2px; }
.bl-mode[aria-checked="true"] { background: var(--bl-accent); border-color: var(--bl-accent); color: #fff; }
.bl-mode[aria-checked="true"] svg, .bl-mode[aria-checked="true"] i { color: #fff; }
.bl-mode[aria-checked="true"] small { color: rgba(255, 255, 255, .88); }
body.dark-theme .bl-mode[aria-checked="true"], body.dark-theme .bl-mode[aria-checked="true"] svg { color: #160d33; }
body.dark-theme .bl-mode[aria-checked="true"] small { color: rgba(22, 13, 51, .78); }
.bl-opt { display: flex; flex-direction: column; gap: 6px; }
.bl-opt[hidden] { display: none; }
.bl-label { font-weight: 700; font-size: .92rem; color: var(--bl-muted); }
.bl-chips { display: flex; gap: 6px; justify-content: center; }
.bl-chip { flex: 1; min-height: 46px; border-radius: 12px; border: 1px solid var(--bl-card-border); background: var(--bl-page-bg); color: inherit; font-weight: 700; cursor: pointer; touch-action: manipulation; }
.bl-chip[aria-checked="true"] { background: var(--bl-accent); border-color: var(--bl-accent); color: #fff; }
body.dark-theme .bl-chip[aria-checked="true"] { color: #160d33; }
.bl-stepper { display: flex; align-items: center; justify-content: center; gap: 10px; }
.bl-step { width: 48px; height: 46px; border-radius: 12px; border: 1px solid var(--bl-card-border); background: var(--bl-page-bg); color: inherit; cursor: pointer; touch-action: manipulation; display: grid; place-items: center; }
.bl-step:disabled { opacity: .4; cursor: default; }
.bl-step-val { min-width: 56px; font-size: 1.5rem; font-weight: 900; font-variant-numeric: tabular-nums; color: var(--bl-panel-text); }
.bl-note { margin: 0; font-size: .84rem; line-height: 1.4; color: var(--bl-muted); }
.bl-how { font-size: .8rem; }
.bl-mode:focus-visible, .bl-chip:focus-visible, .bl-btn:focus-visible, .bl-step:focus-visible { outline: 2px solid var(--bl-accent); outline-offset: 2px; }

.bl-btn { min-height: 48px; padding: 8px 14px; border-radius: 12px; border: 1px solid var(--bl-card-border); background: var(--bl-card-bg); color: inherit; font-weight: 700; font-size: 1rem; display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; touch-action: manipulation; }
.bl-btn:hover { border-color: var(--bl-accent); }
.bl-btn[hidden] { display: none; }
.bl-btn-primary { background: var(--bl-accent); border-color: var(--bl-accent); color: #fff; }
body.dark-theme .bl-btn-primary { color: #160d33; }
.bl-btn-ghost { background: transparent; border-color: transparent; color: var(--bl-muted); }
.bl-over-icon { width: 56px; height: 56px; margin: 0 auto; border-radius: 50%; display: grid; place-items: center; font-size: 24px; color: #fff; background: linear-gradient(135deg, #f59e0b, #7c3aed); }
.bl-over-icon.is-bad { background: linear-gradient(135deg, #64748b, #334155); }
.bl-over-big { margin: 0; font-size: 2rem; font-weight: 900; color: var(--bl-panel-text); font-variant-numeric: tabular-nums; line-height: 1.1; }
.bl-over-big:empty { display: none; }
.bl-over-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.bl-over-list li { padding: 6px 8px; border-radius: 10px; background: var(--bl-page-bg); font-size: .82rem; color: var(--bl-muted); text-align: left; line-height: 1.2; }
.bl-over-list li strong { display: block; color: var(--text-color); font-size: 1rem; font-variant-numeric: tabular-nums; }
.bl-over-rec { margin: 0; font-weight: 800; color: #b45309; }
body.dark-theme .bl-over-rec { color: var(--bl-accent-2); }
.bl-over-rec:empty { display: none; }

.bl-actions { display: flex; justify-content: center; margin: 14px 0 10px; }
.bl-actions .bl-btn { min-width: 180px; }

/* ---- records ---- */
.bl-records { margin-top: 6px; padding: 14px; border-radius: 16px; background: var(--bl-card-bg); border: 1px solid var(--bl-card-border); }
.bl-records h2 { font-size: 1.08rem; font-weight: 800; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.bl-records h2 svg, .bl-records h2 i { color: var(--bl-accent-2); }
.bl-rec-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
@media (min-width: 640px) { .bl-rec-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.bl-rec { padding: 8px 10px; border-radius: 12px; background: var(--bl-page-bg); min-width: 0; }
.bl-rec h3 { font-size: .78rem; font-weight: 800; text-transform: uppercase; letter-spacing: .03em; color: var(--bl-muted); margin: 0 0 4px; }
.bl-rec ol { margin: 0; padding-left: 18px; font-size: .86rem; line-height: 1.45; font-variant-numeric: tabular-nums; }
.bl-rec ol li::marker { color: var(--bl-muted); }
.bl-rec p { margin: 0; font-size: .86rem; color: var(--bl-muted); }
.bl-rec .bl-best { font-weight: 800; color: var(--bl-panel-text); }
.bl-reset-wrap { text-align: center; margin: 8px 0 0; }
.bl-link { border: 0; background: none; padding: 6px; color: var(--bl-muted); font-size: .85rem; text-decoration: underline; cursor: pointer; }

/* ---- help ---- */
.bl-help { margin: 12px auto 0; padding: 12px 14px; border-radius: 14px; background: var(--bl-card-bg); border: 1px solid var(--bl-card-border); }
.bl-help summary { font-weight: 700; cursor: pointer; min-height: 32px; }
.bl-help ul { margin: 10px 0 4px; padding-left: 20px; line-height: 1.55; }
.bl-help li { margin-bottom: 6px; }
.bl-help kbd { font-size: .8em; }
.bl-credit { max-width: 700px; margin: 18px auto 0; padding: 0 16px; text-align: center; color: var(--bl-muted); font-size: .78rem; line-height: 1.45; }
.bl-credit a, .bl-powered a { color: var(--bl-accent); }
.bl-powered { text-align: center; color: var(--bl-muted); font-size: .85rem; margin: 10px 0 0; }

@media (max-width: 420px) {
    .bl-main { padding-top: 88px; }
    .bl-bar { padding: 6px 6px 4px; gap: 4px; }
    .bl-stats { gap: 3px; }
    .bl-stat { padding: 3px 3px; }
    .bl-stat strong { font-size: .92rem; }
    .bl-stat small { font-size: .6rem; }
    .bl-round { width: 34px; height: 34px; font-size: 14px; }
    .bl-tools { gap: 3px; }
    .bl-mode { font-size: .92rem; min-height: 60px; padding: 6px; gap: 6px; }
    .bl-mode small { font-size: .7rem; }
}
@media (max-width: 359.98px) {
    .bl-round { width: 30px; height: 30px; font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) {
    .bl-banner { transition: none; }
}
