:root {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --primary-light: #60a5fa;
    --primary-bg: #dbeafe;
    --primary-gradient: linear-gradient(135deg, #6366f1 0%, #3b82f6 55%, #06b6d4 100%);
    --primary-gradient-hover: linear-gradient(135deg, #4f46e5 0%, #2563eb 55%, #0891b2 100%);
    --success: #10b981;
    --success-bg: #d1fae5;
    --warning: #f59e0b;
    --warning-bg: #fef3c7;
    --danger: #ef4444;
    --danger-bg: #fee2e2;
    --danger-light: #fecaca;
    --purple: #8b5cf6;
    --pink: #ec4899;
    --bg: #f8fafc;
    --bg-elevated: #f1f5f9;
    --surface: #ffffff;
    --surface-hover: #f1f5f9;
    --surface-active: #e2e8f0;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --border-focus: #3b82f6;
    --text: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --shadow-sm: 0 1px 2px 0 rgba(15, 23, 42, 0.06);
    --shadow: 0 1px 3px 0 rgba(15, 23, 42, 0.1), 0 1px 2px -1px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 4px 10px -2px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.06);
    --shadow-lg: 0 12px 28px -6px rgba(15, 23, 42, 0.12), 0 6px 12px -6px rgba(15, 23, 42, 0.08);
    --shadow-xl: 0 20px 40px -10px rgba(59, 130, 246, 0.18), 0 10px 20px -10px rgba(15, 23, 42, 0.12);
    --shadow-focus: 0 0 0 3px rgba(59, 130, 246, 0.18);
    --shadow-focus-danger: 0 0 0 3px rgba(239, 68, 68, 0.22);
    --radius-xs: 4px;
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 18px;
    --radius-xl: 24px;
    --transition: 180ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-lg: 280ms cubic-bezier(0.4, 0, 0.2, 1);
    --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
}

[data-theme="dark"] {
    --primary: #60a5fa;
    --primary-dark: #3b82f6;
    --primary-light: #93c5fd;
    --primary-bg: #1e3a8a;
    --primary-gradient: linear-gradient(135deg, #7c3aed 0%, #3b82f6 55%, #06b6d4 100%);
    --primary-gradient-hover: linear-gradient(135deg, #6d28d9 0%, #2563eb 55%, #0891b2 100%);
    --success: #34d399;
    --success-bg: #064e3b;
    --warning: #fbbf24;
    --warning-bg: #713f12;
    --danger: #f87171;
    --danger-bg: #7f1d1d;
    --danger-light: #7f1d1d;
    --bg: #070d1a;
    --bg-elevated: #0b1220;
    --surface: #0f172a;
    --surface-hover: #1e293b;
    --surface-active: #334155;
    --border: #1f2937;
    --border-strong: #334155;
    --border-focus: #60a5fa;
    --text: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;
    --shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.3);
    --shadow: 0 1px 3px 0 rgba(0,0,0,0.45), 0 1px 2px -1px rgba(0,0,0,0.35);
    --shadow-md: 0 6px 14px -3px rgba(0,0,0,0.5), 0 3px 6px -3px rgba(0,0,0,0.4);
    --shadow-lg: 0 14px 32px -6px rgba(0,0,0,0.6), 0 8px 16px -8px rgba(0,0,0,0.5);
    --shadow-xl: 0 22px 44px -10px rgba(59, 130, 246, 0.35), 0 12px 22px -10px rgba(0,0,0,0.55);
    --shadow-focus: 0 0 0 3px rgba(96, 165, 250, 0.32);
    --shadow-focus-danger: 0 0 0 3px rgba(248, 113, 113, 0.32);
}

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

html, body {
    height: 100%;
    font-family: var(--font-sans);
    background:
      radial-gradient(1200px 600px at 120% -10%, rgba(99,102,241,0.12), transparent 60%),
      radial-gradient(900px 500px at -10% 10%, rgba(6,182,212,0.10), transparent 60%),
      var(--bg);
    background-attachment: fixed;
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    line-height: 1.5;
    overflow-x: hidden;
    text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

[data-theme="dark"] body, body.dark {
    background:
      radial-gradient(1200px 600px at 120% -10%, rgba(124,58,237,0.18), transparent 60%),
      radial-gradient(900px 500px at -10% 10%, rgba(6,182,212,0.14), transparent 60%),
      var(--bg);
}

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a { color: var(--primary); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--primary-dark); text-decoration: underline; }
a:focus-visible { outline: none; border-radius: 4px; box-shadow: var(--shadow-focus); }

::selection { background: var(--primary); color: white; }
[data-theme="dark"] ::selection { background: var(--primary-light); color: #0b1220; }

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
    touch-action: manipulation;
}

input, textarea, select {
    font-family: inherit;
    font-size: 16px;
}

::placeholder { color: var(--text-muted); }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

#app {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 16px;
}

@media (min-width: 768px) {
    .container { padding: 0 24px; }
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    transition: all 0.15s ease;
    text-align: center;
    white-space: nowrap;
    user-select: none;
    touch-action: manipulation;
    min-height: 42px;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:hover { background: var(--primary-dark); color: white; }

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--surface-hover); }

.btn-danger {
    background: var(--danger);
    color: white;
}
.btn-danger:hover { background: #dc2626; color: white; }

.btn-success {
    background: var(--success);
    color: white;
}

.btn-warning {
    background: var(--warning);
    color: white;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }

.btn-icon {
    padding: 8px;
    min-width: 40px;
    min-height: 40px;
    border-radius: var(--radius-sm);
}

.btn-block { width: 100%; }

.btn-sm { padding: 6px 12px; font-size: 13px; min-height: 34px; }
.btn-lg { padding: 14px 22px; font-size: 16px; }

.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: 9999px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.6;
}
.badge-primary { background: var(--primary-light); color: var(--primary-dark); }
[data-theme="dark"] .badge-primary { background: rgba(96,165,250,0.2); color: var(--primary); }
.badge-success { background: #d1fae5; color: #065f46; }
[data-theme="dark"] .badge-success { background: rgba(52,211,153,0.2); color: var(--success); }
.badge-warning { background: #fef3c7; color: #92400e; }
[data-theme="dark"] .badge-warning { background: rgba(251,191,36,0.2); color: var(--warning); }
.badge-danger { background: #fee2e2; color: #991b1b; }
[data-theme="dark"] .badge-danger { background: rgba(248,113,113,0.2); color: var(--danger); }
.badge-secondary { background: var(--surface-hover); color: var(--text-secondary); }

/* Auth */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    background: linear-gradient(135deg, var(--bg) 0%, var(--surface-hover) 100%);
}

.auth-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 32px 28px;
    width: 100%;
    max-width: 420px;
    border: 1px solid var(--border);
}

.auth-logo {
    text-align: center;
    margin-bottom: 24px;
}
.auth-logo .logo-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 12px;
    background: var(--primary);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 30px;
}
.auth-logo h1 {
    font-size: 22px;
    font-weight: 700;
}
.auth-logo p {
    color: var(--text-muted);
    font-size: 14px;
    margin-top: 4px;
}

.form-group {
    margin-bottom: 18px;
}
.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}
.form-control {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s;
    min-height: 44px;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}
textarea.form-control {
    resize: vertical;
    min-height: 100px;
    line-height: 1.6;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.form-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.auth-switch {
    text-align: center;
    margin-top: 20px;
    font-size: 14px;
    color: var(--text-secondary);
}
.auth-switch a { font-weight: 600; }

/* Navbar */
.navbar {
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(8px);
}
.navbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
    gap: 12px;
}
.navbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 17px;
    color: var(--text);
}
.brand-icon {
    width: 34px;
    height: 34px;
    background: var(--primary);
    color: white;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}
.nav-menu {
    display: flex;
    align-items: center;
    gap: 4px;
}
.nav-link {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.15s;
    cursor: pointer;
}
.nav-link:hover, .nav-link.active {
    background: var(--surface-hover);
    color: var(--text);
}
.nav-link.active { color: var(--primary); }
.nav-user {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: 8px;
    padding-left: 12px;
    border-left: 1px solid var(--border);
}
.user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
}
.user-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
}
@media (max-width: 640px) {
    .user-name { display: none; }
    .nav-link span { display: none; }
    .nav-link { padding: 8px 10px; }
}

/* Hamburger + Drawer - SOLO MOBILE (<= 640px), NON tablet */
.navbar .hamburger-btn,
.navbar-inner .hamburger-btn,
.hamburger-btn { display: none !important; }

@media (max-width: 640px) {
    .navbar .hamburger-btn,
    .navbar-inner .hamburger-btn,
    .hamburger-btn { display: inline-flex !important; }
    .navbar .nav-menu:not(.right) { display: none; }
    .navbar-inner {
        justify-content: flex-start;
        gap: 8px;
    }
    .navbar-brand { flex: 1 1 auto; min-width: 0; }
    .navbar .nav-menu.right { display: flex; }
    .navbar .nav-menu.right .nav-user { display: none; }
    .navbar .nav-menu.right .btn-subtle { display: none; }
    .navbar .nav-menu.right > .btn-ghost.btn-icon:not(.hamburger-btn) {
        width: 38px;
        height: 38px;
    }
    .navbar-inner {
        padding-left: 6px;
        padding-right: 6px;
    }
}

@media (max-width: 480px) {
    .navbar .nav-menu.right > .btn-ghost.btn-icon {
        width: 36px;
        height: 36px;
    }
}

body.no-scroll {
    overflow: hidden !important;
    touch-action: none;
}

.mobile-backdrop {
    position: fixed;
    inset: 0;
    z-index: 90;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    animation: backdropFade .22s ease-out both;
}

@keyframes backdropFade {
    from { opacity: 0; }
    to { opacity: 1; }
}

.mobile-drawer {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(86vw, 340px);
    max-width: 100%;
    z-index: 100;
    background: var(--surface);
    border-right: 1px solid var(--border);
    box-shadow: 18px 0 40px -20px rgba(0,0,0,0.35);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: drawerSlide .28s cubic-bezier(.2,.8,.2,1) both;
}
[data-theme="dark"] .mobile-drawer {
    box-shadow: 18px 0 50px -20px rgba(0,0,0,0.65);
}

@keyframes drawerSlide {
    from { transform: translateX(-100%); }
    to { transform: translateX(0); }
}

.drawer-scroll {
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 14px 6px 28px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px 14px;
    border-bottom: 1px solid var(--border);
    margin: 0 6px 6px;
}
.drawer-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 16px;
    color: var(--text);
    min-width: 0;
}
.drawer-brand-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.drawer-close {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
}

.drawer-user-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 14px;
    margin: 6px 10px 2px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--primary-alpha, rgba(99,102,241,0.12)) 0%, rgba(6,182,212,0.10) 100%);
    border: 1px solid var(--border);
}
.drawer-avatar {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 12px -6px var(--primary);
}
.drawer-user-info {
    min-width: 0;
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.drawer-user-name {
    font-weight: 700;
    font-size: 15px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.drawer-user-email {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.drawer-due-row {
    padding: 4px 12px 6px;
    margin: 2px 8px 4px;
}
.drawer-due-badge {
    width: 100%;
    justify-content: flex-start;
    gap: 6px;
    padding: 9px 12px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 10px;
}

.drawer-nav, .drawer-actions {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 4px 8px;
}
.drawer-nav-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 12px;
    background: transparent;
    border: 1px solid transparent;
    text-align: left;
    font-size: 14.5px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all .18s cubic-bezier(.2,.8,.2,1);
    line-height: 1.35;
}
.drawer-nav-item:hover {
    background: var(--surface-hover);
    color: var(--text);
}
.drawer-nav-item:active { transform: scale(.985); }
.drawer-nav-item.active {
    background: var(--primary-alpha, rgba(99,102,241,0.12));
    color: var(--primary);
    border-color: var(--primary-alpha, rgba(99,102,241,0.25));
    font-weight: 600;
}
.drawer-nav-item.danger {
    color: var(--danger);
}
.drawer-nav-item.danger:hover {
    background: rgba(239,68,68,0.10);
    color: var(--danger);
    border-color: rgba(239,68,68,0.18);
}
.drawer-nav-icon {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: currentColor;
}
.drawer-nav-icon svg { width: 20px; height: 20px; stroke-width: 2; }
.drawer-nav-label {
    flex: 1 1 auto;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
    min-width: 0;
    overflow-wrap: anywhere;
}
.drawer-nav-chevron {
    opacity: .7;
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
}
.drawer-nav-chevron svg { width: 18px; height: 18px; }

.drawer-divider {
    height: 1px;
    background: var(--border);
    margin: 10px 18px;
    opacity: .9;
}

.drawer-footer {
    margin-top: auto;
    padding: 18px 18px 6px;
}
.drawer-footer-copy {
    font-size: 11.5px;
    color: var(--text-muted);
    text-align: center;
    opacity: .85;
}

/* Fine hamburger CSS */

/* Main content */
.main {
    flex: 1;
    padding: 20px 0 80px;
}

.page-header {
    margin-bottom: 24px;
}
.page-title {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 4px;
}
.page-subtitle {
    color: var(--text-muted);
    font-size: 14px;
}
.page-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.page-header-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}

/* Search */
.search-box {
    position: relative;
    flex: 1;
    min-width: 200px;
    max-width: 400px;
}
.search-box input {
    width: 100%;
    padding: 10px 14px 10px 40px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    min-height: 42px;
}
.search-box input:focus {
    outline: none;
    border-color: var(--primary);
}
.search-box .search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

/* Stats cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow-sm);
}
.stat-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}
.stat-value {
    font-size: 26px;
    font-weight: 700;
    line-height: 1.2;
}
.stat-sub {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}
.stat-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 10px;
    font-size: 20px;
}
.stat-icon.blue { background: rgba(59,130,246,0.1); color: var(--primary); }
.stat-icon.green { background: rgba(16,185,129,0.1); color: var(--success); }
.stat-icon.orange { background: rgba(245,158,11,0.1); color: var(--warning); }
.stat-icon.red { background: rgba(239,68,68,0.1); color: var(--danger); }

/* Card grids */
.decks-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}
.deck-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    box-shadow: var(--shadow-sm);
}
.deck-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary);
}
.deck-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 10px;
}
.deck-name {
    font-size: 17px;
    font-weight: 600;
    line-height: 1.3;
    word-break: break-word;
}
.deck-desc {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 12px;
    line-height: 1.4;
}
.deck-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 14px;
}
.deck-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}
.deck-actions {
    display: flex;
    gap: 4px;
}
.deck-actions .btn { min-height: 32px; padding: 6px 10px; font-size: 12px; }
.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--surface-hover);
    border-radius: 999px;
    overflow: hidden;
    margin-top: 10px;
}
.progress-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 999px;
    transition: width 0.3s;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    animation: fadeIn 0.15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal {
    background: var(--surface);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    animation: slideUp 0.2s ease;
}
.modal-lg { max-width: 780px; }
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 22px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--surface);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    z-index: 1;
}
.modal-title {
    font-size: 18px;
    font-weight: 700;
}
.modal-body { padding: 22px; }
.modal-footer {
    padding: 16px 22px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
    position: sticky;
    bottom: 0;
    background: var(--surface);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.close-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}
.close-btn:hover { background: var(--surface-hover); color: var(--text); }

/* Cards list */
.cards-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.card-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    transition: all 0.15s;
}
.card-item:hover { background: var(--surface-hover); }
.card-item.difficult { border-left: 4px solid var(--danger); }
.card-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.card-content {
    flex: 1;
    min-width: 0;
}
.card-front {
    font-weight: 600;
    font-size: 15px;
    color: var(--text);
    word-break: break-word;
}
.card-back {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 2px;
    word-break: break-word;
}
.card-stats {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
}
.card-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}
.card-actions .btn { min-height: 32px; padding: 6px 10px; font-size: 12px; }
.card-thumb {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--surface-hover);
}

/* Study mode */
.study-container {
    max-width: 600px;
    margin: 0 auto;
    padding: 0 0 24px;
}
.study-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    gap: 12px;
}
.study-progress-info {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}
.study-timer {
    font-family: 'SF Mono', Menlo, Consolas, monospace;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--surface);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.study-controls-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
    padding: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.study-controls-bar label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}
.study-controls-bar input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

.flashcard-wrapper {
    perspective: 1400px;
    perspective-origin: 50% 50%;
    margin: 0 auto 28px;
    max-width: 600px;
    width: 100%;
    display: block;
}
.flashcard {
    position: relative;
    width: 100%;
    display: block;
    aspect-ratio: 5 / 4;
    max-height: 440px;
    margin: 0 auto;
    cursor: pointer;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(.2,.8,.2,1);
    user-select: none;
    touch-action: manipulation;
}
.flashcard.flipped { transform: rotateY(180deg); }
.flashcard-face {
    position: absolute !important;
    inset: 0;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: var(--radius-xl);
    background: linear-gradient(180deg, var(--surface) 0%, var(--surface-hover) 100%);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    padding: 22px 24px 54px;
    overflow: hidden;
    text-align: center;
}
.flashcard-back { transform: rotateY(180deg); }

.flashcard-lang {
    display: block;
    width: 100%;
    text-align: center;
    font-size: 11px;
    font-weight: 700;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 1.4px;
    margin: 2px 0 4px;
    padding: 0;
    flex: 0 0 auto;
}
.flashcard-main {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 8px 4px;
    gap: 16px;
    width: 100%;
    align-self: center;
    min-height: 0;
}
.flashcard-image {
    max-width: 58%;
    max-height: 170px;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: var(--radius);
    display: block;
    margin: 0 auto;
    align-self: center;
}
.flashcard-text {
    display: block;
    width: 100%;
    text-align: center;
    font-size: 30px;
    font-weight: 700;
    line-height: 1.35;
    word-break: break-word;
    overflow-wrap: anywhere;
    padding: 0 10px;
    margin: 0 auto;
    align-self: center;
    color: var(--text);
}
.flashcard-badges {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-top: 4px;
    flex-wrap: wrap;
}
@media (max-width: 520px) {
    .flashcard-text { font-size: 22px; }
    .flashcard-face { padding: 18px 18px 52px; }
}
@media (max-width: 380px) {
    .flashcard-text { font-size: 19px; }
}
.flashcard-subtext {
    font-size: 16px;
    color: var(--text-secondary);
    font-weight: 500;
    margin-top: 8px;
    text-align: center;
    width: 100%;
}
.flashcard-hint {
    position: absolute;
    bottom: 16px;
    left: 0;
    right: 0;
    width: 100%;
    display: block;
    text-align: center;
    font-size: 12px;
    line-height: 1.4;
    color: var(--text-muted);
    opacity: 0.85;
    padding: 0 16px;
    pointer-events: none;
}

/* Secondary controls (Previous / Flip / Skip) */
.study-secondary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.study-actions {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 12px;
    width: 100%;
    box-sizing: border-box;
}
.study-actions .btn {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    white-space: normal;
    overflow: hidden;
    justify-content: center;
    align-items: center;
    padding: 10px 6px;
    min-height: 44px;
    font-size: 13.5px;
    font-weight: 600;
    line-height: 1.15;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px;
    border-radius: 14px;
    text-overflow: ellipsis;
}
.study-actions .btn .icon,
.study-actions .btn svg {
    width: 18px;
    height: 18px;
    stroke-width: 2.25;
    flex-shrink: 0;
}
@media (max-width: 680px) {
    .study-actions { gap: 6px; }
    .study-actions .btn {
        font-size: 13px;
        padding: 10px 4px;
        min-height: 46px;
    }
    .study-actions .btn .icon,
    .study-actions .btn svg { width: 17px; height: 17px; }
}
@media (max-width: 520px) {
    .study-actions { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
    .study-actions .btn {
        font-size: 12px;
        padding: 9px 3px;
        min-height: 54px;
        flex-direction: column;
        gap: 3px;
    }
    .study-actions .btn .icon,
    .study-actions .btn svg { width: 18px; height: 18px; }
}
@media (max-width: 420px) {
    .study-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
    .study-actions .btn-difficult { grid-column: auto; }
    .study-actions .btn {
        font-size: 13.5px;
        padding: 10px 8px;
        min-height: 48px;
        flex-direction: row;
        gap: 5px;
    }
    .study-actions .btn .icon,
    .study-actions .btn svg { width: 18px; height: 18px; }
}
.btn-know {
    background: var(--success);
    color: white;
}
.btn-know:hover { background: #059669; color: white; }
.btn-easy {
    background: var(--primary);
    color: white;
}
.btn-easy:hover { background: #2563eb; color: white; }
.btn-dont-know {
    background: var(--danger);
    color: white;
}
.btn-dont-know:hover { background: #dc2626; color: white; }
.btn-difficult {
    background: var(--warning);
    color: white;
}
.btn-difficult:hover { background: #d97706; color: white; }

.study-foot {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    padding: 10px 0;
}

/* Study complete */
.study-complete {
    text-align: center;
    padding: 40px 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}
.study-complete h2 { font-size: 24px; margin-bottom: 12px; }
.complete-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 14px;
    margin: 24px 0;
}

/* Charts */
.chart-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
}
.chart-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text);
}
.chart-wrapper {
    position: relative;
    height: 280px;
}
.chart-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 16px;
}

/* Multiline cards (main line + sub lines smaller) */
.multiline-text {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: inherit;
    text-align: inherit;
}
.multiline-text .ml-main {
    font-weight: 600;
    line-height: 1.45;
    font-size: 1em;
    color: var(--text);
    word-break: break-word;
    overflow-wrap: anywhere;
}
.multiline-text .ml-sub {
    margin-top: 6px;
    font-size: 0.78em;
    color: var(--text-muted);
    line-height: 1.55;
    word-break: break-word;
    overflow-wrap: anywhere;
    white-space: normal;
}
.card-front .multiline-text,
.card-back .multiline-text   { align-items: flex-start; text-align: left; }
.flashcard-text .multiline-text {
    align-items: center;
    text-align: center;
    justify-content: center;
}
.flashcard-text .ml-main {
    font-weight: 700;
    font-size: clamp(18px, 3.8vw, 30px);
}
.flashcard-text .ml-sub {
    margin-top: 10px;
    font-size: clamp(12px, 2vw, 17px);
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}
.empty-state .empty-icon {
    font-size: 50px;
    margin-bottom: 14px;
    opacity: 0.6;
}
.empty-state h3 {
    font-size: 18px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}
.empty-state p {
    font-size: 14px;
    margin-bottom: 18px;
}

/* Toast */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 90vw;
}
@media (max-width: 480px) {
    .toast-container { left: 10px; right: 10px; top: 10px; }
}
.toast {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 14px;
    animation: toastIn 0.25s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    word-break: break-word;
}
@keyframes toastIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}
.toast.toast-success { border-left: 4px solid var(--success); }
.toast.toast-error { border-left: 4px solid var(--danger); }
.toast.toast-warning { border-left: 4px solid var(--warning); }
.toast.toast-info { border-left: 4px solid var(--primary); }

/* Loading */
.spinner {
    width: 20px;
    height: 20px;
    border: 2.5px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}
.loading-overlay .loader {
    background: var(--surface);
    padding: 22px 32px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 500;
    color: var(--text-secondary);
}

/* Upload image preview */
.image-uploader {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.15s;
    background: var(--bg);
    margin-bottom: 12px;
}
.image-uploader:hover { border-color: var(--primary); background: var(--surface-hover); }
.image-uploader.has-image { padding: 10px; border-style: solid; }
.image-preview {
    max-width: 100%;
    max-height: 200px;
    border-radius: var(--radius-sm);
    object-fit: contain;
    display: block;
    margin: 0 auto;
}
.image-upload-txt {
    color: var(--text-muted);
    font-size: 14px;
}
.image-upload-txt strong { color: var(--primary); }

/* Dropdown */
.dropdown {
    position: relative;
    display: inline-block;
}
.dropdown-menu {
    position: absolute;
    right: 0;
    top: 100%;
    margin-top: 4px;
    min-width: 180px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    padding: 4px;
    z-index: 120;
    animation: fadeIn 0.12s ease;
    display: none;
}
.deck-menu-wrap.open .dropdown-menu {
    display: block;
}
.deck-menu-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 9px 12px;
    font-size: 14px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text);
    text-align: left;
}
.dropdown-item:hover { background: var(--surface-hover); }
.dropdown-item.danger { color: var(--danger); }
.dropdown-item:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: -1px;
}
.dropdown-item-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: currentColor;
    opacity: .9;
}
.dropdown-item-icon svg { width: 18px; height: 18px; stroke-width: 2.1; }
.dropdown-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

/* Footer */
.footer {
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 20px 0;
    color: var(--text-muted);
    font-size: 13px;
}
.footer-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 18px;
    align-items: center;
    justify-content: space-between;
    text-align: left;
}
.footer-copy { color: var(--text-muted); }
.footer-links {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    align-items: center;
}
.footer-link {
    color: var(--text-secondary);
    font-weight: 500;
    text-decoration: none;
    font-size: 13px;
}
.footer-link:hover {
    color: var(--primary);
    text-decoration: underline;
}
@media (max-width: 520px) {
    .footer-row { justify-content: center; text-align: center; flex-direction: column; }
}

/* Cookie banner */
.cookie-banner {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: 10px;
    z-index: 80;
    animation: cookieUp .24s ease both;
    pointer-events: auto;
}
@keyframes cookieUp { from { opacity:0; transform: translateY(10px);} to { opacity:1; transform: none;} }
.cookie-banner-inner {
    max-width: 680px;
    margin: 0 auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, .16), 0 2px 6px rgba(15,23,42,.06);
    padding: 10px 12px;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    align-items: center;
}
.cookie-banner-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 2px;
    line-height: 1.25;
}
.cookie-banner-p {
    font-size: 12.5px;
    line-height: 1.4;
    color: var(--text-secondary);
    margin: 0;
}
.cookie-banner-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    justify-content: flex-end;
}
.cookie-banner-actions .btn {
    padding: 8px 14px;
    min-height: 34px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 10px;
}
@media (max-width: 640px) {
    .cookie-banner-inner { grid-template-columns: 1fr; padding: 10px 10px; }
    .cookie-banner-actions { justify-content: stretch; }
    .cookie-banner-actions .btn { flex: 1 1 0; min-width: 0; }
}

/* Checkbox row (terms in registration) */
.checkbox-row {
    display: inline-flex;
    align-items: flex-start;
    gap: 10px;
    cursor: pointer;
    padding: 4px 2px;
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.55;
}
.checkbox-row .form-checkbox {
    margin-top: 3px;
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
    cursor: pointer;
    flex-shrink: 0;
}
.checkbox-text { color: var(--text-secondary); }
.checkbox-text .terms-link,
.checkbox-text a {
    color: var(--primary);
    font-weight: 600;
    text-decoration: none;
}
.checkbox-text a:hover { text-decoration: underline; }

.auth-footer-links {
    margin-top: 20px;
    padding-top: 14px;
    border-top: 1px dashed var(--border);
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 14px;
    font-size: 12.5px;
}
.auth-footer-links .auth-footlink {
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
}
.auth-footer-links .auth-footlink:hover {
    color: var(--primary);
    text-decoration: underline;
}

/* Tab styling */
.tabs {
    display: flex;
    gap: 4px;
    padding: 4px;
    background: var(--surface-hover);
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.tab {
    padding: 9px 16px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.12s;
}
.tab:hover { color: var(--text); }
.tab.active {
    background: var(--surface);
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

/* Confirm dialog */
.confirm-text {
    font-size: 15px;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 6px;
}
.confirm-highlight {
    font-weight: 600;
    color: var(--text);
}

/* =========================================================
   MODERN UI: TOGGLES / SLIDERS / INPUTS / TABS / CHIPS
   ========================================================= */

/* ---------- Reset checkboxes/radio per togliere visuali native ---------- */
input[type="checkbox"].ui-switch,
input[type="radio"].ui-switch {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    position: relative;
    width: 44px;
    height: 26px;
    min-width: 44px;
    flex: 0 0 44px;
    background: var(--surface-active);
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    margin: 0;
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition), box-shadow var(--transition);
    outline: none;
    vertical-align: middle;
    box-sizing: border-box;
}
input[type="checkbox"].ui-switch::after,
input[type="radio"].ui-switch::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 3px;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    background: white;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.25), 0 0 0 1px rgba(0,0,0,0.04);
    transition: transform var(--transition), background var(--transition), width var(--transition);
}
input[type="checkbox"].ui-switch:hover,
input[type="radio"].ui-switch:hover {
    border-color: var(--primary-light);
}
input[type="checkbox"].ui-switch:focus-visible,
input[type="radio"].ui-switch:focus-visible {
    box-shadow: var(--shadow-focus);
    border-color: var(--border-focus);
}
input[type="checkbox"].ui-switch:checked,
input[type="radio"].ui-switch:checked {
    background: var(--primary-gradient);
    border-color: transparent;
}
input[type="checkbox"].ui-switch:checked::after,
input[type="radio"].ui-switch:checked::after {
    transform: translate(18px, -50%);
    background: white;
    width: 18px;
}
input[type="checkbox"].ui-switch:disabled,
input[type="radio"].ui-switch:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Variante mini (per tabelle, liste) */
input[type="checkbox"].ui-switch.ui-switch-sm {
    width: 34px;
    height: 20px;
    min-width: 34px;
    flex: 0 0 34px;
}
input[type="checkbox"].ui-switch.ui-switch-sm::after {
    width: 14px;
    height: 14px;
    left: 2px;
}
input[type="checkbox"].ui-switch.ui-switch-sm:checked::after {
    transform: translate(14px, -50%);
}

/* Varianti colori per switch: success, warning, danger */
input[type="checkbox"].ui-switch.ui-switch-success:checked {
    background: linear-gradient(135deg, #10b981, #34d399);
    border-color: transparent;
}
input[type="checkbox"].ui-switch.ui-switch-warning:checked {
    background: linear-gradient(135deg, #f59e0b, #fbbf24);
    border-color: transparent;
}
input[type="checkbox"].ui-switch.ui-switch-danger:checked {
    background: linear-gradient(135deg, #ef4444, #f87171);
    border-color: transparent;
}
input[type="checkbox"].ui-switch.ui-switch-danger:focus-visible {
    box-shadow: var(--shadow-focus-danger);
}

/* ---------- Label accanto a switch ---------- */
.ui-switch-label {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
    padding: 2px 4px;
    border-radius: 10px;
    transition: background var(--transition);
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}
.ui-switch-label:hover {
    background: var(--surface-hover);
}
.ui-switch-label input[type="checkbox"] + .ui-switch-text,
.ui-switch-label .ui-switch-text {
    transition: color var(--transition);
}
.ui-switch-label:has(input:checked) .ui-switch-text,
.ui-switch-label.is-checked .ui-switch-text {
    color: var(--text);
    font-weight: 600;
}
.ui-switch-label:has(input:checked),
.ui-switch-label.is-checked {
    color: var(--text);
}

/* ---------- Gruppo switch multipli (pills) ---------- */
.ui-switch-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 6px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

/* ---------- Chips / Tags ---------- */
.ui-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 11px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 12.5px;
    color: var(--text-secondary);
    cursor: default;
    transition: all var(--transition);
    line-height: 1.2;
    font-weight: 500;
}
.ui-chip.ui-chip-clickable {
    cursor: pointer;
}
.ui-chip.ui-chip-clickable:hover {
    background: var(--surface-hover);
    border-color: var(--border-strong);
    color: var(--text);
    transform: translateY(-1px);
}
.ui-chip.ui-chip-active {
    background: var(--primary-gradient);
    color: white;
    border-color: transparent;
    box-shadow: var(--shadow-sm);
}
.ui-chip.ui-chip-active:hover {
    background: var(--primary-gradient-hover);
    color: white;
}
.ui-chip.ui-chip-success {
    background: var(--success-bg);
    color: var(--success);
    border-color: transparent;
}
.ui-chip.ui-chip-warning {
    background: var(--warning-bg);
    color: var(--warning);
    border-color: transparent;
}
.ui-chip.ui-chip-danger {
    background: var(--danger-bg);
    color: var(--danger);
    border-color: transparent;
}
.ui-chip.ui-chip-purple {
    background: rgba(139, 92, 246, 0.15);
    color: var(--purple);
    border-color: transparent;
}
.ui-chip .ui-chip-count {
    background: rgba(255, 255, 255, 0.25);
    color: inherit;
    padding: 1px 6px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
}
.ui-chip:not(.ui-chip-active) .ui-chip-count {
    background: var(--primary-bg);
    color: var(--primary-dark);
}

/* ---------- Segmented controls (tabs stile iOS) ---------- */
.ui-segmented {
    display: inline-flex;
    padding: 4px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    gap: 2px;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.03);
}
.ui-segmented button {
    padding: 7px 14px;
    border-radius: calc(var(--radius-sm) - 2px);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}
.ui-segmented button:hover {
    color: var(--text);
    background: var(--surface);
}
.ui-segmented button.active {
    background: var(--surface);
    color: var(--primary);
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* ---------- Input / Select / Textarea moderni ---------- */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not(.ui-switch),
select,
textarea {
    width: 100%;
    padding: 11px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-size: 15px;
    line-height: 1.4;
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition), background var(--transition), transform var(--transition);
    box-sizing: border-box;
    font-family: var(--font-sans);
}
textarea {
    min-height: 90px;
    resize: vertical;
    line-height: 1.55;
}
input:not([type]):hover,
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not(.ui-switch):hover,
select:hover,
textarea:hover {
    border-color: var(--border-strong);
}
input:not([type]):focus,
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not(.ui-switch):focus,
select:focus,
textarea:focus {
    border-color: var(--border-focus);
    box-shadow: var(--shadow-focus);
    background: var(--surface);
}
input:not([type]).input-error,
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not(.ui-switch).input-error,
select.input-error,
textarea.input-error {
    border-color: var(--danger);
    box-shadow: var(--shadow-focus-danger);
    background: var(--danger-bg);
    color: var(--text);
}
.input-suffix {
    position: relative;
    display: flex;
    align-items: center;
}
.input-suffix input {
    padding-right: 40px;
}
.input-suffix .suffix {
    position: absolute;
    right: 12px;
    color: var(--text-muted);
    font-size: 13px;
    pointer-events: none;
}

/* ---------- Input file ---------- */
input[type="file"] {
    padding: 8px;
    background: var(--bg-elevated);
    border: 1.5px dashed var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}
input[type="file"]:hover {
    border-color: var(--primary-light);
    background: var(--primary-bg);
    color: var(--primary-dark);
}

/* ---------- Range / slider ---------- */
input[type="range"] {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background: transparent;
    width: 100%;
    height: 28px;
    cursor: pointer;
}
input[type="range"]:focus {
    outline: none;
}
input[type="range"]::-webkit-slider-runnable-track {
    height: 6px;
    border-radius: 999px;
    background: linear-gradient(to right, var(--primary) 0%, var(--primary) var(--val, 50%), var(--surface-active) var(--val, 50%), var(--surface-active) 100%);
    transition: background var(--transition);
}
input[type="range"]::-moz-range-track {
    height: 6px;
    border-radius: 999px;
    background: var(--surface-active);
    border: none;
}
input[type="range"]::-moz-range-progress {
    height: 6px;
    border-radius: 999px;
    background: var(--primary);
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    margin-top: -7px;
    border-radius: 50%;
    background: white;
    border: 2px solid var(--primary);
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}
input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: white;
    border: 2px solid var(--primary);
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    transition: transform var(--transition), box-shadow var(--transition);
}
input[type="range"]:hover::-webkit-slider-thumb {
    transform: scale(1.1);
    box-shadow: 0 3px 10px rgba(59, 130, 246, 0.35);
}
input[type="range"]:hover::-moz-range-thumb {
    transform: scale(1.1);
}
input[type="range"]:focus-visible::-webkit-slider-thumb {
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25), 0 2px 6px rgba(0,0,0,0.15);
}
input[type="range"]:focus-visible::-moz-range-thumb {
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

/* ---------- Pulsanti moderni ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    line-height: 1.25;
    transition: transform var(--transition), box-shadow var(--transition), background var(--transition), color var(--transition), border-color var(--transition), opacity var(--transition);
    border: 1.5px solid transparent;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
}
.btn:active:not(:disabled) {
    transform: translateY(0.5px) scale(0.995);
}
.btn:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus);
}
.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

.btn-primary {
    background: var(--primary-gradient);
    color: white;
    border-color: transparent;
    box-shadow: 0 1px 3px rgba(59, 130, 246, 0.25);
}
.btn-primary:hover:not(:disabled) {
    background: var(--primary-gradient-hover);
    box-shadow: 0 4px 14px rgba(59, 130, 246, 0.38);
    transform: translateY(-1px);
}
.btn-primary:focus-visible {
    box-shadow: var(--shadow-focus), 0 4px 14px rgba(59, 130, 246, 0.38);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border-strong);
}
.btn-secondary:hover:not(:disabled) {
    background: var(--surface-hover);
    border-color: var(--primary);
    color: var(--primary);
}

.btn-success {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    box-shadow: 0 1px 3px rgba(16, 185, 129, 0.25);
}
.btn-success:hover:not(:disabled) {
    background: linear-gradient(135deg, #059669, #047857);
    box-shadow: 0 4px 14px rgba(16, 185, 129, 0.4);
    transform: translateY(-1px);
}

.btn-danger {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
    box-shadow: 0 1px 3px rgba(239, 68, 68, 0.25);
}
.btn-danger:hover:not(:disabled) {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    box-shadow: 0 4px 14px rgba(239, 68, 68, 0.4);
    transform: translateY(-1px);
}
.btn-danger:focus-visible {
    box-shadow: var(--shadow-focus-danger), 0 4px 14px rgba(239, 68, 68, 0.4);
}

.btn-warning {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: white;
    box-shadow: 0 1px 3px rgba(245, 158, 11, 0.25);
}
.btn-warning:hover:not(:disabled) {
    background: linear-gradient(135deg, #d97706, #b45309);
    box-shadow: 0 4px 14px rgba(245, 158, 11, 0.4);
    transform: translateY(-1px);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: transparent;
}
.btn-ghost:hover:not(:disabled) {
    background: var(--surface-hover);
    color: var(--text);
}
.btn-ghost.active {
    background: var(--primary-bg);
    color: var(--primary-dark);
}

.btn-subtle {
    background: var(--bg-elevated);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-subtle:hover:not(:disabled) {
    background: var(--surface-hover);
    color: var(--text);
    border-color: var(--border-strong);
}

.btn-outline {
    background: transparent;
    color: var(--primary);
    border-color: var(--primary);
}
.btn-outline:hover:not(:disabled) {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 14px rgba(59, 130, 246, 0.3);
    transform: translateY(-1px);
}

.btn-icon {
    padding: 8px;
    border-radius: 10px;
    font-size: 15px;
    line-height: 1;
    min-width: 36px;
    min-height: 36px;
}
.btn-icon.btn-sm {
    padding: 5px 6px;
    min-width: 30px;
    min-height: 30px;
    font-size: 13px;
    border-radius: 8px;
}
.btn-icon.btn-lg {
    padding: 12px;
    min-width: 44px;
    min-height: 44px;
    font-size: 18px;
}

.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }
.btn-md { padding: 9px 15px; font-size: 13.5px; }
.btn-lg { padding: 13px 20px; font-size: 15.5px; border-radius: var(--radius-sm); }

.btn-know {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    box-shadow: 0 2px 6px rgba(16, 185, 129, 0.3);
}
.btn-know:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(16, 185, 129, 0.45); }
.btn-easy {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
    box-shadow: 0 2px 6px rgba(59, 130, 246, 0.3);
}
.btn-easy:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(59, 130, 246, 0.45); }
.btn-difficult {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: white;
    box-shadow: 0 2px 6px rgba(245, 158, 11, 0.3);
}
.btn-difficult:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(245, 158, 11, 0.45); }
.btn-dont-know {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
    box-shadow: 0 2px 6px rgba(239, 68, 68, 0.3);
}
.btn-dont-know:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(239, 68, 68, 0.45); }

/* Ripple / press feedback */
.btn:not(:disabled)::before {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0);
    transition: background var(--transition);
    pointer-events: none;
}
.btn:not(:disabled):active::before {
    background: rgba(255,255,255,0.18);
}
.btn-ghost:not(:disabled):active::before,
.btn-subtle:not(:disabled):active::before {
    background: rgba(0,0,0,0.06);
}

/* ---------- Badge / pill ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: 0.01em;
}
.badge-primary { background: var(--primary-bg); color: var(--primary-dark); }
.badge-success { background: var(--success-bg); color: #065f46; }
.badge-warning { background: var(--warning-bg); color: #92400e; }
.badge-danger  { background: var(--danger-bg);  color: #991b1b; }
.badge-muted   { background: var(--bg-elevated); color: var(--text-secondary); border: 1px solid var(--border); }
[data-theme="dark"] .badge-success { color: #6ee7b7; }
[data-theme="dark"] .badge-warning { color: #fde68a; }
[data-theme="dark"] .badge-danger  { color: #fecaca; }
[data-theme="dark"] .badge-primary { color: #bfdbfe; }

/* ---------- Stat cards ---------- */
.stat-card {
    position: relative;
    overflow: hidden;
    transition: transform var(--transition), box-shadow var(--transition);
}
.stat-card::after {
    content: "";
    position: absolute;
    top: 0; right: 0;
    width: 120px; height: 120px;
    background: radial-gradient(circle, rgba(99,102,241,0.10), transparent 70%);
    transform: translate(30%, -30%);
    pointer-events: none;
}
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

/* ---------- Deck cards ---------- */
.deck-card {
    transition: transform var(--transition-lg), box-shadow var(--transition-lg), border-color var(--transition);
    position: relative;
    overflow: visible;
    isolation: isolate;
}
.deck-card::before {
    content: "";
    position: absolute;
    inset: -1px -1px auto auto;
    width: 120px; height: 120px;
    background: radial-gradient(circle at top right, rgba(99,102,241,0.12), transparent 70%);
    pointer-events: none;
    z-index: 0;
    border-radius: inherit;
    -webkit-mask-image: linear-gradient(#000, #000);
    mask-image: linear-gradient(#000, #000);
}
.deck-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-xl);
    border-color: var(--primary-light);
}
.deck-card > * { position: relative; z-index: 1; }

/* ---------- Flashcard improvements ---------- */
.flashcard {
    transition: transform var(--transition-lg), box-shadow var(--transition-lg);
    will-change: transform;
}
.flashcard-face {
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}
.flashcard:hover {
    box-shadow: var(--shadow-xl);
}
.flashcard:active {
    transform: scale(0.992);
}
.flashcard-text {
    transition: transform var(--transition-lg);
}

/* ---------- Navbar / theme button ---------- */
.navbar {
    position: sticky;
    top: 0;
    z-index: 50;
    backdrop-filter: blur(12px) saturate(180%);
    -webkit-backdrop-filter: blur(12px) saturate(180%);
    background: color-mix(in srgb, var(--surface) 82%, transparent);
    border-bottom: 1px solid var(--border);
}
[data-theme="dark"] .navbar {
    background: color-mix(in srgb, var(--surface) 78%, transparent);
}
.nav-link {
    position: relative;
    transition: color var(--transition), background var(--transition);
}
.nav-link::after {
    content: "";
    position: absolute;
    left: 14px; right: 14px; bottom: 4px;
    height: 2px;
    border-radius: 2px;
    background: var(--primary-gradient);
    transform: scaleX(0);
    transform-origin: center;
    transition: transform var(--transition);
}
.nav-link:hover::after {
    transform: scaleX(0.4);
}
.nav-link.active::after {
    transform: scaleX(1);
}
.nav-link.active {
    background: var(--primary-bg);
    color: var(--primary-dark) !important;
    font-weight: 600;
}
[data-theme="dark"] .nav-link.active {
    background: rgba(96, 165, 250, 0.18);
    color: var(--primary-light) !important;
}

/* ---------- Search bar glow ---------- */
.search-box input {
    padding-left: 42px !important;
    transition: all var(--transition);
}
.search-box input:focus {
    box-shadow: var(--shadow-focus), 0 0 0 1px var(--primary) inset;
}
.search-box::before {
    left: 14px;
}

/* ---------- Modal glassmorphism ---------- */
.modal-backdrop {
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    background: rgba(15, 23, 42, 0.55);
}
[data-theme="dark"] .modal-backdrop {
    background: rgba(2, 6, 23, 0.75);
}
.modal {
    animation: modalPopIn var(--transition-lg) cubic-bezier(0.22, 1, 0.36, 1);
    box-shadow: var(--shadow-xl);
}
@keyframes modalPopIn {
    from { opacity: 0; transform: translateY(14px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------- Toast ---------- */
.toast {
    border-radius: var(--radius-sm) !important;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: var(--shadow-lg) !important;
    border: 1px solid var(--border) !important;
    font-weight: 500;
}

/* ---------- Auth hero ---------- */
.auth-hero, .auth-gradient {
    background: var(--primary-gradient) !important;
}

/* ---------- Study controls bar (filtri con toggles) ---------- */
.study-controls-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 18px;
    align-items: center;
    padding: 12px 14px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.study-controls-bar > label.ui-switch-label {
    padding: 4px 8px;
    color: var(--text);
    font-size: 13.5px;
}
.study-controls-bar > label.ui-switch-label:has(input:checked),
.study-controls-bar > label.ui-switch-label.is-checked {
    background: var(--primary-bg);
    color: var(--primary-dark);
    border-radius: 10px;
}
[data-theme="dark"] .study-controls-bar > label.ui-switch-label:has(input:checked),
[data-theme="dark"] .study-controls-bar > label.ui-switch-label.is-checked {
    background: rgba(96, 165, 250, 0.2);
    color: var(--primary-light);
}

/* ---------- Backdrop loading dots ---------- */
.loader {
    border: 3px solid var(--border) !important;
    border-top-color: var(--primary) !important;
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        transition-duration: 0.001ms !important;
    }
}

/* ---------- Responsive tweaks ---------- */
@media (max-width: 640px) {
    .ui-segmented button { padding: 6px 10px; font-size: 12px; }
    .btn-lg { padding: 11px 16px; font-size: 14.5px; }
    input[type="checkbox"].ui-switch { width: 40px; height: 24px; min-width: 40px; flex: 0 0 40px; }
    input[type="checkbox"].ui-switch::after { width: 16px; height: 16px; }
    input[type="checkbox"].ui-switch:checked::after { transform: translate(17px, -50%); }
}

/* ========================================================
   Vector SVG Icons System
   ======================================================== */
.icon {
    display: inline-block;
    width: 1.2em;
    height: 1.2em;
    vertical-align: -0.2em;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
    transition: transform 0.15s ease, stroke 0.15s ease;
}

.btn .icon {
    width: 1.15em;
    height: 1.15em;
    vertical-align: middle;
}

.btn-icon .icon {
    width: 1.25em;
    height: 1.25em;
    vertical-align: middle;
}

.btn-sm .icon {
    width: 1em;
    height: 1em;
}

.btn-lg .icon {
    width: 1.3em;
    height: 1.3em;
}

.nav-link .icon {
    width: 1.2em;
    height: 1.2em;
}

.nav-link:hover .icon {
    transform: translateY(-1px);
}

.brand-icon .icon {
    width: 20px;
    height: 20px;
}

.logo-icon .icon {
    width: 34px;
    height: 34px;
}

.stat-icon .icon {
    width: 22px;
    height: 22px;
}

.empty-state .empty-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.empty-state .empty-icon .icon {
    width: 56px;
    height: 56px;
    stroke-width: 1.6;
    opacity: 0.75;
}

.search-box .search-icon {
    display: flex;
    align-items: center;
}

.search-box .search-icon .icon {
    width: 16px;
    height: 16px;
}

.study-timer {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.study-timer .icon {
    width: 1.15em;
    height: 1.15em;
    color: var(--primary);
}

.study-complete-icon {
    width: 72px;
    height: 72px;
    margin: 0 auto 16px;
    border-radius: 50%;
    background: rgba(245, 158, 11, 0.12);
    color: #f59e0b;
    display: flex;
    align-items: center;
    justify-content: center;
}

[data-theme="dark"] .study-complete-icon {
    background: rgba(245, 158, 11, 0.2);
}

.study-complete-icon .icon {
    width: 40px;
    height: 40px;
}

.close-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.close-btn .icon {
    width: 16px;
    height: 16px;
}

.toast .icon {
    width: 1.25em;
    height: 1.25em;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.dropdown-item .icon {
    width: 1.15em;
    height: 1.15em;
}

.badge .icon {
    width: 1em;
    height: 1em;
    vertical-align: -0.12em;
}

/* ========== Auth: tabs + banners + forgot ========== */
.auth-tabs {
    width: 100%;
    display: flex;
    flex-wrap: nowrap;
    overflow: hidden;
    box-sizing: border-box;
    margin-bottom: 22px;
    border-radius: var(--radius);
    padding: 4px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    gap: 2px;
}
.auth-tabs .ui-seg-btn {
    flex: 1 1 0;
    min-width: 0;
    max-width: 100%;
    padding: 8px 10px;
    font-size: 12.5px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-weight: 600;
    border-radius: calc(var(--radius-sm) - 2px);
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    cursor: pointer;
    transition: all var(--transition);
}
.auth-tabs .ui-seg-btn.active {
    background: var(--surface);
    color: var(--primary);
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.auth-tabs .ui-seg-btn:hover {
    color: var(--text);
}
.auth-tabs .ui-seg-btn .icon,
.auth-tabs .ui-seg-btn svg {
    width: 1em;
    height: 1em;
    flex-shrink: 0;
}
.auth-card form {
    width: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}
.auth-card .form-group,
.auth-card .captcha-group {
    width: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}
.auth-card .captcha-row,
.auth-card .captcha-question {
    width: 100%;
    box-sizing: border-box;
    max-width: 100%;
}
.auth-card .captcha-question {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px dashed var(--border);
    background: var(--bg-soft);
    font-weight: 700;
    font-size: 16px;
    overflow: hidden;
}
.auth-card .captcha-question > span:first-child {
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.auth-card .captcha-question .btn {
    flex-shrink: 0;
}
@media (max-width: 420px) {
    .auth-tabs .ui-seg-btn span { display: none; }
    .auth-tabs .ui-seg-btn { padding: 8px 4px; font-size: 14px; }
    .auth-tabs .ui-seg-btn .icon,
    .auth-tabs .ui-seg-btn svg { width: 1.25em; height: 1.25em; }
    .auth-card { padding: 24px 18px; }
}

.auth-banner {
    border-radius: var(--radius-sm);
    padding: 14px 14px 13px;
    margin-bottom: 18px;
    border: 1px solid transparent;
    font-size: 13px;
    line-height: 1.45;
}
.banner-warning {
    background: color-mix(in srgb, #f59e0b 14%, var(--surface));
    border-color: color-mix(in srgb, #f59e0b 35%, var(--border));
    color: var(--text);
}
.banner-info {
    background: color-mix(in srgb, #3b82f6 12%, var(--surface));
    border-color: color-mix(in srgb, #3b82f6 30%, var(--border));
    color: var(--text);
}
.banner-danger {
    background: color-mix(in srgb, #ef4444 12%, var(--surface));
    border-color: color-mix(in srgb, #ef4444 30%, var(--border));
    color: var(--text);
}
.auth-banner-title {
    font-size: 13.5px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.auth-banner-title .icon,
.auth-banner-title svg {
    width: 1em;
    height: 1em;
    flex-shrink: 0;
}
.auth-banner-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.auth-forgot-row {
    width: 100%;
    box-sizing: border-box;
    text-align: right;
    margin: 10px 0 18px;
    padding: 0;
    font-size: 13px;
}
.auth-forgot-row a {
    display: inline-block;
    color: var(--primary);
    font-weight: 600;
    text-decoration: none;
    max-width: 100%;
    overflow-wrap: anywhere;
}
.auth-forgot-row a:hover { text-decoration: underline; }

.auth-switch {
    width: 100%;
    box-sizing: border-box;
    text-align: center;
    margin-top: 22px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-secondary);
    overflow-wrap: anywhere;
}
.auth-switch a {
    font-weight: 600;
    color: var(--primary);
    text-decoration: none;
}
.auth-switch a:hover { text-decoration: underline; }

.auth-hint {
    font-size: 12.5px;
    color: var(--text-muted);
    line-height: 1.5;
    margin: -6px 0 16px;
}

@media (max-width: 380px) {
    .auth-card { padding: 24px 18px; }
    .auth-tabs .ui-seg-btn { font-size: 12px; }
}

/* ========== PAGINAZIONE ========== */
.pagination-wrap {
    width: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 20px;
    padding: 14px 16px;
    background: var(--glass);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    border-radius: 12px;
}
.pagination-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
}
.pagination-pages {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
    justify-content: center;
    flex: 1 1 auto;
}
.pag-num, .pag-btn {
    height: 34px;
    min-width: 34px;
    padding: 0 10px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 2px;
    transition: all 0.18s cubic-bezier(.2,.8,.2,1);
    cursor: pointer;
    line-height: 1;
    white-space: nowrap;
}
.pag-num { padding: 0 10px; min-width: 34px; }
.pag-btn {
    padding: 0 8px;
    min-width: 34px;
}
.pag-num:hover:not(:disabled), .pag-btn:hover:not(:disabled) {
    transform: translateY(-1px);
}
.pag-num:active:not(:disabled), .pag-btn:active:not(:disabled) {
    transform: translateY(0);
}
.pag-num:disabled, .pag-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}
.pag-ellipsis {
    padding: 0 6px;
    color: var(--text-muted);
    font-size: 15px;
    font-weight: 500;
    user-select: none;
}
.pagination-info {
    text-align: center;
    font-size: 12.5px;
    color: var(--text-muted);
    font-weight: 500;
    letter-spacing: 0.01em;
}

/* ---------- Deck list pagination margin ---------- */
#decks-list-wrap > .pagination-wrap { margin-top: 24px; }
#cards-list-wrap > .pagination-wrap { margin-top: 18px; }
#deck-progress-wrap .pagination-wrap {
    background: rgba(148, 163, 184, 0.06);
    border: 1px dashed var(--border);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
    .pagination-wrap {
        padding: 12px 12px;
        gap: 8px;
    }
    .pagination-controls {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
    }
    .pagination-pages {
        order: 2;
        width: 100%;
        justify-content: center;
    }
    .pag-prev { order: 1; }
    .pag-next { order: 3; }
    .pag-num, .pag-btn {
        height: 32px;
        min-width: 32px;
        padding: 0 8px;
        font-size: 12.5px;
    }
    .pag-num { padding: 0 9px; }
    .pagination-info { font-size: 12px; }
}
@media (max-width: 380px) {
    .pag-num, .pag-btn {
        height: 30px;
        min-width: 30px;
        padding: 0 6px;
        font-size: 12px;
    }
    .pag-num { padding: 0 7px; }
    .pag-ellipsis { padding: 0 3px; font-size: 13px; }
}

/* ========== STUDIO: SWIPE + NAV ========== */
/* On-screen lateral Prev / Next (floating large buttons on card sides) */
.study-nav-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 max(6px, 1%);
}
#study-content {
    position: relative;
}
.study-nav-btn {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: var(--glass, rgba(148, 163, 184, 0.12));
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    cursor: pointer;
    transition: all 0.18s cubic-bezier(.2,.8,.2,1);
    flex-shrink: 0;
    box-shadow: 0 4px 14px -8px rgba(15,23,42,.25);
}
.study-nav-btn svg { width: 24px; height: 24px; stroke-width: 2.1; }
.study-nav-btn:hover:not(:disabled) {
    background: var(--primary-alpha, rgba(99,102,241,0.14));
    color: var(--primary);
    transform: scale(1.06);
    border-color: var(--primary-alpha, rgba(99,102,241,0.3));
}
.study-nav-btn:active:not(:disabled) { transform: scale(.96); }
.study-nav-btn:disabled,
.study-nav-btn.is-disabled {
    opacity: 0.35;
    cursor: not-allowed;
}
.study-nav-prev { margin-left: 2px; }
.study-nav-next { margin-right: 2px; }

/* ---------- Flashcard drag / swipe ---------- */
.study-swipe-root {
    position: relative;
    touch-action: pan-y;
    user-select: none;
    -webkit-user-select: none;
}
.flashcard-wrapper {
    position: relative;
}
.flashcard {
    transform: translate3d(var(--swipe-x, 0), var(--swipe-y, 0), 0) rotate(var(--swipe-rot, 0deg));
    transition: transform 0.26s cubic-bezier(.2,.8,.2,1),
                box-shadow 0.22s ease;
    will-change: transform;
    contain: layout;
}
.study-swipe-root.is-dragging .flashcard {
    transition: none;
    cursor: grabbing;
}
.study-swipe-root:not(.is-dragging) .flashcard {
    cursor: pointer;
}

/* Hint overlays on corners - reveal during drag */
.swipe-hints {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 3;
}
.swipe-hint {
    position: absolute;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 12.5px;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    opacity: 0;
    transform: scale(.9);
    transition: opacity 0.18s ease, transform 0.2s cubic-bezier(.2,.8,.2,1);
    border: 1px solid transparent;
    pointer-events: none;
}
.swipe-hint-icon { display: inline-flex; align-items: center; }
.swipe-hint-icon svg { width: 18px; height: 18px; stroke-width: 2.2; }
.swipe-hint-prev {
    left: 6%;
    top: 50%;
    transform: translate(-50%, -50%) scale(.9);
    background: rgba(34,197,94,0.14);
    color: #16a34a;
    border-color: rgba(34,197,94,0.32);
}
.swipe-hint-next {
    right: 6%;
    top: 50%;
    transform: translate(50%, -50%) scale(.9);
    background: rgba(239,68,68,0.14);
    color: #dc2626;
    border-color: rgba(239,68,68,0.32);
}
.swipe-hint-flip {
    left: 50%;
    top: 10%;
    transform: translate(-50%, -50%) scale(.9);
    background: rgba(99,102,241,0.14);
    color: var(--primary);
    border-color: var(--primary-alpha, rgba(99,102,241,0.32));
}

/* Swipe state classes - reveal matching hint */
.study-swipe-root.is-dragging.swipe-prev .swipe-hint-prev,
.study-swipe-root.is-dragging.swipe-next .swipe-hint-next,
.study-swipe-root.is-dragging.swipe-flip .swipe-hint-flip {
    opacity: 1;
    transform: translate(var(--hint-fix-x, 0), var(--hint-fix-y, -50%)) scale(1);
}
.study-swipe-root.is-dragging.swipe-prev .swipe-hint-prev { --hint-fix-x: -50%; --hint-fix-y: -50%; }
.study-swipe-root.is-dragging.swipe-next .swipe-hint-next { --hint-fix-x: 50%;  --hint-fix-y: -50%; }
.study-swipe-root.is-dragging.swipe-flip .swipe-hint-flip { --hint-fix-x: -50%; --hint-fix-y: -50%; }

/* Increase card shadow while dragging for depth */
.study-swipe-root.is-dragging .flashcard {
    box-shadow: 0 30px 70px -20px rgba(15,23,42,0.35),
                0 18px 36px -18px rgba(15,23,42,0.25) !important;
}

/* ---------- Responsive (nav + swipe) ---------- */
@media (max-width: 768px) {
    .study-nav-btn {
        width: 46px;
        height: 46px;
    }
    .study-nav-btn svg { width: 22px; height: 22px; }
}
@media (max-width: 560px) {
    .study-nav-overlay {
        align-items: flex-end;
        justify-content: center;
        gap: 20px;
        padding: 0 0 8px;
        bottom: 86px;
        inset-block-start: auto;
    }
    .study-nav-btn {
        width: 64px;
        height: 44px;
        border-radius: 14px;
        margin: 0;
    }
    .study-nav-btn svg { width: 24px; height: 24px; }
    .swipe-hint-prev { left: 10px; }
    .swipe-hint-next { right: 10px; }
    .swipe-hint-flip { top: 14px; }
}
@media (max-width: 380px) {
    .swipe-hint {
        font-size: 11px;
        padding: 6px 10px;
    }
    .swipe-hint-icon svg { width: 16px; height: 16px; }
}


