:root {
    --bg: #f0f2f5;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --muted: #64748b;
    --accent: #4f46e5;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

nav {
    background: #1e1b4b;
    padding: 0 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 3.5rem;
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

@media (max-width: 640px) {
    nav { padding: 0 1rem; }
}

.brand {
    font-size: 1.1rem;
    font-weight: 700;
    color: #fff;
    text-decoration: none;
    letter-spacing: 0.3px;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.nav-links a {
    color: rgba(255,255,255,0.72);
    text-decoration: none;
    font-size: 0.875rem;
    transition: color 0.15s;
}

.nav-links a:hover { color: #fff; }

.nav-user {
    font-size: 0.78rem;
    color: rgba(255,255,255,0.4);
    text-decoration: none;
}
.nav-user:hover { color: rgba(255,255,255,0.75); }

.nav-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
}

.nav-toggle span {
    display: block;
    width: 22px;
    height: 2px;
    background: rgba(255,255,255,0.85);
    border-radius: 2px;
    transition: transform 0.2s, opacity 0.2s;
}

.nav-toggle[aria-expanded="true"] span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.nav-toggle[aria-expanded="true"] span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

@media (max-width: 640px) {
    .nav-toggle { display: flex; }

    .nav-links {
        display: none;
        position: absolute;
        top: 3.5rem;
        left: 0;
        right: 0;
        background: #1e1b4b;
        flex-direction: column;
        align-items: stretch;
        padding: 0.5rem 0;
        box-shadow: 0 4px 8px rgba(0,0,0,0.3);
        z-index: 9;
    }

    .nav-links.open { display: flex; }

    .nav-links a {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }
}

main {
    max-width: 860px;
    margin: 2rem auto;
    padding: 0 1.5rem;
}

@media (max-width: 640px) {
    main {
        margin: 1rem auto;
        padding: 0 0.75rem;
    }
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    gap: 0.75rem;
}

.page-header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

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

    .page-header-actions {
        width: 100%;
    }
}

h1 { font-size: 1.5rem; font-weight: 700; }

.alert {
    padding: 0.7rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.875rem;
    border: 1px solid transparent;
}

.alert-error   { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.alert-success { background: #f0fdf4; color: #166534; border-color: #bbf7d0; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 0.1rem;
    padding: 0.5rem 1.1rem;
    border-radius: 6px;
    border: 1px solid transparent;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    font-family: inherit;
    text-decoration: none;
    transition: filter 0.15s, transform 0.1s;
    line-height: 1.4;
}

.btn:active { transform: scale(0.97); }
.btn:hover  { filter: brightness(0.9); }
.btn small   { font-size: 0.7rem; font-weight: 400; opacity: 0.8; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-outline { background: #fff; border-color: var(--border); color: var(--text); }
.btn-danger  { background: #dc2626; color: #fff; }
.btn-sm      { padding: 0.3rem 0.7rem; font-size: 0.8rem; }

.btn-again { background: #dc2626; color: #fff; min-width: 84px; }
.btn-hard  { background: #ea580c; color: #fff; min-width: 84px; }
.btn-good  { background: #16a34a; color: #fff; min-width: 84px; }
.btn-easy  { background: #2563eb; color: #fff; min-width: 84px; }

.btn-group {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    justify-content: center;
    margin-top: 1.5rem;
}

@media (max-width: 640px) {
    .btn-group {
        gap: 0.4rem;
        flex-wrap: nowrap;
    }

    .btn-again, .btn-hard, .btn-good, .btn-easy {
        flex: 1 1 0;
        min-width: 0;
        font-size: 0.8rem;
        padding: 0.5rem 0.25rem;
        white-space: nowrap;
        overflow: hidden;
    }
}

@media (max-width: 420px) {
    .btn-again small, .btn-hard small, .btn-good small, .btn-easy small {
        display: none;
    }
}

.field { margin-bottom: 1.25rem; }

label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.4rem;
}

input[type="text"],
input[type="password"],
textarea {
    width: 100%;
    padding: 0.55rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
    font-family: inherit;
    background: #fff;
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.12);
}

textarea {
    min-height: 160px;
    resize: vertical;
    font-family: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
    font-size: 0.85rem;
    line-height: 1.6;
}

.stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.2rem 1.5rem;
    box-shadow: var(--shadow);
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent);
    line-height: 1;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--muted);
    margin-top: 0.35rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

@media (max-width: 480px) {
    .stats { grid-template-columns: 1fr; }
}

.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    overflow-x: auto;
    box-shadow: var(--shadow);
}

table { width: 100%; border-collapse: collapse; }

th {
    padding: 0.65rem 1rem;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
}

td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
    vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }

.truncate {
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
}

.badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
}

.badge-due { background: #fff7ed; color: #c2410c; }
.badge-ok  { background: #f0fdf4; color: #15803d; }
.badge-new { background: #eff6ff; color: #1d4ed8; }

.flashcard {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 3rem 2.5rem;
    box-shadow: 0 4px 6px rgba(0,0,0,0.04), 0 10px 15px rgba(0,0,0,0.04);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

@media (max-width: 640px) {
    .flashcard { padding: 1.25rem 1rem; }
}

.flashcard-label {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--muted);
    font-weight: 600;
}

.flashcard-content {
    font-size: 1.1rem;
    line-height: 1.75;
}

.flashcard-content p:not(:last-child) {
    margin-bottom: 0.75rem;
}

.flashcard-content ul,
.flashcard-content ol {
    padding-left: 1.5rem;
}

.flashcard-content pre {
    background: #f8fafc;
    padding: 1rem;
    border-radius: 6px;
    overflow-x: auto;
    font-size: 0.85rem;
    border: 1px solid var(--border);
    margin: 0.5rem 0;
}

.flashcard-content code:not(pre code) {
    background: #f1f5f9;
    padding: 0.1em 0.45em;
    border-radius: 4px;
    font-size: 0.88em;
    font-family: 'JetBrains Mono', 'Courier New', monospace;
}

.flashcard-content table {
    display: block;
    overflow-x: auto;
    max-width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    margin: 0.5rem 0;
}

.flashcard-content th,
.flashcard-content td {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    text-align: left;
    white-space: nowrap;
}

.flashcard-content th {
    background: #f8fafc;
    font-weight: 600;
    font-size: 0.8rem;
}

.flashcard-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 1.5rem 0;
}

.empty {
    text-align: center;
    padding: 3rem;
    color: var(--muted);
}

.empty p { margin-bottom: 1rem; }

.auth-wrap {
    max-width: 420px;
    margin: 3.5rem auto;
}

.tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.5rem;
}

.tab-btn {
    padding: 0.65rem 1.25rem;
    font-size: 0.9rem;
    font-family: inherit;
    font-weight: 500;
    color: var(--muted);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}

.tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.tab-pane { display: none; }
.tab-pane.active { display: block; }

.preview-box {
    min-height: 160px;
    padding: 0.6rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #f8fafc;
    font-size: 0.9rem;
    line-height: 1.6;
}

.preview-box p:not(:last-child) {
    margin-bottom: 0.75rem;
}

.preview-box ul,
.preview-box ol {
    padding-left: 1.5rem;
}

.preview-box pre {
    background: #fff;
    padding: 0.75rem;
    border-radius: 6px;
    overflow-x: auto;
    font-size: 0.85rem;
    border: 1px solid var(--border);
    margin: 0.4rem 0;
}

.preview-box code:not(pre code) {
    background: #e2e8f0;
    padding: 0.1em 0.4em;
    border-radius: 4px;
    font-size: 0.88em;
    font-family: 'JetBrains Mono', 'Courier New', monospace;
}

.preview-box table {
    display: block;
    overflow-x: auto;
    max-width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    margin: 0.4rem 0;
}

.preview-box th,
.preview-box td {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    text-align: left;
    white-space: nowrap;
}

.preview-box th {
    background: #f8fafc;
    font-weight: 600;
    font-size: 0.8rem;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-top: 1.5rem;
}

.text-muted { color: var(--muted); font-size: 0.875rem; }

.breadcrumb {
    display: block;
    font-size: 0.8rem;
    color: var(--muted);
    text-decoration: none;
    margin-bottom: 0.2rem;
}
.breadcrumb:hover { color: var(--accent); }

select {
    width: 100%;
    padding: 0.55rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
    font-family: inherit;
    background: #fff;
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.9rem center;
    padding-right: 2.2rem;
}
select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.12);
}

.pagination {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin-top: 1.25rem;
    flex-wrap: wrap;
}

.pagination-sep {
    width: 1px;
    height: 1.25rem;
    background: var(--border);
    margin: 0 0.25rem;
    margin-left: auto;
}

.per-page-form {
    display: flex;
    align-items: center;
}

.per-page-form select {
    width: auto;
    padding: 0.3rem 1.75rem 0.3rem 0.7rem;
    font-size: 0.8rem;
    border-radius: 6px;
    border-color: var(--border);
    background-color: #fff;
}

.pagination-disabled {
    opacity: 0.4;
    cursor: default;
    pointer-events: none;
}

.page-ellipsis {
    color: var(--muted);
    font-size: 0.875rem;
    padding: 0 0.15rem;
}

.deck-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
}

.deck-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    text-decoration: none;
    color: var(--text);
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    transition: box-shadow 0.15s, border-color 0.15s;
    min-height: 110px;
}

.deck-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    border-color: var(--accent);
}

.deck-card-muted { border-style: dashed; }

.deck-name {
    font-weight: 600;
    font-size: 1rem;
}

.deck-desc {
    font-size: 0.82rem;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.deck-stats {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.8rem;
    color: var(--muted);
    margin-top: auto;
    padding-top: 0.5rem;
}

.key-hint {
    font-size: 0.75rem;
    color: var(--muted);
    text-align: center;
    margin-top: 0.75rem;
}

kbd {
    display: inline-block;
    padding: 0.1em 0.45em;
    border-radius: 4px;
    border: 1px solid #cbd5e1;
    background: #f8fafc;
    font-size: 0.75em;
    font-family: inherit;
}
