:root {
    --bg-color: #FBF7F0;
    --text-color: #374151;
    --card-bg: #FBF7F0;
    --primary-color: #1e3a8a;
    --primary-hover: #1e40af;
    --secondary-color: #e5e7eb;
    --rating-know: #10b981;
    --rating-soso: #f59e0b;
    --rating-unknown: #ef4444;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    height: 100dvh;
    overflow: hidden;
}

.top-bar {
    background: var(--card-bg);
    padding: 0.5rem 1rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

.top-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.logo {
    font-weight: 600;
    font-size: 1.5rem;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo-icon {
    stroke-width: 2.5;
}

/* Custom Topic Dropdown */
.topic-dropdown {
    position: relative;
    flex-shrink: 0;
}

.topic-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 10px;
    border-radius: 12px;
    border: 1px solid var(--secondary-color);
    background: var(--card-bg);
    color: var(--primary-color);
    cursor: pointer;
    transition: background 0.2s, box-shadow 0.2s, border-color 0.2s;
}

.topic-btn:hover {
    background: rgba(30, 58, 138, 0.06);
    border-color: rgba(30, 58, 138, 0.25);
    box-shadow: 0 2px 8px rgba(30, 58, 138, 0.1);
}

.topic-btn.open {
    background: rgba(30, 58, 138, 0.08);
    border-color: var(--primary-color);
}

.topic-btn-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.topic-btn-chevron {
    width: 14px;
    height: 14px;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0.5;
}

.topic-btn.open .topic-btn-chevron {
    transform: rotate(180deg);
    opacity: 1;
}

.topic-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 240px;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 16px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12), 0 0 0 1px rgba(255, 255, 255, 0.5) inset;
    padding: 6px;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px) scale(0.97);
    transform-origin: top right;
    transition: opacity 0.2s ease, transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.2s;
}

.topic-menu.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.topic-option {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 14px;
    border: none;
    background: none;
    border-radius: 10px;
    color: var(--text-color);
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    text-align: left;
}

.topic-option:hover {
    background: rgba(30, 58, 138, 0.07);
    color: var(--primary-color);
}

.topic-option.active {
    background: rgba(30, 58, 138, 0.1);
    color: var(--primary-color);
    font-weight: 600;
}

.topic-option.active::after {
    content: '✓';
    margin-left: auto;
    font-size: 0.85rem;
    font-weight: 700;
}

.topic-option svg {
    flex-shrink: 0;
    opacity: 0.7;
}

.topic-option.active svg,
.topic-option:hover svg {
    opacity: 1;
}

.top-progress-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
    color: #4b5563;
    width: 100%;
}

.progress-bar {
    width: 150px;
    height: 4px;
    background: var(--secondary-color);
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--rating-know);
    transition: width 0.3s ease-out;
}

select,
button {
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--secondary-color);
    background: var(--card-bg);
    font-size: 0.9rem;
    outline: none;
    cursor: pointer;
}

button.btn-primary {
    background: var(--primary-color);
    color: white;
    border: none;
    font-weight: 600;
    padding: 12px 24px;
    border-radius: 20px;
    transition: background 0.2s;
}

button.btn-primary:hover {
    background: var(--primary-hover);
}

.main-container {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.tab-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.flashcard-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    perspective: 1000px;
    min-height: 0;
    position: relative;
}

/* Efekt stosu kart pod spodem z teksturą */
.flashcard-container::before,
.flashcard-container::after {
    content: '';
    position: absolute;
    width: 100%;
    max-width: 330px;
    height: 100%;
    max-height: 380px;
    background-color: #ffffff;
    background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyBAMAAAD99n0UAAAAElBMVEUAAAD8/Pz09PT4+Pj29vb////9F9daAAAABXRSTlMABAnz9Xp4I18AAAAJcEhZcwAADsMAAA7DAcdvqGQAAAA9SURBVDjLY2AYBaNgFIyCUUAGA6OhowADAwMhowIDAyGjIgMDISNFApCRIglARookABkpkgBkpEgCkJECKgAArpQC65D8xGkAAAAASUVORK5CYII=");
    opacity: 0.15;
    border-radius: 24px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.03);
    z-index: -1;
    border: 1px solid rgba(0, 0, 0, 0.02);
}

.flashcard-container::before {
    transform: rotate(-2deg) translateY(5px);
    opacity: 0.7;
}

.flashcard-container::after {
    transform: rotate(1deg) translateY(2px);
    opacity: 0.5;
}

.flashcard {
    width: 100%;
    max-width: 350px;
    flex: 1;
    max-height: 400px;
    min-height: 150px;
    position: relative;
    cursor: pointer;
    z-index: 1;
}

/* Wskaźnik odwrócenia (ikona w rogu) */
.flashcard-front::after {
    content: '↺';
    position: absolute;
    top: 22px;
    /* Po przeciwnej stronie badge'a kategorii */
    right: 24px;
    font-size: 1.2rem;
    color: #d1d5db;
    opacity: 0.6;
    transition: transform 0.3s ease;
}

.flashcard:hover .flashcard-front::after {
    transform: rotate(90deg);
    color: var(--primary-color);
}

.flashcard-inner {
    width: 100%;
    height: 100%;
    position: relative;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    transform-style: preserve-3d;
    -webkit-transform-style: preserve-3d;
    will-change: transform;
}

.flashcard.flipped .flashcard-inner {
    transform: rotateY(180deg);
}

.flashcard-front,
.flashcard-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    transform: translateZ(1px); /* Physical separation for Safari */
    -webkit-transform: translateZ(1px);
    transform-style: flat; /* Flatten children for better mix-blend-mode support on WebKit */
    -webkit-transform-style: flat;
    background-color: #ffffff;
    /* Tekstura papieru bezpośrednio w tle dla maksymalnej kompatybilności */
    background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyBAMAAAD99n0UAAAAElBMVEUAAAD8/Pz09PT4+Pj29vb////9F9daAAAABXRSTlMABAnz9Xp4I18AAAAJcEhZcwAADsMAAA7DAcdvqGQAAAA9SURBVDjLY2AYBaNgFIyCUUAGA6OhowADAwMhowIDAyGjIgMDISNFApCRIglARookABkpkgBkpEgCkJECKgAArpQC65D8xGkAAAAASUVORK5CYII=");
    background-repeat: repeat;
    opacity: 1;
    border-radius: 24px;
    border: 1px solid #e5e7eb;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.06);
    isolation: isolate; /* Create new stacking context for mix-blend-mode */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 24px;
    padding-top: 55px;
    padding-bottom: 24px;
    text-align: center;
    overflow: hidden;
    transition: box-shadow 0.3s ease, transform 0.3s ease;
    will-change: transform;
}

/* Wyłączamy zbędne nakładki, które psuły widok na desktopie */
.flashcard-front::before,
.flashcard-back::before {
    display: none !important;
}

.flashcard-front>*,
.flashcard-back>* {
    position: relative;
    z-index: 1;
}

.flashcard:hover .flashcard-front,
.flashcard:hover .flashcard-back {
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.1);
}

.card-content-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 100%;
    min-height: 0;
}

.sentence-wrapper {
    margin-top: auto;
    width: 100%;
}

.flashcard-back {
    transform: rotateY(180deg) translateZ(1px);
    -webkit-transform: rotateY(180deg) translateZ(1px);
}

.card-image {
    margin-bottom: 10px;
    max-height: 45%;
    flex: 1;
    min-height: 100px;
    width: 100%;
    /* Maximal Compatibility: background-blend-mode has the best support for blending on Safari */
    background-image: 
        linear-gradient(rgba(255, 255, 255, 0.4), rgba(255, 255, 255, 0.4)), /* Graphite overlay */
        var(--card-image), 
        url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyBAMAAAD99n0UAAAAElBMVEUAAAD8/Pz09PT4+Pj29vb////9F9daAAAABXRSTlMABAnz9Xp4I18AAAAJcEhZcwAADsMAAA7DAcdvqGQAAAA9SURBVDjLY2AYBaNgFIyCUUAGA6OhowADAwMhowIDAyGjIgMDISNFApCRIglARookABkpkgBkpEgCkJECKgAArpQC65D8xGkAAAAASUVORK5CYII=");
    background-size: cover, contain, auto;
    background-repeat: no-repeat, no-repeat, repeat;
    background-position: center, center, center;
    background-blend-mode: normal, multiply, normal;
    border-radius: 12px;
}

.card-image svg,
.card-image img {
    display: none !important; /* Managed via background-image for compatibility */
}

.card-text {
    font-family: 'Playfair Display', serif;
    font-size: min(2rem, 6vh);
    font-weight: 500;
    color: var(--primary-color);
    margin-bottom: 0;
    overflow-wrap: break-word;
    word-wrap: break-word;
    word-break: break-word;
    /* Wymuszenie łamania długich słów jeśli to konieczne */
    max-width: 100%;
}

.card-sentence {
    font-family: 'Inter', sans-serif;
    font-size: min(1rem, 3.5vh);
    font-weight: 400;
    color: #4b5563;
    font-style: normal;
    overflow-y: auto;
    overflow-wrap: break-word;
    max-width: 100%;
}

.card-category {
    position: absolute;
    top: 20px;
    left: 24px;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--primary-color);
    background: rgba(30, 58, 138, 0.08);
    /* Lekkie tło w kolorze primary */
    padding: 4px 12px;
    border-radius: 100px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    z-index: 2;
}

.hidden {
    display: none !important;
}

.mute-toggle-btn {
    background: none;
    border: none;
    color: #6b7280;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 5px;
    border-radius: 50%;
    transition: background 0.2s, color 0.2s;
}

.mute-toggle-btn:hover {
    background: var(--secondary-color);
    color: var(--primary-color);
}

.text-with-sound {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    /* Symmetrical layout: empty, text, icon */
    align-items: center;
    justify-items: center;
    width: 100%;
    margin-bottom: 5px;
}

.card-text,
.card-sentence {
    grid-column: 2;
    /* Main text is always in the center column */
}

.sound-icon {
    grid-column: 3;
    justify-self: start;
    /* Icon is in the right column, aligned to its start */
    color: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    padding: 5px;
    border-radius: 50%;
    transition: background 0.2s;
}

.sound-icon:hover {
    background: var(--secondary-color);
}

.is-muted .sound-icon {
    display: none !important;
}

.actions {
    margin-top: 15px;
    text-align: center;
    min-height: 50px;
    flex-shrink: 0;
}

.rating-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.btn-rate {
    border: none;
    padding: 12px 20px;
    font-weight: 600;
    color: white;
    border-radius: 14px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    transition: transform 0.2s, box-shadow 0.2s, filter 0.2s;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.btn-rate:active {
    transform: scale(0.95);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.btn-rate:hover {
    filter: brightness(1.1);
}

.btn-unknown {
    background-color: var(--rating-unknown);
}

.btn-soso {
    background-color: var(--rating-soso);
}

.btn-know {
    background-color: var(--rating-know);
}

.bottom-bar {
    background: var(--card-bg);
    display: flex;
    flex-direction: column;
    box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.bottom-nav {
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--secondary-color);
}

.nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: none;
    border: none;
    color: #9ca3af;
    gap: 3px;
    cursor: pointer;
    transition: color 0.2s;
    font-family: inherit;
    padding: 5px 15px;
}

.nav-btn.active {
    color: var(--primary-color);
}

.nav-btn.active .nav-icon {
    transform: scale(1.1);
}

.nav-icon {
    font-size: 1.4rem;
    transition: transform 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-icon svg {
    width: 20px;
    height: 20px;
}

.nav-text {
    display: none;
    /* Ukryte etykiety nawigacji */
}

.sound-icon svg,
.nav-icon svg,
.mute-toggle-btn svg {
    stroke-width: 1.5 !important;
}

.stats-page,
.settings-page {
    padding: 15px;
    max-width: 600px;
    width: 100%;
    margin: 0 auto;
}

.stats-page h2,
.settings-page h2 {
    margin-bottom: 15px;
    color: var(--primary-color);
    text-align: center;
}

.box-style {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 15px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.no-padding-bottom {
    padding-bottom: 0;
}

.stat-block h3 {
    font-size: 1.1rem;
    margin-bottom: 10px;
    color: #374151;
}

.stat-block .progress-bar {
    width: 90%;
    margin: 10px auto;
}

.streak-circle {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.8rem;
    font-weight: 600;
    margin: 10px auto;
    box-shadow: 0 4px 6px rgba(99, 102, 241, 0.4);
}

.category-stats-list {
    list-style: none;
    padding: 0;
    margin: 0 -15px;
}

.category-stats-list li {
    padding: 12px 15px;
    border-bottom: 1px solid var(--secondary-color);
    display: flex;
    justify-content: space-between;
    font-size: 0.95rem;
}

.category-stats-list li:last-child {
    border-bottom: none;
}

.mb-10 {
    margin-bottom: 10px;
}

.small-text {
    font-size: 0.8rem;
    color: #6b7280;
}

.setting-group {
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.setting-group label {
    font-weight: 600;
    font-size: 0.9rem;
    color: #4b5563;
}

.setting-group select {
    width: 100%;
}

.ad-placeholder {
    padding: 10px;
    font-size: 0.8rem;
    color: #9ca3af;
    background: #e5e7eb;
    margin: 10px;
    border-radius: 8px;
    text-align: center;
}

/* Desktop adaptations */
@media(min-width: 768px) {
    .flashcard {
        height: 450px;
        flex: none;
        max-height: none;
        max-width: 400px;
    }

    .bottom-nav {
        justify-content: center;
        gap: 30px;
    }
}

/* Onboarding Tooltips */
.onboarding-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.5); /* Lighter overlay */
    backdrop-filter: blur(1.5px); /* Minimal blur to keep highlights readable */
    z-index: 2000;
    display: flex;
    pointer-events: auto;
    cursor: pointer;
    transition: opacity 0.3s ease;
}

.onboarding-tooltip {
    position: absolute;
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--text-color);
    padding: 24px;
    border-radius: 24px;
    max-width: 340px;
    width: 90vw;
    box-shadow: 
        0 20px 50px rgba(0, 0, 0, 0.3),
        0 0 0 1px rgba(255, 255, 255, 0.5) inset;
    z-index: 2005;
    font-size: 1rem;
    line-height: 1.6;
    font-weight: 500;
    text-align: center;
    transition: top 0.4s cubic-bezier(0.18, 0.89, 0.32, 1.28), left 0.4s cubic-bezier(0.18, 0.89, 0.32, 1.28), opacity 0.3s ease, transform 0.4s cubic-bezier(0.18, 0.89, 0.32, 1.28);
    pointer-events: none;
    animation: tooltipFloat 3s ease-in-out infinite;
}

@keyframes tooltipFloat {
    0%, 100% { transform: translate(var(--tw-translateX, 0), var(--tw-translateY, 0)) translateY(0) scale(1); }
    50% { transform: translate(var(--tw-translateX, 0), var(--tw-translateY, 0)) translateY(-4px) scale(1.01); }
}

.onboarding-tooltip-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.onboarding-step-indicator {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--primary-color);
    font-weight: 800;
    margin-bottom: 4px;
    opacity: 0.8;
}

.onboarding-next-hint {
    font-size: 0.75rem;
    color: #94a3b8;
    margin-top: 8px;
    font-weight: 400;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
}

.onboarding-next-hint::after {
    content: '→';
    font-size: 1rem;
}

.onboarding-tooltip::after {
    content: '';
    position: absolute;
    border: 12px solid transparent;
    left: var(--arrow-left, 50%);
    transition: all 0.3s ease;
}

.tooltip-arrow-top { --tw-translateY: 0px; }
.tooltip-arrow-top::after {
    top: -24px;
    transform: translateX(-50%);
    border-bottom-color: rgba(255, 255, 255, 0.94);
}

.tooltip-arrow-bottom { --tw-translateY: 0px; }
.tooltip-arrow-bottom::after {
    bottom: -24px;
    transform: translateX(-50%);
    border-top-color: rgba(255, 255, 255, 0.94);
}

.tooltip-arrow-left { --tw-translateY: 0px; }
.tooltip-arrow-left::after {
    left: -24px;
    top: 50%;
    transform: translateY(-50%);
    border-right-color: rgba(255, 255, 255, 0.94);
}

.tooltip-arrow-right { --tw-translateY: 0px; }
.tooltip-arrow-right::after {
    right: -24px;
    top: 50%;
    transform: translateY(-50%);
    border-left-color: rgba(255, 255, 255, 0.94);
}

.tooltip-center {
    top: 50% !important;
    left: 50% !important;
    --tw-translateX: -50%;
    --tw-translateY: -50%;
    transform: translate(-50%, -50%) !important;
}

.tooltip-center::after {
    display: none;
}

.onboarding-highlight {
    position: relative !important;
    z-index: 2002 !important;
    background-color: white !important;
    box-shadow: 0 0 0 4px white, 0 0 20px 10px rgba(255, 255, 255, 0.4);
    border-radius: 12px;
    pointer-events: none !important;
}

.onboarding-highlight-nobg {
    position: relative !important;
    z-index: 2002 !important;
    box-shadow: 0 0 0 4px var(--card-bg), 0 0 30px 15px rgba(255, 255, 255, 0.5);
    border-radius: 12px;
    pointer-events: none !important;
}