:root {
    --bg: #f7f3ee;
    --surface: #ffffff;
    --surface-2: #f0ebe4;
    --text: #2b2420;
    --muted: #7d726a;
    --line: #e2d9cf;
    --accent: #7a2e2e;
    --accent-text: #ffffff;
    --chord: #b0451f;
    --ok: #2e7a4a;
    --danger: #a32626;
    --radius: 14px;
    --song-size: 20px;
    color-scheme: light;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #161312;
        --surface: #221d1b;
        --surface-2: #2d2624;
        --text: #f1ebe5;
        --muted: #a69a91;
        --line: #3a322f;
        --accent: #c96a5a;
        --accent-text: #1a1210;
        --chord: #f0a35e;
        --ok: #5fbf83;
        --danger: #f07070;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
body.noscroll { overflow: hidden; }
.app { max-width: 720px; margin: 0 auto; padding: 0 16px calc(32px + env(safe-area-inset-bottom)); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.center { text-align: center; }
.pad { padding: 24px 0; }
.small { font-size: .875rem; }
.hidden { display: none !important; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }

/* ---------- Pasek górny ---------- */
.topbar {
    position: sticky; top: 0; z-index: 5;
    display: flex; align-items: center; gap: 8px;
    margin: 0 -16px 16px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
    background: var(--bg); border-bottom: 1px solid var(--line);
}
.topbar .title { flex: 1; min-width: 0; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .sub { display: block; font-weight: 400; font-size: .8rem; color: var(--muted); }

/* ---------- Karty i formularze ---------- */
.card {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 16px; margin-bottom: 16px;
}
.hero { text-align: center; padding: 40px 0 24px; }
.hero h1 { font-size: 2rem; margin-bottom: 4px; }
label { display: block; font-size: .875rem; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
    width: 100%; font: inherit; color: var(--text);
    background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
    padding: 12px; min-height: 48px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
input.code { font-size: 1.6rem; letter-spacing: .35em; text-align: center; font-variant-numeric: tabular-nums; }
textarea { min-height: 260px; font-family: ui-monospace, Consolas, monospace; font-size: .9rem; line-height: 1.5; }
.field + .field { margin-top: 12px; }
.check { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 1rem; }
.check input { width: 20px; min-height: 20px; }

/* ---------- Przyciski ---------- */
button, .btn {
    font: inherit; font-weight: 600; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 44px; padding: 10px 16px; border-radius: 10px;
    border: 1px solid var(--line); background: var(--surface); color: var(--text);
    text-decoration: none; -webkit-tap-highlight-color: transparent;
}
button:active { transform: scale(.98); }
button:disabled { opacity: .5; cursor: default; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.danger { color: var(--danger); }
.block { width: 100%; }
.icon { min-width: 44px; padding: 8px; }
.ghost { background: transparent; border-color: transparent; }

.seg-control { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px; }
.seg-control button { flex: 1; border: 0; background: transparent; min-height: 40px; }
.seg-control button.on { background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.15); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: transparent; color: var(--muted); }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }

/* ---------- Listy pieśni ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 4px; border-bottom: 1px solid var(--line);
}
.list li.tap { cursor: pointer; }
.list li.tap:active { background: var(--surface-2); }
.list li.current { background: color-mix(in srgb, var(--accent) 12%, transparent); border-radius: 8px; }
.num {
    flex: none; min-width: 44px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums;
    color: var(--accent);
}
.song-line { flex: 1; min-width: 0; }
.song-line .t { display: block; }
.song-line .s { display: block; font-size: .85rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { font-size: .7rem; padding: 2px 6px; border-radius: 6px; background: var(--surface-2); color: var(--muted); }
details.cat { border-bottom: 1px solid var(--line); }
details.cat summary { padding: 12px 4px; font-weight: 700; cursor: pointer; }
details.cat .list li:last-child { border-bottom: 0; }

.section { margin-bottom: 18px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.section-head h3 { margin: 0; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-size: .8rem; }
.section .empty { color: var(--muted); font-size: .9rem; padding: 6px 4px; }

.now-banner {
    display: flex; align-items: center; gap: 10px; width: 100%;
    background: var(--accent); color: var(--accent-text); border: 0; text-align: left;
    padding: 12px 14px; border-radius: var(--radius); margin-bottom: 16px; min-height: 56px;
}
.now-banner .lbl { font-size: .75rem; opacity: .85; display: block; font-weight: 400; }

/* ---------- Widok uczestnika ---------- */
.big-number { text-align: center; padding: 8vh 0 4vh; }
.big-number .n { font-size: min(38vw, 260px); font-weight: 800; line-height: 1; color: var(--accent); font-variant-numeric: tabular-nums; }
.big-number .t { font-size: 1.5rem; margin-top: 12px; }
.waiting { text-align: center; color: var(--muted); padding: 15vh 0; font-size: 1.2rem; }

/* ---------- Tekst pieśni z akordami ---------- */
.song { font-size: var(--song-size); line-height: 1.35; }
.song-title { font-size: calc(var(--song-size) * 1.15); font-weight: 700; margin: 0 0 .8em; }
.stanza { margin: 0 0 1.1em; }
.stanza.ref { padding-left: .9em; border-left: 3px solid var(--line); font-style: italic; }
.ln { white-space: pre-wrap; }
.ln.ch-line { padding-top: 1.15em; position: relative; white-space: normal; }
.w { display: inline-block; white-space: nowrap; }
.tk { display: inline-block; position: relative; white-space: pre; }
.tk .c {
    position: absolute; left: 0; bottom: 100%;
    font-size: .8em; font-weight: 700; color: var(--chord); font-style: normal; white-space: nowrap;
}
.tk.only { min-width: 2.2em; }
body.hide-chords .ln.ch-line { padding-top: 0; }
body.hide-chords .tk .c { display: none; }
body.hide-chords .tk.only { min-width: 0; }
button[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }

/* ---------- Nakładki ---------- */
.overlay {
    position: fixed; inset: 0; z-index: 20;
    background: var(--bg); display: flex; flex-direction: column;
}
.overlay .ov-bar {
    display: flex; align-items: center; gap: 4px;
    padding: calc(6px + env(safe-area-inset-top)) 8px 6px; border-bottom: 1px solid var(--line);
}
.overlay .ov-title { flex: 1; min-width: 0; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 4px; }
.overlay .ov-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 16px 16px 40px; }
.overlay .ov-body > .inner { max-width: 720px; margin: 0 auto; }
.overlay .ov-foot {
    display: flex; gap: 8px; padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line); background: var(--surface);
}
.overlay .ov-foot .grow { flex: 1; }

.sheet-backdrop { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; }
.sheet {
    width: 100%; max-width: 720px; margin: 0 auto; background: var(--surface);
    border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
    max-height: 80vh; overflow-y: auto;
}
.sheet button { width: 100%; justify-content: flex-start; margin-bottom: 6px; }

.toast {
    position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 50;
    transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
    background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
    max-width: calc(100% - 32px); transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); color: #fff; }

.codes { display: flex; gap: 12px; flex-wrap: wrap; }
.codes div { background: var(--surface-2); border-radius: 10px; padding: 8px 12px; }
.codes b { display: block; font-size: 1.4rem; letter-spacing: .12em; font-variant-numeric: tabular-nums; }
.pill { font-size: .75rem; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); }
.pill.on { background: var(--ok); color: #fff; }
.help { font-size: .85rem; color: var(--muted); background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.help code { color: var(--chord); }
