* { box-sizing: border-box; }

:root {
    --bg: #10131a;
    --card: #191e28;
    --card-2: #202633;
    --text: #f4f6f8;
    --muted: #9da7b5;
    --accent: #e7b84b;
    --accent-2: #f0cb70;
    --border: #303847;
    --success: #4fc47a;
    --danger: #ef6b73;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background:
        radial-gradient(circle at top, #252b39 0, var(--bg) 48%),
        var(--bg);
    color: var(--text);
}

button, input { font: inherit; }

.app-shell {
    width: min(100%, 1050px);
    min-height: 100vh;
    margin: 0 auto;
    padding: 32px 20px;
    display: flex;
    align-items: center;
}

.screen { width: 100%; }
.hidden { display: none !important; }

.card {
    background: rgba(25, 30, 40, .96);
    border: 1px solid var(--border);
    border-radius: 22px;
    box-shadow: 0 20px 60px rgba(0,0,0,.32);
}

.start-card, .result-card {
    max-width: 650px;
    margin: auto;
    padding: clamp(28px, 6vw, 60px);
    text-align: center;
}

.badge, .decade {
    color: var(--accent);
    font-size: .78rem;
    font-weight: 800;
    letter-spacing: .16em;
}

h1 {
    margin: 14px 0 10px;
    font-size: clamp(2rem, 6vw, 4rem);
    line-height: 1;
}

h2 {
    margin: 10px 0 26px;
    font-size: clamp(1.25rem, 3vw, 2.15rem);
    line-height: 1.2;
}

.lead {
    color: var(--muted);
    font-size: 1.15rem;
    margin: 0 0 35px;
}

.hint, .muted {
    color: var(--muted);
    font-size: .9rem;
}

form {
    display: grid;
    gap: 12px;
    text-align: left;
}

label {
    font-weight: 700;
    font-size: .95rem;
}

input {
    width: 100%;
    padding: 15px 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--card-2);
    color: var(--text);
    outline: none;
}

input:focus { border-color: var(--accent); }

.primary-btn {
    margin-top: 10px;
    padding: 15px 22px;
    border: 0;
    border-radius: 12px;
    background: var(--accent);
    color: #17130a;
    font-weight: 900;
    cursor: pointer;
    transition: transform .15s, filter .15s;
}

.primary-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    filter: brightness(1.08);
}

.primary-btn:disabled {
    opacity: .45;
    cursor: not-allowed;
}

.quiz-topbar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 20px;
    align-items: center;
    margin-bottom: 16px;
}

.quiz-topbar > div:last-child { text-align: right; }

.progress-box { min-width: min(360px, 42vw); text-align: center; }

.progress {
    height: 7px;
    margin-top: 8px;
    background: #303746;
    border-radius: 99px;
    overflow: hidden;
}

#progress-bar {
    height: 100%;
    width: 10%;
    background: var(--accent);
    transition: width .25s;
}

.score-box strong, .quiz-topbar strong {
    display: block;
    font-size: 1.25rem;
}

.quiz-card {
    padding: clamp(24px, 5vw, 48px);
}

.audio-player {
    margin-bottom: 25px;
    padding: 18px;
    border-radius: 14px;
    background: var(--card-2);
}

.audio-title {
    color: var(--muted);
    font-size: .75rem;
    font-weight: 800;
    letter-spacing: .12em;
    margin-bottom: 10px;
}

audio { width: 100%; }

.audio-missing {
    color: var(--muted);
    font-size: .9rem;
    padding-top: 4px;
}

.answers {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.answer-btn {
    min-height: 72px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--card-2);
    color: var(--text);
    text-align: left;
    cursor: pointer;
    transition: .15s;
}

.answer-btn:hover:not(:disabled) {
    border-color: var(--accent);
    transform: translateY(-1px);
}

.answer-btn.correct {
    border-color: var(--success);
    background: rgba(79,196,122,.14);
}

.answer-btn.wrong {
    border-color: var(--danger);
    background: rgba(239,107,115,.14);
}

.answer-btn:disabled { cursor: default; }

.answer-feedback {
    margin-top: 15px;
    padding: 13px 15px;
    border-radius: 12px;
    font-weight: 700;
}

.answer-feedback.success {
    background: rgba(79,196,122,.12);
    color: var(--success);
}

.answer-feedback.error {
    background: rgba(239,107,115,.12);
    color: var(--danger);
}

.next-btn {
    width: 100%;
    margin-top: 18px;
}

.result-score {
    margin: 25px 0 12px;
    font-size: clamp(4rem, 12vw, 7rem);
    font-weight: 900;
    line-height: 1;
    color: var(--accent);
}

.result-score small {
    color: var(--muted);
    font-size: 1.2rem;
}

.result-meta {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
}

.error {
    margin-top: 15px;
    color: var(--danger);
    font-size: .9rem;
}

@media (max-width: 700px) {
    .app-shell { padding: 18px 12px; }

    .quiz-topbar {
        grid-template-columns: 1fr 1fr;
    }

    .progress-box {
        order: 3;
        grid-column: 1 / -1;
        min-width: 0;
    }

    .quiz-topbar > div:last-child { text-align: right; }

    .answers { grid-template-columns: 1fr; }
}


/* ===== START SCREEN + TOP 10 ===== */

.start-layout {
    position: relative;
    width: min(100%, 900px);
    min-height: 560px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

.start-card {
    position: relative;
    z-index: 2;
    width: min(100%, 650px);
    margin: 0;
}

.ranking-card {
    position: absolute;
    z-index: 1;
    left: calc(100% - 145px);
    top: 50%;
    transform: translateY(-50%);
    width: 315px;
    min-height: 385px;
    padding: 28px 24px 24px 72px;
    border: 1px solid #4b3e25;
    border-radius: 0 20px 20px 0;
    background: #252a22;
    box-shadow: 18px 20px 45px rgba(0,0,0,.25);
}

.ranking-header {
    margin-bottom: 15px;
}

.ranking-kicker {
    display: block;
    color: var(--accent);
    font-size: .68rem;
    font-weight: 900;
    letter-spacing: .15em;
}

.ranking-header h2 {
    margin: 4px 0 0;
    font-size: 1.55rem;
    line-height: 1;
}

.ranking-list {
    display: grid;
    gap: 6px;
}

.ranking-row {
    display: grid;
    grid-template-columns: 30px minmax(0, 1fr) auto;
    align-items: center;
    gap: 7px;
    min-height: 31px;
    padding: 5px 7px;
    border-radius: 8px;
    background: rgba(255,255,255,.035);
    font-size: .82rem;
}

.ranking-row:nth-child(1) {
    background: rgba(231,184,75,.14);
    border: 1px solid rgba(231,184,75,.18);
}

.ranking-row:nth-child(2) {
    background: rgba(190,194,199,.12);
    border: 1px solid rgba(190,194,199,.16);
}

.ranking-row:nth-child(3) {
    background: rgba(150,104,67,.15);
    border: 1px solid rgba(150,104,67,.18);
}

.ranking-row:nth-child(1) .ranking-position {
    color: var(--accent);
}

.ranking-row:nth-child(2) .ranking-position {
    color: #c4c8cc;
}

.ranking-row:nth-child(3) .ranking-position {
    color: #a8754e;
}

.ranking-position {
    color: var(--accent);
    font-weight: 900;
    text-align: center;
}

.ranking-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ranking-score {
    font-weight: 900;
    white-space: nowrap;
}

.ranking-empty,
.ranking-loading,
.ranking-error {
    color: var(--muted);
    font-size: .82rem;
    line-height: 1.4;
}

.ranking-error {
    color: var(--danger);
}

@media (max-width: 900px) {
    .start-layout {
        min-height: 0;
        display: block;
        padding-bottom: 25px;
    }

    .start-card {
        width: min(100%, 650px);
        margin: 0 auto;
    }

    .ranking-card {
        position: relative;
        left: auto;
        top: auto;
        transform: none;
        width: min(88%, 560px);
        min-height: 0;
        margin: -10px auto 0;
        padding: 42px 24px 24px;
        border-radius: 0 0 20px 20px;
    }
    
    
/* ===== ANDROID TABLET: QUIZ FIT TO SCREEN ===== */

@media (max-height: 900px) {

    html,
    body {
        height: 100%;
        min-height: 0;
    }

    body {
        overflow: hidden;
    }

    .app-shell {
        height: 100vh;
        height: 100dvh;
        min-height: 0;
        padding: 10px 14px;
        overflow: hidden;
    }

    /* Ekran quizu zajmuje całą dostępną przestrzeń */
    .screen:has(.quiz-card) {
        height: 100%;
        min-height: 0;
        display: flex;
        flex-direction: column;
    }

    .quiz-topbar {
        flex: 0 0 auto;
        gap: 10px;
        margin-bottom: 8px;
    }

    .quiz-topbar strong,
    .score-box strong {
        font-size: 1rem;
    }

    .quiz-card {
        flex: 1 1 auto;
        min-height: 0;
        padding: clamp(10px, 2vh, 24px);
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    /* Pytanie: mniejsza czcionka i ciaśniejsze odstępy */
    .quiz-card h2 {
        flex: 0 1 auto;
        min-height: 0;
        margin: 4px 0 12px;
        font-size: clamp(1rem, 2.8vh, 2rem);
        line-height: 1.15;
        overflow-wrap: anywhere;
    }

    .audio-player {
        flex: 0 0 auto;
        margin-bottom: 12px;
        padding: 10px;
    }

    .audio-title {
        margin-bottom: 4px;
    }

    .answers {
        flex: 0 1 auto;
        gap: 8px;
    }

    .answer-btn {
        min-height: 0;
        padding: 10px 12px;
        font-size: clamp(0.85rem, 1.8vh, 1.1rem);
        line-height: 1.2;
    }

    .answer-feedback {
        flex: 0 0 auto;
        margin-top: 8px;
        padding: 8px 10px;
    }

    .next-btn {
        flex: 0 0 auto;
        margin-top: 8px;
        padding: 10px 14px;
    }
}

/* Szczególnie niskie ekrany */
@media (max-height: 650px) {

    .app-shell {
        padding: 5px 10px;
    }

    .quiz-topbar {
        margin-bottom: 4px;
    }

    .quiz-card {
        padding: 8px 12px;
    }

    .quiz-card h2 {
        margin: 2px 0 6px;
        font-size: clamp(0.9rem, 2.5vh, 1.4rem);
    }

    .audio-player {
        padding: 6px 10px;
        margin-bottom: 6px;
    }

    .answer-btn {
        padding: 7px 10px;
    }
}
}
