/* =============================================
   Offline Flashcard Maker — style.css
   Clean light aesthetic, 3D card flip, warm neutrals
   ============================================= */

:root {
    --bg: #FAFAF8;
    --surface: #FFFFFF;
    --border: #E5E7EB;
    --text: #111827;
    --muted: #6B7280;
    --primary: #4f46e5;
    --primary-h: #4338ca;
    --easy: #16a34a;
    --medium: #d97706;
    --hard: #dc2626;
    --radius: 14px;
    --radius-sm: 8px;
    --header-h: 56px;
    --shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

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

html {
    font-size: 15px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ── Header ── */
.site-header {
    height: var(--header-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    box-shadow: var(--shadow);
}

.header-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 20px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 1rem;
}

.logo-icon {
    font-size: 1.3rem;
}

.header-actions {
    display: flex;
    gap: 8px;
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.18s ease;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-h);
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
}

.btn-outline {
    background: transparent;
    border-color: var(--border);
    color: var(--muted);
}

.btn-outline:hover {
    color: var(--text);
    background: rgba(0, 0, 0, 0.04);
}

.btn-ghost {
    background: transparent;
    border: none;
    color: var(--muted);
}

.btn-ghost:hover {
    color: var(--text);
}

.btn-danger {
    background: transparent;
    border-color: rgba(220, 38, 38, 0.3);
    color: var(--hard);
}

.btn-danger:hover {
    background: rgba(220, 38, 38, 0.06);
}

.btn-sm {
    padding: 5px 11px;
    font-size: 0.78rem;
}

/* ── Views ── */
.view {
    display: none;
    flex: 1;
}

.view.active {
    display: flex;
    flex-direction: column;
}

/* ── Deck List View ── */
#view-decks {
    max-width: 1100px;
    width: 100%;
    margin: 0 auto;
    padding: 28px 20px;
}

.decks-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 700;
}

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

.decks-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 14px;
}

.deck-card {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--shadow);
    animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.deck-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
}

.deck-color-bar {
    height: 5px;
    width: 100%;
}

.deck-card-body {
    padding: 18px;
}

.deck-card-name {
    font-weight: 700;
    font-size: 1rem;
    margin-bottom: 6px;
}

.deck-card-stats {
    font-size: 0.78rem;
    color: var(--muted);
    margin-bottom: 12px;
}

.deck-card-progress {
    height: 5px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}

.deck-card-progress-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.4s ease;
}

.deck-card-actions {
    position: absolute;
    top: 14px;
    right: 12px;
    display: flex;
    gap: 4px;
}

.deck-action-btn {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 3px 7px;
    font-size: 0.75rem;
    cursor: pointer;
    color: var(--muted);
    transition: all 0.18s;
}

.deck-action-btn:hover {
    color: var(--text);
}

.deck-due-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 0.68rem;
    background: rgba(220, 38, 38, 0.1);
    color: var(--hard);
    border: 1px solid rgba(220, 38, 38, 0.25);
    border-radius: 20px;
    padding: 2px 8px;
    margin-top: 8px;
    font-weight: 600;
}

.empty-state {
    grid-column: 1/-1;
    text-align: center;
    padding: 60px 20px;
    color: var(--muted);
}

.empty-icon {
    font-size: 3rem;
    margin-bottom: 12px;
}

/* ── Deck Detail View ── */
#view-deck-detail {
    max-width: 1100px;
    width: 100%;
    margin: 0 auto;
    padding: 20px;
}

.detail-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.detail-title-wrap {
    flex: 1;
}

.detail-title {
    font-size: 1.3rem;
    font-weight: 700;
}

.detail-stats {
    font-size: 0.78rem;
    color: var(--muted);
    display: block;
    margin-top: 2px;
}

.detail-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.cards-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.card-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    display: grid;
    grid-template-columns: 1fr auto 1fr auto;
    gap: 12px;
    align-items: center;
    animation: fadeIn 0.2s ease;
}

.card-item-front,
.card-item-back {
    font-family: 'Georgia', serif;
    font-size: 0.88rem;
    line-height: 1.5;
    color: var(--text);
    overflow: hidden;
    max-height: 56px;
    text-overflow: ellipsis;
}

.card-divider {
    color: var(--border);
    font-size: 1rem;
}

.card-item-actions {
    display: flex;
    gap: 4px;
}

.card-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 0.85rem;
    color: var(--muted);
}

.card-btn:hover {
    color: var(--text);
    background: rgba(0, 0, 0, 0.05);
}

.card-item-rating {
    display: flex;
    gap: 2px;
}

.rating-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--border);
}

.rating-dot.easy {
    background: var(--easy);
}

.rating-dot.medium {
    background: var(--medium);
}

.rating-dot.hard {
    background: var(--hard);
}

/* ── Study View ── */
#view-study {
    background: linear-gradient(135deg, #f0f0ff 0%, #fafaf8 100%);
}

.study-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(8px);
}

.study-progress-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.study-progress-bar {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}

.study-progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
    transition: width 0.4s ease;
}

.study-progress-text {
    font-size: 0.75rem;
    color: var(--muted);
    text-align: center;
}

.study-shortcuts-hint {
    font-size: 0.7rem;
    color: var(--muted);
    white-space: nowrap;
}

.study-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 24px;
    padding: 24px;
}

/* ── 3D Card Flip ── */
.card-3d-wrapper {
    perspective: 1400px;
    width: 100%;
    max-width: 520px;
    height: 280px;
    cursor: pointer;
}

.card-3d {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.55s cubic-bezier(0.4, 0.2, 0.2, 1.0);
}

.card-3d.flipped {
    transform: rotateY(180deg);
}

.card-face-front,
.card-face-back {
    position: absolute;
    inset: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 28px;
    text-align: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

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

.card-face-label {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--muted);
    margin-bottom: 16px;
}

.card-face-content {
    font-family: 'Georgia', serif;
    font-size: 1.15rem;
    line-height: 1.7;
    color: var(--text);
    max-height: 180px;
    overflow-y: auto;
    width: 100%;
}

/* ── Rating ── */
.rating-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
}

.rate-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 24px;
    border: 2px solid;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 600;
    transition: all 0.18s;
    background: var(--surface);
}

.rate-hard {
    border-color: rgba(220, 38, 38, 0.4);
    color: var(--hard);
}

.rate-medium {
    border-color: rgba(217, 119, 6, 0.4);
    color: var(--medium);
}

.rate-easy {
    border-color: rgba(22, 163, 74, 0.4);
    color: var(--easy);
}

.rate-hard:hover {
    background: rgba(220, 38, 38, 0.08);
    transform: translateY(-2px);
}

.rate-medium:hover {
    background: rgba(217, 119, 6, 0.08);
    transform: translateY(-2px);
}

.rate-easy:hover {
    background: rgba(22, 163, 74, 0.08);
    transform: translateY(-2px);
}

.rate-interval {
    font-size: 0.7rem;
    font-weight: 400;
    opacity: 0.75;
}

/* ── Session Complete ── */
.session-complete {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    text-align: center;
}

.session-icon {
    font-size: 3.5rem;
}

.session-complete h2 {
    font-size: 1.4rem;
    font-weight: 700;
}

.session-complete p {
    color: var(--muted);
}

/* ── Modal ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay[hidden] {
    display: none;
}

.modal-card {
    width: 100%;
    max-width: 480px;
    background: var(--surface);
    border-radius: var(--radius);
    animation: slideUp 0.22s ease-out;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    padding: 18px 20px 14px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    font-weight: 700;
    font-size: 0.95rem;
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 1rem;
    padding: 4px 8px;
    border-radius: 6px;
}

.modal-close:hover {
    background: rgba(0, 0, 0, 0.06);
}

.modal-body {
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 70vh;
    overflow-y: auto;
}

.modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.form-label {
    font-size: 0.73rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}

.form-input,
.form-textarea {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    font-family: inherit;
    font-size: 0.85rem;
    background: var(--bg);
    color: var(--text);
    width: 100%;
}

.form-input:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.form-textarea {
    resize: vertical;
    line-height: 1.6;
}

.card-text {
    font-family: 'Georgia', serif;
}

/* ── Color Picker ── */
.color-picker {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.color-swatch {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 3px solid transparent;
    cursor: pointer;
    transition: all 0.18s;
}

.color-swatch.selected {
    border-color: var(--text);
    transform: scale(1.15);
}

/* ── CSV Import ── */
.file-drop-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    transition: border-color 0.2s;
}

.file-drop-area.drag-over {
    border-color: var(--primary);
    background: rgba(79, 70, 229, 0.04);
}

.file-drop-hint {
    font-size: 0.78rem;
    color: var(--muted);
}

.file-selected {
    font-size: 0.78rem;
    color: var(--easy);
    font-weight: 600;
}

.import-hint {
    font-size: 0.78rem;
    color: var(--muted);
    line-height: 1.5;
}

code {
    background: rgba(0, 0, 0, 0.06);
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 0.85em;
}

/* ── Toast ── */
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--text);
    color: #fff;
    border-radius: var(--radius-sm);
    padding: 10px 16px;
    font-size: 0.84rem;
    z-index: 999;
    opacity: 0;
    transform: translateY(8px);
    transition: all 0.25s ease;
    pointer-events: none;
    max-width: 280px;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

/* ── Responsive ── */
@media (max-width: 600px) {
    .card-item {
        grid-template-columns: 1fr;
    }

    .card-divider {
        display: none;
    }

    .study-shortcuts-hint {
        display: none;
    }
}