:root {
    --background-color: #f5f5f7;
    --surface-color: #ffffff;
    --surface-muted: #f2f2f7;
    --text-color: #1d1d1f;
    --secondary-text: #6e6e73;
    --border-color: #d2d2d7;
    --accent-color: #0071e3;
    --accent-hover: #005bb5;
    --shadow-soft: 0 24px 60px -32px rgba(15, 23, 42, 0.25);
    --button-hover: #e6f2ff;
    --radius-lg: 26px;
    --radius-md: 20px;
    --radius-sm: 14px;
    --danger: #ff3b30;
    --danger-hover: #d70015;
    --success: #34c759;
    --success-hover: #248a3d;
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    margin: 0;
    min-height: 100vh;
    padding: clamp(2rem, 4vw, 4rem) clamp(1.25rem, 4vw, 3rem) 4rem;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background: radial-gradient(ellipse at top, rgba(0, 113, 227, 0.12), transparent 60%),
        radial-gradient(ellipse at bottom, rgba(120, 120, 128, 0.08), transparent 65%);
    z-index: -1;
}

mark {
    background: rgba(0, 113, 227, 0.25);
    color: inherit;
    padding: 0 0.2rem;
    border-radius: 6px;
}

.app-header {
    max-width: 1100px;
    margin: 0 auto 3rem auto;
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
    padding: clamp(1.75rem, 3vw, 2.5rem);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 2rem;
}

.app-status {
    max-width: 1100px;
    margin: 0 auto 2rem auto;
    display: none;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1.25rem;
    border-radius: var(--radius-md);
    border: 1px solid rgba(0, 113, 227, 0.18);
    background: rgba(0, 113, 227, 0.08);
    color: var(--text-color);
    box-shadow: var(--shadow-soft);
    font-size: 0.95rem;
}

.app-status.is-visible {
    display: flex;
}

.app-status[data-status-type='success'] {
    border-color: rgba(52, 199, 89, 0.3);
    background: rgba(52, 199, 89, 0.12);
}

.app-status[data-status-type='warning'] {
    border-color: rgba(255, 149, 0, 0.35);
    background: rgba(255, 149, 0, 0.12);
}

.app-status[data-status-type='error'] {
    border-color: rgba(255, 69, 58, 0.35);
    background: rgba(255, 69, 58, 0.12);
}

.brand {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.brand-symbol {
    width: 56px;
    height: 56px;
    border-radius: 20px;
    background: linear-gradient(135deg, rgba(0, 113, 227, 0.18), rgba(0, 113, 227, 0.05));
    display: grid;
    place-items: center;
    font-size: 1.6rem;
    color: var(--accent-color);
}

.brand-copy h1 {
    font-size: clamp(1.75rem, 3vw, 2.4rem);
    margin: 0 0 0.5rem 0;
    font-weight: 700;
}

.brand-copy p {
    margin: 0;
    color: var(--secondary-text);
    font-size: 1rem;
}

button {
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    padding: 0.75rem 1.6rem;
    border-radius: 999px;
    border: none;
    background: var(--accent-color);
    color: #ffffff;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    box-shadow: 0 18px 38px -24px rgba(0, 113, 227, 0.7);
}

button:hover {
    transform: translateY(-1px);
    background: var(--accent-hover);
    box-shadow: 0 22px 42px -22px rgba(0, 113, 227, 0.75);
}

button:focus-visible {
    outline: 3px solid rgba(0, 113, 227, 0.35);
    outline-offset: 3px;
}

button:disabled,
button:disabled:hover {
    cursor: not-allowed;
    opacity: 0.6;
    transform: none;
    box-shadow: none;
    background: var(--surface-muted);
    color: var(--secondary-text);
}

.button-ghost:disabled,
.button-ghost:disabled:hover {
    border: 1px solid var(--border-color);
}

.button-ghost {
    background: var(--surface-muted);
    color: var(--text-color);
    box-shadow: none;
    border: 1px solid var(--border-color);
}

.button-ghost:hover {
    background: var(--button-hover);
    color: var(--text-color);
    box-shadow: none;
}

.main-layout {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 2.5rem;
}

.panel {
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
    padding: clamp(1.75rem, 2.8vw, 2.5rem);
}

.is-hidden {
    display: none !important;
}

.panel-header h2 {
    margin: 0 0 0.75rem 0;
    font-size: 1.5rem;
}

.panel-header p {
    margin: 0 0 1.75rem 0;
    color: var(--secondary-text);
    font-size: 0.95rem;
    line-height: 1.5;
}

.quick-actions .panel-header p {
    margin-bottom: 1.5rem;
}

.action-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
}

.action-card {
    background: var(--surface-muted);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 1.5rem;
    border: 1px solid rgba(210, 210, 215, 0.6);
}

.action-card h3 {
    margin: 0 0 0.5rem 0;
    font-size: 1.1rem;
}

.action-card p {
    margin: 0;
    color: var(--secondary-text);
    line-height: 1.5;
}

.action-card button {
    width: 100%;
    justify-content: center;
}

.action-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.card-form {
    display: grid;
    gap: 1.5rem;
}

.form-field {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

label {
    font-weight: 600;
    font-size: 0.95rem;
}

textarea {
    width: 100%;
    border-radius: var(--radius-md);
    padding: 1rem 1.2rem;
    border: 1px solid var(--border-color);
    background: var(--surface-muted);
    font-family: inherit;
    font-size: 1rem;
    color: var(--text-color);
    resize: vertical;
    min-height: 120px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

textarea:focus {
    outline: none;
    border-color: var(--accent-color);
    background: #ffffff;
    box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.12);
}

input[type="text"],
input[type="search"],
select {
    width: 100%;
    border-radius: var(--radius-md);
    padding: 0.85rem 1.1rem;
    border: 1px solid var(--border-color);
    background: var(--surface-muted);
    font-family: inherit;
    font-size: 1rem;
    color: var(--text-color);
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

select {
    appearance: none;
    -webkit-appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, var(--secondary-text) 50%),
        linear-gradient(135deg, var(--secondary-text) 50%, transparent 50%);
    background-position: calc(100% - 18px) calc(1.1rem), calc(100% - 13px) calc(1.1rem);
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
}

input[type="text"]:focus,
input[type="search"]:focus,
select:focus {
    outline: none;
    border-color: var(--accent-color);
    background: #ffffff;
    box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.12);
}

.card-form button {
    justify-content: center;
    width: fit-content;
}

.card-panel {
    overflow: hidden;
}

.card-panel.is-learning-active {
    opacity: 0.25;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.card-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: stretch;
    margin-bottom: 1.25rem;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.toolbar-group--search {
    flex: 1 1 260px;
    min-width: 220px;
}

.toolbar-group--selection {
    gap: 0.85rem;
}

.toolbar-group--count {
    margin-left: auto;
    align-items: center;
}

.toolbar-label {
    font-size: 0.9rem;
    color: var(--secondary-text);
}

.toolbar-group select {
    min-width: 200px;
}

.selection-info {
    font-size: 0.9rem;
    color: var(--secondary-text);
}

.card-count {
    font-size: 0.9rem;
    color: var(--secondary-text);
    font-weight: 600;
}

.search-field {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    background: var(--surface-muted);
    padding: 0.35rem 0.75rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.search-field:focus-within {
    border-color: var(--accent-color);
    background: #ffffff;
    box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.12);
}

.search-field i {
    color: var(--secondary-text);
}

.search-field input[type="search"] {
    border: none;
    background: transparent;
    padding: 0.35rem 0.25rem;
    flex: 1;
    font-size: 0.95rem;
    color: var(--text-color);
}

.search-field input[type="search"]:focus {
    outline: none;
}

.search-field .search-clear {
    background: transparent;
    border: none;
    color: var(--secondary-text);
    box-shadow: none;
    padding: 0.25rem;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    cursor: pointer;
}

.search-field .search-clear:hover {
    background: rgba(0, 113, 227, 0.12);
    color: var(--accent-color);
}

.search-field .search-clear:focus-visible {
    outline: 2px solid rgba(0, 113, 227, 0.25);
    outline-offset: 2px;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.75rem;
}

.card-container {
    background: var(--surface-muted);
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(210, 210, 215, 0.6);
    position: relative;
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card-container:hover {
    transform: translateY(-4px);
    box-shadow: 0 20px 45px -28px rgba(28, 28, 30, 0.35);
}

.card-container.is-selected {
    border-color: rgba(0, 113, 227, 0.45);
    box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.18);
}

.card-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 1.25rem 1.25rem 0 1.25rem;
}

.level-badge {
    background: rgba(0, 113, 227, 0.12);
    color: var(--accent-color);
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.category-badge {
    background: var(--surface-color);
    color: var(--secondary-text);
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    border: 1px solid rgba(210, 210, 215, 0.6);
}

.flashcard {
    height: 240px;
    perspective: 1000px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem 1.75rem;
}

.flashcard[role="button"]:focus-visible {
    outline: 3px solid rgba(0, 113, 227, 0.35);
    outline-offset: 4px;
}

.flashcard-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.6s ease;
    transform-style: preserve-3d;
}

.flashcard.is-flipped .flashcard-inner,
#lern-karte.is-flipped .flashcard-inner {
    transform: rotateY(180deg);
}

.flashcard-front,
.flashcard-back {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 1.75rem;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    background: var(--surface-color);
    border: 1px solid rgba(210, 210, 215, 0.6);
    box-shadow: inset 0 -1px 0 rgba(210, 210, 215, 0.4);
    backface-visibility: hidden;
    font-size: 1.1rem;
    line-height: 1.6;
    color: var(--text-color);
}

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

.card-progress {
    padding: 0.75rem 1.25rem 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    color: var(--secondary-text);
}

.card-progress__track {
    width: 100%;
    height: 8px;
    border-radius: 999px;
    background: var(--surface-muted);
    border: 1px solid rgba(210, 210, 215, 0.6);
    overflow: hidden;
}

.card-progress__value {
    height: 100%;
    width: 0%;
    background: var(--accent-color);
    border-radius: inherit;
    transition: width 0.3s ease-in-out;
}

.card-progress__label {
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.card-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1rem 1.25rem 1.25rem 1.25rem;
    border-top: 1px solid rgba(210, 210, 215, 0.6);
}

.card-selection {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.95rem 1.25rem;
    border-top: 1px solid rgba(210, 210, 215, 0.6);
    color: var(--secondary-text);
    font-size: 0.92rem;
    background: var(--surface-color);
}

.card-selection label {
    cursor: pointer;
}

.card-selection input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent-color);
    cursor: pointer;
}

.card-container.is-selected .card-selection {
    background: rgba(0, 113, 227, 0.08);
    color: var(--accent-color);
    font-weight: 600;
}

.action-btn {
    background: transparent;
    border: none;
    color: var(--secondary-text);
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
    cursor: pointer;
}

.action-btn:hover {
    background: rgba(0, 113, 227, 0.1);
    color: var(--accent-color);
    transform: translateY(-1px);
}

.action-btn:focus-visible {
    outline: 2px solid rgba(0, 113, 227, 0.2);
    outline-offset: 3px;
}

.edit-form {
    display: none;
    flex-direction: column;
    gap: 1rem;
    padding: 1.25rem 1.25rem 1.5rem 1.25rem;
    background: var(--surface-color);
    border-top: 1px solid rgba(210, 210, 215, 0.6);
}

.card-container.is-editing .card-meta,
.card-container.is-editing .flashcard,
.card-container.is-editing .card-progress,
.card-container.is-editing .card-selection,
.card-container.is-editing .card-actions {
    display: none;
}

.card-container.is-editing .edit-form {
    display: flex;
}

.edit-form textarea {
    min-height: 100px;
}

.btn-save {
    width: 100%;
}

.empty-state {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 2.5rem 1.5rem;
    color: var(--secondary-text);
    text-align: center;
    border: 2px dashed rgba(210, 210, 215, 0.6);
    border-radius: var(--radius-md);
    background: var(--surface-color);
}

.empty-state i {
    font-size: 1.75rem;
    color: var(--accent-color);
}

.lern-modus-container {
    text-align: center;
}

.progress {
    margin: 0 auto 2rem auto;
    max-width: 520px;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    align-items: stretch;
}

.progress-label {
    font-size: 0.95rem;
    color: var(--secondary-text);
    letter-spacing: 0.02em;
}

.progress-track {
    width: 100%;
    height: 14px;
    background: var(--surface-muted);
    border-radius: 999px;
    border: 1px solid rgba(210, 210, 215, 0.7);
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: var(--accent-color);
    border-radius: inherit;
    transition: width 0.3s ease-in-out;
}

#lern-karte {
    margin: 2rem auto;
    max-width: 520px;
}

#lern-karte .flashcard-front,
#lern-karte .flashcard-back {
    border-radius: var(--radius-md);
}

.antwort-buttons {
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
    margin: 2rem 0;
}

.btn-rot {
    background: var(--danger);
    box-shadow: 0 18px 34px -24px rgba(255, 59, 48, 0.6);
}

.btn-rot:hover {
    background: var(--danger-hover);
    box-shadow: 0 20px 38px -22px rgba(215, 0, 21, 0.65);
}

.btn-gruen {
    background: var(--success);
    box-shadow: 0 18px 34px -24px rgba(52, 199, 89, 0.6);
}

.btn-gruen:hover {
    background: var(--success-hover);
    box-shadow: 0 20px 38px -22px rgba(36, 138, 61, 0.65);
}

#lernmodus-beenden-btn {
    margin: 0 auto;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@media (max-width: 900px) {
    .app-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .brand {
        align-items: flex-start;
    }

    .card-grid {
        grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    }
}

@media (max-width: 640px) {
    body {
        padding: 1.5rem 1.25rem 3rem;
    }

    .panel {
        padding: 1.5rem;
    }

    .card-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .toolbar-group,
    .toolbar-group--selection,
    .toolbar-group--search,
    .toolbar-group--count {
        width: 100%;
        justify-content: space-between;
    }

    .toolbar-group--count {
        margin-left: 0;
    }

    .toolbar-group select {
        flex: 1;
        min-width: 0;
    }

    .selection-info {
        flex: 1;
    }

    .search-field {
        width: 100%;
    }

    .flashcard {
        padding: 1.25rem 1.25rem;
    }

    .flashcard-front,
    .flashcard-back {
        padding: 1.5rem;
    }
}
