*,
*::before,
*::after {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: #0a0a0b;
    color: #f2f2f2;
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
    overflow: hidden; 
}

h1:focus {
    outline: none;
}

/* ——— Blazor UI Components ——— */

#blazor-error-ui {
    color-scheme: light only;
    background: #1a1a1c;
    color: #fff;
    bottom: 0;
    box-shadow: 0 -1px 0 rgba(255, 255, 255, 0.08);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.75rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

.blazor-error-boundary {
    background: #b32121;
    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
}

.blazor-error-boundary::after {
    content: "An error has occurred.";
}

.loading-progress {
    position: absolute;
    display: block;
    width: 8rem;
    height: 8rem;
    inset: 20vh 0 auto 0;
    margin: 0 auto 0 auto;
}

.loading-progress circle {
    fill: none;
    stroke: #333;
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: 600;
    color: #888;
    inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
}

/* ——— Main Layout (The Deck) ——— */

.deck {
    --deck-inline: clamp(0.5rem, 3vw, 2rem); 
    --deck-bottom: max(1.25rem, env(safe-area-inset-bottom, 0px));
    
    display: flex;
    flex-direction: column;
    height: 100dvh;
    width: 100%;
    max-width: 48rem; 
    margin: 0 auto;
    padding: 0 var(--deck-inline) var(--deck-bottom);
}

.deck-header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: max(0.75rem, env(safe-area-inset-top, 0px));
    padding-bottom: 0.5rem;
}

.deck-brand {
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #4a4a4e;
}

.deck-count {
    font-size: 0.8rem;
    color: #5c5c62;
    margin-left: auto;
    margin-right: 0.5rem;
}

.deck-import {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    color: #6b6b70;
    cursor: pointer;
    transition: all 0.2s;
}

.deck-import:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.05);
}

.deck-import-input {
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
}

.deck-main {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    justify-content: center; 
    min-height: 0;
}

/* ——— The Flashcard ——— */

.card-stage {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 0;
    perspective: 1200px;
}

.flashcard {
    height: 100%;
    max-height: min(75dvh, 42rem);
    width: 100%;
    max-width: clamp(280px, 85vh * 0.65, 400px); 
    aspect-ratio: 3 / 4.2; 
    position: relative;
    cursor: grab;
    touch-action: none;
}

.flashcard:active {
    cursor: grabbing;
}

.flashcard-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.6s cubic-bezier(0.23, 1, 0.32, 1);
    transform-style: preserve-3d;
}

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

.flashcard-front,
.flashcard-back {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    border-radius: 32px; 
    background: #161618;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 30px 60px -12px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 2rem 1.5rem;
}

.flashcard-back {
    transform: rotateY(180deg);
    background: #1c1c1e;
}

.word-text {
    font-size: clamp(1.5rem, 5vw, 2.5rem);
    font-weight: 800;
    text-align: center;
    line-height: 1.2;
    color: #fff;
    margin: 0;
}

.flashcard-scroll {
    width: 100%;
    max-height: 100%;
    overflow-y: auto;
    text-align: center;
}

.back-line {
    margin: 0 0 0.75rem;
    font-size: 1rem;
    line-height: 1.5;
    color: #a1a1a6;
}

.card-hint {
    position: absolute;
    bottom: 1.5rem;
    font-size: 0.6rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: #515154;
}

/* ——— Action Buttons ——— */

.deck-actions {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2.5rem; 
    padding: 1.5rem 0 0.5rem;
}

.action-btn {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.1s linear, background-color 0.2s ease;
    background: #1c1c1e;
}

.action-btn:active {
    transform: scale(0.96); 
}

.action-btn--pass {
    color: #ff453a;
    border: 1px solid rgba(255, 69, 58, 0.2);
}

.action-btn--pass:hover {
    background: rgba(255, 69, 58, 0.08);
}

.action-btn--ok {
    background: #30d158; 
    color: #000;
    box-shadow: 0 8px 20px rgba(48, 209, 88, 0.2);
}

.action-btn--ok:hover {
    background: #34e060;
    box-shadow: 0 10px 25px rgba(48, 209, 88, 0.3);
}

/* Empty State / Not Found */
.deck-muted { color: #5c5c62; font-size: 0.9rem; text-align: center; }
.deck-empty { font-size: 1.15rem; font-weight: 600; color: #c4c4c8; margin-bottom: 0.5rem; text-align: center; }

.not-found {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.not-found-link { color: #30d158; text-decoration: none; font-weight: 600; }

/* ——— Small Screen & Landscape Optimizations ——— */

@media (max-height: 700px) {
    .deck-actions { gap: 1.5rem; padding: 1rem 0 0; }
    .action-btn { width: 60px; height: 60px; }
}

@media (min-width: 1024px) {
    .flashcard {
        width: 380px; 
    }
}