:root {
    --bg: #f4f7fb;
    --surface: #ffffff;
    --text: #172033;
    --muted: #64748b;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --border: #dbe3ef;
    --success: #166534;
    --success-bg: #dcfce7;
    --danger: #b91c1c;
    --danger-bg: #fee2e2;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

.container {
    width: min(1100px, calc(100% - 32px));
    margin: 0 auto;
}

.narrow { max-width: 720px; padding-top: 48px; }

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.nav {
    min-height: 68px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.brand {
    font-weight: 800;
    color: var(--text);
    text-decoration: none;
    font-size: 1.2rem;
}

nav { display: flex; flex-wrap: wrap; gap: 16px; }
nav a { color: var(--text); text-decoration: none; font-weight: 600; }
nav a:hover { color: var(--primary); }

.hero { padding: 42px 0 24px; }
.hero h1 { margin: 0 0 8px; font-size: clamp(2rem, 5vw, 3.2rem); line-height: 1.1; }
.hero p { color: var(--muted); margin: 0; }

.story-grid { display: grid; gap: 22px; padding-bottom: 50px; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 8px 30px rgba(15, 23, 42, .05);
}

.story-heading {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
}

.story-heading h2 { margin: 8px 0 14px; }
.badge {
    display: inline-block;
    background: #dbeafe;
    color: #1e40af;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: .8rem;
    font-weight: 700;
}

.story-text {
    font-size: 1.12rem;
    padding: 18px;
    background: #f8fafc;
    border-radius: 12px;
    user-select: text;
}

details { margin-top: 14px; }
summary { cursor: pointer; font-weight: 700; }
.translation { padding: 12px 0; color: var(--muted); }

.word-box { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 18px; }

.word-form {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 12px;
    align-items: end;
}

label { display: grid; gap: 6px; font-weight: 650; }

input, textarea, select {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 11px 12px;
    font: inherit;
    background: #fff;
}

input:focus, textarea:focus, select:focus {
    outline: 3px solid #bfdbfe;
    border-color: var(--primary);
}

.button {
    display: inline-block;
    border: 0;
    border-radius: 10px;
    padding: 11px 16px;
    background: var(--primary);
    color: white;
    font-weight: 750;
    text-decoration: none;
    cursor: pointer;
}

.button:hover { background: var(--primary-dark); }
.button.secondary { background: #e2e8f0; color: var(--text); }

.notice {
    border-radius: 10px;
    padding: 12px 14px;
    background: #e0f2fe;
    margin: 12px 0 20px;
}

.notice.success { background: var(--success-bg); color: var(--success); }
.notice.error { background: var(--danger-bg); color: var(--danger); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px; border-bottom: 1px solid var(--border); text-align: left; }
th { background: #f8fafc; }

.link-danger {
    border: 0;
    background: transparent;
    color: var(--danger);
    font-weight: 700;
    cursor: pointer;
}

.quiz-card { max-width: 700px; margin-bottom: 50px; }
.quiz-label { color: var(--muted); margin-bottom: 0; }
.quiz-word { font-size: 2.5rem; font-weight: 850; margin: 8px 0 22px; }
.quiz-form { display: flex; gap: 12px; align-items: end; }
.quiz-form label { flex: 1; }

.stack-form { display: grid; gap: 18px; }
.muted { color: var(--muted); }

@media (max-width: 760px) {
    .nav { align-items: flex-start; flex-direction: column; padding: 14px 0; }
    .word-form { grid-template-columns: 1fr; }
    .story-heading { flex-direction: column; }
    .quiz-form { flex-direction: column; align-items: stretch; }
}


.translatable-word {
    border-radius: 4px;
    cursor: help;
    transition: background .15s ease;
}

.translatable-word:hover {
    background: #fef3c7;
}

.translation-tooltip {
    position: fixed;
    z-index: 1000;
    max-width: 280px;
    padding: 9px 12px;
    border-radius: 9px;
    background: #172033;
    color: #fff;
    box-shadow: 0 10px 30px rgba(15, 23, 42, .25);
    font-size: .94rem;
    line-height: 1.35;
    pointer-events: none;
}

.selection-translation {
    position: absolute;
    z-index: 1001;
    width: min(390px, calc(100vw - 32px));
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 13px;
    background: #fff;
    box-shadow: 0 16px 45px rgba(15, 23, 42, .2);
}

.selection-close {
    position: absolute;
    right: 8px;
    top: 5px;
    border: 0;
    background: transparent;
    font-size: 1.5rem;
    cursor: pointer;
}

.selection-source {
    padding-right: 24px;
    color: var(--muted);
    font-size: .9rem;
    max-height: 75px;
    overflow: auto;
}

.selection-result {
    margin: 10px 0 14px;
    font-weight: 700;
    max-height: 120px;
    overflow: auto;
}


/* Okno tłumaczenia w stylu wcześniejszej wersji */
.translation-tooltip { display: none !important; }

.word-popup {
    position: absolute;
    z-index: 9999;
    width: 310px;
    overflow: visible;
    border: 1px solid #e5e7eb;
    border-radius: 18px;
    background: #ffffff;
    box-shadow: 0 18px 45px rgba(15, 23, 42, .24);
    text-align: center;
    animation: popupIn .16s ease-out;
}

.word-popup::after {
    content: "";
    position: absolute;
    left: 50%;
    bottom: -12px;
    width: 24px;
    height: 24px;
    transform: translateX(-50%) rotate(45deg);
    background: #ffd95a;
    border-radius: 3px;
    z-index: -1;
}

.word-popup.below-word::after {
    top: -12px;
    bottom: auto;
    background: #ffffff;
}

.word-popup-body {
    padding: 22px 22px 18px;
}

.word-popup-title {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    font-size: 29px;
    font-weight: 700;
    color: #111827;
}

.word-popup-sound {
    width: 42px;
    height: 42px;
    padding: 0;
    display: inline-grid;
    place-items: center;
    border: 1px solid #cfd5df;
    border-radius: 50%;
    background: #fff;
    color: #111827;
    font-size: 21px;
    cursor: pointer;
}

.word-popup-phonetic {
    min-height: 25px;
    margin-top: 4px;
    color: #b2b6bf;
    font-size: 18px;
}

.word-popup-translation {
    margin-top: 8px;
    font-size: 25px;
    color: #202124;
}

.word-popup-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    overflow: hidden;
    border-radius: 0 0 17px 17px;
}

.word-popup-actions button {
    min-height: 68px;
    border: 0;
    border-radius: 0;
    font-size: 21px;
    font-weight: 500;
    cursor: pointer;
}

.word-known {
    background: #06d98b;
    color: #07271c;
}

.word-learn {
    background: #ffd95a;
    color: #3f3210;
}

.word-known-mark {
    background: #bff3dc !important;
}

.word-learn-mark {
    background: #ffe38a !important;
}

@keyframes popupIn {
    from { opacity: 0; transform: translateY(6px) scale(.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 420px) {
    .word-popup {
        width: min(310px, calc(100vw - 24px));
    }
}


.reading-controls {
    margin: 0 0 24px;
    padding: 18px 22px;
}

.reading-controls label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.reading-controls input[type="range"] {
    width: 100%;
    padding: 0;
    accent-color: var(--primary);
}

.rate-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 4px;
    color: var(--muted);
    font-size: .85rem;
}


/* Panel tłumaczenia zaznaczonej frazy */
.selection-translation {
    width: min(520px, calc(100vw - 32px));
    padding: 20px;
    border-radius: 18px;
}

.phrase-popup-heading {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-right: 34px;
    margin-bottom: 12px;
    font-size: 1rem;
    font-weight: 800;
    color: var(--muted);
}

.phrase-speak {
    width: 44px;
    height: 44px;
    display: inline-grid;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: #fff;
    font-size: 1.25rem;
    cursor: pointer;
}

.phrase-speak:hover {
    background: #eff6ff;
    border-color: #93c5fd;
}

.selection-source {
    max-height: 130px;
    overflow: auto;
    padding: 14px 16px;
    border-radius: 12px;
    background: #f8fafc;
    color: var(--text);
    font-size: 1.05rem;
    font-weight: 650;
    line-height: 1.55;
}

.phrase-divider {
    height: 1px;
    margin: 16px 0;
    background: var(--border);
}

.phrase-label {
    margin-bottom: 6px;
    color: var(--muted);
    font-size: .9rem;
    font-weight: 750;
}

.selection-result {
    max-height: 150px;
    overflow: auto;
    margin: 0 0 18px;
    padding: 14px 16px;
    border-radius: 12px;
    background: #fff7d6;
    color: var(--text);
    font-size: 1.08rem;
    font-weight: 750;
    line-height: 1.55;
}

.phrase-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    flex-wrap: wrap;
}

.phrase-actions .button {
    min-height: 44px;
}

@media (max-width: 560px) {
    .phrase-actions {
        flex-direction: column;
    }

    .phrase-actions .button {
        width: 100%;
    }
}


.speak-button.resume-reading {
    background: #16a34a;
    color: #ffffff;
}

.speak-button.resume-reading:hover {
    background: #15803d;
}


.auth-card {
    max-width: 520px;
    margin: 48px auto;
}

.auth-card h1 {
    margin-top: 0;
}

.auth-link {
    margin-top: 20px;
    color: var(--muted);
}

.nav-user {
    color: var(--muted);
    font-weight: 700;
}


.edit-word-form {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) minmax(220px, 1.2fr) auto auto;
    gap: 14px;
    align-items: end;
}

.word-stats {
    display: flex;
    gap: 14px;
    align-items: center;
    white-space: nowrap;
    color: var(--muted);
}

.word-actions {
    display: flex;
    align-items: end;
}

.delete-word-form {
    margin-top: 10px;
    text-align: right;
}

@media (max-width: 860px) {
    .edit-word-form {
        grid-template-columns: 1fr;
    }

    .word-stats {
        justify-content: flex-start;
    }

    .word-actions .button {
        width: 100%;
    }
}


/* Czytelny widok słownika */
.vocabulary-hero {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 24px;
}

.vocabulary-count {
    min-width: 110px;
    padding: 14px 18px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface);
    text-align: center;
    box-shadow: 0 8px 24px rgba(15, 23, 42, .05);
}

.vocabulary-count strong {
    display: block;
    font-size: 1.8rem;
    line-height: 1;
}

.vocabulary-count span {
    color: var(--muted);
    font-size: .9rem;
}

.vocabulary-list {
    display: grid;
    gap: 18px;
    padding-bottom: 50px;
}

.vocabulary-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 132px;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--surface);
    box-shadow: 0 10px 30px rgba(15, 23, 42, .06);
}

.vocabulary-card-main {
    position: relative;
    padding: 22px;
}

.word-number {
    position: absolute;
    top: 10px;
    right: 14px;
    color: #94a3b8;
    font-size: .75rem;
}

.vocabulary-edit-form {
    display: grid;
    gap: 20px;
}

.vocabulary-fields {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) 32px minmax(220px, 1.2fr);
    gap: 12px;
    align-items: end;
}

.vocabulary-fields label span {
    color: var(--muted);
    font-size: .8rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .06em;
}

.vocabulary-fields input {
    min-height: 50px;
    border-width: 2px;
    font-size: 1.08rem;
    font-weight: 700;
}

.english-field input {
    background: #eff6ff;
    border-color: #bfdbfe;
    color: #1e3a8a;
}

.polish-field input {
    background: #fff7d6;
    border-color: #fde68a;
    color: #713f12;
}

.translation-arrow {
    padding-bottom: 11px;
    color: #94a3b8;
    font-size: 1.6rem;
    font-weight: 800;
    text-align: center;
}

.vocabulary-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.word-statistics {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.word-statistics > div {
    min-width: 82px;
    padding: 8px 11px;
    border-radius: 10px;
}

.word-statistics span {
    display: block;
    font-size: .72rem;
    font-weight: 800;
    text-transform: uppercase;
}

.word-statistics strong {
    font-size: 1.1rem;
}

.stat-good {
    background: #dcfce7;
    color: #166534;
}

.stat-bad {
    background: #fee2e2;
    color: #991b1b;
}

.stat-accuracy {
    background: #e0f2fe;
    color: #075985;
}

.save-word-button {
    white-space: nowrap;
}

.vocabulary-card-actions {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 12px;
    padding: 18px;
    border-left: 1px solid var(--border);
    background: #f8fafc;
}

.vocabulary-card-actions form {
    margin: 0;
}

.speak-vocabulary-word,
.delete-vocabulary-word {
    width: 100%;
    min-height: 44px;
    border-radius: 10px;
    font: inherit;
    font-weight: 750;
    cursor: pointer;
}

.speak-vocabulary-word {
    border: 1px solid #bfdbfe;
    background: #eff6ff;
    color: #1d4ed8;
}

.speak-vocabulary-word:hover {
    background: #dbeafe;
}

.delete-vocabulary-word {
    border: 1px solid #fecaca;
    background: #fff;
    color: #b91c1c;
}

.delete-vocabulary-word:hover {
    background: #fee2e2;
}

.empty-vocabulary {
    max-width: 620px;
    margin: 20px auto 50px;
    text-align: center;
}

.empty-icon {
    font-size: 3rem;
}

@media (max-width: 860px) {
    .vocabulary-card {
        grid-template-columns: 1fr;
    }

    .vocabulary-card-actions {
        flex-direction: row;
        border-top: 1px solid var(--border);
        border-left: 0;
    }

    .vocabulary-card-actions > * {
        flex: 1;
    }
}

@media (max-width: 680px) {
    .vocabulary-hero {
        align-items: flex-start;
        flex-direction: column;
    }

    .vocabulary-fields {
        grid-template-columns: 1fr;
    }

    .translation-arrow {
        display: none;
    }

    .vocabulary-footer {
        align-items: stretch;
        flex-direction: column;
    }

    .save-word-button {
        width: 100%;
    }

    .vocabulary-card-actions {
        flex-direction: column;
    }
}
