/*
 * Design v3 — powłoka: telefon = dolny pasek (4 pozycje + „Więcej”) i stały, zwarty HUD zasobów; od 900 px = boczny pasek
 * (ikony + etykiety, zwijany do samych ikon). Treść w kolumnie do --content-max. Ruch 150-250 ms, wyłączany przez prefers-reduced-motion (base.css).
 */

body {
    display: flex;
    flex-direction: column;
    gap: var(--s3);
    margin: 0;
    padding: calc(var(--safe-top) + 10px) calc(var(--page-pad) + var(--safe-right)) calc(var(--tabbar-h) + var(--safe-bottom) + 28px)
        calc(var(--page-pad) + var(--safe-left));
}

body > :is(.topbar, .banner, .workforce-bar, .resources, .panels) {
    width: 100%;
    max-width: var(--content-max, 1240px);
    margin-left: auto;
    margin-right: auto;
}

:root { --content-max: 1240px; }

/* ---------- nagłówek ---------- */
.topbar {
    display: flex;
    align-items: center;
    gap: var(--s2);
    min-height: 48px;
}

.topbar h1 {
    flex: none;
    width: 124px;
    height: 26px;
    font-size: 0;
    background: url("../img/art/logo.svg") left center / contain no-repeat;
}

.owner-select {
    display: flex;
    align-items: center;
    gap: var(--s2);
    margin-left: auto;
    font-size: var(--fs-sm);
    color: var(--text-muted);
    min-width: 0;
}

.owner-select input {
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    color: var(--text);
    padding: 0 var(--s3);
    height: 38px;
    border-radius: var(--radius-pill);
    width: 112px;
    min-width: 0;
    font-size: 16px; /* 16px: iOS nie powiększa strony po fokusie */
    transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

.owner-select input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--glow-accent); outline: none; }
.owner-select .hint { display: none; }

.icon-btn {
    width: 42px;
    height: 42px;
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: var(--radius-pill);
    font-size: 18px;
    cursor: pointer;
    transition: color var(--t-fast), background var(--t-fast), border-color var(--t-fast), transform 100ms;
}

.icon-btn:hover { color: var(--accent); background: var(--surface-3); border-color: var(--border-strong); }
.icon-btn:active { transform: scale(0.94); }

/* ---------- baner połączenia ---------- */
.banner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--s2);
    background: rgba(240, 119, 90, 0.12);
    border: 1px solid rgba(240, 119, 90, 0.4);
    color: #ffc9ba;
    border-radius: var(--radius-sm);
    padding: var(--s2) var(--s3);
    font-size: var(--fs-sm);
}

.banner small { color: #e0ae9d; }
.banner-actions { display: flex; gap: var(--s2); }

.banner-btn {
    min-height: 36px;
    padding: 0 var(--s3);
    background: rgba(240, 119, 90, 0.2);
    color: #ffe3d9;
    border: 1px solid rgba(240, 119, 90, 0.5);
    border-radius: var(--radius-pill);
    cursor: pointer;
}

/* ---------- HUD: siła robocza (chip) ---------- */
.workforce-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--s2) var(--s4);
    padding: var(--s2) var(--s4);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-1);
    font-size: var(--fs-sm);
    color: var(--text-soft);
}

.workforce-bar .wf-line { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.workforce-bar .wf-line b { color: var(--text); font-size: var(--fs-md); }
.workforce-bar .wf-detail { color: var(--text-muted); }

.workforce-bar .wf-track {
    flex: 1 1 120px;
    min-width: 90px;
    height: 8px;
    background: var(--surface-3);
    border-radius: var(--radius-pill);
    overflow: hidden;
}

.workforce-bar .wf-fill {
    height: 100%;
    border-radius: var(--radius-pill);
    background: linear-gradient(90deg, #7fae45, #b7dd72);
    transition: width 0.4s var(--ease-out);
}

.workforce-bar .upkeep { flex: 1 1 100%; font-size: var(--fs-xs); color: var(--text-muted); }
.workforce-bar .starving { color: var(--danger); font-weight: 700; }
.workforce-bar .alerts, .workforce-bar .construction-banner { flex: 1 1 100%; }

/* ---------- HUD: surowce (stały, zwarty) ----------
   Kolejność w DOM (index.html) = kolejność wizualna: surowce → ludzie → treść (bez CSS `order`, żeby fokus klawiatury szedł po kolei). */
.resources {
    position: sticky;
    top: calc(var(--safe-top) + 6px);
    z-index: 15;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--s2);
}

/* ---------- zakładki: dolny pasek (telefon) ---------- */
.tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    display: flex;
    padding: 6px calc(var(--safe-right) + 8px) calc(var(--safe-bottom) + 6px) calc(var(--safe-left) + 8px);
    background: var(--glass);
    -webkit-backdrop-filter: blur(18px) saturate(1.3);
    backdrop-filter: blur(18px) saturate(1.3);
    border-top: 1px solid var(--glass-edge);
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.4);
}

.tab-btn {
    position: relative;
    flex: 1 1 0;
    min-width: 0;
    min-height: 54px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    background: transparent;
    border: 0;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 6px;
    transition: color var(--t-fast), background var(--t-fast), transform 100ms;
}

.tab-btn:active { transform: scale(0.94); }

.tab-icon { font-size: 21px; line-height: 1; }

.tab-label {
    font-size: var(--fs-xs);
    font-weight: 600;
    white-space: nowrap;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tab-btn.active {
    color: var(--accent);
    background: linear-gradient(180deg, rgba(240, 180, 64, 0.16), rgba(240, 180, 64, 0.04));
    box-shadow: inset 0 0 0 1px rgba(240, 180, 64, 0.22);
}

.tab-group { display: contents; }
.tab-group-label { display: none; }

.tab-badge {
    position: absolute;
    top: 3px;
    right: calc(50% - 26px);
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--rust);
    color: #fff;
    font-size: 10.5px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
    box-shadow: 0 0 0 2px var(--bg);
}

/* ---------- arkusz „Więcej” (telefon) ---------- */
.more-backdrop {
    position: fixed;
    inset: 0;
    z-index: 18;
    background: rgba(5, 4, 2, 0.6);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
    animation: d-fade var(--t-med) ease-out;
}

.more-sheet {
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 6px);
    z-index: 19;
    max-height: calc(100dvh - var(--tabbar-h) - var(--safe-bottom) - var(--safe-top) - 28px);
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    padding: var(--s3) var(--s3) var(--s4);
    box-shadow: var(--shadow-3);
    animation: d-rise var(--t-med) var(--ease-out);
}

.more-head { display: flex; align-items: center; justify-content: space-between; color: var(--text); margin-bottom: var(--s1); }

.more-close {
    width: 40px;
    height: 40px;
    background: var(--surface-3);
    border: 0;
    border-radius: var(--radius-pill);
    color: var(--text-muted);
    font-size: 16px;
    cursor: pointer;
}

.more-group + .more-group { margin-top: var(--s3); }

.more-group-title {
    font-family: var(--font);
    font-size: var(--fs-xs);
    font-weight: 700;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: var(--s2);
}

.more-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s2); }

.more-tile {
    position: relative;
    min-height: 70px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: var(--s2) 4px;
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-soft);
    cursor: pointer;
    transition: background var(--t-fast), border-color var(--t-fast), transform 100ms;
}

.more-tile:active { transform: scale(0.95); }
.more-tile .tab-label { font-size: var(--fs-xs); }
.more-tile.active { color: var(--accent); border-color: rgba(240, 180, 64, 0.5); background: rgba(240, 180, 64, 0.1); }
.more-tile .tab-badge { top: 4px; right: 6px; }

body.more-open { overflow: hidden; }

.tab-panel { min-height: 120px; }

/* ---------- toast ---------- */
#toast {
    position: fixed;
    left: 50%;
    bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
    transform: translate(-50%, 20px);
    max-width: min(92vw, 440px);
    background: var(--surface-3);
    border: 1px solid var(--border-strong);
    color: var(--text);
    padding: var(--s3) var(--s4);
    border-radius: var(--radius-pill);
    font-size: var(--fs-sm);
    box-shadow: var(--shadow-2);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--t-med) ease, transform var(--t-med) var(--ease-out);
    z-index: 40;
}

#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- okna dialogowe ---------- */
dialog {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    padding: var(--s5);
    width: min(92vw, 440px);
    box-shadow: var(--shadow-3);
}

dialog::backdrop { background: rgba(5, 4, 2, 0.7); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
dialog h2 { color: var(--text); font-size: var(--fs-lg); margin-bottom: var(--s3); }
dialog label { display: block; font-size: var(--fs-sm); color: var(--text-muted); margin-bottom: 6px; }

dialog input {
    width: 100%;
    height: var(--touch);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 0 var(--s3);
    font-size: 16px;
}

.dialog-actions { display: flex; justify-content: flex-end; gap: var(--s2); margin-top: var(--s4); }

/* ---------- szeroki ekran: boczny pasek ---------- */
@media (min-width: 640px) {
    :root { --page-pad: 22px; --gap: 16px; }
    .owner-select .hint { display: inline; }
}

@media (min-width: 900px) {
    body {
        padding: 18px calc(var(--page-pad) + var(--safe-right)) 48px calc(var(--sb-w) + var(--page-pad) + 14px);
        transition: padding-left var(--t-med) var(--ease-out);
    }

    html.sb-collapsed { --sb-w: 80px; }

    .topbar h1 { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
    .topbar { justify-content: flex-end; }
    .owner-select { margin-left: 0; }

    .resources { top: 8px; }
    .more-sheet, .more-backdrop { display: none !important; }

    .tabs {
        top: 0;
        right: auto;
        bottom: 0;
        width: var(--sb-w);
        flex-direction: column;
        padding: calc(var(--safe-top) + 14px) 12px 20px;
        overflow-x: hidden;
        overflow-y: auto;
        border-top: 0;
        border-right: 1px solid var(--glass-edge);
        box-shadow: 8px 0 30px rgba(0, 0, 0, 0.28);
        transition: width var(--t-med) var(--ease-out);
    }

    .tabs::before {
        content: "";
        flex: none;
        height: 38px;
        margin: 4px 8px 14px;
        background: url("../img/art/logo.svg") left center / contain no-repeat;
    }

    html.sb-collapsed .tabs::before { background-image: url("../img/art/logo-mark.svg"); background-position: center; margin: 4px 0 14px; }

    .tab-group { display: flex; flex-direction: column; gap: 1px; margin-bottom: var(--s2); }

    .tab-group-label {
        display: block;
        padding: 6px 12px 4px;
        font-size: 10.5px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.12em;
        color: var(--text-faint);
        white-space: nowrap;
        overflow: hidden;
    }

    .tab-group-items { display: flex; flex-direction: column; gap: 2px; }

    .tab-btn {
        flex: none;
        flex-direction: row;
        justify-content: flex-start;
        min-height: 40px;
        gap: 12px;
        padding: 0 12px;
        border-radius: 14px;
        font-size: var(--fs-md);
    }

    .tab-btn:hover:not(.active) { background: rgba(255, 233, 180, 0.06); color: var(--text); }
    .tab-label { font-size: 14.5px; }

    .tab-btn.active::before {
        content: "";
        position: absolute;
        left: -12px;
        top: 10px;
        bottom: 10px;
        width: 4px;
        border-radius: 0 4px 4px 0;
        background: var(--accent);
        box-shadow: 0 0 12px var(--glow-accent);
    }

    .tab-badge { position: static; margin-left: auto; }

    html.sb-collapsed .tab-label, html.sb-collapsed .tab-group-label { display: none; }
    html.sb-collapsed .tab-btn { justify-content: center; padding: 0; }
    html.sb-collapsed .tab-badge { position: absolute; top: 4px; right: 10px; margin: 0; }
    html.sb-collapsed .tab-group + .tab-group { border-top: 1px solid var(--border); padding-top: var(--s2); }

    #toast { bottom: 28px; margin-left: calc(var(--sb-w) / 2); }
}

/* przełącznik zwijania paska (tworzony w shell.js): okrągły guzik na krawędzi bocznego paska */
.sb-toggle {
    display: none;
    position: fixed;
    left: calc(var(--sb-w) - 15px);
    top: 30px;
    z-index: 21;
    width: 30px;
    height: 30px;
    padding: 0;
    align-items: center;
    justify-content: center;
    background: var(--surface-4);
    color: var(--text-muted);
    border: 1px solid var(--border-strong);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: var(--shadow-1);
    transition: color var(--t-fast), background var(--t-fast), left var(--t-med) var(--ease-out);
}

.sb-toggle:hover { color: var(--accent); background: #3f3a2a; }
.sb-toggle .ico { width: 16px; height: 16px; transition: transform var(--t-med) var(--ease-out); }
.sb-toggle .sb-toggle-label { display: none; }
html.sb-collapsed .sb-toggle .ico { transform: rotate(180deg); }

@media (min-width: 900px) {
    .sb-toggle { display: inline-flex; }
}

@media (max-width: 639px) {
    .owner-select label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
    .owner-select { flex: 1 1 60px; }
    .owner-select input { width: 100%; height: 36px; }
    .topbar h1 { width: 104px; }
    .topbar { gap: 6px; }
}
@media (max-width: 400px) { .workforce-bar .wf-line { white-space: normal; flex-wrap: wrap; max-width: 100%; } }

/* HUD: wiersz Dane / Części / Dysk twardy (fala K4) — pełna szerokość pod kartami surowców i nieprzezroczyste tło,
   bo .resources jest przyklejone (sticky) i przy przewijaniu treść strony prześwitywała między pigułkami. */
.resources > .inv-row {
    grid-column: 1 / -1;
    padding: 3px 6px;
    background: var(--glass, rgba(15, 14, 11, 0.92));
    border-radius: 10px;
}
.resources > .inv-row .stat-pill { padding-top: 2px; padding-bottom: 2px; }

/* Przyklejony HUD surowców (UX-P1): jedno wspólne, nieprzezroczyste tło całego paska — przerwy między kartami i wiersz
   Dane/Części/Dysk nie prześwitują już treścią przewijanej strony. Pasek przylega do samej góry (top: 0), a odstęp daje padding. */
.resources {
    top: 0;
    padding-top: calc(var(--safe-top) + 6px);
    padding-bottom: 6px;
    background: linear-gradient(180deg, rgba(15, 14, 11, 0.99), rgba(15, 14, 11, 0.97));
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    /* boczne „skrzydła” tła (cień bez rozmycia) zamiast ujemnych marginesów — kolumna zostaje wyśrodkowana */
    box-shadow: -8px 0 0 rgba(15, 14, 11, 0.99), 8px 0 0 rgba(15, 14, 11, 0.99);
}
.resources > .inv-row { background: transparent; }

/* ---------- UX-P2B: zwinięty HUD po przewinięciu (html.hud-compact, ui/hud.js) ----------
   Jedna linia na surowiec: ikona, zapas, /h i „Zbierz” jako mała ikona; cienki pasek zapełnienia przy dolnej krawędzi.
   Wiersz Dane/Części/Dysk i metadane chowają się (pełne dane wracają po przewinięciu do góry). Różnicę wysokości
   kompensuje margin-bottom ustawiany w JS, więc treść strony nie skacze. */
html.hud-compact .resources { padding-top: calc(var(--safe-top) + 4px); padding-bottom: 4px; row-gap: 0; }
html.hud-compact .resources > .inv-row { display: none; }
html.hud-compact .resource-card {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    padding: 4px 8px 6px;
    border-radius: 12px;
}
html.hud-compact .resource-card .r-head { flex: 1 1 auto; flex-direction: row; align-items: center; gap: 8px; min-width: 0; }
html.hud-compact .resource-card .r-icon { width: 26px; height: 26px; border-radius: 8px; }
html.hud-compact .resource-card .r-icon .ico { width: 16px; height: 16px; }
html.hud-compact .resource-card .r-label,
html.hud-compact .resource-card .r-meta,
html.hud-compact .resource-card .r-cd { display: none; }
html.hud-compact .resource-card .r-value-row { flex-direction: row; align-items: baseline; gap: 6px; }
html.hud-compact .resource-card .r-value { font-size: 16px; }
html.hud-compact .resource-card .r-rate { font-size: 11px; }
html.hud-compact .resource-card .r-bar-track { position: absolute; left: 10px; right: 10px; bottom: 3px; height: 2px; }
html.hud-compact .resource-card > :is(.gather-btn, .tip-wrap) { flex: none; justify-self: auto; width: auto; }
html.hud-compact .resource-card .gather-btn { width: 32px; min-width: 32px; min-height: 30px; height: 30px; padding: 0; animation: none; }
html.hud-compact .resource-card .gather-btn .gb-txt { display: none; }

@media (max-width: 639px) {
    html.hud-compact .resources { gap: 4px; }
    html.hud-compact .resource-card { gap: 3px; padding: 3px 4px 5px; min-height: 36px; }
    html.hud-compact .resource-card .r-head { gap: 4px; }
    html.hud-compact .resource-card .r-icon { width: 18px; height: 18px; border-radius: 6px; background: none; box-shadow: none; }
    html.hud-compact .resource-card .r-icon .ico { width: 15px; height: 15px; }
    html.hud-compact .resource-card .r-value-row { flex-direction: column; align-items: flex-start; gap: 0; }
    html.hud-compact .resource-card .r-value { font-size: 13px; line-height: 1.1; }
    html.hud-compact .resource-card .r-rate { font-size: 9.5px; line-height: 1.1; }
    html.hud-compact .resource-card .gather-btn { width: 26px; min-width: 26px; height: 26px; min-height: 26px; }
    html.hud-compact .resource-card .gather-btn .ico { width: 13px; height: 13px; }
    html.hud-compact .resource-card .r-bar-track { left: 6px; right: 6px; bottom: 2px; }
}

/* Pasek „Ludzie” poza Panelem i Budynkami: jedna linia (UX-P2B). */
.workforce-bar.wf-mini { padding: 6px 14px; gap: 6px 12px; }
.workforce-bar.wf-mini .wf-line b { font-size: var(--fs-sm); }
.workforce-bar.wf-mini .wf-line { white-space: nowrap; }
.workforce-bar .wf-auto .tip-wrap { display: inline-flex; }
.workforce-bar .wf-auto-btn:disabled { opacity: 0.55; cursor: not-allowed; border-style: dashed; }
.workforce-bar .wf-auto-msg { display: inline-flex; align-items: center; gap: 5px; padding: 2px 10px; border-radius: var(--radius-pill); font-size: var(--fs-xs); background: var(--surface-3); color: var(--text-soft); animation: d-fade var(--t-med) ease-out; }
.workforce-bar .wf-auto-msg.good { color: var(--good); background: rgba(156, 203, 88, 0.12); }
.workforce-bar .wf-auto-msg .ico { width: 14px; height: 14px; }

/* Zwinięty HUD na telefonie (~87 px na kartę): dwie linijki — [ikona zapas] / [bilans  Zbierz] — żeby nic się nie ucinało. */
@media (max-width: 639px) {
    html.hud-compact .resource-card {
        display: grid;
        grid-template-columns: 15px minmax(0, 1fr) auto;
        grid-template-areas: "ico val val" "rate rate btn";
        align-items: center;
        gap: 1px 3px;
        padding: 3px 5px 5px;
    }
    html.hud-compact .resource-card :is(.r-head, .r-text, .r-value-row) { display: contents; }
    html.hud-compact .resource-card .r-icon { grid-area: ico; width: 15px; height: 15px; }
    html.hud-compact .resource-card .r-icon .ico { width: 14px; height: 14px; }
    html.hud-compact .resource-card .r-value { grid-area: val; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
    html.hud-compact .resource-card .r-rate { grid-area: rate; min-width: 0; overflow: hidden; white-space: nowrap; }
    html.hud-compact .resource-card > :is(.gather-btn, .tip-wrap) { grid-area: btn; }
    html.hud-compact .resource-card .gather-btn { width: 24px; min-width: 24px; height: 22px; min-height: 22px; }
    html.hud-compact .resource-card .gather-btn .ico { width: 12px; height: 12px; }
}

/* ======================================================================================================================
   UX-P3B: nawigacja dwupoziomowa (sekcje w menu + pasek podzakładek), zablokowane sekcje, Ustawienia, tryb kompaktowy.
   ====================================================================================================================== */

/* pozycja zablokowana (progresywne odblokowanie): wyszarzona, z podpisem „🔒 od Ratusza 1”; klikalna (pokazuje wyjaśnienie) */
.tab-lock {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
}
.tab-lock .ico { width: 11px; height: 11px; }
.tab-btn.is-locked, .more-tile.is-locked { color: var(--text-muted); }
.tab-btn.is-locked .tab-icon, .more-tile.is-locked .tab-icon, .subtab-btn.is-locked .tab-icon { opacity: 0.4; filter: grayscale(1); }
.more-tile.is-locked { border-style: dashed; background: var(--surface-2); }
.more-tile .tab-lock { font-size: 10.5px; }

/* szeroki ekran: jedna lista sekcji (bez etykiet grup); podpis blokady w drugiej linii etykiety */
@media (min-width: 900px) {
    .tabs > .tab-group-items { display: flex; flex-direction: column; gap: 2px; }
    .tab-btn.is-locked { min-height: 48px; }
    .tab-btn.is-locked .tab-label { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; line-height: 1.15; }
    html.sb-collapsed .tab-btn.is-locked .tab-label { display: none; }
}

/* ---------- pasek podzakładek nad treścią ---------- */
.subtabs { margin: 0 0 var(--gap); }
.subtabs[hidden] { display: none; }

.subtabs-track {
    display: flex;
    width: fit-content;
    max-width: 100%;
    gap: 4px;
    padding: 4px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    box-shadow: var(--shadow-1);
}
.subtabs-track::-webkit-scrollbar { display: none; }

.subtab-btn {
    position: relative;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: var(--touch);
    padding: 0 var(--s4);
    background: transparent;
    border: 0;
    border-radius: var(--radius-pill);
    color: var(--text-muted);
    font: inherit;
    font-size: var(--fs-sm);
    font-weight: 650;
    white-space: nowrap;
    cursor: pointer;
    transition: color var(--t-fast), background var(--t-fast);
}
.subtab-btn:hover:not(.active) { color: var(--text); background: rgba(255, 233, 180, 0.06); }
.subtab-btn.active {
    color: var(--accent);
    background: linear-gradient(180deg, rgba(240, 180, 64, 0.18), rgba(240, 180, 64, 0.06));
    box-shadow: inset 0 0 0 1px rgba(240, 180, 64, 0.3);
}
.subtab-btn .tab-icon {
    display: inline-block;
    width: 20px;
    height: 20px;
    font-size: var(--tab-fs, 16px);
    line-height: 20px;
    text-align: center;
    background: var(--tab-ico, none) center / contain no-repeat;
}
html body .subtab-btn .tab-badge { position: static; margin: 0; box-shadow: none; }
.subtab-btn.is-locked { color: var(--text-muted); font-weight: 600; }

@media (max-width: 639px) {
    .subtabs-track { width: auto; }
    .subtab-btn { flex: 1 1 auto; min-width: 0; padding: 0 10px; gap: 5px; }
    .subtab-btn .tab-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
    .subtab-btn .tab-lock { display: none; } /* na telefonie wystarczy ikona kłódki w kolorze — szczegóły w wyjaśnieniu */
    .subtab-btn.is-locked .tab-label::after { content: " 🔒"; }
}

/* ---------- wyjaśnienie zamiast treści zablokowanej zakładki ---------- */
.tab-lock-panel[hidden] { display: none; }
.lock-card {
    display: flex;
    align-items: flex-start;
    gap: var(--s4);
    max-width: 760px;
    padding: var(--s5);
    background: linear-gradient(180deg, rgba(240, 180, 64, 0.07), var(--surface));
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-1);
}
.lock-card-ico {
    flex: none;
    display: grid;
    place-items: center;
    width: 56px;
    height: 56px;
    border-radius: 16px;
    background: var(--surface-3);
    color: var(--accent);
}
.lock-card-ico .ico { width: 28px; height: 28px; }
.lock-card h2 { margin: 0 0 var(--s2); font-size: var(--fs-lg); color: var(--text); display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.lock-card-tag { padding: 2px 10px; border-radius: var(--radius-pill); background: rgba(240, 180, 64, 0.16); color: var(--accent); font-size: 12px; font-weight: 700; }
.lock-card p { margin: 0 0 var(--s2); color: var(--text-soft); line-height: 1.5; max-width: 62ch; }
.lock-card .lock-card-have { color: var(--text-muted); font-size: var(--fs-sm); }
.lock-card-have b { color: var(--text); }
.lock-card-actions { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s3); }

@media (max-width: 639px) {
    .lock-card { flex-direction: column; padding: var(--s4); gap: var(--s3); }
    .lock-card-ico { width: 44px; height: 44px; }
    .lock-card-actions > * { flex: 1 1 100%; }
}

/* ---------- okno Ustawień: preferencje gracza (js/ui/settings.js) ---------- */
#settings { width: min(94vw, 520px); max-height: min(92dvh, 820px); overflow-y: auto; }
.settings-prefs { margin-bottom: var(--s4); display: grid; gap: var(--s3); }
dialog .settings-api-label small { color: var(--text-muted); font-weight: 400; }
.set-group { margin: 0; padding: var(--s3) var(--s3) var(--s2); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); }
.set-group legend { padding: 0 6px; font-size: var(--fs-sm); font-weight: 700; color: var(--text); }
.set-group .hint { margin: 0 0 var(--s2); font-size: var(--fs-xs); color: var(--text-muted); }
dialog .set-check, dialog .set-field {
    display: flex;
    align-items: center;
    gap: var(--s3);
    min-height: var(--touch);
    margin: 0;
    padding: 4px 0;
    color: var(--text);
    font-size: var(--fs-sm);
    cursor: pointer;
}
.set-check input { flex: none; width: 22px; height: 22px; margin: 0; accent-color: var(--accent); }
.set-check > span, .set-field > span { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.set-check small, .set-field small { color: var(--text-muted); font-size: var(--fs-xs); line-height: 1.35; }
.set-field { flex-wrap: wrap; justify-content: space-between; }
.set-field select {
    min-height: 40px;
    padding: 0 var(--s3);
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 15px;
}

/* ---------- tryb kompaktowy (body.compact, Ustawienia → Wygląd) ---------- */
body.compact { --s3: 8px; --s4: 12px; --s5: 16px; --s6: 22px; --gap: 10px; --radius: 14px; --radius-lg: 16px; }
body.compact .tab-panel[data-tab] { --banner-h: 46px; }
body.compact .tab-panel[data-tab]::before { font-size: 19px; padding-bottom: 8px; }
body.compact .card-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr)); }
body.compact .ac-media { aspect-ratio: 21 / 9; }
body.compact .ac-media.r-4x5, body.compact .ac-media.r-portrait { aspect-ratio: 16 / 10; }
body.compact .ac-body { gap: 6px; }
body.compact .subtab-btn { min-height: 40px; }
body.compact .lock-card { padding: var(--s4); }
@media (min-width: 900px) {
    body.compact .tab-btn { min-height: 36px; }
}
