:root {
    --bg: #111318;
    --bg-2: #181a24;
    --surface: rgba(255, 255, 255, 0.055);
    --surface-2: rgba(255, 255, 255, 0.09);
    --border: rgba(255, 255, 255, 0.09);
    --border-hover: rgba(255, 255, 255, 0.18);
    --accent: #4a5cb8;
    --accent-2: #6e84d8;
    --accent-dim: #3a4a9a;
    --accent-glow: rgba(74, 92, 184, 0.38);
    --gradient: linear-gradient(135deg, #4a5cb8 0%, #6e84d8 100%);
    --text: #f2eef0;
    --text-muted: #5e6278;
    --text-dim: #3e4058;
    --danger: #f87171;
    --radius: 14px;
    --radius-sm: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    background-color: var(--bg);
    background-image:
        radial-gradient(ellipse 80% 55% at 15% 8%, rgba(74, 92, 184, 0.15) 0%, transparent 70%),
        radial-gradient(ellipse 60% 45% at 88% 90%, rgba(110, 132, 216, 0.1) 0%, transparent 70%);
    background-attachment: fixed;
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 16px;
    min-height: 100vh;
    touch-action: manipulation;
}

body::after {
    content: '';
    position: fixed;
    inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)'/%3E%3C/svg%3E");
    background-size: 300px 300px;
    opacity: 0.035;
    pointer-events: none;
    z-index: 9999;
    mix-blend-mode: screen;
}

nav {
    display: flex;
    align-items: center;
    padding: 10px 24px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: rgba(17, 19, 24, 0.88);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 10;
}

.nav-brand {
    font-size: 1.25rem;
    font-weight: 800;
    text-decoration: none;
    letter-spacing: -0.5px;
    background: var(--gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.nav-logout {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.9rem;
    padding: 6px 10px;
}
.nav-logout:hover { color: var(--text); }

main {
    max-width: 640px;
    margin: 0 auto;
    padding: 24px 16px 80px;
}

@media (min-width: 900px) {
    main { max-width: 960px; }
}

/* Page header */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 12px;
    flex-wrap: wrap;
}
.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}
.page-header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
}

/* Buttons */
.btn-primary {
    display: inline-block;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    background: var(--gradient);
    color: #fff;
    font-size: 0.9rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
}
.btn-primary:hover { opacity: 0.9; }

.btn-outline {
    display: inline-block;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.9rem;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
}
.btn-outline:hover { border-color: var(--border-hover); color: var(--text); }

.btn-back {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
}
.btn-back:hover { color: var(--text); }

.btn-danger {
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    background: rgba(248, 113, 113, 0.15);
    border: 1px solid rgba(248, 113, 113, 0.3);
    color: var(--danger);
    font-size: 0.85rem;
    cursor: pointer;
}
.btn-danger:hover { background: rgba(248, 113, 113, 0.25); }

.btn-danger-sm {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: var(--radius-sm);
    background: none;
    border: 1px solid rgba(248, 113, 113, 0.25);
    color: var(--danger);
    font-size: 1rem;
    cursor: pointer;
    flex-shrink: 0;
}
.btn-danger-sm:hover { background: rgba(248, 113, 113, 0.1); }

/* Deck list */
.deck-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.deck-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    gap: 12px;
    overflow: hidden;
    transition: border-color 0.15s;
}
.deck-card:hover { border-color: var(--border-hover); }

.deck-card-link {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 16px 20px;
    text-decoration: none;
    color: inherit;
}

.deck-name {
    font-weight: 600;
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.deck-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.deck-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    padding-right: 16px;
}

.due-badge {
    background: rgba(74, 92, 184, 0.2);
    color: var(--accent-2);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 20px;
}

/* Forms */
.form-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.form-card label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.form-card input[type="text"],
.form-card input[type="password"] {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 1rem;
    padding: 10px 14px;
    outline: none;
}
.form-card input:focus {
    border-color: var(--accent);
}

.form-error {
    color: var(--danger);
    font-size: 0.9rem;
}

/* Login */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.login-wrap {
    width: 100%;
    max-width: 360px;
    padding: 0 16px;
}

.login-title {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -1px;
    background: var(--gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 32px;
    text-align: center;
}

.login-form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.login-form input {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 1rem;
    padding: 10px 14px;
    outline: none;
}
.login-form input:focus { border-color: var(--accent); }

/* Empty state */
.empty-state {
    color: var(--text-muted);
    text-align: center;
    padding: 48px 0;
    font-size: 0.95rem;
}

/* Animations */
@keyframes fadeSlideUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}
main { animation: fadeSlideUp 0.3s ease; }

/* Form extras */
.form-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}

.form-textarea {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 1rem;
    font-family: inherit;
    padding: 10px 14px;
    outline: none;
    resize: vertical;
    min-height: 60px;
}
.form-textarea:focus { border-color: var(--accent); }

.form-row-end {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 4px;
}

.csv-label {
    font-size: 0.9rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    transition: border-color 0.15s, color 0.15s;
    white-space: nowrap;
}
.csv-label:hover { border-color: var(--border-hover); color: var(--text); }

/* Card list */
.card-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.card-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.card-due-in {
    font-size: 0.72rem;
    color: var(--text-dim);
    white-space: nowrap;
}

.card-item-due {
    border-color: rgba(74, 92, 184, 0.35);
    background: rgba(74, 92, 184, 0.07);
}

.card-faces {
    flex: 1;
    display: flex;
    align-items: baseline;
    gap: 8px;
    min-width: 0;
    font-size: 0.9rem;
    overflow: hidden;
}

.card-face-front {
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 40%;
    flex-shrink: 0;
}

.card-face-sep {
    color: var(--text-dim);
    flex-shrink: 0;
    font-size: 0.8rem;
}

.card-face-back {
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.card-item-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: var(--radius-sm);
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    text-decoration: none;
    font-size: 1rem;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}
.btn-icon:hover { border-color: var(--border-hover); color: var(--text); }

/* Review session */
.review-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.review-progress {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent-2);
    background: rgba(74, 92, 184, 0.15);
    padding: 4px 12px;
    border-radius: 20px;
}

.review-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px 24px;
    min-height: 200px;
}

.review-face-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-dim);
    margin-bottom: 12px;
}

.review-face-text {
    font-size: 1.25rem;
    line-height: 1.5;
    color: var(--text);
    white-space: pre-wrap;
}

.review-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 24px 0;
}

.review-show-btn {
    width: 100%;
    padding: 14px;
    font-size: 1rem;
}

.rating-buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.rating-btn {
    padding: 12px 6px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    -webkit-tap-highlight-color: transparent;
    outline: none;
    transition: filter 0.15s;
}
.rating-btn:hover { filter: brightness(1.25); }
.rating-btn:active { filter: brightness(0.9); }

.rating-again {
    background: rgba(248, 113, 113, 0.15);
    border-color: rgba(248, 113, 113, 0.3);
    color: #f87171;
}
.rating-hard {
    background: rgba(251, 146, 60, 0.15);
    border-color: rgba(251, 146, 60, 0.3);
    color: #fb923c;
}
.rating-good {
    background: rgba(74, 222, 128, 0.12);
    border-color: rgba(74, 222, 128, 0.3);
    color: #4ade80;
}
.rating-easy {
    background: rgba(74, 92, 184, 0.2);
    border-color: rgba(74, 92, 184, 0.4);
    color: var(--accent-2);
}

/* Review done screen */
.review-done {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 48px 0 32px;
}

.review-done-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: rgba(74, 92, 184, 0.2);
    border: 1px solid rgba(74, 92, 184, 0.4);
    color: var(--accent-2);
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
}

.review-done-title {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.3px;
    margin-bottom: 8px;
}

.review-done-sub {
    color: var(--text-muted);
    font-size: 0.95rem;
}

.btn-ghost {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 0.78rem;
    cursor: pointer;
    padding: 4px 2px;
}
.btn-ghost:hover { color: var(--text-muted); }

.practice-notice {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-dim);
    margin-top: 10px;
}

/* Rating guide */
.rating-guide {
    margin-top: 12px;
    text-align: center;
}

.rating-guide-toggle {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 4px 8px;
}
.rating-guide-toggle:hover { color: var(--text-muted); }

.rating-guide-body {
    margin-top: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    text-align: left;
}

.rating-guide-row {
    display: flex;
    align-items: baseline;
    gap: 12px;
    padding: 5px 0;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.rating-guide-row span:first-child {
    font-weight: 700;
    width: 44px;
    flex-shrink: 0;
}
.rg-again { color: #f87171; }
.rg-hard  { color: #fb923c; }
.rg-good  { color: #4ade80; }
.rg-easy  { color: var(--accent-2); }

/* Confirm modal */
.confirm-box {
    position: relative;
    background: #2a2840;
    border: 1px solid rgba(110, 132, 216, 0.2);
    border-radius: 16px;
    padding: 28px 24px 20px;
    max-width: 300px;
    width: 88%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
}
