/* ═══════════════════════════════════════
   STUDY LAYOUT
   ═══════════════════════════════════════ */

.study-page {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    --sidebar-w: 260px;
}

/* ── Header offset to align with card area ── */

.header-row {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    flex-shrink: 0;
}

.header-offset {
    /* occupies first grid column */
}

.header-offset + .header-inner {
    grid-column: 2;
    max-width: 720px;
    padding: 0 20px;
    height: 52px;
    justify-self: center;
    width: 100%;
}

/* ── Body ── */

.study-body {
    display: flex;
    flex: 1;
    min-height: 0;
}

/* ── Sidebar ── */

.sidebar {
    width: 260px;
    flex-shrink: 0;
    background: var(--paper-cream);
    border-right: 1px solid var(--paper-warm);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

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

.sidebar-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--ink-dark);
    font-family: var(--font-display);
    letter-spacing: 0.01em;
}

.sidebar-close {
    display: none;
    font-size: 22px;
    color: var(--ink-light);
    padding: 0;
    line-height: 1;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 6px 0;
}

/* ── Main Content ── */

.study-main {
    flex: 1;
    min-width: 0;
    max-width: 720px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    flex-direction: column;
}

.card-frame {
    flex: 1;
    width: 100%;
    border: none;
    background: var(--paper-cream);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    min-height: 200px;
}

.action-bar {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    padding: 16px 0;
    flex-shrink: 0;
}

/* ── Directory Items ── */

.dir-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 9px 20px;
    cursor: pointer;
    transition: background 0.2s ease;
    border-left: 3px solid transparent;
}

.dir-item:hover {
    background: var(--paper-warm);
}

.dir-item.active {
    background: var(--terracotta-glow);
    border-left-color: var(--terracotta);
}

.dir-item.active .dir-name {
    color: var(--terracotta-dark);
    font-weight: 500;
}

.dir-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.dir-indent {
    width: 16px;
    color: var(--ink-muted);
    font-size: 12px;
}

.dir-name {
    font-size: 14px;
    color: var(--ink-dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dir-count {
    font-size: 12px;
    color: var(--ink-light);
    background: var(--paper-warm);
    padding: 2px 8px;
    border-radius: 10px;
    flex-shrink: 0;
}

.dir-item.dir-folder { font-weight: 500; }
.dir-item.dir-folder .dir-name { color: var(--ink-dark); }
.dir-item.dir-folder.active .dir-name { color: var(--terracotta-dark); }

.dir-item {
    padding-left: calc(var(--level, 0) * 30px + 12px);
}

.dir-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.dir-collapse {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    font-size: 10px;
    cursor: pointer;
    user-select: none;
    color: var(--ink-light);
    transition: transform 0.15s ease;
    flex-shrink: 0;
}

.dir-collapse:hover { color: var(--ink-dark); }

.dir-icon { margin-right: 4px; font-size: 14px; }
.dir-item.dir-hidden { display: none; }

.dir-item.active .dir-count {
    background: var(--terracotta);
    color: white;
}

.sidebar-overlay { display: none; }

/* ── Menu Button (mobile toggle) ── */

.menu-btn {
    display: none;
    width: 40px;
    height: 40px;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    color: var(--ink-medium);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: 20px;
}

.menu-btn:hover {
    color: var(--terracotta);
    background: var(--terracotta-glow);
}

/* ═══════════════════════════════════════
   RESPONSIVE: MOBILE
   ═══════════════════════════════════════ */

@media (max-width: 767px) {
    .menu-btn { display: flex; }

    .sidebar-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(26, 21, 18, 0.35);
        z-index: 998;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.25s ease, visibility 0.25s ease;
    }

    .sidebar-overlay.show { opacity: 1; visibility: visible; }

    .sidebar {
        position: fixed;
        top: 0;
        left: -280px;
        width: 280px;
        height: 100vh;
        z-index: 999;
        transition: left 0.3s var(--ease-out);
        box-shadow: 4px 0 28px rgba(44, 33, 22, 0.12);
    }

    .sidebar.open { left: 0; }

    .sidebar-close {
        display: flex;
        width: 32px;
        height: 32px;
        align-items: center;
        justify-content: center;
        border-radius: var(--radius-sm);
    }

    .sidebar-close:hover {
        background: var(--paper-warm);
        color: var(--ink-dark);
    }

    .study-main { width: 100%; }
    .study-body { position: relative; }
    .header-offset { display: none; }
    .header-row { grid-template-columns: 1fr; }
    .header-offset + .header-inner { grid-column: 1; height: 50px; }

    .header-inner {
        padding: 0 12px;
        height: 50px;
        gap: 8px;
    }

    .header-title { font-size: 15px; }
    .progress-text { font-size: 12px; padding: 5px 10px; }
    .header-purchase { font-size: 12px; }

    .logo { font-size: 28px; }
    .logo-subtitle { font-size: 11px; letter-spacing: 0.15em; }
    .logo-wrap { padding: 36px 0 24px; }

    .deck-grid { gap: 16px; padding: 0 0 32px; }
    .deck-card { border-radius: 12px; }
    .card-header { padding: 14px 16px 12px; gap: 12px; }
    .card-icon { width: 42px; height: 42px; font-size: 20px; }
    .card-title { font-size: 0.95rem; }
    .card-count { font-size: 0.75rem; }
    .card-content { padding: 0 16px 14px; }
    .card-summary { font-size: 0.8rem; -webkit-line-clamp: 1; }
    .card-tags { gap: 4px; margin-top: 8px; }
    .tag { padding: 2px 6px; font-size: 0.7rem; }
    .card-footer { padding: 10px 16px; }
    .preview-btn { font-size: 0.75rem; padding: 5px 10px; }
    .deck-btn { font-size: 11px; padding: 2px 7px; }
    .study-main { padding: 0 12px; }
}


/* ═══════════════════════════════════════
   MISC: EMPTY STATE, SKELETON, FLASHCARD
   ═══════════════════════════════════════ */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    transition: all var(--transition-fast);
}

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

.btn-secondary {
    background: var(--paper-cream);
    color: var(--ink-dark);
    border: 1px solid var(--paper-warm);
}
.btn-secondary:hover { background: var(--paper-warm); }

.empty-state {
    text-align: center;
    padding: 80px 24px;
}

.empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.35;
}

.empty-title {
    font-family: var(--font-display);
    font-size: 18px;
    color: var(--ink-dark);
    margin-bottom: 6px;
    font-weight: 600;
}

.empty-desc {
    font-size: 14px;
    color: var(--ink-light);
}

.loading-skeleton {
    background: linear-gradient(90deg, var(--paper-cream) 25%, var(--paper-warm) 50%, var(--paper-cream) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-sm);
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ── Flashcard 3D flip (legacy/preview) ── */

.flashcard-container {
    perspective: 1200px;
    width: 100%;
    max-width: 560px;
    margin: 0 auto;
}

.flashcard {
    position: relative;
    width: 100%;
    min-height: 360px;
    cursor: pointer;
    transform-style: preserve-3d;
    transition: transform 0.6s var(--ease-out);
}

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

.flashcard-face {
    position: absolute;
    width: 100%;
    min-height: 360px;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: var(--radius-lg);
    padding: 40px;
}

.flashcard-front {
    background: var(--paper-white);
    border: 1px solid var(--paper-warm);
    box-shadow: var(--shadow-card);
}

.flashcard-back {
    background: var(--paper-cream);
    border: 1px solid var(--paper-warm);
    box-shadow: var(--shadow-card);
    transform: rotateY(180deg);
}

.card-content { width: 100%; text-align: left; }

.flip-hint {
    text-align: center;
    margin-top: 20px;
    font-size: 13px;
    color: var(--ink-muted);
}

.flashcard.flipping { pointer-events: none; }

.flashcard-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--ink-muted);
    margin-bottom: 24px;
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
}

.flashcard-title {
    font-family: var(--font-display);
    font-size: 36px;
    font-weight: 600;
    color: var(--ink-dark);
    line-height: 1.3;
    margin-bottom: 20px;
}

.flashcard-divider {
    width: 60px;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--terracotta), transparent);
    margin: 16px 0;
}

.flashcard-content {
    font-size: 16px;
    color: var(--ink-medium);
    line-height: 1.8;
    max-width: 400px;
}

.flashcard-hint {
    position: absolute;
    bottom: 20px;
    font-size: 13px;
    color: var(--ink-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

.flashcard-hint svg { width: 14px; height: 14px; }

/* ── Action Buttons (study page legacy) ── */

.action-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
    padding: 28px 0;
}

