:root {
    --app-header-height: 58px;
    --tab-bar-height: 70px;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 120;
    height: var(--app-header-height);
    border-bottom: 1px solid var(--border);
    background: var(--header-bg);
    backdrop-filter: blur(20px) saturate(150%);
}

.app-header-inner {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    width: min(100% - 28px, var(--max-width));
    height: 100%;
    margin-inline: auto;
    gap: 12px;
}

.app-header-search {
    display: flex;
    align-items: center;
    justify-self: start;
    width: min(300px, 100%);
    height: 38px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-2);
}

.app-header-search span {
    padding-left: 12px;
    color: var(--muted);
    font-size: 18px;
}

.app-header-search input {
    min-width: 0;
    flex: 1;
    height: 100%;
    padding: 0 11px;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--text);
    -webkit-text-fill-color: var(--text);
    caret-color: var(--accent);
    font-size: 13px;
}

.app-header-search input::placeholder {
    color: var(--muted-2);
    -webkit-text-fill-color: var(--muted-2);
}

.app-search-toggle {
    display: none;
    justify-self: start;
}

.app-wordmark {
    position: absolute;
    left: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: max-content;
    color: var(--text);
    font-size: 17px;
    font-weight: 850;
    letter-spacing: -.035em;
    transform: translateX(-50%);
}

.app-wordmark span {
    color: var(--accent);
}

.app-header-actions {
    display: flex;
    align-items: center;
    justify-self: end;
    gap: 8px;
}

.app-header-action {
    display: grid;
    width: 38px;
    height: 38px;
    place-items: center;
    border: 1px solid var(--border-strong);
    border-radius: 11px;
    background: var(--surface);
    color: var(--text);
    font-family: Inter, system-ui, sans-serif;
    font-size: 18px;
    font-weight: 800;
    line-height: 1;
    box-shadow: 0 4px 16px rgba(0,0,0,.08);
}

.app-header-action svg {
    width: 19px;
    height: 19px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.app-header-action > span {
    display: grid;
    width: 100%;
    height: 100%;
    place-items: center;
    color: inherit;
    line-height: 1;
}

.app-header-action:hover,
.app-header-action:focus-visible {
    border-color: rgba(255, 77, 104, .5);
    color: var(--accent);
}

html[data-theme="light"] .app-header-action {
    background: #fff;
    border-color: rgba(24,31,45,.16);
    color: #2d3440;
}

.app-search-drawer {
    position: absolute;
    top: calc(100% + 1px);
    left: 0;
    right: 0;
    padding: 10px 14px 13px;
    border-bottom: 1px solid var(--border);
    background: var(--header-bg);
    box-shadow: 0 18px 35px rgba(0,0,0,.22);
    backdrop-filter: blur(20px) saturate(150%);
}

.app-search-drawer[hidden] {
    display: none;
}

.app-search-drawer form {
    display: flex;
    width: min(100%, 720px);
    height: 44px;
    margin-inline: auto;
    border: 1px solid var(--border-strong);
    border-radius: 13px;
    background: var(--surface-2);
}

.app-search-drawer input {
    min-width: 0;
    flex: 1;
    padding: 0 14px;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--text);
    -webkit-text-fill-color: var(--text);
}

.app-search-drawer button {
    margin: 5px;
    padding: 0 16px;
    border: 0;
    border-radius: 9px;
    background: var(--accent);
    color: white;
    font-weight: 800;
}

.app-tab-bar {
    position: fixed;
    z-index: 125;
    left: 0;
    right: 0;
    bottom: 0;
    display: none;
    height: calc(var(--tab-bar-height) + env(safe-area-inset-bottom));
    padding: 7px 8px env(safe-area-inset-bottom);
    border-top: 1px solid var(--border);
    background: var(--header-bg);
    box-shadow: 0 -12px 35px rgba(0,0,0,.18);
    backdrop-filter: blur(20px) saturate(150%);
}

.app-tab-bar a {
    display: flex;
    min-width: 0;
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    border-radius: 12px;
    color: var(--muted-2);
    font-size: 10px;
    font-weight: 750;
}

.app-tab-bar a > span:first-child {
    font-size: 20px;
    line-height: 1;
}

.app-tab-bar a.active {
    background: var(--accent-soft);
    color: var(--accent);
}

@media (max-width: 820px) {
    :root {
        --app-header-height: 54px;
        --tab-bar-height: 66px;
    }

    body {
        padding-bottom: calc(var(--tab-bar-height) + env(safe-area-inset-bottom));
    }

    .app-header-inner {
        width: min(100% - 20px, var(--max-width));
        gap: 7px;
    }

    .app-header-search {
        display: none;
    }

    .app-search-toggle {
        display: grid;
    }

    .app-header-actions .app-library-shortcut {
        display: grid;
    }

    .app-header-action {
        width: 36px;
        height: 36px;
        border-radius: 11px;
    }

    .app-wordmark {
        font-size: 16px;
    }

    .app-tab-bar {
        display: flex;
    }

    .site-footer {
        margin-bottom: 0;
    }
}

@media (max-width: 390px) {
    .app-header-actions {
        gap: 5px;
    }

    .app-header-action {
        width: 34px;
        height: 34px;
    }

    .app-wordmark {
        font-size: 15px;
    }
}

@media (min-width: 821px) {
    .app-tab-bar {
        display: flex;
        left: 50%;
        right: auto;
        bottom: 14px;
        width: min(560px, calc(100% - 32px));
        height: 62px;
        padding: 6px;
        border: 1px solid var(--border);
        border-radius: 19px;
        transform: translateX(-50%);
    }

    body {
        padding-bottom: 88px;
    }
}

/* --- Zpět nahoru --- */
.back-to-top {
    position: fixed;
    z-index: 110;
    right: 20px;
    bottom: 22px;
    display: grid;
    width: 44px;
    height: 44px;
    place-items: center;
    padding: 0;
    border: 1px solid var(--border-strong);
    border-radius: 50%;
    background: var(--panel-bg-strong);
    color: var(--text);
    font-size: 19px;
    font-weight: 800;
    opacity: 0;
    box-shadow: 0 14px 32px rgba(0, 0, 0, .28);
    backdrop-filter: blur(16px) saturate(150%);
    cursor: pointer;
    pointer-events: none;
    transform: translateY(12px);
    transition: opacity 180ms ease, transform 180ms ease, border-color 180ms ease;
}

.back-to-top.visible {
    opacity: 1;
    pointer-events: auto;
    transform: none;
}

.back-to-top:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* --- Náhodný titul --- */
.app-surprise svg {
    stroke-width: 1.9;
}

/* --- Nabídka instalace na plochu --- */
.install-banner {
    position: fixed;
    z-index: 128;
    left: 50%;
    bottom: 22px;
    display: flex;
    width: min(440px, calc(100% - 24px));
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--border-strong);
    border-radius: 18px;
    background: var(--panel-bg-strong);
    box-shadow: var(--shadow);
    backdrop-filter: blur(22px) saturate(150%);
    transform: translateX(-50%);
    animation: install-banner-in 240ms ease-out;
}

.install-banner img {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    border-radius: 11px;
}

.install-banner-text {
    min-width: 0;
    flex: 1;
}

.install-banner-text strong {
    display: block;
    font-size: 13px;
}

.install-banner-text small {
    display: block;
    margin-top: 2px;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.35;
}

.install-banner-actions {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.install-banner-actions button {
    padding: 7px 13px;
    border: 1px solid transparent;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 800;
    cursor: pointer;
}

.install-banner-actions [data-install-accept] {
    background: var(--accent);
    color: #fff;
}

.install-banner-actions [data-install-dismiss] {
    border-color: var(--border-strong);
    background: transparent;
    color: var(--muted);
}

@keyframes install-banner-in {
    from { opacity: 0; transform: translate(-50%, 14px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

body.has-install-banner .back-to-top {
    bottom: 96px;
}

@media (max-width: 820px) {
    .app-surprise {
        display: none;
    }

    .back-to-top {
        right: 14px;
        bottom: calc(var(--tab-bar-height) + env(safe-area-inset-bottom) + 12px);
        width: 40px;
        height: 40px;
    }

    .install-banner {
        bottom: calc(var(--tab-bar-height) + env(safe-area-inset-bottom) + 12px);
    }

    body.has-install-banner .back-to-top {
        bottom: calc(var(--tab-bar-height) + env(safe-area-inset-bottom) + 108px);
    }
}

@media (min-width: 821px) {
    .back-to-top {
        bottom: 90px;
    }

    .install-banner {
        bottom: 90px;
    }

    body.has-install-banner .back-to-top {
        bottom: 164px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .back-to-top {
        transition: opacity 120ms ease;
        transform: none;
    }

    .install-banner {
        animation: none;
    }
}
