* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --bg-primary: #000000;
    --bg-secondary: #1C1C1E;
    --bg-tertiary: #2C2C2E;
    --bg-elevated: #3A3A3C;
    --text-primary: #FFFFFF;
    --text-secondary: #EBEBF5;
    --text-tertiary: #EBEBF599;
    --text-quaternary: #EBEBF54D;
    --border-primary: #38383A;
    --border-secondary: #48484A;
    --accent-primary: #0A84FF;
    --accent-secondary: #64D2FF;
    --success: #30D158;
    --danger: #FF453A;
    --warning: #FFD60A;
    --sidebar-width: 260px;
    --bottom-nav-height: 80px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.6);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.8);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro Display', 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ============================================================
   SCREENS
   ============================================================ */

.screen { display: none; width: 100%; height: 100vh; }
.screen.active { display: flex; }

/* ============================================================
   LOGIN
   ============================================================ */

#loginScreen {
    justify-content: center;
    align-items: center;
    background: var(--bg-primary);
}

.login-container { text-align: center; max-width: 380px; padding: 48px 24px; }

.logo {
    width: 80px; height: 80px; margin: 0 auto 32px;
    background: var(--bg-secondary); border-radius: var(--radius-lg);
    display: flex; align-items: center; justify-content: center;
    border: 1px solid var(--border-primary);
}
.logo svg { width: 40px; height: 40px; }

.login-container h1 { font-size: 34px; font-weight: 700; margin-bottom: 8px; letter-spacing: -0.03em; }
.subtitle { font-size: 17px; color: var(--text-tertiary); margin-bottom: 40px; }
.hint { font-size: 13px; color: var(--text-quaternary); }

.login-form { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.login-form input {
    padding: 14px 16px; font-size: 17px;
    background: var(--bg-secondary); border: 1px solid var(--border-primary);
    border-radius: var(--radius-md); color: var(--text-primary); outline: none;
    transition: all 0.2s;
}
.login-form input:focus { border-color: var(--accent-primary); background: var(--bg-tertiary); }

/* ============================================================
   BUTTONS
   ============================================================ */

.primary-button {
    padding: 12px 20px; font-size: 17px; font-weight: 600;
    background: var(--accent-primary); color: white; border: none;
    border-radius: var(--radius-md); cursor: pointer; transition: all 0.2s;
}
.primary-button:hover { background: var(--accent-secondary); transform: translateY(-1px); }
.primary-button:active { transform: translateY(0); }

.secondary-button {
    padding: 10px 18px; font-size: 15px; font-weight: 600;
    background: var(--bg-tertiary); color: var(--text-primary);
    border: 1px solid var(--border-primary); border-radius: var(--radius-md);
    cursor: pointer; transition: all 0.2s;
}
.secondary-button:hover { background: var(--bg-elevated); border-color: var(--border-secondary); }

.danger-button {
    padding: 12px 20px; font-size: 17px; font-weight: 600;
    background: var(--danger); color: white; border: none;
    border-radius: var(--radius-md); cursor: pointer; width: 100%; transition: opacity 0.2s;
}
.danger-button:hover { opacity: 0.85; }

.text-button {
    background: none; border: none; color: var(--accent-primary);
    font-size: 13px; cursor: pointer; padding: 4px 0; transition: opacity 0.2s;
}
.text-button:hover { opacity: 0.7; }

.icon-button {
    background: var(--bg-secondary); border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm); padding: 8px 14px; color: var(--text-primary);
    font-size: 15px; cursor: pointer; transition: all 0.2s; font-weight: 500;
}
.icon-button:hover { background: var(--bg-tertiary); }

/* ============================================================
   LAYOUT
   ============================================================ */

#mainApp { display: grid; }

/* Sidebar */
.sidebar {
    width: var(--sidebar-width); background: var(--bg-secondary);
    border-right: 1px solid var(--border-primary);
    display: flex; flex-direction: column; overflow-y: auto;
}
.sidebar-header { padding: 20px 16px; border-bottom: 1px solid var(--border-primary); }
.user-info { display: flex; align-items: center; gap: 12px; }
.user-avatar {
    width: 44px; height: 44px; background: var(--bg-tertiary);
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
    border: 1px solid var(--border-primary);
}
.user-avatar svg { width: 20px; height: 20px; }
.user-details { flex: 1; }
.user-name { font-size: 15px; font-weight: 600; margin-bottom: 2px; }

.sidebar-nav { flex: 1; padding: 12px 8px; }

.nav-item {
    display: flex; align-items: center; gap: 10px; width: 100%;
    padding: 10px 12px; background: none; border: none;
    border-radius: var(--radius-sm); color: var(--text-secondary);
    font-size: 15px; cursor: pointer; transition: all 0.2s; margin-bottom: 2px;
}
.nav-item:hover { background: var(--bg-tertiary); }
.nav-item.active { background: var(--accent-primary); color: white; font-weight: 500; }
.nav-icon { width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; }
.nav-icon svg { width: 20px; height: 20px; }

.sidebar-footer { padding: 16px; border-top: 1px solid var(--border-primary); }
.today-stats { display: flex; gap: 16px; }
.stat-item { flex: 1; }
.stat-label { font-size: 11px; color: var(--text-quaternary); text-transform: uppercase; letter-spacing: 0.06em; display: block; margin-bottom: 4px; font-weight: 600; }
.stat-value { font-size: 20px; font-weight: 700; color: var(--text-primary); letter-spacing: -0.02em; }

/* Bottom Nav */
.bottom-nav {
    display: none; position: fixed; bottom: 0; left: 0; right: 0;
    height: var(--bottom-nav-height); background: var(--bg-secondary);
    border-top: 1px solid var(--border-primary); padding: 8px 8px 20px;
    z-index: 100;
}
.bottom-nav .nav-item { flex-direction: column; padding: 8px; gap: 4px; font-size: 11px; font-weight: 500; }
.bottom-nav .nav-icon { width: 24px; height: 24px; }
.bottom-nav .nav-icon svg { width: 24px; height: 24px; }

/* Main content */
.main-content { flex: 1; overflow-y: auto; overflow-x: hidden; background: var(--bg-primary); }
.view { display: none; width: 100%; min-height: 100%; }
.view.active { display: block; }

.view-header {
    padding: 32px; display: flex; justify-content: space-between;
    align-items: center; border-bottom: 1px solid var(--border-primary);
}
.view-header h1 { font-size: 34px; font-weight: 700; letter-spacing: -0.03em; }

/* ============================================================
   PACK SELECTION  (works on both mobile and desktop)
   ============================================================ */

.pack-selection {
    padding: 32px;
}

.pack-selection h2 {
    font-size: 28px; font-weight: 700; margin-bottom: 24px; letter-spacing: -0.02em;
}

/* Desktop pack list sits inside the cards view, visible when cardsContainer is hidden */
.desktop-pack-section {
    padding: 32px;
}
.desktop-pack-section h2 {
    font-size: 28px; font-weight: 700; margin-bottom: 24px; letter-spacing: -0.02em;
}

.packs-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.pack-card {
    background: var(--bg-secondary); border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg); padding: 24px; cursor: pointer;
    transition: all 0.2s; position: relative;
}
.pack-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.pack-card-icon {
    width: 48px; height: 48px; margin-bottom: 16px;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg-tertiary); border-radius: var(--radius-md);
    border: 1px solid var(--border-primary);
}
.pack-card-icon svg { width: 24px; height: 24px; }
.pack-card-name { font-size: 17px; font-weight: 600; margin-bottom: 8px; }
.pack-card-desc { font-size: 13px; color: var(--text-tertiary); margin-bottom: 12px; line-height: 1.4; }
.pack-card-count { font-size: 13px; color: var(--text-quaternary); font-weight: 500; }

/* ============================================================
   CARDS CONTAINER — full-screen feed overlay
   ============================================================ */

.cards-container {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    z-index: 200;
    overflow: hidden;
}

/* On desktop, push right of sidebar */
@media (min-width: 769px) {
    .cards-container { left: var(--sidebar-width); }
}

/* Floating header */
.cards-header {
    position: absolute; top: 0; left: 0; right: 0; z-index: 10;
    display: flex; align-items: center; gap: 16px; padding: 16px 24px;
    background: linear-gradient(to bottom, rgba(0,0,0,0.85) 0%, transparent 100%);
    pointer-events: none; /* let swipe pass through except buttons */
}
.cards-header button { pointer-events: all; }
.cards-header h2 {
    flex: 1; font-size: 17px; font-weight: 600;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pack-progress { font-size: 15px; color: var(--text-tertiary); font-weight: 500; white-space: nowrap; }

/* The swipeable stage — fills everything */
.card-stage {
    flex: 1; width: 100%; height: 100%;
    position: relative; overflow: hidden;
    touch-action: none; /* we control all touch ourselves */
    user-select: none;
}

/* ── Virtualized slots ──────────────────────────────────────── */

.card-slot {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 72px 32px 40px;
    /* GPU layer for smooth transform */
    will-change: transform;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

@media (min-width: 769px) {
    .card-slot { padding: 72px 80px 40px; }
}

@media (max-width: 768px) {
    .card-slot { padding: 68px 16px 28px; }
}

.card-container {
    width: 100%; max-width: 640px; height: 100%;
    cursor: grab;
}
.card-container:active { cursor: grabbing; }

/* The actual card */
.card {
    width: 100%; height: 100%;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 24px;
    padding: 32px;
    display: flex; flex-direction: column; gap: 20px;
    overflow-y: auto;           /* card text can scroll internally */
    overflow-x: hidden;
    overscroll-behavior: contain;
    box-shadow: var(--shadow-lg);
    /* GPU compositing */
    will-change: transform;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* On mobile, slightly less padding */
@media (max-width: 768px) {
    .card { padding: 24px; border-radius: 20px; gap: 16px; }
}

.card-category {
    font-size: 11px; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.08em; color: var(--accent-primary);
    padding: 6px 12px;
    background: rgba(10,132,255,0.12); border: 1px solid rgba(10,132,255,0.2);
    border-radius: var(--radius-sm); width: fit-content;
    flex-shrink: 0;
}
.card-title { font-size: 26px; font-weight: 700; line-height: 1.2; letter-spacing: -0.02em; flex-shrink: 0; }
.card-theory { font-size: 16px; line-height: 1.55; color: var(--text-secondary); flex-shrink: 0; }

.card-code {
    background: #000; border-radius: var(--radius-md);
    overflow: hidden; border: 1px solid var(--border-primary);
    flex-shrink: 0;
    /* CRITICAL: allow horizontal scroll inside code, don't intercept */
    touch-action: pan-x pinch-zoom;
}
.card-code pre {
    margin: 0; padding: 18px;
    overflow-x: auto;
    touch-action: pan-x pinch-zoom; /* browser handles horizontal */
}
.card-code code {
    font-size: 13px; line-height: 1.6;
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Courier New', monospace;
}

/* ── Swipe direction indicators ─────────────────────────────── */

.swipe-indicator {
    position: absolute; left: 50%; transform: translateX(-50%);
    width: 52px; height: 52px; opacity: 0; pointer-events: none;
    transition: opacity 0.15s ease;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg-secondary); border-radius: 50%;
    border: 1px solid var(--border-primary); z-index: 20;
    will-change: opacity;
}
.swipe-indicator svg { width: 26px; height: 26px; }
.swipe-indicator.top    { top: 88px; }
.swipe-indicator.bottom { bottom: 28px; }

/* ── Progress dots (right side) ─────────────────────────────── */

.card-progress-dots {
    position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
    display: flex; flex-direction: column; gap: 5px;
    z-index: 10; pointer-events: none;
}
.progress-dot {
    width: 4px; height: 4px; border-radius: 2px;
    background: rgba(255,255,255,0.2);
    transition: all 0.3s cubic-bezier(0.4,0,0.2,1);
}
.progress-dot.active { background: var(--accent-primary); height: 18px; }
.progress-dot.passed { background: rgba(255,255,255,0.45); }

/* ============================================================
   MODAL
   ============================================================ */

.modal {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.85); z-index: 1000;
    justify-content: center; align-items: center; padding: 20px;
}
.modal.active { display: flex; }

.modal-content {
    background: var(--bg-secondary); border-radius: var(--radius-lg);
    padding: 32px; max-width: 500px; width: 100%;
    box-shadow: var(--shadow-lg); border: 1px solid var(--border-primary);
}
.modal-content.large { max-width: 800px; }

.modal-icon {
    width: 72px; height: 72px; margin: 0 auto 20px;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg-tertiary); border-radius: var(--radius-lg);
    border: 1px solid var(--border-primary);
}
.modal-icon svg { width: 36px; height: 36px; }
.modal-content h3 { text-align: center; font-size: 24px; font-weight: 700; margin-bottom: 12px; }
.modal-content p  { text-align: center; font-size: 15px; color: var(--text-tertiary); margin-bottom: 24px; line-height: 1.4; }
.modal-actions { display: flex; gap: 12px; justify-content: center; }

.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 24px; padding-bottom: 16px; border-bottom: 1px solid var(--border-primary);
}
.modal-header h3 { font-size: 24px; font-weight: 700; margin: 0; text-align: left; }
.modal-close {
    background: var(--bg-tertiary); border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm); width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; font-size: 18px; transition: all 0.2s; color: var(--text-tertiary);
}
.modal-close:hover { background: var(--bg-elevated); }
.modal-body { margin-bottom: 24px; max-height: 60vh; overflow-y: auto; }
.modal-footer { display: flex; gap: 12px; justify-content: flex-end; padding-top: 16px; border-top: 1px solid var(--border-primary); }

/* ============================================================
   FORM ELEMENTS
   ============================================================ */

.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.form-group input,
.form-group textarea {
    width: 100%; padding: 12px 16px; font-size: 15px;
    background: var(--bg-tertiary); border: 1px solid var(--border-primary);
    border-radius: var(--radius-md); color: var(--text-primary); outline: none;
    font-family: inherit; resize: vertical; transition: all 0.2s;
}
.form-group input:focus,
.form-group textarea:focus { border-color: var(--accent-primary); background: var(--bg-elevated); }

/* ============================================================
   CARDS EDITOR
   ============================================================ */

.cards-editor { display: flex; flex-direction: column; gap: 12px; max-height: 400px; overflow-y: auto; margin-bottom: 12px; }
.card-editor-item { background: var(--bg-tertiary); border: 1px solid var(--border-primary); border-radius: var(--radius-md); padding: 16px; }
.card-editor-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.card-editor-index { font-size: 13px; font-weight: 600; color: var(--text-tertiary); }
.delete-card-button { background: none; border: none; color: var(--danger); font-size: 20px; cursor: pointer; padding: 4px; width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); transition: background 0.2s; }
.delete-card-button:hover { background: rgba(255,69,58,0.1); }
.card-editor-fields { display: flex; flex-direction: column; gap: 12px; }
.card-editor-fields input,
.card-editor-fields textarea { width: 100%; padding: 10px 14px; font-size: 14px; background: var(--bg-secondary); border: 1px solid var(--border-primary); border-radius: var(--radius-sm); color: var(--text-primary); outline: none; font-family: inherit; }

/* ============================================================
   PACKS MANAGER
   ============================================================ */

.packs-manager { padding: 32px; }
.packs-list { display: grid; gap: 16px; }
.pack-manager-item { background: var(--bg-secondary); border: 1px solid var(--border-primary); border-radius: var(--radius-lg); padding: 24px; display: flex; justify-content: space-between; align-items: center; transition: all 0.2s; }
.pack-manager-item:hover { background: var(--bg-tertiary); }
.pack-manager-info { flex: 1; }
.pack-manager-name { font-size: 17px; font-weight: 600; margin-bottom: 4px; }
.pack-manager-meta { font-size: 13px; color: var(--text-tertiary); }
.pack-manager-actions { display: flex; gap: 8px; }
.pack-manager-actions button { padding: 8px 16px; font-size: 14px; }

/* ============================================================
   ROADMAP
   ============================================================ */

.roadmap-container { padding: 32px; }
.roadmap-content { max-width: 900px; margin: 0 auto; }
.roadmap-header { margin-bottom: 40px; }
.roadmap-title { font-size: 28px; font-weight: 700; margin-bottom: 16px; }
.roadmap-progress-bar { height: 6px; background: var(--bg-tertiary); border-radius: 3px; overflow: hidden; }
.roadmap-progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary)); transition: width 0.3s; }
.roadmap-items { position: relative; }
.roadmap-line { position: absolute; left: 20px; top: 0; bottom: 0; width: 2px; background: var(--bg-tertiary); }
.roadmap-line-fill { position: absolute; top: 0; width: 100%; background: linear-gradient(180deg, var(--accent-primary), var(--accent-secondary)); transition: height 0.3s; }
.roadmap-item { position: relative; display: flex; gap: 20px; margin-bottom: 16px; padding-left: 60px; }
.roadmap-dot { position: absolute; left: 12px; top: 4px; width: 20px; height: 20px; background: var(--bg-tertiary); border: 2px solid var(--bg-primary); border-radius: 50%; transition: all 0.3s; cursor: pointer; }
.roadmap-dot.completed { background: var(--accent-primary); }
.roadmap-item-content { flex: 1; background: var(--bg-secondary); border: 1px solid var(--border-primary); border-radius: var(--radius-md); padding: 16px 20px; cursor: pointer; transition: all 0.2s; }
.roadmap-item-content:hover { background: var(--bg-tertiary); }
.roadmap-item-content.completed { opacity: 0.5; }
.roadmap-item-title { font-size: 15px; font-weight: 500; }
.roadmap-empty { text-align: center; padding: 60px 20px; color: var(--text-tertiary); }

/* ============================================================
   STATISTICS
   ============================================================ */

.stats-container { padding: 32px; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 16px; margin-bottom: 32px; }
.stat-card { background: var(--bg-secondary); border: 1px solid var(--border-primary); border-radius: var(--radius-lg); padding: 24px; display: flex; align-items: center; gap: 16px; transition: all 0.2s; }
.stat-card:hover { background: var(--bg-tertiary); }
.stat-icon { width: 48px; height: 48px; display: flex; align-items: center; justify-content: center; background: var(--bg-tertiary); border-radius: var(--radius-md); border: 1px solid var(--border-primary); }
.stat-icon svg { width: 24px; height: 24px; }
.stat-info { flex: 1; }
.stat-value.large { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.activity-calendar { background: var(--bg-secondary); border: 1px solid var(--border-primary); border-radius: var(--radius-lg); padding: 24px; }
.activity-calendar h3 { font-size: 17px; font-weight: 600; margin-bottom: 20px; }
.activity-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(12px,1fr)); gap: 4px; max-width: 600px; }
.activity-day { width: 12px; height: 12px; background: var(--bg-tertiary); border-radius: 2px; }
.activity-day.active-1 { background: rgba(10,132,255,0.3); }
.activity-day.active-2 { background: rgba(10,132,255,0.5); }
.activity-day.active-3 { background: rgba(10,132,255,0.7); }
.activity-day.active-4 { background: var(--accent-primary); }

/* ============================================================
   SETTINGS (mobile)
   ============================================================ */

.settings-container { padding: 32px; }
.settings-section { background: var(--bg-secondary); border: 1px solid var(--border-primary); border-radius: var(--radius-lg); padding: 24px; margin-bottom: 20px; }
.settings-section h3 { font-size: 17px; font-weight: 600; margin-bottom: 16px; }
.setting-item { padding: 16px 0; border-bottom: 1px solid var(--border-primary); }
.setting-item:last-child { border-bottom: none; }
.setting-info { margin-bottom: 12px; }
.setting-label { font-size: 13px; color: var(--text-tertiary); margin-bottom: 4px; font-weight: 500; }
.setting-value { font-size: 15px; font-weight: 600; }
.settings-packs { display: flex; flex-direction: column; gap: 12px; }

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (min-width: 769px) {
    #mainApp { grid-template-columns: var(--sidebar-width) 1fr; }
    .mobile-only { display: none !important; }
    .main-content { padding-bottom: 0; }
}

@media (max-width: 768px) {
    .desktop-only { display: none !important; }
    .sidebar { display: none; }
    .bottom-nav { display: flex; justify-content: space-around; }
    .main-content { padding-bottom: var(--bottom-nav-height); }
    .view-header { padding: 20px; }
    .view-header h1 { font-size: 28px; }
    .pack-selection { padding: 20px; }
    .packs-grid { grid-template-columns: 1fr; gap: 12px; }
    .stats-grid { grid-template-columns: 1fr; gap: 12px; }
    .stats-container, .roadmap-container, .packs-manager { padding: 20px; }
    .roadmap-item { padding-left: 50px; }
}

/* ============================================================
   SCROLLBAR
   ============================================================ */

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